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 |
|
43 | // Functions added to implement the 'bind' builtin in OSH
|
44 | void list_funmap_names();
|
45 | void read_init_file(BigStr* s);
|
46 | void function_dumper(bool print_readably);
|
47 | void macro_dumper(bool print_readably);
|
48 | void variable_dumper(bool print_readably);
|
49 | void query_bindings(BigStr* fn_name);
|
50 | void unbind_rl_function(BigStr* fn_name);
|
51 | void use_temp_keymap(BigStr* fn_name);
|
52 | void restore_orig_keymap();
|
53 | void print_shell_cmd_map();
|
54 | void unbind_keyseq(BigStr* keyseq);
|
55 |
|
56 | static constexpr uint32_t field_mask() {
|
57 | return maskbit(offsetof(Readline, completer_delims_)) |
|
58 | maskbit(offsetof(Readline, completer_)) |
|
59 | maskbit(offsetof(Readline, display_));
|
60 | }
|
61 |
|
62 | static constexpr ObjHeader obj_header() {
|
63 | return ObjHeader::ClassFixed(field_mask(), sizeof(Readline));
|
64 | }
|
65 |
|
66 | int begidx_;
|
67 | int endidx_;
|
68 | BigStr* completer_delims_;
|
69 | completion::ReadlineCallback* completer_;
|
70 | comp_ui::_IDisplay* display_;
|
71 |
|
72 | // readline will set this to NULL when EOF is received, else this will point
|
73 | // to a line of input.
|
74 | char* latest_line_;
|
75 |
|
76 | // readline will set this flag when either:
|
77 | // - it receives EOF
|
78 | // - it has a complete line of input (it has seen "\n")
|
79 | bool ready_;
|
80 | };
|
81 |
|
82 | Readline* MaybeGetReadline();
|
83 |
|
84 | } // namespace py_readline
|
85 |
|
86 | #endif // FRONTEND_PYREADLINE_H
|