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 <string>
5#include <vector>
6#include <functional>
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
78 void SetAutoCompleteCallback(std::function<std::vector<std::string>(const std::string&)> callback) {
79 autocomplete_callback_ = callback;
80 }
81
85 void SetCommandSuggestionCallback(std::function<std::string(const std::string&)> callback) {
87 }
88
92 void Render() const;
93
94 private:
95 // Mode handling
96 void SwitchMode(VimModeType new_mode);
97
98 // Normal mode commands
99 void HandleNormalMode(int ch);
100 void MoveLeft();
101 void MoveRight();
102 void MoveWordForward();
103 void MoveWordBackward();
104 void MoveToLineStart();
105 void MoveToLineEnd();
106 void DeleteChar();
107 void DeleteLine();
108 void YankLine();
109 void PasteBefore();
110 void PasteAfter();
111 void Undo();
112 void Redo();
113
114 // Insert mode commands
115 void HandleInsertMode(int ch);
116 void InsertChar(char c);
117 void Backspace();
118 void Delete();
119 void Complete();
120
121 // History navigation
122 void HistoryPrev();
123 void HistoryNext();
124
125 // Visual feedback
126 void ShowSuggestion() const;
127
129 std::string current_line_;
130 int cursor_pos_ = 0;
131
132 // History
133 std::vector<std::string> history_;
135
136 // Undo/redo
137 std::vector<std::string> undo_stack_;
138 std::vector<std::string> redo_stack_;
139
140 // Yank buffer
141 std::string yank_buffer_;
142
143 // Autocomplete
144 std::function<std::vector<std::string>(const std::string&)> autocomplete_callback_;
145 std::function<std::string(const std::string&)> command_suggestion_callback_;
146 std::vector<std::string> autocomplete_options_;
148
149 // State
150 bool line_complete_ = false;
151};
152
153} // namespace agent
154} // namespace cli
155} // namespace yaze
156
157#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::vector< std::string > redo_stack_
Definition vim_mode.h:138
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:85
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:146
std::vector< std::string > history_
Definition vim_mode.h:133
void Render() const
Render the current line with syntax highlighting.
Definition vim_mode.cc:424
std::string current_line_
Definition vim_mode.h:129
std::function< std::string(const std::string &)> command_suggestion_callback_
Definition vim_mode.h:145
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::function< std::vector< std::string >(const std::string &)> autocomplete_callback_
Definition vim_mode.h:144
std::vector< std::string > undo_stack_
Definition vim_mode.h:137
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
Main namespace for the application.