cpp

Coverage Report

Created: 2025-06-02 15:02

/home/uke/oil/cpp/frontend_pyreadline.h
Line
Count
Source (jump to first uncovered line)
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
// hacky forward decl
21
namespace readline_osh {
22
class BindXCallback;
23
}  // namespace readline_osh
24
25
namespace py_readline {
26
27
class Readline {
28
 public:
29
  Readline();
30
  BigStr* prompt_input(BigStr* prompt);
31
  void parse_and_bind(BigStr* s);
32
  void add_history(BigStr* line);
33
  void read_history_file(BigStr* path);
34
  void write_history_file(BigStr* path);
35
  void set_completer(completion::ReadlineCallback* completer);
36
  void set_completer_delims(BigStr* delims);
37
  void set_completion_display_matches_hook(
38
      comp_ui::_IDisplay* display = nullptr);
39
  BigStr* get_line_buffer();
40
  int get_begidx();
41
  int get_endidx();
42
  void clear_history();
43
  BigStr* get_history_item(int pos);
44
  void remove_history_item(int pos);
45
  int get_current_history_length();
46
  void resize_terminal();
47
48
  // Functions added to implement the 'bind' builtin in OSH
49
  void list_funmap_names();
50
  void read_init_file(BigStr* s);
51
  void function_dumper(bool print_readably);
52
  void macro_dumper(bool print_readably);
53
  void variable_dumper(bool print_readably);
54
  void query_bindings(BigStr* fn_name);
55
  void unbind_rl_function(BigStr* fn_name);
56
  void use_temp_keymap(BigStr* fn_name);
57
  void restore_orig_keymap();
58
  void print_shell_cmd_map();
59
  void unbind_keyseq(BigStr* keyseq);
60
  void bind_shell_command(BigStr* keyseq, BigStr* cmd);
61
  void set_bind_shell_command_hook(readline_osh::BindXCallback* hook);
62
63
0
  static constexpr uint32_t field_mask() {
64
0
    return maskbit(offsetof(Readline, completer_delims_)) |
65
0
           maskbit(offsetof(Readline, completer_)) |
66
0
           maskbit(offsetof(Readline, display_));
67
0
  }
68
69
0
  static constexpr ObjHeader obj_header() {
70
0
    return ObjHeader::ClassFixed(field_mask(), sizeof(Readline));
71
0
  }
72
73
  int begidx_;
74
  int endidx_;
75
  BigStr* completer_delims_;
76
  completion::ReadlineCallback* completer_;
77
  comp_ui::_IDisplay* display_;
78
  readline_osh::BindXCallback* bindx_cb_;
79
80
  // readline will set this to NULL when EOF is received, else this will point
81
  // to a line of input.
82
  char* latest_line_;
83
84
  // readline will set this flag when either:
85
  //   - it receives EOF
86
  //   - it has a complete line of input (it has seen "\n")
87
  bool ready_;
88
};
89
90
Readline* MaybeGetReadline();
91
92
}  // namespace py_readline
93
94
#endif  // FRONTEND_PYREADLINE_H