12 #ifndef SST_CORE_IMPL_INTERACTIVE_CMDLINEEDITOR_H 13 #define SST_CORE_IMPL_INTERACTIVE_CMDLINEEDITOR_H 29 writeStr(
const std::string& msg)
31 (void)!write(STDOUT_FILENO, msg.data(), msg.size());
46 static constexpr
char esc_char =
'\x1B';
47 static constexpr
char tab_char =
'\x9';
48 static constexpr
char lf_char =
'\xa';
49 static constexpr
char bs_char =
'\x7f';
50 static constexpr
char ctrl_a =
'\x1';
51 static constexpr
char ctrl_b =
'\x2';
52 static constexpr
char ctrl_d =
'\x4';
53 static constexpr
char ctrl_e =
'\x5';
54 static constexpr
char ctrl_f =
'\x6';
55 static constexpr
char ctrl_k =
'\xb';
57 const std::string arrow_up =
"[A";
58 const std::string arrow_dn =
"[B";
59 const std::string arrow_rt =
"[C";
60 const std::string arrow_lf =
"[D";
61 const std::map<std::string, std::string> arrowKeyMap = {
64 { arrow_rt,
"Right" },
68 const std::string clear_line_ctl =
"\x1B[2K";
69 const std::string move_left_ctl =
"\x1B[1D";
70 const std::string move_right_ctl =
"\x1B[1C";
71 const std::string esc_ctl =
"\x1B[";
72 const std::string move_up_ctl =
"\x1B[1F";
74 const std::string prompt =
"> ";
75 const std::string prompt_clear =
"\x1B[2K\r> ";
77 static constexpr
int max_line_size = 2048;
81 void redraw_line(
const std::string& s);
82 void getline(
const std::vector<std::string>& cmdHistory, std::string& newcmd);
85 void set_cmd_strings(
const std::list<std::string>& sortedStrings);
86 void set_listing_callback(std::function<
void(std::list<std::string>&)> callback) { listing_callback_ = callback; }
89 std::ofstream dbgFile;
93 std::list<std::string> cmdStrings = {};
94 std::function<void(std::list<std::string>& callback)> listing_callback_ =
nullptr;
99 int restoreTermMode();
100 bool read2chars(
char (&seq)[3]);
101 void move_cursor_left();
102 void move_cursor_right(
int slen);
103 void auto_complete(std::string& cmd);
104 bool selectMatches(
const std::list<std::string>& list,
const std::string& searchfor,
105 std::vector<std::string>& matches, std::string& newcmd);
109 static bool compareCharCaseInsensitive(
char c1,
char c2)
111 return std::tolower(static_cast<unsigned char>(c1)) == std::tolower(static_cast<unsigned char>(c2));
122 static bool matchBeginStringCaseInsensitive(
const std::string& searchfor,
const std::string& longstr)
124 if ( longstr.length() < searchfor.length() )
return false;
125 std::string matchstr = longstr.substr(0, searchfor.length());
126 return std::equal(searchfor.begin(), searchfor.end(), matchstr.begin(), compareCharCaseInsensitive);
130 void flush_bad_escape();
133 #endif // SST_CORE_IMPL_INTERACTIVE_CMDLINEEDITOR_H The command line editor uses termios to detect key presses and perform auto-completions.
Definition: cmdLineEditor.h:43