juk3n/fluffypublic Fork
⑂ edf35e1
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 ftxui library

juk3n committed 2024-06-07T17:14:16+02:00 Browse files
edf35e1 parent: 52b2642
modified CMakeLists.txt +37 -3
@@ -1,9 +1,43 @@
1-cmake_minimum_required(VERSION 3.10)
2-project(fluffy)
1+cmake_minimum_required(VERSION 3.14)
2+
3+include(FetchContent)
4+
5+set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
6+FetchContent_Declare(ftxui
7+ GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
8+ GIT_TAG v4.0.0
9+)
10+FetchContent_MakeAvailable(ftxui)
11+if(NOT ftxui_POPULATED)
12+ FetchContent_Populate(ftxui)
13+ add_subdirectory(${ftxui_SOURCE_DIR} ${ftxui_BINARY_DIR} EXCLUDE_FROM_ALL)
14+endif()
15+
16+project(fluffy LANGUAGES CXX VERSION 1.0.0)
317
418 set(CMAKE_CXX_STANDARD 20)
519 set(CMAKE_CXX_STANDARD_REQUIRED True)
620
21+
22+find_package(SQLite3 REQUIRED)
23+
724 include_directories(${CMAKE_SOURCE_DIR}/include)
825
9-add_executable(fluffy src/main.cpp src/sqlite3.c)
\ No newline at end of file
26+add_executable(fluffy src/main.cpp src/sqlite3.c)
27+
28+target_link_libraries(fluffy
29+ PRIVATE ftxui::screen
30+ PRIVATE ftxui::dom
31+ PRIVATE ftxui::component # Not needed for this example.
32+ PRIVATE SQLite::SQLite3
33+)
34+
35+if (EMSCRIPTEN)
36+ string(APPEND CMAKE_CXX_FLAGS " -s USE_PTHREADS")
37+ string(APPEND CMAKE_EXE_LINKER_FLAGS " -s ASYNCIFY")
38+ string(APPEND CMAKE_EXE_LINKER_FLAGS " -s PROXY_TO_PTHREAD")
39+
40+ foreach(file "index.html" "run_webassembly.py")
41+ configure_file("src/${file}" ${file})
42+ endforeach(file)
43+endif()
\ No newline at end of file
@@ -1,9 +1,43 @@
1-cmake_minimum_required(VERSION 3.10)1+cmake_minimum_required(VERSION 3.14)
2-project(fluffy)2+
3+include(FetchContent)
4+
5+set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
6+FetchContent_Declare(ftxui
7+ GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
8+ GIT_TAG v4.0.0
9+)
10+FetchContent_MakeAvailable(ftxui)
11+if(NOT ftxui_POPULATED)
12+ FetchContent_Populate(ftxui)
13+ add_subdirectory(${ftxui_SOURCE_DIR} ${ftxui_BINARY_DIR} EXCLUDE_FROM_ALL)
14+endif()
15+
16+project(fluffy LANGUAGES CXX VERSION 1.0.0)
3 17
4 set(CMAKE_CXX_STANDARD 20)18 set(CMAKE_CXX_STANDARD 20)
5 set(CMAKE_CXX_STANDARD_REQUIRED True)19 set(CMAKE_CXX_STANDARD_REQUIRED True)
6 20
21+
22+find_package(SQLite3 REQUIRED)
23+
7 include_directories(${CMAKE_SOURCE_DIR}/include)24 include_directories(${CMAKE_SOURCE_DIR}/include)
8 25
9-add_executable(fluffy src/main.cpp src/sqlite3.c)
\ No newline at end of file\ No newline at end of file
26+add_executable(fluffy src/main.cpp src/sqlite3.c)
27+
28+target_link_libraries(fluffy
29+ PRIVATE ftxui::screen
30+ PRIVATE ftxui::dom
31+ PRIVATE ftxui::component # Not needed for this example.
32+ PRIVATE SQLite::SQLite3
33+)
34+
35+if (EMSCRIPTEN)
36+ string(APPEND CMAKE_CXX_FLAGS " -s USE_PTHREADS")
37+ string(APPEND CMAKE_EXE_LINKER_FLAGS " -s ASYNCIFY")
38+ string(APPEND CMAKE_EXE_LINKER_FLAGS " -s PROXY_TO_PTHREAD")
39+
40+ foreach(file "index.html" "run_webassembly.py")
41+ configure_file("src/${file}" ${file})
42+ endforeach(file)
43+endif()
\ No newline at end of file\ No newline at end of file
modified src/main.cpp +31 -10
@@ -1,3 +1,7 @@
1+#include "ftxui/dom/elements.hpp"
2+#include "ftxui/screen/screen.hpp"
3+#include "ftxui/screen/string.hpp"
4+
15 #include <iostream>
26 #include <string>
37 #include <cstdlib>
@@ -5,6 +9,9 @@
59 #include <../include/sqlite3.h>
610 #include <map>
711
12+
13+using namespace ftxui;
14+
815 std::map<std::string, std::string> games;
916
1017 std::string database_initialization_command = "CREATE TABLE GAME("
@@ -90,18 +97,31 @@ int main() {
9097 }
9198 sqlite3_finalize(stmt);
9299
93- sqlite3_close(database);
94- int choice;
100+ int choice = 1;
95101 do {
96102 system("clear");
97- std::cout << "Welcome to fluffy (0 - exit, 1-x - run a game)" << std::endl;
98- int i{ 1 };
103+ std::vector<Element> localGames = {};
99104 for (const auto& [name, path] : games) {
100- std::cout << i ;
101- std::cout << ": " + name << std::endl;
102- i++;
105+ localGames.push_back(hbox({text(" " + name)}) | color(Color::Green));
103106 }
104-
107+
108+ auto summary = [&] {
109+ auto content = vbox(localGames);
110+ return window(text(L" Fluffy v0.1 "), content);
111+ };
112+
113+ auto document = //
114+ vbox({
115+ summary(),
116+ });
117+
118+ // Limit the size of the document to 80 char.
119+ document = document | size(WIDTH, LESS_THAN, 80);
120+
121+ auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
122+ Render(screen, document);
123+
124+ std::cout << screen.ToString() << '\0' << std::endl;
105125 std::cin >> choice;
106126 switch (choice)
107127 {
@@ -121,6 +141,7 @@ int main() {
121141 break;
122142 }
123143 } while (choice != 0);
124-
125- return 0;
144+
145+ sqlite3_close(database);
146+ return EXIT_SUCCESS;
126147 }
\ No newline at end of file
@@ -1,3 +1,7 @@
1+#include "ftxui/dom/elements.hpp"
2+#include "ftxui/screen/screen.hpp"
3+#include "ftxui/screen/string.hpp"
4+
1 #include <iostream>5 #include <iostream>
2 #include <string>6 #include <string>
3 #include <cstdlib>7 #include <cstdlib>
@@ -5,6 +9,9 @@
5 #include <../include/sqlite3.h>9 #include <../include/sqlite3.h>
6 #include <map>10 #include <map>
7 11
12+
13+using namespace ftxui;
14+
8 std::map<std::string, std::string> games;15 std::map<std::string, std::string> games;
9 16
10 std::string database_initialization_command = "CREATE TABLE GAME("17 std::string database_initialization_command = "CREATE TABLE GAME("
@@ -90,18 +97,31 @@ int main() {
90 }97 }
91 sqlite3_finalize(stmt);98 sqlite3_finalize(stmt);
92 99
93- sqlite3_close(database);100+ int choice = 1;
94- int choice;
95 do {101 do {
96 system("clear");102 system("clear");
97- std::cout << "Welcome to fluffy (0 - exit, 1-x - run a game)" << std::endl;103+ std::vector<Element> localGames = {};
98- int i{ 1 };
99 for (const auto& [name, path] : games) {104 for (const auto& [name, path] : games) {
100- std::cout << i ;105+ localGames.push_back(hbox({text(" " + name)}) | color(Color::Green));
101- std::cout << ": " + name << std::endl;
102- i++;
103 }106 }
104- 107+
108+ auto summary = [&] {
109+ auto content = vbox(localGames);
110+ return window(text(L" Fluffy v0.1 "), content);
111+ };
112+
113+ auto document = //
114+ vbox({
115+ summary(),
116+ });
117+
118+ // Limit the size of the document to 80 char.
119+ document = document | size(WIDTH, LESS_THAN, 80);
120+
121+ auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
122+ Render(screen, document);
123+
124+ std::cout << screen.ToString() << '\0' << std::endl;
105 std::cin >> choice;125 std::cin >> choice;
106 switch (choice)126 switch (choice)
107 {127 {
@@ -121,6 +141,7 @@ int main() {
121 break;141 break;
122 }142 }
123 } while (choice != 0);143 } while (choice != 0);
124-144+
125- return 0;145+ sqlite3_close(database);
146+ return EXIT_SUCCESS;
126 }147 }
\ No newline at end of file\ No newline at end of file