File tree Expand file tree Collapse file tree 10 files changed +60
-17
lines changed Expand file tree Collapse file tree 10 files changed +60
-17
lines changed Original file line number Diff line number Diff line change @@ -9,4 +9,4 @@ install_manifest.txt
9
9
compile_commands.json
10
10
CTestTestfile.cmake
11
11
_deps
12
- cpp-tui-workshop
12
+ * .out
Original file line number Diff line number Diff line change @@ -5,13 +5,20 @@ project(cpp-tui-workshop LANGUAGES CXX)
5
5
find_package (ftxui REQUIRED)
6
6
find_package (cpr REQUIRED)
7
7
8
- file (GLOB_RECURSE SRC_FILES "src/*.cpp" )
9
- add_executable (cpp-tui-workshop ${SRC_FILES} )
10
- target_include_directories (cpp-tui-workshop PRIVATE src)
8
+ function (register_executable TARGET_NAME SRC_PATH LIBRARIES)
9
+ file (GLOB_RECURSE SRC_FILES "${SRC_PATH} /*.cpp" )
10
+ add_executable ("${TARGET_NAME} .out" ${SRC_FILES} )
11
+ target_link_libraries ("${TARGET_NAME} .out" ${LIBRARIES} )
12
+ endfunction ()
11
13
12
- target_link_libraries (cpp-tui-workshop
13
- PRIVATE ftxui::screen
14
- PRIVATE ftxui::dom
15
- PRIVATE ftxui::component
16
- PRIVATE cpr::cpr
14
+ register_executable(
15
+ "weather-app"
16
+ "weather-app"
17
+ "ftxui::screen;ftxui::dom;ftxui::component;cpr::cpr"
18
+ )
19
+
20
+ register_executable(
21
+ "basic-demo"
22
+ "basic-demo"
23
+ "ftxui::screen;ftxui::dom;ftxui::component"
17
24
)
Original file line number Diff line number Diff line change @@ -21,6 +21,16 @@ using [CMake](https://cmake.org/).
21
21
nix build .#
22
22
```
23
23
24
+ This gives you a ` result ` folder containing the binaries in ` result/bin ` .
25
+
26
+ If you want to directly run the program without running the build command, you
27
+ can do:
28
+
29
+ ``` sh
30
+ nix run .# weather-app
31
+ nix run .# basic-demo
32
+ ```
33
+
24
34
To run, you can either use ` nix run ` and skip building entirely or run
25
35
` ./result/bin/cpp-tui-workshop ` .
26
36
@@ -40,4 +50,4 @@ cmake .
40
50
cmake --build .
41
51
```
42
52
43
- To run, you can run ` ./cpp-tui-workshop ` .
53
+ To run, you can run any of the ` .out ` files .
Original file line number Diff line number Diff line change
1
+ #include < ftxui/component/captured_mouse.hpp>
2
+ #include < ftxui/component/component.hpp>
3
+ #include < ftxui/component/component_base.hpp>
4
+ #include < ftxui/component/screen_interactive.hpp>
5
+ #include < ftxui/dom/elements.hpp>
6
+
7
+ using namespace ftxui ;
8
+
9
+ int main () {
10
+ auto interface = [&] {
11
+ return window (text (" Title" ) | center, vbox ({
12
+ text (" Hello!!" ) | center,
13
+ }));
14
+ };
15
+
16
+ auto screen = ScreenInteractive::Fullscreen ();
17
+ screen.Loop (Renderer (interface));
18
+ }
Original file line number Diff line number Diff line change 34
34
35
35
installPhase = ''
36
36
mkdir -p $out/bin
37
- mv cpp-tui-workshop $out/bin
37
+ for bin in *.out; do
38
+ dst="$out/bin/$(basename $bin .out)"
39
+ mv $bin $dst
40
+ done
38
41
'' ;
42
+ } ;
39
43
40
- meta = {
41
- mainProgram = "cpp-tui-workshop" ;
44
+ apps = builtins . listToAttrs ( map ( exe : {
45
+ name = exe ;
46
+ value = {
47
+ type = "app" ;
48
+ program = "${ self . packages . ${ system } . default } /bin/${ exe } " ;
42
49
} ;
43
- } ;
50
+ } ) [ "weather-app" "basic-demo" ] ) ;
44
51
}
45
52
) ;
46
53
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change @@ -131,17 +131,18 @@ int main() {
131
131
132
132
if (event == Event::Custom) {
133
133
// Check if the weather data is ready.
134
- weather_future.wait ();
135
134
if (weather_future.valid ()) {
136
135
try {
137
136
weather_maybe =
138
137
std::make_unique<Weather::Conditions>(weather_future.get ());
139
138
} catch (...) {
140
139
weather_maybe = std::current_exception ();
141
140
}
141
+ return true ;
142
+ } else if (weather_maybe.index () == 0 ) {
143
+ // Data is still loading. Try again later.
144
+ screen.PostEvent (Event::Custom);
142
145
}
143
-
144
- return true ;
145
146
}
146
147
147
148
return false ;
File renamed without changes.
File renamed without changes.
You can’t perform that action at this time.
0 commit comments