mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-22 18:59:59 +08:00
parent
2eddd0fa17
commit
ef0de8d873
112
CMakeLists.txt
112
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
|
||||
$<INSTALL_INTERFACE:include>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
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)
|
||||
|
51
README.md
51
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 <iostream>
|
||||
|
||||
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)
|
||||
|
@ -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)
|
||||
|
85
examples/html/test.html
Normal file
85
examples/html/test.html
Normal file
@ -0,0 +1,85 @@
|
||||
<!doctype html>
|
||||
<html lang="en_US">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
||||
|
||||
<style>
|
||||
html, body, textarea{
|
||||
margin:0;
|
||||
padding:0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow:hidden;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color:gray;
|
||||
};
|
||||
|
||||
textarea {
|
||||
white-space: pre-wrap;
|
||||
background-color:white;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script type="text/c++">
|
||||
#include <iostream>
|
||||
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto document =
|
||||
hbox(
|
||||
window(text(L" main frame ") | hcenter,
|
||||
vbox(
|
||||
text(L"Line 1"),
|
||||
text(L"Line 2"),
|
||||
text(L"Line 3"),
|
||||
vbox(
|
||||
text(L"Line 4"),
|
||||
text(L"Line 5"),
|
||||
text(L"Line 6")
|
||||
) | border,
|
||||
hbox(
|
||||
window(text(L"frame 2"),
|
||||
vbox(
|
||||
text(L"Line 4"),
|
||||
gauge(0.5) | border,
|
||||
text(L"Line 6")
|
||||
)
|
||||
),
|
||||
window(text(L"frame 3"),
|
||||
vbox(
|
||||
text(L"Line 7"),
|
||||
text(L"Line 8"),
|
||||
text(L"Line 9")
|
||||
)
|
||||
)
|
||||
),
|
||||
text(L"footer footer footer footer footer")
|
||||
)
|
||||
),
|
||||
filler()
|
||||
);
|
||||
auto screen = Screen::Create(Dimension::Fit(document));
|
||||
Render(screen, document.get());
|
||||
std::cout << screen.ToString() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<textarea id="box"></textarea>
|
||||
</body>
|
||||
<script>
|
||||
window.Module = {
|
||||
'print': function(text) {
|
||||
console.log(text);
|
||||
document.getElementById("box").value += text + '\n';
|
||||
}
|
||||
};
|
||||
</script>
|
||||
</html>
|
6
examples/util/CMakeLists.txt
Normal file
6
examples/util/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
||||
function(example name)
|
||||
add_executable(${name} ${name}.cpp)
|
||||
target_link_libraries(${name} PUBLIC component)
|
||||
endfunction(example)
|
||||
|
||||
example(print_key_press)
|
@ -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
|
||||
$<INSTALL_INTERFACE:include>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
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()
|
@ -3,7 +3,7 @@
|
||||
namespace ftxui {
|
||||
|
||||
Element nothing(Element element) {
|
||||
return std::move(element);
|
||||
return element;
|
||||
}
|
||||
|
||||
Decorator compose(Decorator a, Decorator b) {
|
@ -1,5 +1,5 @@
|
||||
#include "ftxui/screen/box.hpp"
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
|
||||
namespace ftxui {
|
||||
// static
|
@ -1,3 +1,4 @@
|
||||
#include <iostream>
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
@ -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
|
52
tutorial/build-with-cmake.md
Normal file
52
tutorial/build-with-cmake.md
Normal file
@ -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 <iostream>
|
||||
|
||||
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
|
||||
~~~
|
39
tutorial/build-with-nxxm.md
Normal file
39
tutorial/build-with-nxxm.md
Normal file
@ -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 <iostream>
|
||||
|
||||
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
|
||||
~~~
|
@ -6,8 +6,7 @@
|
||||
* [Widget.](#widget)
|
||||
+ [text](#text)
|
||||
+ [border](#border)
|
||||
+ [separator](#separator)
|
||||
+ [gauge](#gauge)
|
||||
+ [separator](#separator) [gauge](#gauge)
|
||||
* [Decorator](#decorator)
|
||||
- [Components.](#components)
|
||||
* [Input](#input)
|
Loading…
Reference in New Issue
Block a user