Vim-style line editing for z3ed CLI chat. More...
#include <vim_mode.h>
Public Member Functions | |
VimMode () | |
bool | ProcessKey (int ch) |
Process a key press. | |
std::string | GetLine () const |
Get the current line being edited. | |
VimModeType | GetMode () const |
Get the current mode. | |
std::string | GetModeString () const |
Get mode string for display. | |
int | GetCursorPos () const |
Get cursor position. | |
void | Reset () |
Reset for new line. | |
void | AddToHistory (const std::string &line) |
Add line to history. | |
void | SetAutoCompleteCallback (std::function< std::vector< std::string >(const std::string &)> callback) |
Set autocomplete callback. | |
void | SetCommandSuggestionCallback (std::function< std::string(const std::string &)> callback) |
Set command suggestion callback. | |
void | Render () const |
Render the current line with syntax highlighting. | |
Private Member Functions | |
void | SwitchMode (VimModeType new_mode) |
void | HandleNormalMode (int ch) |
void | MoveLeft () |
void | MoveRight () |
void | MoveWordForward () |
void | MoveWordBackward () |
void | MoveToLineStart () |
void | MoveToLineEnd () |
void | DeleteChar () |
void | DeleteLine () |
void | YankLine () |
void | PasteBefore () |
void | PasteAfter () |
void | Undo () |
void | Redo () |
void | HandleInsertMode (int ch) |
void | InsertChar (char c) |
void | Backspace () |
void | Delete () |
void | Complete () |
void | HistoryPrev () |
void | HistoryNext () |
void | ShowSuggestion () const |
Private Attributes | |
VimModeType | mode_ = VimModeType::INSERT |
std::string | current_line_ |
int | cursor_pos_ = 0 |
std::vector< std::string > | history_ |
int | history_index_ = -1 |
std::vector< std::string > | undo_stack_ |
std::vector< std::string > | redo_stack_ |
std::string | yank_buffer_ |
std::function< std::vector< std::string >(const std::string &)> | autocomplete_callback_ |
std::function< std::string(const std::string &)> | command_suggestion_callback_ |
std::vector< std::string > | autocomplete_options_ |
int | autocomplete_index_ = 0 |
bool | line_complete_ = false |
Vim-style line editing for z3ed CLI chat.
Provides vim keybindings for enhanced terminal UX:
Definition at line 34 of file vim_mode.h.
yaze::cli::agent::VimMode::VimMode | ( | ) |
Definition at line 61 of file vim_mode.cc.
bool yaze::cli::agent::VimMode::ProcessKey | ( | int | ch | ) |
Process a key press.
ch | Character input |
Definition at line 95 of file vim_mode.cc.
References yaze::cli::agent::COMMAND_LINE, HandleInsertMode(), HandleNormalMode(), yaze::cli::agent::INSERT, line_complete_, mode_, yaze::cli::agent::NORMAL, SwitchMode(), and yaze::cli::agent::VISUAL.
|
inline |
Get the current line being edited.
Definition at line 48 of file vim_mode.h.
References current_line_.
|
inline |
std::string yaze::cli::agent::VimMode::GetModeString | ( | ) | const |
Get mode string for display.
Definition at line 67 of file vim_mode.cc.
References yaze::cli::agent::COMMAND_LINE, yaze::cli::agent::INSERT, mode_, yaze::cli::agent::NORMAL, and yaze::cli::agent::VISUAL.
|
inline |
void yaze::cli::agent::VimMode::Reset | ( | ) |
Reset for new line.
Definition at line 81 of file vim_mode.cc.
References current_line_, cursor_pos_, line_complete_, and redo_stack_.
void yaze::cli::agent::VimMode::AddToHistory | ( | const std::string & | line | ) |
Add line to history.
Definition at line 88 of file vim_mode.cc.
References history_, and history_index_.
|
inline |
Set autocomplete callback.
Definition at line 78 of file vim_mode.h.
References autocomplete_callback_.
|
inline |
Set command suggestion callback.
Definition at line 85 of file vim_mode.h.
References command_suggestion_callback_.
void yaze::cli::agent::VimMode::Render | ( | ) | const |
Render the current line with syntax highlighting.
Definition at line 424 of file vim_mode.cc.
References yaze::cli::agent::COMMAND_LINE, current_line_, cursor_pos_, yaze::cli::agent::INSERT, mode_, and yaze::cli::agent::NORMAL.
Referenced by HandleInsertMode(), HandleNormalMode(), and SwitchMode().
|
private |
Definition at line 120 of file vim_mode.cc.
References mode_, and Render().
Referenced by HandleInsertMode(), HandleNormalMode(), and ProcessKey().
|
private |
Definition at line 127 of file vim_mode.cc.
References yaze::cli::agent::COMMAND_LINE, DeleteChar(), DeleteLine(), HistoryNext(), HistoryPrev(), yaze::cli::agent::INSERT, line_complete_, MoveLeft(), MoveRight(), MoveToLineEnd(), MoveToLineStart(), MoveWordBackward(), MoveWordForward(), PasteAfter(), PasteBefore(), Render(), SwitchMode(), Undo(), and YankLine().
Referenced by ProcessKey().
|
private |
Definition at line 269 of file vim_mode.cc.
References cursor_pos_.
Referenced by HandleNormalMode().
|
private |
Definition at line 275 of file vim_mode.cc.
References current_line_, and cursor_pos_.
Referenced by HandleNormalMode().
|
private |
Definition at line 281 of file vim_mode.cc.
References current_line_, and cursor_pos_.
Referenced by HandleNormalMode().
|
private |
Definition at line 292 of file vim_mode.cc.
References current_line_, and cursor_pos_.
Referenced by HandleNormalMode().
|
private |
Definition at line 302 of file vim_mode.cc.
References cursor_pos_.
Referenced by HandleNormalMode().
|
private |
Definition at line 306 of file vim_mode.cc.
References current_line_, and cursor_pos_.
Referenced by HandleNormalMode().
|
private |
Definition at line 311 of file vim_mode.cc.
References current_line_, cursor_pos_, and undo_stack_.
Referenced by Delete(), and HandleNormalMode().
|
private |
Definition at line 318 of file vim_mode.cc.
References current_line_, cursor_pos_, undo_stack_, and yank_buffer_.
Referenced by HandleNormalMode().
|
private |
Definition at line 325 of file vim_mode.cc.
References current_line_, and yank_buffer_.
Referenced by HandleNormalMode().
|
private |
Definition at line 329 of file vim_mode.cc.
References current_line_, cursor_pos_, undo_stack_, and yank_buffer_.
Referenced by HandleNormalMode().
|
private |
Definition at line 336 of file vim_mode.cc.
References current_line_, cursor_pos_, undo_stack_, and yank_buffer_.
Referenced by HandleNormalMode().
|
private |
Definition at line 347 of file vim_mode.cc.
References current_line_, cursor_pos_, redo_stack_, and undo_stack_.
Referenced by HandleNormalMode().
|
private |
Definition at line 356 of file vim_mode.cc.
References current_line_, cursor_pos_, redo_stack_, and undo_stack_.
|
private |
Definition at line 232 of file vim_mode.cc.
References Backspace(), Complete(), cursor_pos_, HistoryNext(), HistoryPrev(), InsertChar(), line_complete_, yaze::cli::agent::NORMAL, Render(), and SwitchMode().
Referenced by ProcessKey().
|
private |
Definition at line 365 of file vim_mode.cc.
References current_line_, cursor_pos_, and undo_stack_.
Referenced by HandleInsertMode().
|
private |
Definition at line 371 of file vim_mode.cc.
References current_line_, cursor_pos_, and undo_stack_.
Referenced by HandleInsertMode().
|
private |
Definition at line 379 of file vim_mode.cc.
References DeleteChar().
|
private |
Definition at line 383 of file vim_mode.cc.
References autocomplete_callback_, autocomplete_options_, current_line_, cursor_pos_, and undo_stack_.
Referenced by HandleInsertMode().
|
private |
Definition at line 397 of file vim_mode.cc.
References current_line_, cursor_pos_, history_, and history_index_.
Referenced by HandleInsertMode(), and HandleNormalMode().
|
private |
Definition at line 410 of file vim_mode.cc.
References current_line_, cursor_pos_, history_, and history_index_.
Referenced by HandleInsertMode(), and HandleNormalMode().
|
private |
|
private |
Definition at line 128 of file vim_mode.h.
Referenced by GetMode(), GetModeString(), ProcessKey(), Render(), and SwitchMode().
|
private |
Definition at line 129 of file vim_mode.h.
Referenced by Backspace(), Complete(), DeleteChar(), DeleteLine(), GetLine(), HistoryNext(), HistoryPrev(), InsertChar(), MoveRight(), MoveToLineEnd(), MoveWordBackward(), MoveWordForward(), PasteAfter(), PasteBefore(), Redo(), Render(), Reset(), Undo(), and YankLine().
|
private |
Definition at line 130 of file vim_mode.h.
Referenced by Backspace(), Complete(), DeleteChar(), DeleteLine(), GetCursorPos(), HandleInsertMode(), HistoryNext(), HistoryPrev(), InsertChar(), MoveLeft(), MoveRight(), MoveToLineEnd(), MoveToLineStart(), MoveWordBackward(), MoveWordForward(), PasteAfter(), PasteBefore(), Redo(), Render(), Reset(), and Undo().
|
private |
Definition at line 133 of file vim_mode.h.
Referenced by AddToHistory(), HistoryNext(), and HistoryPrev().
|
private |
Definition at line 134 of file vim_mode.h.
Referenced by AddToHistory(), HistoryNext(), and HistoryPrev().
|
private |
Definition at line 137 of file vim_mode.h.
Referenced by Backspace(), Complete(), DeleteChar(), DeleteLine(), InsertChar(), PasteAfter(), PasteBefore(), Redo(), and Undo().
|
private |
Definition at line 138 of file vim_mode.h.
|
private |
Definition at line 141 of file vim_mode.h.
Referenced by DeleteLine(), PasteAfter(), PasteBefore(), and YankLine().
|
private |
Definition at line 144 of file vim_mode.h.
Referenced by Complete(), and SetAutoCompleteCallback().
|
private |
Definition at line 145 of file vim_mode.h.
Referenced by SetCommandSuggestionCallback().
|
private |
Definition at line 146 of file vim_mode.h.
Referenced by Complete().
|
private |
Definition at line 147 of file vim_mode.h.
|
private |
Definition at line 150 of file vim_mode.h.
Referenced by HandleInsertMode(), HandleNormalMode(), ProcessKey(), and Reset().