yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
autocomplete_ui.cc
Go to the documentation of this file.
1#include <ftxui/component/component.hpp>
2#include <ftxui/component/screen_interactive.hpp>
3#include <ftxui/dom/elements.hpp>
4
6
7namespace yaze {
8namespace cli {
9
10using namespace ftxui;
11
12Component CreateAutocompleteInput(std::string* input_str,
13 AutocompleteEngine* engine) {
14 auto input = Input(input_str, "Type command...");
15
16 return Renderer(input, [input, input_str, engine] {
17 auto suggestions = engine->GetSuggestions(*input_str);
18
19 Elements suggestion_list;
20 for (size_t i = 0; i < std::min(suggestions.size(), size_t(5)); ++i) {
21 const auto& s = suggestions[i];
22 suggestion_list.push_back(hbox({
23 text("→ ") | color(Color::Cyan),
24 text(s.text) | bold,
25 text(" ") | flex,
26 text(s.description) | dim,
27 }));
28 }
29
30 return vbox({
31 hbox({
32 text("❯ ") | color(Color::GreenLight),
33 input->Render() | flex,
34 }),
35
36 (suggestions.empty() ? text("")
37 : vbox({
38 separator(),
39 text("Suggestions:") | dim,
40 vbox(suggestion_list),
41 }) | size(HEIGHT, LESS_THAN, 8)),
42 });
43 });
44}
45
46Component CreateQuickActionMenu(ScreenInteractive& screen) {
47 // Note: This function is a placeholder for future quick action menu
48 // integration. Currently not used in the TUI, but kept for API compatibility.
49 struct MenuState {
50 int selected = 0;
51 std::vector<std::string> actions = {
52 "Quick Actions Menu - Not Yet Implemented",
53 "⬅️ Back",
54 };
55 };
56
57 auto state = std::make_shared<MenuState>();
58 auto menu = Menu(&state->actions, &state->selected);
59
60 return CatchEvent(menu, [&screen, state](const Event& e) {
61 if (e == Event::Return && state->selected == 1) {
62 screen.ExitLoopClosure()();
63 return true;
64 }
65 return false;
66 });
67}
68
69} // namespace cli
70} // namespace yaze
std::vector< Suggestion > GetSuggestions(const std::string &input)
Definition cli.h:17
Component CreateQuickActionMenu(ScreenInteractive &screen)
Component CreateAutocompleteInput(std::string *input_str, AutocompleteEngine *engine)
Create an input component with autocomplete suggestions.