juk3n/fluffypublic Fork
⑂ bbc8515
Commits
⬇ Clone ▾
git clone https://git.rickub.com/juk3n/fluffy.git
git clone ssh://git@rickub.com/juk3n/fluffy.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

added menu like view

juk3n committed 2024-06-11T21:43:09+02:00 Browse files
bbc8515 parent: 4f1f5a9
modified CMakeLists.txt +1 -1
@@ -5,7 +5,7 @@ include(FetchContent)
55 set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
66 FetchContent_Declare(ftxui
77 GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
8- GIT_TAG v4.0.0
8+ GIT_TAG v5.0.0
99 )
1010 FetchContent_MakeAvailable(ftxui)
1111 if(NOT ftxui_POPULATED)
@@ -5,7 +5,7 @@ include(FetchContent)
5 set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)5 set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
6 FetchContent_Declare(ftxui6 FetchContent_Declare(ftxui
7 GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui7 GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
8- GIT_TAG v4.0.08+ GIT_TAG v5.0.0
9 )9 )
10 FetchContent_MakeAvailable(ftxui)10 FetchContent_MakeAvailable(ftxui)
11 if(NOT ftxui_POPULATED)11 if(NOT ftxui_POPULATED)
modified src/main.cpp +25 -23
@@ -1,6 +1,9 @@
11 #include "ftxui/dom/elements.hpp"
22 #include "ftxui/screen/screen.hpp"
33 #include "ftxui/screen/string.hpp"
4+#include "ftxui/component/component.hpp"
5+#include "ftxui/component/component_options.hpp"
6+#include "ftxui/component/screen_interactive.hpp"
47
58 #include <iostream>
69 #include <string>
@@ -95,22 +98,12 @@ int main() {
9598 }
9699 sqlite3_finalize(stmt);
97100
98- int choice = 1;
101+ int exit_id = games.size();
102+ int choice = 0;
99103 do {
100104 system("clear");
101- std::vector<Element> localGames = {};
102- for (const auto& [name, path] : games) {
103- localGames.push_back(hbox({text(" " + name)}) | color(Color::Green));
104- }
105-
106- auto summary = [&] {
107- auto content = vbox(localGames);
108- return window(text(L" Games "), content);
109- };
110-
111105 auto document = vbox({
112- text(L" Fluffy v0.1 "),
113- vbox({summary()}),
106+ center(text(L" Fluffy v0.1 ")),
114107 });
115108
116109 document = document | size(WIDTH, LESS_THAN, 120);
@@ -119,15 +112,26 @@ int main() {
119112 Render(screen, document);
120113
121114 std::cout << screen.ToString() << '\0' << std::endl;
122- std::cin >> choice;
123- switch (choice)
124- {
125- case 0:
126- break;
127- default:
128- int i{ 1 };
115+
116+
117+ auto menu_screen = ScreenInteractive::TerminalOutput();
118+
119+ std::vector<std::string> localGames = {};
120+ for (const auto& [name, path] : games) {
121+ localGames.push_back(name);
122+ }
123+ localGames.push_back("Exit");
124+
125+ MenuOption option;
126+ option.on_enter = menu_screen.ExitLoopClosure();
127+ auto menu = Menu(&localGames, &choice, option);
128+ menu_screen.Loop(menu);
129+
130+ if (choice != exit_id) {
131+ int i{ 0 };
129132 std::string pathToRun = "";
130133 for (const auto& [name, path] : games) {
134+
131135 if (i == choice) {
132136 pathToRun = path;
133137
@@ -135,10 +139,8 @@ int main() {
135139 i++;
136140 }
137141 system(pathToRun.c_str());
138- break;
139142 }
140- } while (choice != 0);
141-
143+ } while (choice != exit_id);
142144 sqlite3_close(database);
143145 return EXIT_SUCCESS;
144146 }
\ No newline at end of file
@@ -1,6 +1,9 @@
1 #include "ftxui/dom/elements.hpp"1 #include "ftxui/dom/elements.hpp"
2 #include "ftxui/screen/screen.hpp"2 #include "ftxui/screen/screen.hpp"
3 #include "ftxui/screen/string.hpp"3 #include "ftxui/screen/string.hpp"
4+#include "ftxui/component/component.hpp"
5+#include "ftxui/component/component_options.hpp"
6+#include "ftxui/component/screen_interactive.hpp"
4 7
5 #include <iostream>8 #include <iostream>
6 #include <string>9 #include <string>
@@ -95,22 +98,12 @@ int main() {
95 }98 }
96 sqlite3_finalize(stmt);99 sqlite3_finalize(stmt);
97 100
98- int choice = 1;101+ int exit_id = games.size();
102+ int choice = 0;
99 do {103 do {
100 system("clear");104 system("clear");
101- std::vector<Element> localGames = {};
102- for (const auto& [name, path] : games) {
103- localGames.push_back(hbox({text(" " + name)}) | color(Color::Green));
104- }
105-
106- auto summary = [&] {
107- auto content = vbox(localGames);
108- return window(text(L" Games "), content);
109- };
110-
111 auto document = vbox({105 auto document = vbox({
112- text(L" Fluffy v0.1 "),106+ center(text(L" Fluffy v0.1 ")),
113- vbox({summary()}),
114 });107 });
115 108
116 document = document | size(WIDTH, LESS_THAN, 120);109 document = document | size(WIDTH, LESS_THAN, 120);
@@ -119,15 +112,26 @@ int main() {
119 Render(screen, document);112 Render(screen, document);
120 113
121 std::cout << screen.ToString() << '\0' << std::endl;114 std::cout << screen.ToString() << '\0' << std::endl;
122- std::cin >> choice;115+
123- switch (choice)116+
124- {117+ auto menu_screen = ScreenInteractive::TerminalOutput();
125- case 0:118+
126- break;119+ std::vector<std::string> localGames = {};
127- default:120+ for (const auto& [name, path] : games) {
128- int i{ 1 };121+ localGames.push_back(name);
122+ }
123+ localGames.push_back("Exit");
124+
125+ MenuOption option;
126+ option.on_enter = menu_screen.ExitLoopClosure();
127+ auto menu = Menu(&localGames, &choice, option);
128+ menu_screen.Loop(menu);
129+
130+ if (choice != exit_id) {
131+ int i{ 0 };
129 std::string pathToRun = "";132 std::string pathToRun = "";
130 for (const auto& [name, path] : games) {133 for (const auto& [name, path] : games) {
134+
131 if (i == choice) {135 if (i == choice) {
132 pathToRun = path;136 pathToRun = path;
133 137
@@ -135,10 +139,8 @@ int main() {
135 i++;139 i++;
136 }140 }
137 system(pathToRun.c_str());141 system(pathToRun.c_str());
138- break;
139 }142 }
140- } while (choice != 0);143+ } while (choice != exit_id);
141-
142 sqlite3_close(database);144 sqlite3_close(database);
143 return EXIT_SUCCESS;145 return EXIT_SUCCESS;
144 }146 }
\ No newline at end of file\ No newline at end of file