juk3n/fluffypublic Fork
⑂ 5714ed8
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.

moved console app running to separate function

Adrian Duraj committed 2024-06-26T12:49:37+02:00 Browse files
5714ed8 parent: 80e2bea
modified CMakeLists.txt +1 -1
@@ -8,7 +8,7 @@ include(FetchContent)
88 set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
99 FetchContent_Declare(ftxui
1010 GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
11- GIT_TAG v4.0.0
11+ GIT_TAG v5.0.0
1212 )
1313 FetchContent_MakeAvailable(ftxui)
1414 if(NOT ftxui_POPULATED)
@@ -8,7 +8,7 @@ include(FetchContent)
8 set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)8 set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
9 FetchContent_Declare(ftxui9 FetchContent_Declare(ftxui
10 GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui10 GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
11- GIT_TAG v4.0.011+ GIT_TAG v5.0.0
12 )12 )
13 FetchContent_MakeAvailable(ftxui)13 FetchContent_MakeAvailable(ftxui)
14 if(NOT ftxui_POPULATED)14 if(NOT ftxui_POPULATED)
modified src/main.cpp +43 -47
@@ -39,7 +39,7 @@ void printMessage(std::string message) {
3939 void execute_sql_command(sqlite3 *database, std::string command) {
4040 int exit = 0;
4141 char *messageError;
42- exit = sqlite3_exec(database, command.c_str(), NULL, 0, &messageError);
42+ exit = sqlite3_exec(database, command.c_str(), nullptr, nullptr, &messageError);
4343
4444 if (exit != SQLITE_OK) {
4545 printMessage("Error with command: " + command + " " + messageError);
@@ -130,6 +130,44 @@ auto Style() -> ButtonOption {
130130 return option;
131131 }
132132
133+auto runConsoleApp(sqlite3* database) -> void {
134+ system("clear");
135+
136+ std::vector<std::string> localGames = {};
137+ for (auto &game : games) {
138+ localGames.emplace_back(game.getName());
139+ }
140+ localGames.emplace_back("Exit");
141+
142+ auto gamesContainer{Container::Vertical({})};
143+ for (auto &game : games) {
144+ gamesContainer->Add(Button(
145+ game.getName(), [&] { runGame(database, game.getName()); }, Style()));
146+ }
147+
148+ auto menu_screen = ScreenInteractive::TerminalOutput();
149+
150+ auto quitButton = Button("Exit", menu_screen.ExitLoopClosure(), Style());
151+ gamesContainer->Add(quitButton);
152+
153+ int menuOptionSelected{0};
154+ auto appContainer =
155+ Container::Tab({gamesContainer}, &menuOptionSelected);
156+
157+ auto container = Container::Horizontal({
158+ appContainer,
159+ });
160+ auto renderer = Renderer(container, [&] {
161+ return vbox({
162+ center(text(L" Fluffy v0.1 ")),
163+ appContainer->Render(),
164+ }) |
165+ border | size(WIDTH, LESS_THAN, 120);
166+ });
167+ menu_screen.Loop(renderer);
168+
169+}
170+
133171 auto main(int argc, char const *argv[]) -> int {
134172 bool newCreation = not std::filesystem::exists("data.db");
135173 char *messageError;
@@ -150,7 +188,7 @@ auto main(int argc, char const *argv[]) -> int {
150188 initialize_database(database);
151189 }
152190
153- exit = sqlite3_prepare_v2(database, select_all_games_command.c_str(), -1, &stmt, 0);
191+ exit = sqlite3_prepare_v2(database, select_all_games_command.c_str(), -1, &stmt, nullptr);
154192
155193 if (exit) {
156194 std::cerr << "Error retrieving data" << sqlite3_errmsg(database)
@@ -171,53 +209,11 @@ auto main(int argc, char const *argv[]) -> int {
171209
172210 if (argc > 1) {
173211 handleCommand(argc, argv, database);
174- return 0;
175- }
176-
177- system("clear");
178-
179- std::vector<std::string> menuOptions{
180- "Games",
181- };
182- int menuOptionSelected{0};
183- auto menuOptionToggle = Toggle(&menuOptions, &menuOptionSelected);
184-
185- std::vector<std::string> localGames = {};
186- for (auto &game : games) {
187- localGames.emplace_back(game.getName());
188212 }
189- localGames.emplace_back("Exit");
190-
191- auto gamesContainer{Container::Vertical({})};
192- for (auto &game : games) {
193- gamesContainer->Add(Button(
194- game.getName(), [&] { runGame(database, game.getName()); }, Style()));
213+ else {
214+ runConsoleApp(database);
195215 }
196-
197- auto menu_screen = ScreenInteractive::TerminalOutput();
198-
199- auto quitButton = Button("Exit", menu_screen.ExitLoopClosure(), Style());
200- gamesContainer->Add(quitButton);
201-
202- auto appContainer =
203- Container::Tab({gamesContainer}, &menuOptionSelected);
204-
205- auto container = Container::Horizontal({
206- menuOptionToggle,
207- appContainer,
208- });
209-
210- auto renderer = Renderer(container, [&] {
211- return vbox({
212- center(text(L" Fluffy v0.1 ")),
213- menuOptionToggle->Render(),
214- appContainer->Render(),
215- }) |
216- border | size(WIDTH, LESS_THAN, 120);
217- });
218-
219- menu_screen.Loop(renderer);
220-
216+
221217 sqlite3_close(database);
222218 return EXIT_SUCCESS;
223219 }
\ No newline at end of file
@@ -39,7 +39,7 @@ void printMessage(std::string message) {
39 void execute_sql_command(sqlite3 *database, std::string command) {39 void execute_sql_command(sqlite3 *database, std::string command) {
40 int exit = 0;40 int exit = 0;
41 char *messageError;41 char *messageError;
42- exit = sqlite3_exec(database, command.c_str(), NULL, 0, &messageError);42+ exit = sqlite3_exec(database, command.c_str(), nullptr, nullptr, &messageError);
43 43
44 if (exit != SQLITE_OK) {44 if (exit != SQLITE_OK) {
45 printMessage("Error with command: " + command + " " + messageError);45 printMessage("Error with command: " + command + " " + messageError);
@@ -130,6 +130,44 @@ auto Style() -> ButtonOption {
130 return option;130 return option;
131 }131 }
132 132
133+auto runConsoleApp(sqlite3* database) -> void {
134+ system("clear");
135+
136+ std::vector<std::string> localGames = {};
137+ for (auto &game : games) {
138+ localGames.emplace_back(game.getName());
139+ }
140+ localGames.emplace_back("Exit");
141+
142+ auto gamesContainer{Container::Vertical({})};
143+ for (auto &game : games) {
144+ gamesContainer->Add(Button(
145+ game.getName(), [&] { runGame(database, game.getName()); }, Style()));
146+ }
147+
148+ auto menu_screen = ScreenInteractive::TerminalOutput();
149+
150+ auto quitButton = Button("Exit", menu_screen.ExitLoopClosure(), Style());
151+ gamesContainer->Add(quitButton);
152+
153+ int menuOptionSelected{0};
154+ auto appContainer =
155+ Container::Tab({gamesContainer}, &menuOptionSelected);
156+
157+ auto container = Container::Horizontal({
158+ appContainer,
159+ });
160+ auto renderer = Renderer(container, [&] {
161+ return vbox({
162+ center(text(L" Fluffy v0.1 ")),
163+ appContainer->Render(),
164+ }) |
165+ border | size(WIDTH, LESS_THAN, 120);
166+ });
167+ menu_screen.Loop(renderer);
168+
169+}
170+
133 auto main(int argc, char const *argv[]) -> int {171 auto main(int argc, char const *argv[]) -> int {
134 bool newCreation = not std::filesystem::exists("data.db");172 bool newCreation = not std::filesystem::exists("data.db");
135 char *messageError;173 char *messageError;
@@ -150,7 +188,7 @@ auto main(int argc, char const *argv[]) -> int {
150 initialize_database(database);188 initialize_database(database);
151 }189 }
152 190
153- exit = sqlite3_prepare_v2(database, select_all_games_command.c_str(), -1, &stmt, 0);191+ exit = sqlite3_prepare_v2(database, select_all_games_command.c_str(), -1, &stmt, nullptr);
154 192
155 if (exit) {193 if (exit) {
156 std::cerr << "Error retrieving data" << sqlite3_errmsg(database)194 std::cerr << "Error retrieving data" << sqlite3_errmsg(database)
@@ -171,53 +209,11 @@ auto main(int argc, char const *argv[]) -> int {
171 209
172 if (argc > 1) {210 if (argc > 1) {
173 handleCommand(argc, argv, database);211 handleCommand(argc, argv, database);
174- return 0;
175- }
176-
177- system("clear");
178-
179- std::vector<std::string> menuOptions{
180- "Games",
181- };
182- int menuOptionSelected{0};
183- auto menuOptionToggle = Toggle(&menuOptions, &menuOptionSelected);
184-
185- std::vector<std::string> localGames = {};
186- for (auto &game : games) {
187- localGames.emplace_back(game.getName());
188 }212 }
189- localGames.emplace_back("Exit");213+ else {
190-214+ runConsoleApp(database);
191- auto gamesContainer{Container::Vertical({})};
192- for (auto &game : games) {
193- gamesContainer->Add(Button(
194- game.getName(), [&] { runGame(database, game.getName()); }, Style()));
195 }215 }
196-216+
197- auto menu_screen = ScreenInteractive::TerminalOutput();
198-
199- auto quitButton = Button("Exit", menu_screen.ExitLoopClosure(), Style());
200- gamesContainer->Add(quitButton);
201-
202- auto appContainer =
203- Container::Tab({gamesContainer}, &menuOptionSelected);
204-
205- auto container = Container::Horizontal({
206- menuOptionToggle,
207- appContainer,
208- });
209-
210- auto renderer = Renderer(container, [&] {
211- return vbox({
212- center(text(L" Fluffy v0.1 ")),
213- menuOptionToggle->Render(),
214- appContainer->Render(),
215- }) |
216- border | size(WIDTH, LESS_THAN, 120);
217- });
218-
219- menu_screen.Loop(renderer);
220-
221 sqlite3_close(database);217 sqlite3_close(database);
222 return EXIT_SUCCESS;218 return EXIT_SUCCESS;
223 }219 }
\ No newline at end of file\ No newline at end of file