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