diff --git a/CMakeLists.txt b/CMakeLists.txt index 57efcf4..b237613 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,6 +148,13 @@ foreach(lib screen dom component) endforeach() +if (EMSCRIPTEN) + #string(APPEND CMAKE_CXX_FLAGS " -s ASSERTIONS=1") + string(APPEND CMAKE_CXX_FLAGS " -s ASYNCIFY") + string(APPEND CMAKE_CXX_FLAGS " -s USE_PTHREADS") + string(APPEND CMAKE_CXX_FLAGS " -s PROXY_TO_PTHREAD") +endif() + if(FTXUI_ENABLE_INSTALL) include(GNUInstallDirs) install(TARGETS screen dom component diff --git a/README.md b/README.md index 194172c..d7f32da 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ A simple C++ library for terminal based user interface. - [Starter example project](https://github.com/ArthurSonzogni/ftxui-starter) - [Documentation](https://arthursonzogni.com/FTXUI/doc/) +- [Examples (WebAssembly)](https://arthursonzogni.com/FTXUI/examples/) - [Build using CMake](https://arthursonzogni.com/FTXUI/doc/#build-using-cmake) - [Build using nxxm](https://arthursonzogni.com/FTXUI/doc/#build-using-cmake) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index ff779c0..41e3207 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,3 +1,14 @@ add_subdirectory(component) add_subdirectory(dom) add_subdirectory(util) + +if (EMSCRIPTEN) + foreach(file + "index.html" + "run_webassembly.sh") + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/${file} + ${CMAKE_CURRENT_BINARY_DIR}/${file} + ) + endforeach(file) +endif() diff --git a/examples/dom/border.cpp b/examples/dom/border.cpp index 7a49f3e..57fa7b3 100644 --- a/examples/dom/border.cpp +++ b/examples/dom/border.cpp @@ -28,7 +28,7 @@ int main(int argc, const char* argv[]) { }); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document); - std::cout << screen.ToString() << std::endl; + screen.Print(); } // Copyright 2020 Arthur Sonzogni. All rights reserved. diff --git a/examples/dom/color_gallery.cpp b/examples/dom/color_gallery.cpp index db1c25b..0775ad1 100644 --- a/examples/dom/color_gallery.cpp +++ b/examples/dom/color_gallery.cpp @@ -126,7 +126,7 @@ int main(int argc, const char* argv[]) { auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document); - std::cout << screen.ToString(); + screen.Print(); return 0; } diff --git a/examples/dom/color_info_palette256.cpp b/examples/dom/color_info_palette256.cpp index 56820f3..68a1d18 100644 --- a/examples/dom/color_info_palette256.cpp +++ b/examples/dom/color_info_palette256.cpp @@ -30,7 +30,7 @@ int main(int argc, const char* argv[]) { auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document); - std::cout << screen.ToString(); + screen.Print(); return 0; } diff --git a/examples/dom/color_truecolor_HSV.cpp b/examples/dom/color_truecolor_HSV.cpp index 887f27c..ad902bb 100644 --- a/examples/dom/color_truecolor_HSV.cpp +++ b/examples/dom/color_truecolor_HSV.cpp @@ -26,7 +26,7 @@ int main(int argc, const char* argv[]) { auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document); - std::cout << screen.ToString(); + screen.Print(); return 0; } diff --git a/examples/dom/color_truecolor_RGB.cpp b/examples/dom/color_truecolor_RGB.cpp index ed1495b..d35788e 100644 --- a/examples/dom/color_truecolor_RGB.cpp +++ b/examples/dom/color_truecolor_RGB.cpp @@ -45,7 +45,7 @@ int main(int argc, const char* argv[]) { auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document); - std::cout << screen.ToString(); + screen.Print(); return 0; } diff --git a/examples/dom/dbox.cpp b/examples/dom/dbox.cpp index 67561ef..2fc712c 100644 --- a/examples/dom/dbox.cpp +++ b/examples/dom/dbox.cpp @@ -17,7 +17,7 @@ int main(int argc, const char* argv[]) { auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document); - std::cout << screen.ToString(); + screen.Print(); return 0; } diff --git a/examples/dom/gauge.cpp b/examples/dom/gauge.cpp index 2d7ecd3..eb2a96d 100644 --- a/examples/dom/gauge.cpp +++ b/examples/dom/gauge.cpp @@ -19,7 +19,8 @@ int main(int argc, const char* argv[]) { }); auto screen = Screen(100, 1); Render(screen, document); - std::cout << reset_position << screen.ToString() << std::flush; + std::cout << reset_position; + screen.Print(); reset_position = screen.ResetPosition(); std::this_thread::sleep_for(0.01s); diff --git a/examples/dom/graph.cpp b/examples/dom/graph.cpp index dbf7f1e..78c8f46 100644 --- a/examples/dom/graph.cpp +++ b/examples/dom/graph.cpp @@ -60,8 +60,8 @@ int main(int argc, const char* argv[]) { auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document); - std::cout << reset_position << screen.ToString() << std::flush; - + std::cout << reset_position; + screen.Print(); reset_position = screen.ResetPosition(); std::this_thread::sleep_for(0.03s); diff --git a/examples/dom/hflow.cpp b/examples/dom/hflow.cpp index ef6beb2..aa140a6 100644 --- a/examples/dom/hflow.cpp +++ b/examples/dom/hflow.cpp @@ -39,7 +39,7 @@ int main(int argc, const char* argv[]) { auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document); - std::cout << screen.ToString() << std::endl; + screen.Print(); return 0; } diff --git a/examples/dom/html_like.cpp b/examples/dom/html_like.cpp index 6485cf1..be565e8 100644 --- a/examples/dom/html_like.cpp +++ b/examples/dom/html_like.cpp @@ -41,8 +41,8 @@ int main(int argc, const char* argv[]) { auto screen = Screen::Create(Dimension::Full()); Render(screen, document); - std::cout << reset_position << screen.ToString() << std::flush; - + std::cout << reset_position; + screen.Print(); reset_position = screen.ResetPosition(); std::this_thread::sleep_for(0.01s); diff --git a/examples/dom/package_manager.cpp b/examples/dom/package_manager.cpp index 3875945..11cbd5f 100644 --- a/examples/dom/package_manager.cpp +++ b/examples/dom/package_manager.cpp @@ -123,7 +123,8 @@ int main(int argc, const char* argv[]) { auto document = render(); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document); - std::cout << reset_position << screen.ToString() << std::flush; + std::cout << reset_position; + screen.Print(); reset_position = screen.ResetPosition(); // Simulate time. diff --git a/examples/dom/paragraph.cpp b/examples/dom/paragraph.cpp index 7ed3d14..adb1f38 100644 --- a/examples/dom/paragraph.cpp +++ b/examples/dom/paragraph.cpp @@ -25,7 +25,7 @@ int main(int argc, const char* argv[]) { auto screen = Screen::Create(Dimension::Full(), Dimension::Full()); Render(screen, document); - std::cout << screen.ToString(); + screen.Print(); getchar(); return 0; diff --git a/examples/dom/separator.cpp b/examples/dom/separator.cpp index e575868..f3bf1a3 100644 --- a/examples/dom/separator.cpp +++ b/examples/dom/separator.cpp @@ -18,8 +18,7 @@ int main(int argc, const char* argv[]) { border; auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document); - - std::cout << screen.ToString() << std::endl; + screen.Print(); return 0; } diff --git a/examples/dom/size.cpp b/examples/dom/size.cpp index 392c62e..dfeea1d 100644 --- a/examples/dom/size.cpp +++ b/examples/dom/size.cpp @@ -18,7 +18,7 @@ int main(int argc, const char* argv[]) { auto document = hbox(std::move(content)); auto screen = Screen::Create(Dimension::Fit(document)); Render(screen, document); - std::cout << screen.ToString() << std::endl; + screen.Print(); return 0; } diff --git a/examples/dom/spinner.cpp b/examples/dom/spinner.cpp index 52cfe87..7fff889 100644 --- a/examples/dom/spinner.cpp +++ b/examples/dom/spinner.cpp @@ -28,7 +28,8 @@ int main(int argc, const char* argv[]) { }); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document); - std::cout << reset_position << screen.ToString() << std::flush; + std::cout << reset_position; + screen.Print(); reset_position = screen.ResetPosition(); std::this_thread::sleep_for(0.1s); diff --git a/examples/dom/style_blink.cpp b/examples/dom/style_blink.cpp index 0445add..114a0d4 100644 --- a/examples/dom/style_blink.cpp +++ b/examples/dom/style_blink.cpp @@ -12,8 +12,7 @@ int main(int argc, const char* argv[]) { }); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document); - - std::cout << screen.ToString(); + screen.Print(); return 0; } diff --git a/examples/dom/style_bold.cpp b/examples/dom/style_bold.cpp index 89cb641..e395d78 100644 --- a/examples/dom/style_bold.cpp +++ b/examples/dom/style_bold.cpp @@ -12,8 +12,7 @@ int main(int argc, const char* argv[]) { }); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document); - - std::cout << screen.ToString(); + screen.Print(); return 0; } diff --git a/examples/dom/style_color.cpp b/examples/dom/style_color.cpp index 5c4ec50..f50fddb 100644 --- a/examples/dom/style_color.cpp +++ b/examples/dom/style_color.cpp @@ -51,8 +51,7 @@ int main(int argc, const char* argv[]) { auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document); - - std::cout << screen.ToString(); + screen.Print(); return 0; } diff --git a/examples/dom/style_dim.cpp b/examples/dom/style_dim.cpp index 53823a2..1c4d446 100644 --- a/examples/dom/style_dim.cpp +++ b/examples/dom/style_dim.cpp @@ -12,8 +12,7 @@ int main(int argc, const char* argv[]) { }); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document); - - std::cout << screen.ToString(); + screen.Print(); return 0; } diff --git a/examples/dom/style_gallery.cpp b/examples/dom/style_gallery.cpp index a180789..0ce864f 100644 --- a/examples/dom/style_gallery.cpp +++ b/examples/dom/style_gallery.cpp @@ -19,8 +19,7 @@ int main(int argc, const char* argv[]) { // clang-format on auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document); - - std::cout << screen.ToString(); + screen.Print(); return 0; } diff --git a/examples/dom/style_inverted.cpp b/examples/dom/style_inverted.cpp index ad930ab..9a19181 100644 --- a/examples/dom/style_inverted.cpp +++ b/examples/dom/style_inverted.cpp @@ -11,8 +11,7 @@ int main(int argc, const char* argv[]) { }); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document); - - std::cout << screen.ToString(); + screen.Print(); return 0; } diff --git a/examples/dom/style_underlined.cpp b/examples/dom/style_underlined.cpp index 41c5fd4..dedf04a 100644 --- a/examples/dom/style_underlined.cpp +++ b/examples/dom/style_underlined.cpp @@ -12,8 +12,7 @@ int main(int argc, const char* argv[]) { }); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document); - - std::cout << screen.ToString(); + screen.Print(); return 0; } diff --git a/examples/dom/vbox_hbox.cpp b/examples/dom/vbox_hbox.cpp index 93bb984..92d23cd 100644 --- a/examples/dom/vbox_hbox.cpp +++ b/examples/dom/vbox_hbox.cpp @@ -26,8 +26,7 @@ int main(int argc, const char* argv[]) { }); auto screen = Screen::Create(Dimension::Full()); Render(screen, document); - - std::cout << screen.ToString(); + screen.Print(); getchar(); return 0; diff --git a/examples/dom/window.cpp b/examples/dom/window.cpp index 18726da..df84561 100644 --- a/examples/dom/window.cpp +++ b/examples/dom/window.cpp @@ -16,7 +16,7 @@ int main(void) { auto screen = Screen::Create(Dimension::Fixed(80), Dimension::Fixed(10)); Render(screen, document); - std::cout << screen.ToString() << '\n'; + screen.Print(); } // Copyright 2020 Arthur Sonzogni. All rights reserved. diff --git a/examples/index.html b/examples/index.html new file mode 100644 index 0000000..fde820a --- /dev/null +++ b/examples/index.html @@ -0,0 +1,164 @@ + +
+ ++ FTXUI is a single + C++ library for terminal user interface. +
++ On this page, you can try all the examples contained in: ./example/ + Those are compiled using WebAssembly. +
+ + +