1 | // frontend_pyreadline.h
|
2 |
|
3 | #ifndef FRONTEND_PYREADLINE_H
|
4 | #define FRONTEND_PYREADLINE_H
|
5 |
|
6 | #include "mycpp/runtime.h"
|
7 |
|
8 | // hacky forward decl
|
9 | namespace completion {
|
10 | class ReadlineCallback;
|
11 | BigStr* ExecuteReadlineCallback(ReadlineCallback*, BigStr*, int);
|
12 | } // namespace completion
|
13 |
|
14 | // hacky forward decl
|
15 | namespace comp_ui {
|
16 | class _IDisplay;
|
17 | void ExecutePrintCandidates(_IDisplay*, BigStr*, List<BigStr*>*, int);
|
18 | } // namespace comp_ui
|
19 |
|
20 | namespace py_readline {
|
21 |
|
22 | class Readline {
|
23 | public:
|
24 | Readline();
|
25 | BigStr* prompt_input(BigStr* prompt);
|
26 | void parse_and_bind(BigStr* s);
|
27 | void add_history(BigStr* line);
|
28 | void read_history_file(BigStr* path);
|
29 | void write_history_file(BigStr* path);
|
30 | void set_completer(completion::ReadlineCallback* completer);
|
31 | void set_completer_delims(BigStr* delims);
|
32 | void set_completion_display_matches_hook(
|
33 | comp_ui::_IDisplay* display = nullptr);
|
34 | BigStr* get_line_buffer();
|
35 | int get_begidx();
|
36 | int get_endidx();
|
37 | void clear_history();
|
38 | BigStr* get_history_item(int pos);
|
39 | void remove_history_item(int pos);
|
40 | int get_current_history_length();
|
41 | void resize_terminal();
|
42 | void list_funmap_names();
|
43 |
|
44 | static constexpr uint32_t field_mask() {
|
45 | return maskbit(offsetof(Readline, completer_delims_)) |
|
46 | maskbit(offsetof(Readline, completer_)) |
|
47 | maskbit(offsetof(Readline, display_));
|
48 | }
|
49 |
|
50 | static constexpr ObjHeader obj_header() {
|
51 | return ObjHeader::ClassFixed(field_mask(), sizeof(Readline));
|
52 | }
|
53 |
|
54 | int begidx_;
|
55 | int endidx_;
|
56 | BigStr* completer_delims_;
|
57 | completion::ReadlineCallback* completer_;
|
58 | comp_ui::_IDisplay* display_;
|
59 |
|
60 | // readline will set this to NULL when EOF is received, else this will point
|
61 | // to a line of input.
|
62 | char* latest_line_;
|
63 |
|
64 | // readline will set this flag when either:
|
65 | // - it receives EOF
|
66 | // - it has a complete line of input (it has seen "\n")
|
67 | bool ready_;
|
68 | };
|
69 |
|
70 | Readline* MaybeGetReadline();
|
71 |
|
72 | } // namespace py_readline
|
73 |
|
74 | #endif // FRONTEND_PYREADLINE_H
|