yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
enhanced_tui.h
Go to the documentation of this file.
1#ifndef YAZE_SRC_CLI_SERVICE_AGENT_ENHANCED_TUI_H_
2#define YAZE_SRC_CLI_SERVICE_AGENT_ENHANCED_TUI_H_
3
4#include <string>
5#include <vector>
6#include <map>
7#include <functional>
8
9#include "absl/status/status.h"
10#include "absl/status/statusor.h"
12
13namespace yaze {
14
15class Rom;
16
17namespace cli {
18namespace agent {
19
24enum class TUITheme {
25 kDefault, // Default terminal colors
26 kDark, // Dark theme with bright accents
27 kLight, // Light theme with dark text
28 kZelda, // Zelda-themed colors (green/gold)
29 kCyberpunk // Cyberpunk theme (neon colors)
30};
31
36enum class TUIComponent {
37 kHeader, // Top header with title and status
38 kCommandPalette, // Command palette with fuzzy search
39 kChatArea, // Main chat conversation area
40 kToolOutput, // Tool execution results
41 kStatusBar, // Bottom status bar
42 kSidebar, // Sidebar with ROM info and shortcuts
43 kHelpPanel, // Context-sensitive help panel
44 kHistoryPanel // Command history and suggestions
45};
46
51struct TUIStyle {
52 std::string foreground_color;
53 std::string background_color;
54 std::string accent_color;
55 std::string border_color;
56 bool bold = false;
57 bool italic = false;
58 bool underline = false;
59};
60
65struct TUIConfig {
71 bool enable_transparency = false;
72 int max_history_size = 1000;
73 int max_output_lines = 10000;
74 bool auto_scroll = true;
75 bool show_timestamps = true;
76 bool show_command_hints = true;
77 bool enable_shortcuts = true;
78 std::string prompt_style = ">>> ";
79 std::string continuation_prompt = "... ";
80};
81
100 public:
101 explicit EnhancedTUI(const TUIConfig& config = TUIConfig{});
102 ~EnhancedTUI();
103
104 // Initialize the TUI (setup terminal, colors, etc.)
105 absl::Status Initialize();
106
107 // Cleanup and restore terminal state
108 void Shutdown();
109
110 // Set ROM context for command execution
111 void SetRomContext(Rom* rom);
112
113 // Main event loop
114 absl::Status Run();
115
116 // Display a message in the chat area
117 void DisplayMessage(const std::string& message,
118 const std::string& sender = "User",
119 bool is_error = false);
120
121 // Display tool output in the tool area
122 void DisplayToolOutput(const std::string& output,
123 const std::string& tool_name);
124
125 // Display command suggestions
126 void DisplaySuggestions(const std::vector<std::string>& suggestions);
127
128 // Update status bar with current information
129 void UpdateStatusBar(const std::string& status);
130
131 // Show help panel for a specific command
132 void ShowHelp(const std::string& command);
133
134 // Register a command handler
135 void RegisterCommand(const std::string& name,
136 std::function<absl::Status(const std::vector<std::string>&)> handler,
137 const std::string& description = "");
138
139 // Get current configuration
140 const TUIConfig& GetConfig() const { return config_; }
141
142 // Update configuration
143 void SetConfig(const TUIConfig& config);
144
145 private:
146 // Terminal control
147 void SetupTerminal();
148 void RestoreTerminal();
149 void ClearScreen();
150 void RefreshDisplay();
151
152 // Layout management
153 void CalculateLayout();
154 void DrawHeader();
155 void DrawCommandPalette();
156 void DrawChatArea();
157 void DrawToolOutput();
158 void DrawStatusBar();
159 void DrawSidebar();
161
162 // Input handling
163 absl::Status HandleInput();
164 void HandleKeyPress(int key);
165 void HandleMouseEvent(int x, int y, int button);
166 void HandleNormalKey(int key);
167 void HandleCommandPaletteKey(int key);
169
170 // Command processing
171 absl::Status ProcessCommand(const std::string& input);
172 std::vector<std::string> GetCommandSuggestions(const std::string& partial);
173 void ExecuteCommand(const std::string& command, const std::vector<std::string>& args);
174
175 // Styling and theming
176 TUIStyle GetStyle(TUIComponent component) const;
177 std::string ApplyStyle(const std::string& text, const TUIStyle& style) const;
178 void LoadTheme(TUITheme theme);
179
180 // Utility functions
181 std::string FormatTimestamp() const;
182 std::string TruncateText(const std::string& text, int max_width) const;
183 std::vector<std::string> WrapText(const std::string& text, int width) const;
184
186 Rom* rom_context_ = nullptr;
187
188 // Terminal state
192
193 // Layout state
194 struct Layout {
198 int help_width = 40;
199 int chat_height = 15;
200 int tool_height = 8;
202
203 // UI state
204 std::string current_input_;
205 std::vector<std::string> command_history_;
206 std::vector<std::string> output_history_;
207 std::map<std::string, std::function<absl::Status(const std::vector<std::string>&)>> commands_;
208 std::map<std::string, std::string> command_descriptions_;
209
210 // Styling
211 std::map<TUIComponent, TUIStyle> styles_;
212 std::map<TUITheme, std::map<TUIComponent, TUIStyle>> themes_;
213
214 // Input state
215 int cursor_x_ = 0;
216 int cursor_y_ = 0;
218 std::string palette_filter_;
219 std::vector<std::string> palette_matches_;
221};
222
234 public:
235 explicit TUICommandHandler(EnhancedTUI* tui) : tui_(tui) {}
236
237 protected:
238 // Override to provide TUI-specific output
239 virtual void DisplayProgress(const std::string& message) {
240 if (tui_) {
241 tui_->UpdateStatusBar(message);
242 }
243 }
244
245 virtual void DisplayRichOutput(const std::string& output) {
246 if (tui_) {
248 }
249 }
250
251 virtual absl::StatusOr<std::string> PromptUser(const std::string& /* prompt */) {
252 // TODO: Implement interactive prompting in TUI
253 return absl::UnimplementedError("Interactive prompting not yet implemented");
254 }
255
256 virtual std::string GetCommandName() const = 0;
257
258 private:
259 EnhancedTUI* tui_ = nullptr;
260};
261
267 public:
269
270 // Add a command to the autocomplete database
271 void AddCommand(const std::string& command, const std::string& description);
272
273 // Get completions for a partial input
274 std::vector<std::string> GetCompletions(const std::string& partial);
275
276 // Get fuzzy matches for a query
277 std::vector<std::string> GetFuzzyMatches(const std::string& query);
278
279 // Learn from user input patterns
280 void LearnFromInput(const std::string& input);
281
282 private:
283 std::map<std::string, std::string> commands_;
284 std::map<std::string, int> usage_count_;
285 std::vector<std::string> recent_commands_;
286};
287
288// Helper function to convert TUITheme to string
289std::string TUIThemeToString(TUITheme theme);
290
291} // namespace agent
292} // namespace cli
293} // namespace yaze
294
295#endif // YAZE_SRC_CLI_SERVICE_AGENT_ENHANCED_TUI_H_
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:71
Enhanced Terminal User Interface for z3ed CLI.
void UpdateStatusBar(const std::string &status)
struct yaze::cli::agent::EnhancedTUI::Layout layout_
std::vector< std::string > output_history_
std::vector< std::string > GetCommandSuggestions(const std::string &partial)
void DisplayToolOutput(const std::string &output, const std::string &tool_name)
void LoadTheme(TUITheme theme)
void RegisterCommand(const std::string &name, std::function< absl::Status(const std::vector< std::string > &)> handler, const std::string &description="")
absl::Status ProcessCommand(const std::string &input)
std::map< TUIComponent, TUIStyle > styles_
std::string TruncateText(const std::string &text, int max_width) const
std::map< std::string, std::function< absl::Status(const std::vector< std::string > &)> > commands_
const TUIConfig & GetConfig() const
void DisplaySuggestions(const std::vector< std::string > &suggestions)
std::vector< std::string > palette_matches_
void DisplayMessage(const std::string &message, const std::string &sender="User", bool is_error=false)
void ShowHelp(const std::string &command)
std::string FormatTimestamp() const
std::string ApplyStyle(const std::string &text, const TUIStyle &style) const
std::vector< std::string > WrapText(const std::string &text, int width) const
void SetConfig(const TUIConfig &config)
void ExecuteCommand(const std::string &command, const std::vector< std::string > &args)
TUIStyle GetStyle(TUIComponent component) const
std::map< std::string, std::string > command_descriptions_
std::vector< std::string > command_history_
void HandleMouseEvent(int x, int y, int button)
std::map< TUITheme, std::map< TUIComponent, TUIStyle > > themes_
Advanced autocomplete system for the TUI.
std::map< std::string, std::string > commands_
std::vector< std::string > recent_commands_
std::vector< std::string > GetFuzzyMatches(const std::string &query)
std::map< std::string, int > usage_count_
std::vector< std::string > GetCompletions(const std::string &partial)
void LearnFromInput(const std::string &input)
void AddCommand(const std::string &command, const std::string &description)
Base class for TUI-integrated command handlers.
virtual void DisplayProgress(const std::string &message)
virtual void DisplayRichOutput(const std::string &output)
virtual std::string GetCommandName() const =0
virtual absl::StatusOr< std::string > PromptUser(const std::string &)
Base class for CLI command handlers.
TUITheme
Visual themes for the enhanced TUI.
TUIComponent
Different UI components in the enhanced TUI.
std::string TUIThemeToString(TUITheme theme)
Main namespace for the application.
Configuration for the enhanced TUI.
Visual styling configuration for TUI components.