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