yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
vim_mode.h
Go to the documentation of this file.
1#ifndef YAZE_CLI_SERVICE_AGENT_VIM_MODE_H_
2#define YAZE_CLI_SERVICE_AGENT_VIM_MODE_H_
3
4#include <functional>
5#include <string>
6#include <vector>
7
8namespace yaze {
9namespace cli {
10namespace agent {
11
16enum class VimModeType {
17 NORMAL, // Command mode (ESC)
18 INSERT, // Insert mode (i, a, o, etc.)
19 VISUAL, // Visual selection mode (v)
20 COMMAND_LINE // Ex command mode (:)
21};
22
34class VimMode {
35 public:
36 VimMode();
37
43 bool ProcessKey(int ch);
44
48 std::string GetLine() const { return current_line_; }
49
53 VimModeType GetMode() const { return mode_; }
54
58 std::string GetModeString() const;
59
63 int GetCursorPos() const { return cursor_pos_; }
64
68 void Reset();
69
73 void AddToHistory(const std::string& line);
74
79 std::function<std::vector<std::string>(const std::string&)> callback) {
80 autocomplete_callback_ = callback;
81 }
82
87 std::function<std::string(const std::string&)> callback) {
89 }
90
94 void Render() const;
95
96 private:
97 // Mode handling
98 void SwitchMode(VimModeType new_mode);
99
100 // Normal mode commands
101 void HandleNormalMode(int ch);
102 void MoveLeft();
103 void MoveRight();
104 void MoveWordForward();
105 void MoveWordBackward();
106 void MoveToLineStart();
107 void MoveToLineEnd();
108 void DeleteChar();
109 void DeleteLine();
110 void YankLine();
111 void PasteBefore();
112 void PasteAfter();
113 void Undo();
114 void Redo();
115
116 // Insert mode commands
117 void HandleInsertMode(int ch);
118 void InsertChar(char c);
119 void Backspace();
120 void Delete();
121 void Complete();
122
123 // History navigation
124 void HistoryPrev();
125 void HistoryNext();
126
127 // Visual feedback
128 void ShowSuggestion() const;
129
131 std::string current_line_;
132 int cursor_pos_ = 0;
133
134 // History
135 std::vector<std::string> history_;
137
138 // Undo/redo
139 std::vector<std::string> undo_stack_;
140 std::vector<std::string> redo_stack_;
141
142 // Yank buffer
143 std::string yank_buffer_;
144
145 // Autocomplete
146 std::function<std::vector<std::string>(const std::string&)>
148 std::function<std::string(const std::string&)> command_suggestion_callback_;
149 std::vector<std::string> autocomplete_options_;
151
152 // State
153 bool line_complete_ = false;
154};
155
156} // namespace agent
157} // namespace cli
158} // namespace yaze
159
160#endif // YAZE_CLI_SERVICE_AGENT_VIM_MODE_H_
Vim-style line editing for z3ed CLI chat.
Definition vim_mode.h:34
VimModeType GetMode() const
Get the current mode.
Definition vim_mode.h:53
std::function< std::vector< std::string >(const std::string &) autocomplete_callback_)
Definition vim_mode.h:147
std::vector< std::string > redo_stack_
Definition vim_mode.h:140
void HandleInsertMode(int ch)
Definition vim_mode.cc:232
void SwitchMode(VimModeType new_mode)
Definition vim_mode.cc:120
bool ProcessKey(int ch)
Process a key press.
Definition vim_mode.cc:95
void SetCommandSuggestionCallback(std::function< std::string(const std::string &)> callback)
Set command suggestion callback.
Definition vim_mode.h:86
void HandleNormalMode(int ch)
Definition vim_mode.cc:127
void Reset()
Reset for new line.
Definition vim_mode.cc:81
std::string GetModeString() const
Get mode string for display.
Definition vim_mode.cc:67
std::vector< std::string > autocomplete_options_
Definition vim_mode.h:149
std::function< std::string(const std::string &) command_suggestion_callback_)
Definition vim_mode.h:148
std::vector< std::string > history_
Definition vim_mode.h:135
void Render() const
Render the current line with syntax highlighting.
Definition vim_mode.cc:429
std::string current_line_
Definition vim_mode.h:131
void SetAutoCompleteCallback(std::function< std::vector< std::string >(const std::string &)> callback)
Set autocomplete callback.
Definition vim_mode.h:78
void AddToHistory(const std::string &line)
Add line to history.
Definition vim_mode.cc:88
std::vector< std::string > undo_stack_
Definition vim_mode.h:139
std::string GetLine() const
Get the current line being edited.
Definition vim_mode.h:48
int GetCursorPos() const
Get cursor position.
Definition vim_mode.h:63
VimModeType
Vim editing modes.
Definition vim_mode.h:16