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;
80 virtual ~CmdLineEditor() =
default;
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;
92 enum TAB_STATE { FILL_COMMON, LIST_COMMON };
96 std::list<std::string> cmdStrings = {};
97 std::function<void(std::list<std::string>& callback)> listing_callback_ =
nullptr;
100 TAB_STATE tab_state = TAB_STATE::FILL_COMMON;
101 int checktty(
int rc);
103 int restoreTermMode();
104 bool read2chars(
char (&seq)[3]);
105 void move_cursor_left();
106 void move_cursor_right(
int slen);
107 void auto_complete(std::string& cmd);
108 bool selectMatches(
const std::list<std::string>& list,
const std::string& searchfor,
109 std::vector<std::string>& matches, std::string& newcmd);
110 std::string findLongestCommonPrefix(
const std::vector<std::string>& strings);
114 static bool compareCharCaseInsensitive(
char c1,
char c2)
116 return std::tolower(
static_cast<unsigned char>(c1)) == std::tolower(
static_cast<unsigned char>(c2));
127 static bool matchBeginStringCaseInsensitive(
const std::string& searchfor,
const std::string& longstr)
129 if ( longstr.length() < searchfor.length() )
return false;
130 std::string matchstr = longstr.substr(0, searchfor.length());
131 return std::equal(searchfor.begin(), searchfor.end(), matchstr.begin(), compareCharCaseInsensitive);
135 void flush_bad_escape();