diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b79896..d4f3c66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,5 +6,115 @@ project(ftxui enable_testing() -add_subdirectory(ftxui) +cmake_minimum_required(VERSION 3.0) +find_package(Threads) + +add_library(screen + src/ftxui/screen/box.cpp + src/ftxui/screen/screen.cpp + src/ftxui/screen/string.cpp + src/ftxui/screen/terminal.cpp +) + +add_library(dom + src/ftxui/dom/blink.cpp + src/ftxui/dom/bold.cpp + src/ftxui/dom/border.cpp + src/ftxui/dom/color.cpp + src/ftxui/dom/composite_decorator.cpp + src/ftxui/dom/dbox.cpp + src/ftxui/dom/dim.cpp + src/ftxui/dom/flex.cpp + src/ftxui/dom/frame.cpp + src/ftxui/dom/gauge.cpp + src/ftxui/dom/graph.cpp + src/ftxui/dom/hbox.cpp + src/ftxui/dom/hflow.cpp + src/ftxui/dom/inverted.cpp + src/ftxui/dom/node.cpp + src/ftxui/dom/node_decorator.cpp + src/ftxui/dom/paragraph.cpp + src/ftxui/dom/separator.cpp + src/ftxui/dom/size.cpp + src/ftxui/dom/spinner.cpp + src/ftxui/dom/text.cpp + src/ftxui/dom/underlined.cpp + src/ftxui/dom/util.cpp + src/ftxui/dom/vbox.cpp +) + +add_library(component + src/ftxui/component/checkbox.cpp + src/ftxui/component/component.cpp + src/ftxui/component/container.cpp + src/ftxui/component/event.cpp + src/ftxui/component/input.cpp + src/ftxui/component/menu.cpp + src/ftxui/component/radiobox.cpp + src/ftxui/component/screen_interactive.cpp + src/ftxui/component/toggle.cpp +) + +target_link_libraries(dom PUBLIC screen) +target_link_libraries(component PUBLIC dom) +target_link_libraries(component PUBLIC Threads::Threads) + +foreach(lib screen dom component) + target_include_directories(${lib} + PUBLIC + $ + $ + PRIVATE src + ) + target_compile_features(${lib} PUBLIC cxx_std_17) + target_compile_options(${lib} PRIVATE -Wall) +endforeach() + +include(GNUInstallDirs) +install(TARGETS screen dom component + EXPORT ftxui-export + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/ftxui/ + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/ftxui/ +) + +install(DIRECTORY include/ftxui DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + ftxui-config.cmake + VERSION ${PACKAGE_VERSION} + COMPATIBILITY AnyNewerVersion +) + +install(EXPORT ftxui-export + FILE ftxui-targets.cmake + NAMESPACE ftxui:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ftxui +) + +# Note: For gtest, please follow: +# https://stackoverflow.com/questions/24295876/cmake-cannot-find-a-googletest-required-library +find_package(GTest) +if (GTEST_FOUND AND THREADS_FOUND) + add_executable(dom_tests + tests/gauge_test.cpp + tests/hbox_test.cpp + tests/text_test.cpp + tests/vbox_test.cpp + ) + + target_link_libraries(dom_tests + PRIVATE dom + PRIVATE Threads::Threads + PRIVATE ${GTEST_BOTH_LIBRARIES} + ) + + target_include_directories(dom_tests + PRIVATE ${GTest_INCLUDE_DIRS} + ) + gtest_discover_tests(dom_tests) + add_test(dom_tests dom_tests) + +endif() + add_subdirectory(examples) diff --git a/README.md b/README.md index b0478d8..fff8f15 100644 --- a/README.md +++ b/README.md @@ -35,56 +35,17 @@ A simple C++ library for terminal based user interface. └────────────────────────────────────────────────────────────────────────────┘ ~~~ +## Build + +* With [CMake](https://cmake.org) : See [Instructions](./tutorial/build-with-cmake.md) +* With [nxxm](https://nxxm.github.io) :See [Instructions](./tutorial/build-with-nxxm.md) + ## Tutorial -See [Tutorial](./tutorial.md) +See [Tutorial](./tutorial/tutorial.md) ## Project using FTXUI - None! This is still a newborn project. Please add a link to your project here. -## Build using CMake -~~~bash -mkdir build && cd build -cmake .. -make -sudo make install -~~~ - -## Use library using CMake - -CMakeLists.txt -~~~cmake -cmake_minimum_required(VERSION 3.0) - -find_package(ftxui REQUIRED) -add_executable(main main.cpp) -target_link_libraries(main PUBLIC ftxui::dom) -~~~ - -main.cpp -~~~cpp -#include "ftxui/screen/screen.hpp" -#include "ftxui/dom/elements.hpp" -#include - -int main(int argc, const char *argv[]) -{ - using namespace ftxui; - auto document = - hbox( - text(L"left") | bold, - text(L"middle") | flex, - text(L"right") - ), - auto screen = Screen::Create(Dimension::Full, Dimension::Fit(document)); - Render(screen, document.get()); - - std::cout << screen.ToString(); - - return 0; -} -~~~ - ## Hosted on: * [github](https://github.com/ArthurSonzogni/ftxui) * [gitlab](https://gitlab.com/ArthurSonzogni/ftxui) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index ded04f0..ff779c0 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,7 +1,3 @@ -cmake_minimum_required(VERSION 3.0) - add_subdirectory(component) add_subdirectory(dom) - -add_executable(print_key_press print_key_press.cpp) -target_link_libraries(print_key_press PUBLIC component) +add_subdirectory(util) diff --git a/examples/html/test.html b/examples/html/test.html new file mode 100644 index 0000000..3ecf075 --- /dev/null +++ b/examples/html/test.html @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + diff --git a/examples/util/CMakeLists.txt b/examples/util/CMakeLists.txt new file mode 100644 index 0000000..7b2db4f --- /dev/null +++ b/examples/util/CMakeLists.txt @@ -0,0 +1,6 @@ +function(example name) + add_executable(${name} ${name}.cpp) + target_link_libraries(${name} PUBLIC component) +endfunction(example) + +example(print_key_press) diff --git a/examples/print_key_press.cpp b/examples/util/print_key_press.cpp similarity index 100% rename from examples/print_key_press.cpp rename to examples/util/print_key_press.cpp diff --git a/ftxui/CMakeLists.txt b/ftxui/CMakeLists.txt deleted file mode 100644 index bdbe098..0000000 --- a/ftxui/CMakeLists.txt +++ /dev/null @@ -1,110 +0,0 @@ -cmake_minimum_required(VERSION 3.0) -find_package(Threads) - -add_library(screen - src/ftxui/screen/box.cpp - src/ftxui/screen/screen.cpp - src/ftxui/screen/string.cpp - src/ftxui/screen/terminal.cpp -) - -add_library(dom - src/ftxui/dom/blink.cpp - src/ftxui/dom/bold.cpp - src/ftxui/dom/border.cpp - src/ftxui/dom/color.cpp - src/ftxui/dom/composite_decorator.cpp - src/ftxui/dom/dbox.cpp - src/ftxui/dom/dim.cpp - src/ftxui/dom/flex.cpp - src/ftxui/dom/frame.cpp - src/ftxui/dom/gauge.cpp - src/ftxui/dom/graph.cpp - src/ftxui/dom/hbox.cpp - src/ftxui/dom/hflow.cpp - src/ftxui/dom/inverted.cpp - src/ftxui/dom/node.cpp - src/ftxui/dom/node_decorator.cpp - src/ftxui/dom/paragraph.cpp - src/ftxui/dom/separator.cpp - src/ftxui/dom/size.cpp - src/ftxui/dom/spinner.cpp - src/ftxui/dom/text.cpp - src/ftxui/dom/underlined.cpp - src/ftxui/dom/util.cpp - src/ftxui/dom/vbox.cpp -) - -add_library(component - src/ftxui/component/checkbox.cpp - src/ftxui/component/component.cpp - src/ftxui/component/container.cpp - src/ftxui/component/event.cpp - src/ftxui/component/input.cpp - src/ftxui/component/menu.cpp - src/ftxui/component/radiobox.cpp - src/ftxui/component/screen_interactive.cpp - src/ftxui/component/toggle.cpp -) - -target_link_libraries(dom PUBLIC screen) -target_link_libraries(component PUBLIC dom) -target_link_libraries(component PUBLIC Threads::Threads) - -foreach(lib screen dom component) - target_include_directories(${lib} - PUBLIC - $ - $ - PRIVATE src - ) - target_compile_features(${lib} PUBLIC cxx_std_17) - target_compile_options(${lib} PRIVATE -Wall) -endforeach() - -include(GNUInstallDirs) -install(TARGETS screen dom component - EXPORT ftxui-export - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/ftxui/ - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/ftxui/ -) - -install(DIRECTORY include/ftxui DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) - -include(CMakePackageConfigHelpers) -write_basic_package_version_file( - ftxui-config.cmake - VERSION ${PACKAGE_VERSION} - COMPATIBILITY AnyNewerVersion -) - -install(EXPORT ftxui-export - FILE ftxui-targets.cmake - NAMESPACE ftxui:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ftxui -) - -# Note: For gtest, please follow: -# https://stackoverflow.com/questions/24295876/cmake-cannot-find-a-googletest-required-library -find_package(GTest) -if (GTEST_FOUND AND THREADS_FOUND) - add_executable(dom_tests - src/ftxui/dom/gauge_test.cpp - src/ftxui/dom/hbox_test.cpp - src/ftxui/dom/text_test.cpp - src/ftxui/dom/vbox_test.cpp - ) - - target_link_libraries(dom_tests - PRIVATE dom - PRIVATE Threads::Threads - PRIVATE ${GTEST_BOTH_LIBRARIES} - ) - - target_include_directories(dom_tests - PRIVATE ${GTest_INCLUDE_DIRS} - ) - gtest_discover_tests(dom_tests) - add_test(dom_tests dom_tests) - -endif() diff --git a/ftxui/include/ftxui/README.md b/include/ftxui/README.md similarity index 100% rename from ftxui/include/ftxui/README.md rename to include/ftxui/README.md diff --git a/ftxui/include/ftxui/component/checkbox.hpp b/include/ftxui/component/checkbox.hpp similarity index 100% rename from ftxui/include/ftxui/component/checkbox.hpp rename to include/ftxui/component/checkbox.hpp diff --git a/ftxui/include/ftxui/component/component.hpp b/include/ftxui/component/component.hpp similarity index 100% rename from ftxui/include/ftxui/component/component.hpp rename to include/ftxui/component/component.hpp diff --git a/ftxui/include/ftxui/component/container.hpp b/include/ftxui/component/container.hpp similarity index 100% rename from ftxui/include/ftxui/component/container.hpp rename to include/ftxui/component/container.hpp diff --git a/ftxui/include/ftxui/component/event.hpp b/include/ftxui/component/event.hpp similarity index 100% rename from ftxui/include/ftxui/component/event.hpp rename to include/ftxui/component/event.hpp diff --git a/ftxui/include/ftxui/component/input.hpp b/include/ftxui/component/input.hpp similarity index 100% rename from ftxui/include/ftxui/component/input.hpp rename to include/ftxui/component/input.hpp diff --git a/ftxui/include/ftxui/component/menu.hpp b/include/ftxui/component/menu.hpp similarity index 100% rename from ftxui/include/ftxui/component/menu.hpp rename to include/ftxui/component/menu.hpp diff --git a/ftxui/include/ftxui/component/radiobox.hpp b/include/ftxui/component/radiobox.hpp similarity index 100% rename from ftxui/include/ftxui/component/radiobox.hpp rename to include/ftxui/component/radiobox.hpp diff --git a/ftxui/include/ftxui/component/screen_interactive.hpp b/include/ftxui/component/screen_interactive.hpp similarity index 100% rename from ftxui/include/ftxui/component/screen_interactive.hpp rename to include/ftxui/component/screen_interactive.hpp diff --git a/ftxui/include/ftxui/component/toggle.hpp b/include/ftxui/component/toggle.hpp similarity index 100% rename from ftxui/include/ftxui/component/toggle.hpp rename to include/ftxui/component/toggle.hpp diff --git a/ftxui/include/ftxui/dom/elements.hpp b/include/ftxui/dom/elements.hpp similarity index 100% rename from ftxui/include/ftxui/dom/elements.hpp rename to include/ftxui/dom/elements.hpp diff --git a/ftxui/include/ftxui/dom/node.hpp b/include/ftxui/dom/node.hpp similarity index 100% rename from ftxui/include/ftxui/dom/node.hpp rename to include/ftxui/dom/node.hpp diff --git a/ftxui/include/ftxui/dom/requirement.hpp b/include/ftxui/dom/requirement.hpp similarity index 100% rename from ftxui/include/ftxui/dom/requirement.hpp rename to include/ftxui/dom/requirement.hpp diff --git a/ftxui/include/ftxui/dom/take_any_args.hpp b/include/ftxui/dom/take_any_args.hpp similarity index 100% rename from ftxui/include/ftxui/dom/take_any_args.hpp rename to include/ftxui/dom/take_any_args.hpp diff --git a/ftxui/include/ftxui/screen/box.hpp b/include/ftxui/screen/box.hpp similarity index 100% rename from ftxui/include/ftxui/screen/box.hpp rename to include/ftxui/screen/box.hpp diff --git a/ftxui/include/ftxui/screen/color.hpp b/include/ftxui/screen/color.hpp similarity index 100% rename from ftxui/include/ftxui/screen/color.hpp rename to include/ftxui/screen/color.hpp diff --git a/ftxui/include/ftxui/screen/screen.hpp b/include/ftxui/screen/screen.hpp similarity index 100% rename from ftxui/include/ftxui/screen/screen.hpp rename to include/ftxui/screen/screen.hpp diff --git a/ftxui/include/ftxui/screen/string.hpp b/include/ftxui/screen/string.hpp similarity index 100% rename from ftxui/include/ftxui/screen/string.hpp rename to include/ftxui/screen/string.hpp diff --git a/ftxui/include/ftxui/util/autoreset.hpp b/include/ftxui/util/autoreset.hpp similarity index 100% rename from ftxui/include/ftxui/util/autoreset.hpp rename to include/ftxui/util/autoreset.hpp diff --git a/ftxui/src/ftxui/component/checkbox.cpp b/src/ftxui/component/checkbox.cpp similarity index 100% rename from ftxui/src/ftxui/component/checkbox.cpp rename to src/ftxui/component/checkbox.cpp diff --git a/ftxui/src/ftxui/component/component.cpp b/src/ftxui/component/component.cpp similarity index 100% rename from ftxui/src/ftxui/component/component.cpp rename to src/ftxui/component/component.cpp diff --git a/ftxui/src/ftxui/component/container.cpp b/src/ftxui/component/container.cpp similarity index 100% rename from ftxui/src/ftxui/component/container.cpp rename to src/ftxui/component/container.cpp diff --git a/ftxui/src/ftxui/component/event.cpp b/src/ftxui/component/event.cpp similarity index 100% rename from ftxui/src/ftxui/component/event.cpp rename to src/ftxui/component/event.cpp diff --git a/ftxui/src/ftxui/component/input.cpp b/src/ftxui/component/input.cpp similarity index 100% rename from ftxui/src/ftxui/component/input.cpp rename to src/ftxui/component/input.cpp diff --git a/ftxui/src/ftxui/component/menu.cpp b/src/ftxui/component/menu.cpp similarity index 100% rename from ftxui/src/ftxui/component/menu.cpp rename to src/ftxui/component/menu.cpp diff --git a/ftxui/src/ftxui/component/radiobox.cpp b/src/ftxui/component/radiobox.cpp similarity index 100% rename from ftxui/src/ftxui/component/radiobox.cpp rename to src/ftxui/component/radiobox.cpp diff --git a/ftxui/src/ftxui/component/screen_interactive.cpp b/src/ftxui/component/screen_interactive.cpp similarity index 100% rename from ftxui/src/ftxui/component/screen_interactive.cpp rename to src/ftxui/component/screen_interactive.cpp diff --git a/ftxui/src/ftxui/component/toggle.cpp b/src/ftxui/component/toggle.cpp similarity index 100% rename from ftxui/src/ftxui/component/toggle.cpp rename to src/ftxui/component/toggle.cpp diff --git a/ftxui/src/ftxui/dom/blink.cpp b/src/ftxui/dom/blink.cpp similarity index 100% rename from ftxui/src/ftxui/dom/blink.cpp rename to src/ftxui/dom/blink.cpp diff --git a/ftxui/src/ftxui/dom/bold.cpp b/src/ftxui/dom/bold.cpp similarity index 100% rename from ftxui/src/ftxui/dom/bold.cpp rename to src/ftxui/dom/bold.cpp diff --git a/ftxui/src/ftxui/dom/border.cpp b/src/ftxui/dom/border.cpp similarity index 100% rename from ftxui/src/ftxui/dom/border.cpp rename to src/ftxui/dom/border.cpp diff --git a/ftxui/src/ftxui/dom/color.cpp b/src/ftxui/dom/color.cpp similarity index 100% rename from ftxui/src/ftxui/dom/color.cpp rename to src/ftxui/dom/color.cpp diff --git a/ftxui/src/ftxui/dom/composite_decorator.cpp b/src/ftxui/dom/composite_decorator.cpp similarity index 100% rename from ftxui/src/ftxui/dom/composite_decorator.cpp rename to src/ftxui/dom/composite_decorator.cpp diff --git a/ftxui/src/ftxui/dom/dbox.cpp b/src/ftxui/dom/dbox.cpp similarity index 100% rename from ftxui/src/ftxui/dom/dbox.cpp rename to src/ftxui/dom/dbox.cpp diff --git a/ftxui/src/ftxui/dom/dim.cpp b/src/ftxui/dom/dim.cpp similarity index 100% rename from ftxui/src/ftxui/dom/dim.cpp rename to src/ftxui/dom/dim.cpp diff --git a/ftxui/src/ftxui/dom/flex.cpp b/src/ftxui/dom/flex.cpp similarity index 100% rename from ftxui/src/ftxui/dom/flex.cpp rename to src/ftxui/dom/flex.cpp diff --git a/ftxui/src/ftxui/dom/frame.cpp b/src/ftxui/dom/frame.cpp similarity index 100% rename from ftxui/src/ftxui/dom/frame.cpp rename to src/ftxui/dom/frame.cpp diff --git a/ftxui/src/ftxui/dom/gauge.cpp b/src/ftxui/dom/gauge.cpp similarity index 100% rename from ftxui/src/ftxui/dom/gauge.cpp rename to src/ftxui/dom/gauge.cpp diff --git a/ftxui/src/ftxui/dom/graph.cpp b/src/ftxui/dom/graph.cpp similarity index 100% rename from ftxui/src/ftxui/dom/graph.cpp rename to src/ftxui/dom/graph.cpp diff --git a/ftxui/src/ftxui/dom/hbox.cpp b/src/ftxui/dom/hbox.cpp similarity index 100% rename from ftxui/src/ftxui/dom/hbox.cpp rename to src/ftxui/dom/hbox.cpp diff --git a/ftxui/src/ftxui/dom/hflow.cpp b/src/ftxui/dom/hflow.cpp similarity index 100% rename from ftxui/src/ftxui/dom/hflow.cpp rename to src/ftxui/dom/hflow.cpp diff --git a/ftxui/src/ftxui/dom/inverted.cpp b/src/ftxui/dom/inverted.cpp similarity index 100% rename from ftxui/src/ftxui/dom/inverted.cpp rename to src/ftxui/dom/inverted.cpp diff --git a/ftxui/src/ftxui/dom/node.cpp b/src/ftxui/dom/node.cpp similarity index 100% rename from ftxui/src/ftxui/dom/node.cpp rename to src/ftxui/dom/node.cpp diff --git a/ftxui/src/ftxui/dom/node_decorator.cpp b/src/ftxui/dom/node_decorator.cpp similarity index 100% rename from ftxui/src/ftxui/dom/node_decorator.cpp rename to src/ftxui/dom/node_decorator.cpp diff --git a/ftxui/src/ftxui/dom/node_decorator.hpp b/src/ftxui/dom/node_decorator.hpp similarity index 100% rename from ftxui/src/ftxui/dom/node_decorator.hpp rename to src/ftxui/dom/node_decorator.hpp diff --git a/ftxui/src/ftxui/dom/paragraph.cpp b/src/ftxui/dom/paragraph.cpp similarity index 100% rename from ftxui/src/ftxui/dom/paragraph.cpp rename to src/ftxui/dom/paragraph.cpp diff --git a/ftxui/src/ftxui/dom/separator.cpp b/src/ftxui/dom/separator.cpp similarity index 100% rename from ftxui/src/ftxui/dom/separator.cpp rename to src/ftxui/dom/separator.cpp diff --git a/ftxui/src/ftxui/dom/size.cpp b/src/ftxui/dom/size.cpp similarity index 100% rename from ftxui/src/ftxui/dom/size.cpp rename to src/ftxui/dom/size.cpp diff --git a/ftxui/src/ftxui/dom/spinner.cpp b/src/ftxui/dom/spinner.cpp similarity index 100% rename from ftxui/src/ftxui/dom/spinner.cpp rename to src/ftxui/dom/spinner.cpp diff --git a/ftxui/src/ftxui/dom/text.cpp b/src/ftxui/dom/text.cpp similarity index 100% rename from ftxui/src/ftxui/dom/text.cpp rename to src/ftxui/dom/text.cpp diff --git a/ftxui/src/ftxui/dom/underlined.cpp b/src/ftxui/dom/underlined.cpp similarity index 100% rename from ftxui/src/ftxui/dom/underlined.cpp rename to src/ftxui/dom/underlined.cpp diff --git a/ftxui/src/ftxui/dom/util.cpp b/src/ftxui/dom/util.cpp similarity index 95% rename from ftxui/src/ftxui/dom/util.cpp rename to src/ftxui/dom/util.cpp index c125873..05da882 100644 --- a/ftxui/src/ftxui/dom/util.cpp +++ b/src/ftxui/dom/util.cpp @@ -3,7 +3,7 @@ namespace ftxui { Element nothing(Element element) { - return std::move(element); + return element; } Decorator compose(Decorator a, Decorator b) { diff --git a/ftxui/src/ftxui/dom/vbox.cpp b/src/ftxui/dom/vbox.cpp similarity index 100% rename from ftxui/src/ftxui/dom/vbox.cpp rename to src/ftxui/dom/vbox.cpp diff --git a/ftxui/src/ftxui/screen/box.cpp b/src/ftxui/screen/box.cpp similarity index 92% rename from ftxui/src/ftxui/screen/box.cpp rename to src/ftxui/screen/box.cpp index de091f7..6bb6506 100644 --- a/ftxui/src/ftxui/screen/box.cpp +++ b/src/ftxui/screen/box.cpp @@ -1,5 +1,5 @@ #include "ftxui/screen/box.hpp" -#include +#include namespace ftxui { // static diff --git a/ftxui/src/ftxui/screen/screen.cpp b/src/ftxui/screen/screen.cpp similarity index 100% rename from ftxui/src/ftxui/screen/screen.cpp rename to src/ftxui/screen/screen.cpp diff --git a/ftxui/src/ftxui/screen/string.cpp b/src/ftxui/screen/string.cpp similarity index 100% rename from ftxui/src/ftxui/screen/string.cpp rename to src/ftxui/screen/string.cpp diff --git a/ftxui/src/ftxui/screen/terminal.cpp b/src/ftxui/screen/terminal.cpp similarity index 66% rename from ftxui/src/ftxui/screen/terminal.cpp rename to src/ftxui/screen/terminal.cpp index bfc92cf..45f23a8 100644 --- a/ftxui/src/ftxui/screen/terminal.cpp +++ b/src/ftxui/screen/terminal.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -7,9 +8,14 @@ namespace ftxui { Terminal::Dimensions Terminal::Size() { +#ifdef __EMSCRIPTEN__ + return Dimensions{80,43}; +#else winsize w; ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); + std::cerr << w.ws_col << "," << w.ws_row << std::endl; return Dimensions{w.ws_col, w.ws_row}; +#endif } } // namespace ftxui diff --git a/ftxui/src/ftxui/screen/terminal.hpp b/src/ftxui/screen/terminal.hpp similarity index 100% rename from ftxui/src/ftxui/screen/terminal.hpp rename to src/ftxui/screen/terminal.hpp diff --git a/ftxui/src/ftxui/dom/gauge_test.cpp b/tests/gauge_test.cpp similarity index 100% rename from ftxui/src/ftxui/dom/gauge_test.cpp rename to tests/gauge_test.cpp diff --git a/ftxui/src/ftxui/dom/hbox_test.cpp b/tests/hbox_test.cpp similarity index 100% rename from ftxui/src/ftxui/dom/hbox_test.cpp rename to tests/hbox_test.cpp diff --git a/ftxui/src/ftxui/dom/text_test.cpp b/tests/text_test.cpp similarity index 100% rename from ftxui/src/ftxui/dom/text_test.cpp rename to tests/text_test.cpp diff --git a/ftxui/src/ftxui/dom/vbox_test.cpp b/tests/vbox_test.cpp similarity index 100% rename from ftxui/src/ftxui/dom/vbox_test.cpp rename to tests/vbox_test.cpp diff --git a/tutorial/build-with-cmake.md b/tutorial/build-with-cmake.md new file mode 100644 index 0000000..91cf753 --- /dev/null +++ b/tutorial/build-with-cmake.md @@ -0,0 +1,52 @@ +# Build ftxui and install + +~~~bash +mkdir build && cd build +cmake .. +make +sudo make install +~~~ + +# Example project + +main.cpp +~~~cpp +#include "ftxui/screen/screen.hpp" +#include "ftxui/dom/elements.hpp" +#include + +int main(int argc, const char *argv[]) { + using namespace ftxui; + auto document = + hbox( + text(L"left") | bold | border, + text(L"middle") | flex | border, + text(L"right") | border + ); + auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); + Render(screen, document.get()); + + std::cout << screen.ToString(); + + return 0; +} +~~~ + +# Add dependency + +CMakeLists.txt +~~~cmake +cmake_minimum_required(VERSION 3.0) + +find_package(ftxui REQUIRED) +add_executable(main main.cpp) +target_link_libraries(main PUBLIC ftxui::dom) +~~~ + +# Build +~~~ +mkdir build && cd build +cmake .. +make +./main +~~~ diff --git a/tutorial/build-with-nxxm.md b/tutorial/build-with-nxxm.md new file mode 100644 index 0000000..0ce5837 --- /dev/null +++ b/tutorial/build-with-nxxm.md @@ -0,0 +1,39 @@ +# Add dependency + +.nxxm/deps +~~~json +{ + "arthursonzogni/ftxui": {} +} +~~~ + +# Example project + +main.cpp +~~~cpp +#include "ftxui/screen/screen.hpp" +#include "ftxui/dom/elements.hpp" +#include + +int main(int argc, const char *argv[]) { + using namespace ftxui; + auto document = + hbox( + text(L"left") | bold | border, + text(L"middle") | flex | border, + text(L"right") | border + ); + auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); + Render(screen, document.get()); + + std::cout << screen.ToString(); + + return 0; +} +~~~ + +# Build + +~~~ +nxxm . -t clang-cxx17 +~~~ diff --git a/tutorial.md b/tutorial/tutorial.md similarity index 99% rename from tutorial.md rename to tutorial/tutorial.md index 33175c5..3861f74 100644 --- a/tutorial.md +++ b/tutorial/tutorial.md @@ -6,8 +6,7 @@ * [Widget.](#widget) + [text](#text) + [border](#border) - + [separator](#separator) - + [gauge](#gauge) + + [separator](#separator) [gauge](#gauge) * [Decorator](#decorator) - [Components.](#components) * [Input](#input)