21constexpr int KEY_ESC = 27;
22constexpr int KEY_ENTER = 10;
23constexpr int KEY_BACKSPACE = 127;
26constexpr int KEY_TAB = 9;
29const char* CLEAR_LINE =
"\033[2K\r";
31const char* SAVE_CURSOR =
"\033[s";
32const char* RESTORE_CURSOR =
"\033[u";
37 static struct termios orig_termios;
38 static bool has_orig =
false;
42 tcgetattr(STDIN_FILENO, &orig_termios);
46 struct termios raw = orig_termios;
47 raw.c_lflag &= ~(ECHO | ICANON);
50 tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw);
53 tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios);
121 if (new_mode !=
mode_) {
179 read(STDIN_FILENO, &next_ch, 1);
181 if (next_ch ==
'd') {
193 read(STDIN_FILENO, &next_ch, 1);
195 if (next_ch ==
'y') {
257 if (ch >= 32 && ch < 127) {
426 std::cout << CLEAR_LINE;
430 std::cout <<
"-- INSERT -- ";
432 std::cout <<
"-- NORMAL -- ";
443 for (
int i = 0; i < display_offset +
cursor_pos_; ++i) {
444 std::cout <<
"\033[C";
std::vector< std::string > redo_stack_
void HandleInsertMode(int ch)
void SwitchMode(VimModeType new_mode)
bool ProcessKey(int ch)
Process a key press.
void HandleNormalMode(int ch)
void Reset()
Reset for new line.
std::string GetModeString() const
Get mode string for display.
std::vector< std::string > autocomplete_options_
std::vector< std::string > history_
void Render() const
Render the current line with syntax highlighting.
std::string current_line_
void AddToHistory(const std::string &line)
Add line to history.
std::function< std::vector< std::string >(const std::string &)> autocomplete_callback_
std::vector< std::string > undo_stack_
void SetRawMode(bool enable)
const char * MOVE_CURSOR_HOME
VimModeType
Vim editing modes.
Main namespace for the application.