yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::cli::agent::VimMode Class Reference

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
 

Detailed Description

Vim-style line editing for z3ed CLI chat.

Provides vim keybindings for enhanced terminal UX:

  • Normal mode: hjkl navigation, dd, yy, p, u
  • Insert mode: Regular text input
  • Command history: Ctrl+P, Ctrl+N or j/k in normal mode
  • Tab completion for commands
  • Syntax highlighting for code blocks

Definition at line 34 of file vim_mode.h.

Constructor & Destructor Documentation

◆ VimMode()

yaze::cli::agent::VimMode::VimMode ( )

Definition at line 61 of file vim_mode.cc.

Member Function Documentation

◆ ProcessKey()

bool yaze::cli::agent::VimMode::ProcessKey ( int  ch)

Process a key press.

Parameters
chCharacter input
Returns
True if the line is complete (Enter pressed in insert mode)

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.

Here is the call graph for this function:

◆ GetLine()

std::string yaze::cli::agent::VimMode::GetLine ( ) const
inline

Get the current line being edited.

Definition at line 48 of file vim_mode.h.

References current_line_.

◆ GetMode()

VimModeType yaze::cli::agent::VimMode::GetMode ( ) const
inline

Get the current mode.

Definition at line 53 of file vim_mode.h.

References mode_.

◆ GetModeString()

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.

◆ GetCursorPos()

int yaze::cli::agent::VimMode::GetCursorPos ( ) const
inline

Get cursor position.

Definition at line 63 of file vim_mode.h.

References cursor_pos_.

◆ Reset()

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_.

◆ AddToHistory()

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_.

◆ SetAutoCompleteCallback()

void yaze::cli::agent::VimMode::SetAutoCompleteCallback ( std::function< std::vector< std::string >(const std::string &)>  callback)
inline

Set autocomplete callback.

Definition at line 78 of file vim_mode.h.

References autocomplete_callback_.

◆ SetCommandSuggestionCallback()

void yaze::cli::agent::VimMode::SetCommandSuggestionCallback ( std::function< std::string(const std::string &)>  callback)
inline

Set command suggestion callback.

Definition at line 85 of file vim_mode.h.

References command_suggestion_callback_.

◆ Render()

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().

◆ SwitchMode()

void yaze::cli::agent::VimMode::SwitchMode ( VimModeType  new_mode)
private

Definition at line 120 of file vim_mode.cc.

References mode_, and Render().

Referenced by HandleInsertMode(), HandleNormalMode(), and ProcessKey().

Here is the call graph for this function:

◆ HandleNormalMode()

◆ MoveLeft()

void yaze::cli::agent::VimMode::MoveLeft ( )
private

Definition at line 269 of file vim_mode.cc.

References cursor_pos_.

Referenced by HandleNormalMode().

◆ MoveRight()

void yaze::cli::agent::VimMode::MoveRight ( )
private

Definition at line 275 of file vim_mode.cc.

References current_line_, and cursor_pos_.

Referenced by HandleNormalMode().

◆ MoveWordForward()

void yaze::cli::agent::VimMode::MoveWordForward ( )
private

Definition at line 281 of file vim_mode.cc.

References current_line_, and cursor_pos_.

Referenced by HandleNormalMode().

◆ MoveWordBackward()

void yaze::cli::agent::VimMode::MoveWordBackward ( )
private

Definition at line 292 of file vim_mode.cc.

References current_line_, and cursor_pos_.

Referenced by HandleNormalMode().

◆ MoveToLineStart()

void yaze::cli::agent::VimMode::MoveToLineStart ( )
private

Definition at line 302 of file vim_mode.cc.

References cursor_pos_.

Referenced by HandleNormalMode().

◆ MoveToLineEnd()

void yaze::cli::agent::VimMode::MoveToLineEnd ( )
private

Definition at line 306 of file vim_mode.cc.

References current_line_, and cursor_pos_.

Referenced by HandleNormalMode().

◆ DeleteChar()

void yaze::cli::agent::VimMode::DeleteChar ( )
private

Definition at line 311 of file vim_mode.cc.

References current_line_, cursor_pos_, and undo_stack_.

Referenced by Delete(), and HandleNormalMode().

◆ DeleteLine()

void yaze::cli::agent::VimMode::DeleteLine ( )
private

Definition at line 318 of file vim_mode.cc.

References current_line_, cursor_pos_, undo_stack_, and yank_buffer_.

Referenced by HandleNormalMode().

◆ YankLine()

void yaze::cli::agent::VimMode::YankLine ( )
private

Definition at line 325 of file vim_mode.cc.

References current_line_, and yank_buffer_.

Referenced by HandleNormalMode().

◆ PasteBefore()

void yaze::cli::agent::VimMode::PasteBefore ( )
private

Definition at line 329 of file vim_mode.cc.

References current_line_, cursor_pos_, undo_stack_, and yank_buffer_.

Referenced by HandleNormalMode().

◆ PasteAfter()

void yaze::cli::agent::VimMode::PasteAfter ( )
private

Definition at line 336 of file vim_mode.cc.

References current_line_, cursor_pos_, undo_stack_, and yank_buffer_.

Referenced by HandleNormalMode().

◆ Undo()

void yaze::cli::agent::VimMode::Undo ( )
private

Definition at line 347 of file vim_mode.cc.

References current_line_, cursor_pos_, redo_stack_, and undo_stack_.

Referenced by HandleNormalMode().

◆ Redo()

void yaze::cli::agent::VimMode::Redo ( )
private

Definition at line 356 of file vim_mode.cc.

References current_line_, cursor_pos_, redo_stack_, and undo_stack_.

◆ HandleInsertMode()

void yaze::cli::agent::VimMode::HandleInsertMode ( int  ch)
private

◆ InsertChar()

void yaze::cli::agent::VimMode::InsertChar ( char  c)
private

Definition at line 365 of file vim_mode.cc.

References current_line_, cursor_pos_, and undo_stack_.

Referenced by HandleInsertMode().

◆ Backspace()

void yaze::cli::agent::VimMode::Backspace ( )
private

Definition at line 371 of file vim_mode.cc.

References current_line_, cursor_pos_, and undo_stack_.

Referenced by HandleInsertMode().

◆ Delete()

void yaze::cli::agent::VimMode::Delete ( )
private

Definition at line 379 of file vim_mode.cc.

References DeleteChar().

Here is the call graph for this function:

◆ Complete()

void yaze::cli::agent::VimMode::Complete ( )
private

◆ HistoryPrev()

void yaze::cli::agent::VimMode::HistoryPrev ( )
private

Definition at line 397 of file vim_mode.cc.

References current_line_, cursor_pos_, history_, and history_index_.

Referenced by HandleInsertMode(), and HandleNormalMode().

◆ HistoryNext()

void yaze::cli::agent::VimMode::HistoryNext ( )
private

Definition at line 410 of file vim_mode.cc.

References current_line_, cursor_pos_, history_, and history_index_.

Referenced by HandleInsertMode(), and HandleNormalMode().

◆ ShowSuggestion()

void yaze::cli::agent::VimMode::ShowSuggestion ( ) const
private

Member Data Documentation

◆ mode_

VimModeType yaze::cli::agent::VimMode::mode_ = VimModeType::INSERT
private

Definition at line 128 of file vim_mode.h.

Referenced by GetMode(), GetModeString(), ProcessKey(), Render(), and SwitchMode().

◆ current_line_

◆ cursor_pos_

◆ history_

std::vector<std::string> yaze::cli::agent::VimMode::history_
private

Definition at line 133 of file vim_mode.h.

Referenced by AddToHistory(), HistoryNext(), and HistoryPrev().

◆ history_index_

int yaze::cli::agent::VimMode::history_index_ = -1
private

Definition at line 134 of file vim_mode.h.

Referenced by AddToHistory(), HistoryNext(), and HistoryPrev().

◆ undo_stack_

std::vector<std::string> yaze::cli::agent::VimMode::undo_stack_
private

◆ redo_stack_

std::vector<std::string> yaze::cli::agent::VimMode::redo_stack_
private

Definition at line 138 of file vim_mode.h.

Referenced by Redo(), Reset(), and Undo().

◆ yank_buffer_

std::string yaze::cli::agent::VimMode::yank_buffer_
private

Definition at line 141 of file vim_mode.h.

Referenced by DeleteLine(), PasteAfter(), PasteBefore(), and YankLine().

◆ autocomplete_callback_

std::function<std::vector<std::string>(const std::string&)> yaze::cli::agent::VimMode::autocomplete_callback_
private

Definition at line 144 of file vim_mode.h.

Referenced by Complete(), and SetAutoCompleteCallback().

◆ command_suggestion_callback_

std::function<std::string(const std::string&)> yaze::cli::agent::VimMode::command_suggestion_callback_
private

Definition at line 145 of file vim_mode.h.

Referenced by SetCommandSuggestionCallback().

◆ autocomplete_options_

std::vector<std::string> yaze::cli::agent::VimMode::autocomplete_options_
private

Definition at line 146 of file vim_mode.h.

Referenced by Complete().

◆ autocomplete_index_

int yaze::cli::agent::VimMode::autocomplete_index_ = 0
private

Definition at line 147 of file vim_mode.h.

◆ line_complete_

bool yaze::cli::agent::VimMode::line_complete_ = false
private

Definition at line 150 of file vim_mode.h.

Referenced by HandleInsertMode(), HandleNormalMode(), ProcessKey(), and Reset().


The documentation for this class was generated from the following files: