mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-12-16 01:48:56 +08:00
Compare commits
46 Commits
HarryPehko
...
d7247002d3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7247002d3 | ||
|
|
6aed3877f6 | ||
|
|
756dd601aa | ||
|
|
33f78dd7a8 | ||
|
|
f1dfc8f2f8 | ||
|
|
9577dfc0b3 | ||
|
|
4898e859d8 | ||
|
|
6a783ce9b5 | ||
|
|
a4a4e20902 | ||
|
|
ce43ba6bea | ||
|
|
7abac6c5f9 | ||
|
|
cdc6a61854 | ||
|
|
118949b295 | ||
|
|
bc3657d62a | ||
|
|
6e7c0cb212 | ||
|
|
2d12c4b3db | ||
|
|
88a9132d75 | ||
|
|
83b83e30ec | ||
|
|
bc45cd6ad5 | ||
|
|
cdf8144bf1 | ||
|
|
ed5f04ccc0 | ||
|
|
4b8c8ea00d | ||
|
|
9e1120c146 | ||
|
|
006ec1cbed | ||
|
|
16c25ae441 | ||
|
|
05b4bffe3b | ||
|
|
ffc6dcd3bf | ||
|
|
f6dceabdc9 | ||
|
|
cb8ebdeb44 | ||
|
|
dd37fba100 | ||
|
|
4d627c1ffb | ||
|
|
1dff6a5c35 | ||
|
|
0c67566427 | ||
|
|
85c3dc45ca | ||
|
|
84f691e9d3 | ||
|
|
2e36aa061a | ||
|
|
8ed06a4812 | ||
|
|
571f6dcdcf | ||
|
|
e57c275512 | ||
|
|
1c37cdd192 | ||
|
|
772d4ebeed | ||
|
|
5f5bc9019d | ||
|
|
f87b6a4d12 | ||
|
|
0d50fa25fe | ||
|
|
730ebeed1d | ||
|
|
69928b374e |
2
.bazelrc
2
.bazelrc
@@ -1,5 +1,3 @@
|
|||||||
common --enable_bzlmod
|
|
||||||
|
|
||||||
build --features=layering_check
|
build --features=layering_check
|
||||||
build --enable_bzlmod
|
build --enable_bzlmod
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,3 @@
|
|||||||
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
|
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
|
||||||
BasedOnStyle: Chromium
|
BasedOnStyle: Chromium
|
||||||
Standard: Cpp11
|
Standard: Cpp11
|
||||||
|
|
||||||
InsertBraces: true
|
|
||||||
InsertNewlineAtEOF: true
|
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -44,7 +44,6 @@ out/
|
|||||||
!doc/**/*.html
|
!doc/**/*.html
|
||||||
!doc/**/*.xml
|
!doc/**/*.xml
|
||||||
!doc/**/*.md
|
!doc/**/*.md
|
||||||
!doc/*.md
|
|
||||||
|
|
||||||
# examples directory:
|
# examples directory:
|
||||||
!examples/**/*.cpp
|
!examples/**/*.cpp
|
||||||
|
|||||||
10
BUILD.bazel
10
BUILD.bazel
@@ -13,6 +13,7 @@ load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
|
|||||||
load(":bazel/ftxui.bzl", "ftxui_cc_library")
|
load(":bazel/ftxui.bzl", "ftxui_cc_library")
|
||||||
load(":bazel/ftxui.bzl", "generate_examples")
|
load(":bazel/ftxui.bzl", "generate_examples")
|
||||||
load(":bazel/ftxui.bzl", "windows_copts")
|
load(":bazel/ftxui.bzl", "windows_copts")
|
||||||
|
load(":bazel/ftxui.bzl", "pthread_linkopts")
|
||||||
|
|
||||||
# A meta target depending on all of the ftxui submodules.
|
# A meta target depending on all of the ftxui submodules.
|
||||||
# Note that component depends on dom and screen, so ftxui is just an alias for
|
# Note that component depends on dom and screen, so ftxui is just an alias for
|
||||||
@@ -158,18 +159,11 @@ ftxui_cc_library(
|
|||||||
"src/ftxui/component/resizable_split.cpp",
|
"src/ftxui/component/resizable_split.cpp",
|
||||||
"src/ftxui/component/screen_interactive.cpp",
|
"src/ftxui/component/screen_interactive.cpp",
|
||||||
"src/ftxui/component/slider.cpp",
|
"src/ftxui/component/slider.cpp",
|
||||||
"src/ftxui/component/task.cpp",
|
|
||||||
"src/ftxui/component/task_internal.hpp",
|
|
||||||
"src/ftxui/component/task_queue.cpp",
|
|
||||||
"src/ftxui/component/task_queue.hpp",
|
|
||||||
"src/ftxui/component/task_runner.cpp",
|
|
||||||
"src/ftxui/component/task_runner.hpp",
|
|
||||||
"src/ftxui/component/terminal_input_parser.cpp",
|
"src/ftxui/component/terminal_input_parser.cpp",
|
||||||
"src/ftxui/component/terminal_input_parser.hpp",
|
"src/ftxui/component/terminal_input_parser.hpp",
|
||||||
"src/ftxui/component/util.cpp",
|
"src/ftxui/component/util.cpp",
|
||||||
"src/ftxui/component/window.cpp",
|
"src/ftxui/component/window.cpp",
|
||||||
|
|
||||||
|
|
||||||
# Private header from ftxui:dom.
|
# Private header from ftxui:dom.
|
||||||
"src/ftxui/dom/node_decorator.hpp",
|
"src/ftxui/dom/node_decorator.hpp",
|
||||||
|
|
||||||
@@ -190,6 +184,7 @@ ftxui_cc_library(
|
|||||||
"include/ftxui/component/screen_interactive.hpp",
|
"include/ftxui/component/screen_interactive.hpp",
|
||||||
"include/ftxui/component/task.hpp",
|
"include/ftxui/component/task.hpp",
|
||||||
],
|
],
|
||||||
|
linkopts = pthread_linkopts(),
|
||||||
deps = [
|
deps = [
|
||||||
":dom",
|
":dom",
|
||||||
":screen",
|
":screen",
|
||||||
@@ -212,6 +207,7 @@ cc_test(
|
|||||||
"src/ftxui/component/menu_test.cpp",
|
"src/ftxui/component/menu_test.cpp",
|
||||||
"src/ftxui/component/modal_test.cpp",
|
"src/ftxui/component/modal_test.cpp",
|
||||||
"src/ftxui/component/radiobox_test.cpp",
|
"src/ftxui/component/radiobox_test.cpp",
|
||||||
|
"src/ftxui/component/receiver_test.cpp",
|
||||||
"src/ftxui/component/resizable_split_test.cpp",
|
"src/ftxui/component/resizable_split_test.cpp",
|
||||||
"src/ftxui/component/slider_test.cpp",
|
"src/ftxui/component/slider_test.cpp",
|
||||||
"src/ftxui/component/terminal_input_parser_test.cpp",
|
"src/ftxui/component/terminal_input_parser_test.cpp",
|
||||||
|
|||||||
@@ -24,11 +24,6 @@ Next
|
|||||||
import ftxui.util;
|
import ftxui.util;
|
||||||
```
|
```
|
||||||
Thanks @mikomikotaishi for PR #1015.
|
Thanks @mikomikotaishi for PR #1015.
|
||||||
- Remove dependency on 'pthread'.
|
|
||||||
|
|
||||||
### Component
|
|
||||||
- Fix ScreenInteractive::FixedSize screen stomps on the preceding terminal
|
|
||||||
output. Thanks @zozowell in #1064.
|
|
||||||
|
|
||||||
|
|
||||||
6.1.9 (2025-05-07)
|
6.1.9 (2025-05-07)
|
||||||
|
|||||||
@@ -144,20 +144,26 @@ add_library(component
|
|||||||
src/ftxui/component/resizable_split.cpp
|
src/ftxui/component/resizable_split.cpp
|
||||||
src/ftxui/component/screen_interactive.cpp
|
src/ftxui/component/screen_interactive.cpp
|
||||||
src/ftxui/component/slider.cpp
|
src/ftxui/component/slider.cpp
|
||||||
src/ftxui/component/task.cpp
|
|
||||||
src/ftxui/component/task_internal.hpp
|
|
||||||
src/ftxui/component/task_queue.cpp
|
|
||||||
src/ftxui/component/task_queue.hpp
|
|
||||||
src/ftxui/component/task_runner.cpp
|
|
||||||
src/ftxui/component/task_runner.hpp
|
|
||||||
src/ftxui/component/terminal_input_parser.cpp
|
src/ftxui/component/terminal_input_parser.cpp
|
||||||
src/ftxui/component/terminal_input_parser.hpp
|
src/ftxui/component/terminal_input_parser.hpp
|
||||||
src/ftxui/component/util.cpp
|
src/ftxui/component/util.cpp
|
||||||
src/ftxui/component/window.cpp
|
src/ftxui/component/window.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(dom PUBLIC screen)
|
target_link_libraries(dom
|
||||||
target_link_libraries(component PUBLIC dom)
|
PUBLIC screen
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(component
|
||||||
|
PUBLIC dom
|
||||||
|
)
|
||||||
|
|
||||||
|
if (NOT EMSCRIPTEN)
|
||||||
|
find_package(Threads)
|
||||||
|
target_link_libraries(component
|
||||||
|
PUBLIC Threads::Threads
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
include(cmake/ftxui_set_options.cmake)
|
include(cmake/ftxui_set_options.cmake)
|
||||||
ftxui_set_options(screen)
|
ftxui_set_options(screen)
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -18,7 +18,7 @@
|
|||||||
<br/>
|
<br/>
|
||||||
<a href="https://arthursonzogni.github.io/FTXUI/">Documentation</a> ·
|
<a href="https://arthursonzogni.github.io/FTXUI/">Documentation</a> ·
|
||||||
<a href="https://github.com/ArthurSonzogni/FTXUI/issues">Report a Bug</a> ·
|
<a href="https://github.com/ArthurSonzogni/FTXUI/issues">Report a Bug</a> ·
|
||||||
<a href="https://arthursonzogni.github.io/FTXUI/examples/">Examples</a> .
|
<a href="https://arthursonzogni.github.io/FTXUI/examples.html">Examples</a> .
|
||||||
<a href="https://github.com/ArthurSonzogni/FTXUI/issues">Request Feature</a> ·
|
<a href="https://github.com/ArthurSonzogni/FTXUI/issues">Request Feature</a> ·
|
||||||
<a href="https://github.com/ArthurSonzogni/FTXUI/pulls">Send a Pull Request</a>
|
<a href="https://github.com/ArthurSonzogni/FTXUI/pulls">Send a Pull Request</a>
|
||||||
|
|
||||||
@@ -50,9 +50,8 @@ A simple cross-platform C++ library for terminal based user interfaces!
|
|||||||
- [Conan](https://conan.io/center/recipes/ftxui) [Debian package](https://tracker.debian.org/pkg/ftxui)
|
- [Conan](https://conan.io/center/recipes/ftxui) [Debian package](https://tracker.debian.org/pkg/ftxui)
|
||||||
- [Ubuntu package](https://launchpad.net/ubuntu/+source/ftxui)
|
- [Ubuntu package](https://launchpad.net/ubuntu/+source/ftxui)
|
||||||
- [Arch Linux](https://aur.archlinux.org/packages/ftxui/)
|
- [Arch Linux](https://aur.archlinux.org/packages/ftxui/)
|
||||||
- [OpenSUSE](https://build.opensuse.org/package/show/devel:libraries:c_c++/ftxui)
|
- [OpenSUSE](https://build.opensuse.org/package/show/devel:libraries:c_c++/ftxui)
|
||||||
- [XMake](https://xmake.io) repository [package](https://github.com/xmake-io/xmake-repo/blob/dev/packages/f/ftxui/xmake.lua)
|
- [XMake](https://xmake.io) repository [package](https://github.com/xmake-io/xmake-repo/blob/dev/packages/f/ftxui/xmake.lua)
|
||||||
- [Nix](https://github.com/ArthurSonzogni/FTXUI/blob/main/flake.nix)
|
|
||||||
* Good practices: documentation, tests, fuzzers, performance tests, automated CI, automated packaging, etc...
|
* Good practices: documentation, tests, fuzzers, performance tests, automated CI, automated packaging, etc...
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
@@ -98,7 +97,7 @@ Element can be arranged together:
|
|||||||
- inside a grid with `gridbox`
|
- inside a grid with `gridbox`
|
||||||
- wrap along one direction using the `flexbox`.
|
- wrap along one direction using the `flexbox`.
|
||||||
|
|
||||||
Element can become flexible using the `flex` decorator.
|
Element can become flexible using the the `flex` decorator.
|
||||||
|
|
||||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2dom_2vbox_hbox_8cpp-example.html) using `hbox`, `vbox` and `filler`.
|
[Example](https://arthursonzogni.github.io/FTXUI/examples_2dom_2vbox_hbox_8cpp-example.html) using `hbox`, `vbox` and `filler`.
|
||||||
|
|
||||||
@@ -378,8 +377,6 @@ Several games using the FTXUI have been made during the Game Jam:
|
|||||||
- [smoothlife](https://github.com/cpp-best-practices/game_jam/blob/main/Jam1_April_2022/smoothlife.md)
|
- [smoothlife](https://github.com/cpp-best-practices/game_jam/blob/main/Jam1_April_2022/smoothlife.md)
|
||||||
- [Consu](https://github.com/cpp-best-practices/game_jam/blob/main/Jam1_April_2022/consu.md)
|
- [Consu](https://github.com/cpp-best-practices/game_jam/blob/main/Jam1_April_2022/consu.md)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Build using CMake
|
## Build using CMake
|
||||||
|
|
||||||
It is **highly** recommended to use CMake FetchContent to depend on FTXUI so you may specify which commit you would like to depend on.
|
It is **highly** recommended to use CMake FetchContent to depend on FTXUI so you may specify which commit you would like to depend on.
|
||||||
@@ -433,7 +430,6 @@ If you don't, FTXUI may be used from the following packages:
|
|||||||
- [Ubuntu package](https://launchpad.net/ubuntu/+source/ftxui),
|
- [Ubuntu package](https://launchpad.net/ubuntu/+source/ftxui),
|
||||||
- [Arch Linux](https://aur.archlinux.org/packages/ftxui/),
|
- [Arch Linux](https://aur.archlinux.org/packages/ftxui/),
|
||||||
- [OpenSUSE](https://build.opensuse.org/package/show/devel:libraries:c_c++/ftxui),
|
- [OpenSUSE](https://build.opensuse.org/package/show/devel:libraries:c_c++/ftxui),
|
||||||
[Nix](https://github.com/ArthurSonzogni/FTXUI/blob/main/flake.nix),
|
|
||||||
[](https://repology.org/project/libftxui/versions)
|
[](https://repology.org/project/libftxui/versions)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,16 @@ def windows_copts():
|
|||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def pthread_linkopts():
|
||||||
|
return select({
|
||||||
|
# With MSVC, threading is already built-in (you don't need -pthread.
|
||||||
|
"@rules_cc//cc/compiler:msvc-cl": [],
|
||||||
|
"@rules_cc//cc/compiler:clang-cl": [],
|
||||||
|
"@rules_cc//cc/compiler:clang": ["-pthread"],
|
||||||
|
"@rules_cc//cc/compiler:gcc": ["-pthread"],
|
||||||
|
"//conditions:default": ["-pthread"],
|
||||||
|
})
|
||||||
|
|
||||||
def ftxui_cc_library(
|
def ftxui_cc_library(
|
||||||
name,
|
name,
|
||||||
srcs = [],
|
srcs = [],
|
||||||
|
|||||||
@@ -6,43 +6,42 @@ add_library(ftxui-modules)
|
|||||||
|
|
||||||
target_sources(ftxui-modules
|
target_sources(ftxui-modules
|
||||||
PUBLIC FILE_SET CXX_MODULES FILES
|
PUBLIC FILE_SET CXX_MODULES FILES
|
||||||
src/ftxui/ftxui.cppm
|
|
||||||
src/ftxui/component.cppm
|
src/ftxui/component.cppm
|
||||||
src/ftxui/component/animation.cppm
|
src/ftxui/component/Animation.cppm
|
||||||
src/ftxui/component/captured_mouse.cppm
|
src/ftxui/component/CapturedMouse.cppm
|
||||||
src/ftxui/component/component.cppm
|
src/ftxui/component/Component.cppm
|
||||||
src/ftxui/component/component_base.cppm
|
src/ftxui/component/ComponentBase.cppm
|
||||||
src/ftxui/component/component_options.cppm
|
src/ftxui/component/ComponentOptions.cppm
|
||||||
src/ftxui/component/event.cppm
|
src/ftxui/component/Event.cppm
|
||||||
src/ftxui/component/loop.cppm
|
src/ftxui/component/Loop.cppm
|
||||||
src/ftxui/component/mouse.cppm
|
src/ftxui/component/Mouse.cppm
|
||||||
src/ftxui/component/receiver.cppm
|
src/ftxui/component/Receiver.cppm
|
||||||
src/ftxui/component/screen_interactive.cppm
|
src/ftxui/component/ScreenInteractive.cppm
|
||||||
src/ftxui/component/task.cppm
|
src/ftxui/component/Task.cppm
|
||||||
src/ftxui/dom.cppm
|
src/ftxui/dom.cppm
|
||||||
src/ftxui/dom/canvas.cppm
|
src/ftxui/dom/Canvas.cppm
|
||||||
src/ftxui/dom/deprecated.cppm
|
src/ftxui/dom/Deprecated.cppm
|
||||||
src/ftxui/dom/direction.cppm
|
src/ftxui/dom/Direction.cppm
|
||||||
src/ftxui/dom/elements.cppm
|
src/ftxui/dom/Elements.cppm
|
||||||
src/ftxui/dom/flexbox_config.cppm
|
src/ftxui/dom/FlexboxConfig.cppm
|
||||||
src/ftxui/dom/linear_gradient.cppm
|
src/ftxui/dom/LinearGradient.cppm
|
||||||
src/ftxui/dom/node.cppm
|
src/ftxui/dom/Node.cppm
|
||||||
src/ftxui/dom/requirement.cppm
|
src/ftxui/dom/Requirement.cppm
|
||||||
src/ftxui/dom/selection.cppm
|
src/ftxui/dom/Selection.cppm
|
||||||
src/ftxui/dom/table.cppm
|
src/ftxui/dom/Table.cppm
|
||||||
src/ftxui/screen.cppm
|
src/ftxui/screen.cppm
|
||||||
src/ftxui/screen/box.cppm
|
src/ftxui/screen/Box.cppm
|
||||||
src/ftxui/screen/color.cppm
|
src/ftxui/screen/Color.cppm
|
||||||
src/ftxui/screen/color_info.cppm
|
src/ftxui/screen/ColorInfo.cppm
|
||||||
src/ftxui/screen/deprecated.cppm
|
src/ftxui/screen/Deprecated.cppm
|
||||||
src/ftxui/screen/image.cppm
|
src/ftxui/screen/Image.cppm
|
||||||
src/ftxui/screen/pixel.cppm
|
src/ftxui/screen/Pixel.cppm
|
||||||
src/ftxui/screen/screen.cppm
|
src/ftxui/screen/Screen.cppm
|
||||||
src/ftxui/screen/string.cppm
|
src/ftxui/screen/String.cppm
|
||||||
src/ftxui/screen/terminal.cppm
|
src/ftxui/screen/Terminal.cppm
|
||||||
src/ftxui/util.cppm
|
src/ftxui/util.cppm
|
||||||
src/ftxui/util/autoreset.cppm
|
src/ftxui/util/AutoReset.cppm
|
||||||
src/ftxui/util/ref.cppm
|
src/ftxui/util/Ref.cppm
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(ftxui-modules
|
target_link_libraries(ftxui-modules
|
||||||
@@ -53,7 +52,6 @@ target_link_libraries(ftxui-modules
|
|||||||
)
|
)
|
||||||
|
|
||||||
target_compile_features(ftxui-modules PUBLIC cxx_std_20)
|
target_compile_features(ftxui-modules PUBLIC cxx_std_20)
|
||||||
# TODO: Explain why this is needed.
|
|
||||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||||
target_compile_options(ftxui-modules PUBLIC -fmodules-ts)
|
target_compile_options(ftxui-modules PUBLIC -fmodules-ts)
|
||||||
endif ()
|
endif ()
|
||||||
|
|||||||
@@ -101,5 +101,6 @@ endfunction()
|
|||||||
|
|
||||||
if (EMSCRIPTEN)
|
if (EMSCRIPTEN)
|
||||||
string(APPEND CMAKE_CXX_FLAGS " -s USE_PTHREADS")
|
string(APPEND CMAKE_CXX_FLAGS " -s USE_PTHREADS")
|
||||||
|
string(APPEND CMAKE_EXE_LINKER_FLAGS " -s ASYNCIFY")
|
||||||
string(APPEND CMAKE_EXE_LINKER_FLAGS " -s PROXY_TO_PTHREAD")
|
string(APPEND CMAKE_EXE_LINKER_FLAGS " -s PROXY_TO_PTHREAD")
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -19,10 +19,11 @@ add_executable(ftxui-tests
|
|||||||
src/ftxui/component/menu_test.cpp
|
src/ftxui/component/menu_test.cpp
|
||||||
src/ftxui/component/modal_test.cpp
|
src/ftxui/component/modal_test.cpp
|
||||||
src/ftxui/component/radiobox_test.cpp
|
src/ftxui/component/radiobox_test.cpp
|
||||||
|
src/ftxui/util/ref_test.cpp
|
||||||
|
src/ftxui/component/receiver_test.cpp
|
||||||
src/ftxui/component/resizable_split_test.cpp
|
src/ftxui/component/resizable_split_test.cpp
|
||||||
src/ftxui/component/screen_interactive_test.cpp
|
src/ftxui/component/screen_interactive_test.cpp
|
||||||
src/ftxui/component/slider_test.cpp
|
src/ftxui/component/slider_test.cpp
|
||||||
src/ftxui/component/task_test.cpp
|
|
||||||
src/ftxui/component/terminal_input_parser_test.cpp
|
src/ftxui/component/terminal_input_parser_test.cpp
|
||||||
src/ftxui/component/toggle_test.cpp
|
src/ftxui/component/toggle_test.cpp
|
||||||
src/ftxui/dom/blink_test.cpp
|
src/ftxui/dom/blink_test.cpp
|
||||||
@@ -50,7 +51,6 @@ add_executable(ftxui-tests
|
|||||||
src/ftxui/dom/vbox_test.cpp
|
src/ftxui/dom/vbox_test.cpp
|
||||||
src/ftxui/screen/color_test.cpp
|
src/ftxui/screen/color_test.cpp
|
||||||
src/ftxui/screen/string_test.cpp
|
src/ftxui/screen/string_test.cpp
|
||||||
src/ftxui/util/ref_test.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(ftxui-tests
|
target_link_libraries(ftxui-tests
|
||||||
|
|||||||
92
doc/cpp-modules.md
Normal file
92
doc/cpp-modules.md
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
@page cpp20-modules C++20 Modules
|
||||||
|
|
||||||
|
> [!WARNING]
|
||||||
|
> This feature is still in development, and the API may change in future releases.
|
||||||
|
> Your contribution is needed to help us improve the compatibility and usability
|
||||||
|
> of C++20 modules in FTXUI. If you encounter any issues or have suggestions,
|
||||||
|
> please open an issue.
|
||||||
|
|
||||||
|
FTXUI provides an experimental support for [C++20
|
||||||
|
modules](https://en.cppreference.com/w/cpp/language/modules) to improve
|
||||||
|
compilation times and code organization. The existing API has a module
|
||||||
|
corresponding to each header.
|
||||||
|
|
||||||
|
**Example with CMake and Ninja**
|
||||||
|
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
import ftxui;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
auto screen = ftxui::ScreenInteractive::TerminalOutput();
|
||||||
|
auto button = ftxui::Button("Click me", screen.QuitClosure());
|
||||||
|
screen.Loop(button);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cmake \
|
||||||
|
-DCMAKE_GENERATOR=Ninja \
|
||||||
|
-DFTXUI_BUILD_MODULES=ON \
|
||||||
|
..
|
||||||
|
|
||||||
|
ninja
|
||||||
|
```
|
||||||
|
> [!NOTE]
|
||||||
|
> To use modules, you need a C++20 compatible compiler, CMake version 3.20 or
|
||||||
|
> higher, and use a compatible generator like Ninja. Note that Makefile
|
||||||
|
> generators **do not support modules**.
|
||||||
|
|
||||||
|
### Module list
|
||||||
|
|
||||||
|
The modules directly reference the corresponding header, or a group of related
|
||||||
|
headers to provide a more convenient interface. The following modules
|
||||||
|
are available:
|
||||||
|
|
||||||
|
- `ftxui`
|
||||||
|
- `ftxui.component`
|
||||||
|
- `ftxui.component.Animation`
|
||||||
|
- `ftxui.component.CapturedMouse`
|
||||||
|
- `ftxui.component.Component`
|
||||||
|
- `ftxui.component.ComponentBase`
|
||||||
|
- `ftxui.component.ComponentOptions`
|
||||||
|
- `ftxui.component.Event`
|
||||||
|
- `ftxui.component.Loop`
|
||||||
|
- `ftxui.component.Mouse`
|
||||||
|
- `ftxui.component.Receiver`
|
||||||
|
- `ftxui.component.ScreenInteractive`
|
||||||
|
- `ftxui.component.Task`
|
||||||
|
- `ftxui.dom`
|
||||||
|
- `ftxui.dom.Canvas`
|
||||||
|
- `ftxui.dom.Deprecated`
|
||||||
|
- `ftxui.dom.Direction`
|
||||||
|
- `ftxui.dom.Elements`
|
||||||
|
- `ftxui.dom.FlexboxConfig`
|
||||||
|
- `ftxui.dom.LinearGradient`
|
||||||
|
- `ftxui.dom.Node`
|
||||||
|
- `ftxui.dom.Requirement`
|
||||||
|
- `ftxui.dom.Selection`
|
||||||
|
- `ftxui.dom.Table`
|
||||||
|
- `ftxui.screen`
|
||||||
|
- `ftxui.screen.Box`
|
||||||
|
- `ftxui.screen.Color`
|
||||||
|
- `ftxui.screen.ColorInfo`
|
||||||
|
- `ftxui.screen.Deprecated`
|
||||||
|
- `ftxui.screen.Image`
|
||||||
|
- `ftxui.screen.Pixel`
|
||||||
|
- `ftxui.screen.Screen`
|
||||||
|
- `ftxui.screen.String`
|
||||||
|
- `ftxui.screen.Terminal`
|
||||||
|
- `ftxui.util`
|
||||||
|
- `ftxui.util.AutoReset`
|
||||||
|
- `ftxui.util.Ref`
|
||||||
|
|
||||||
|
> ![NOTE]
|
||||||
|
> The module `ftxui` transitively imports all `ftxui.*` modules and thus
|
||||||
|
> has a dependency on those modules.
|
||||||
|
|
||||||
|
> ![NOTE] The list can be generated with the following command:
|
||||||
|
> ```sh
|
||||||
|
> git grep "export module" | cut -d: -f2 | cut -d\ -f3
|
||||||
|
> ```
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
@page cpp20-modules C++20 Modules
|
|
||||||
|
|
||||||
|
|
||||||
> [!WARNING]
|
|
||||||
> This feature is still in development, and the API may change in future releases.
|
|
||||||
> Your contribution is needed to help us improve the compatibility and usability
|
|
||||||
> of C++20 modules in FTXUI. If you encounter any issues or have suggestions,
|
|
||||||
> please open an issue.
|
|
||||||
|
|
||||||
FTXUI experimentally supports
|
|
||||||
[C++20 modules](https://en.cppreference.com/w/cpp/language/modules) to reduce
|
|
||||||
compilation times and improve code organization. Each header has a
|
|
||||||
corresponding module.
|
|
||||||
|
|
||||||
Use the FTXUI_BUILD_MODULES option to build the FTXUI project itself to provide C++ 20 modules,
|
|
||||||
for example with CMake and Ninja:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
cmake \
|
|
||||||
-DCMAKE_GENERATOR=Ninja \
|
|
||||||
-DFTXUI_BUILD_MODULES=ON \
|
|
||||||
..
|
|
||||||
|
|
||||||
ninja
|
|
||||||
```
|
|
||||||
|
|
||||||
> [!NOTE]
|
|
||||||
> To use modules, you need a C++20 compatible compiler, CMake version 3.20 or
|
|
||||||
> higher, and use a compatible generator like Ninja. Note that Makefile
|
|
||||||
> generators **do not support modules**.
|
|
||||||
|
|
||||||
Then, in your own code you can consume the modules and code as normal:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
import ftxui;
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
auto screen = ftxui::ScreenInteractive::TerminalOutput();
|
|
||||||
auto button = ftxui::Button("Click me", screen.QuitClosure());
|
|
||||||
screen.Loop(button);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Note, the `ftxui` convenience module which simply pulls together all the modules:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
export import ftxui.component;
|
|
||||||
export import ftxui.dom;
|
|
||||||
export import ftxui.screen;
|
|
||||||
export import ftxui.util;
|
|
||||||
```
|
|
||||||
You can instead import only the module(s) you need if desired.
|
|
||||||
|
|
||||||
To properly find and link the modules with CMake, use `target_link_libraries` to get the right
|
|
||||||
compiler, linker, etc. flags.
|
|
||||||
|
|
||||||
```cmake
|
|
||||||
target_link_libraries(my_executable
|
|
||||||
#...whatever...
|
|
||||||
PRIVATE ftxui::modules
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
### Module list
|
|
||||||
|
|
||||||
The modules directly reference the corresponding header, or a group of related
|
|
||||||
headers to provide a more convenient interface. The following modules
|
|
||||||
are available:
|
|
||||||
|
|
||||||
- `ftxui`
|
|
||||||
- `ftxui.component`
|
|
||||||
- `ftxui.component.Animation`
|
|
||||||
- `ftxui.component.CapturedMouse`
|
|
||||||
- `ftxui.component.Component`
|
|
||||||
- `ftxui.component.ComponentBase`
|
|
||||||
- `ftxui.component.ComponentOptions`
|
|
||||||
- `ftxui.component.Event`
|
|
||||||
- `ftxui.component.Loop`
|
|
||||||
- `ftxui.component.Mouse`
|
|
||||||
- `ftxui.component.Receiver`
|
|
||||||
- `ftxui.component.ScreenInteractive`
|
|
||||||
- `ftxui.component.Task`
|
|
||||||
- `ftxui.dom`
|
|
||||||
- `ftxui.dom.Canvas`
|
|
||||||
- `ftxui.dom.Deprecated`
|
|
||||||
- `ftxui.dom.Direction`
|
|
||||||
- `ftxui.dom.Elements`
|
|
||||||
- `ftxui.dom.FlexboxConfig`
|
|
||||||
- `ftxui.dom.LinearGradient`
|
|
||||||
- `ftxui.dom.Node`
|
|
||||||
- `ftxui.dom.Requirement`
|
|
||||||
- `ftxui.dom.Selection`
|
|
||||||
- `ftxui.dom.Table`
|
|
||||||
- `ftxui.screen`
|
|
||||||
- `ftxui.screen.Box`
|
|
||||||
- `ftxui.screen.Color`
|
|
||||||
- `ftxui.screen.ColorInfo`
|
|
||||||
- `ftxui.screen.Deprecated`
|
|
||||||
- `ftxui.screen.Image`
|
|
||||||
- `ftxui.screen.Pixel`
|
|
||||||
- `ftxui.screen.Screen`
|
|
||||||
- `ftxui.screen.String`
|
|
||||||
- `ftxui.screen.Terminal`
|
|
||||||
- `ftxui.util`
|
|
||||||
- `ftxui.util.AutoReset`
|
|
||||||
- `ftxui.util.Ref`
|
|
||||||
@@ -108,6 +108,7 @@
|
|||||||
console.log("navtree.textContent", navtree.textContent);
|
console.log("navtree.textContent", navtree.textContent);
|
||||||
if (!navtree.textContent.includes("Getting Started") &&
|
if (!navtree.textContent.includes("Getting Started") &&
|
||||||
!navtree.textContent.includes("Installation") &&
|
!navtree.textContent.includes("Installation") &&
|
||||||
|
!navtree.textContent.includes("Modules") &&
|
||||||
!navtree.textContent.includes("ftxui / screen") &&
|
!navtree.textContent.includes("ftxui / screen") &&
|
||||||
!navtree.textContent.includes("ftxui / dom") &&
|
!navtree.textContent.includes("ftxui / dom") &&
|
||||||
!navtree.textContent.includes("ftxui / component") &&
|
!navtree.textContent.includes("ftxui / component") &&
|
||||||
|
|||||||
@@ -16,11 +16,6 @@ This page serves as an entry point for the available integration methods.
|
|||||||
- @subpage installation_vcpkg
|
- @subpage installation_vcpkg
|
||||||
- @subpage installation_conan
|
- @subpage installation_conan
|
||||||
- @subpage installation_manual
|
- @subpage installation_manual
|
||||||
- @subpage installation_nix
|
|
||||||
- @subpage installation_debian
|
|
||||||
- @subpage installation_arch
|
|
||||||
- @subpage installation_opensuse
|
|
||||||
- @subpage installation_xmake
|
|
||||||
|
|
||||||
## Next Steps
|
## Next Steps
|
||||||
|
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
@page installation_arch Arch Linux
|
|
||||||
|
|
||||||
FTXUI is packaged on the AUR. Install using an AUR helper:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
yay -S ftxui
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also manually download the PKGBUILD from <https://aur.archlinux.org/packages/ftxui>.
|
|
||||||
|
|
||||||
Once installed, you can use it in your CMake projects by adding the following to your `CMakeLists.txt`:
|
|
||||||
|
|
||||||
```cmake
|
|
||||||
find_package(ftxui REQUIRED)
|
|
||||||
add_executable(main main.cpp)
|
|
||||||
target_link_libraries(main
|
|
||||||
PRIVATE ftxui::screen
|
|
||||||
PRIVATE ftxui::dom
|
|
||||||
PRIVATE ftxui::component
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
> [!note]
|
|
||||||
> This is an unofficial package. That means it is not maintained by the FTXUI
|
|
||||||
> team, but by the community. The package maintainers seems to actively update
|
|
||||||
> the package to the latest version. Thanks to the maintainers for their work!
|
|
||||||
|
|
||||||
<div class="section_buttons">
|
|
||||||
|
|
||||||
| Previous |
|
|
||||||
|:------------------|
|
|
||||||
| [Getting Started](getting-started.html) |
|
|
||||||
|
|
||||||
</div>
|
|
||||||
@@ -10,7 +10,7 @@ This page explains how to depend on FTXUI using [CMake](https://cmake.org).
|
|||||||
|
|
||||||
This approach downloads FTXUI at configure time and doesn't require a system-wide install.
|
This approach downloads FTXUI at configure time and doesn't require a system-wide install.
|
||||||
|
|
||||||
```cmake
|
```fortran
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
FetchContent_Declare(ftxui
|
FetchContent_Declare(ftxui
|
||||||
@@ -34,8 +34,8 @@ This ensures reproducible builds and easy dependency management.
|
|||||||
|
|
||||||
If FTXUI is installed system-wide or via a package manager (e.g. vcpkg or Conan), you can use:
|
If FTXUI is installed system-wide or via a package manager (e.g. vcpkg or Conan), you can use:
|
||||||
|
|
||||||
```cmake
|
```fortran
|
||||||
find_package(ftxui REQUIRED)
|
fortranind_package(ftxui REQUIRED)
|
||||||
|
|
||||||
add_executable(main main.cpp)
|
add_executable(main main.cpp)
|
||||||
target_link_libraries(main
|
target_link_libraries(main
|
||||||
@@ -51,7 +51,7 @@ Make sure the package is visible in your `CMAKE_PREFIX_PATH`.
|
|||||||
|
|
||||||
You can also add FTXUI as a [Git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules), keeping it as part of your repository:
|
You can also add FTXUI as a [Git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules), keeping it as part of your repository:
|
||||||
|
|
||||||
```cmake
|
```fortran
|
||||||
git submodule add https://github.com/ArthurSonzogni/FTXUI external/ftxui
|
git submodule add https://github.com/ArthurSonzogni/FTXUI external/ftxui
|
||||||
git submodule update --init --recursive
|
git submodule update --init --recursive
|
||||||
```
|
```
|
||||||
@@ -66,7 +66,7 @@ git submodule update --init --recursive
|
|||||||
|
|
||||||
Then in your `CMakeLists.txt`:
|
Then in your `CMakeLists.txt`:
|
||||||
|
|
||||||
```cmake
|
```fortran
|
||||||
add_subdirectory(external/ftxui)
|
add_subdirectory(external/ftxui)
|
||||||
|
|
||||||
add_executable(main main.cpp)
|
add_executable(main main.cpp)
|
||||||
|
|||||||
@@ -1,19 +1,15 @@
|
|||||||
@page installation_conan Conan
|
@page installation_conan Conan
|
||||||
|
@tableofcontents
|
||||||
|
|
||||||
Unofficial recipe for FTXUI exists on Conan Center:
|
## Conan Package
|
||||||
<https://conan.io/center/recipes/ftxui>
|
|
||||||
|
|
||||||
> [!note]
|
Unofficial support for FTXUI exists on Conan Center:
|
||||||
> This is an unofficial recipe. That means it is not maintained by the FTXUI
|
|
||||||
> team, but by the community. The package maintainers seems to actively update
|
|
||||||
> the package to the latest version. Thanks to the maintainers for their work!
|
|
||||||
|
|
||||||
|
- https://conan.io/center/recipes/ftxui
|
||||||
|
|
||||||
@todo Add instructions on how to use the conan recipe.
|
## TODO
|
||||||
|
|
||||||
@todo Please consider adding an "official" recipe to Conan Center if know how.
|
This page is incomplete. If you use FTXUI with Conan and can provide a minimal working setup, feel free to contribute.
|
||||||
It could be a github action that will automatically update the conan center
|
|
||||||
when a new release is made.
|
|
||||||
|
|
||||||
<div class="section_buttons">
|
<div class="section_buttons">
|
||||||
|
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
@page installation_debian Debian/Ubuntu
|
|
||||||
|
|
||||||
## Debian and Ubuntu Packages (Unofficial)
|
|
||||||
|
|
||||||
Pre-built packages are provided by the distributions. Install with:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
sudo apt install libftxui-dev
|
|
||||||
```
|
|
||||||
|
|
||||||
The following packages are available:
|
|
||||||
- `ftxui-doc`
|
|
||||||
- `ftxui-examples`
|
|
||||||
- `libftxui-component<version>`
|
|
||||||
- `libftxui-dev`
|
|
||||||
- `libftxui-dom<version>`
|
|
||||||
- `libftxui-screen<version>`
|
|
||||||
|
|
||||||
Once installed, you can use it in your CMake projects by adding the following to
|
|
||||||
your `CMakeLists.txt`:
|
|
||||||
|
|
||||||
```cmake
|
|
||||||
find_package(ftxui REQUIRED)
|
|
||||||
add_executable(main main.cpp)
|
|
||||||
target_link_libraries(main
|
|
||||||
PRIVATE ftxui::screen
|
|
||||||
PRIVATE ftxui::dom
|
|
||||||
PRIVATE ftxui::component
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
> [!note]
|
|
||||||
> This is an **unofficial** package. That means it is not maintained by the FTXUI
|
|
||||||
> team, but by the community.
|
|
||||||
|
|
||||||
<div class="section_buttons">
|
|
||||||
|
|
||||||
| Previous |
|
|
||||||
|:------------------|
|
|
||||||
| [Getting Started](getting-started.html) |
|
|
||||||
|
|
||||||
</div>
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
@page installation_manual Manual
|
|
||||||
@tableofcontents
|
|
||||||
|
|
||||||
## Building from Source (Official)
|
|
||||||
|
|
||||||
Clone and build the project using CMake:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git clone https://github.com/ArthurSonzogni/FTXUI.git
|
|
||||||
cd FTXUI
|
|
||||||
cmake -S . -B build -DFTXUI_ENABLE_INSTALL=ON -D
|
|
||||||
cmake --build build -j
|
|
||||||
sudo cmake --install build
|
|
||||||
```
|
|
||||||
|
|
||||||
Once installed you can use it in your CMake projects by adding the following to your `CMakeLists.txt`:
|
|
||||||
|
|
||||||
```cmake
|
|
||||||
find_package(ftxui REQUIRED)
|
|
||||||
add_executable(main main.cpp)
|
|
||||||
target_link_libraries(main
|
|
||||||
PRIVATE ftxui::screen
|
|
||||||
PRIVATE ftxui::dom
|
|
||||||
PRIVATE ftxui::component
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
<div class="section_buttons">
|
|
||||||
|
|
||||||
| Previous |
|
|
||||||
|:------------------|
|
|
||||||
| [Getting Started](getting-started.html) |
|
|
||||||
|
|
||||||
</div>
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
@page installation_nix Nix
|
|
||||||
|
|
||||||
> [!note]
|
|
||||||
> FTXUI author is not very knowledgeable about Nix. This page has been mostly
|
|
||||||
> generated by AI. If you have any suggestions to improve it, please open a
|
|
||||||
> PR.
|
|
||||||
|
|
||||||
## Nix Flake
|
|
||||||
|
|
||||||
FTXUI ships with a `flake.nix` providing both packages and a development shell.
|
|
||||||
|
|
||||||
### Build the Library
|
|
||||||
|
|
||||||
```bash
|
|
||||||
nix build github:ArthurSonzogni/FTXUI
|
|
||||||
```
|
|
||||||
|
|
||||||
The resulting package is accessible via the `result` link.
|
|
||||||
|
|
||||||
### Use as a Dependency
|
|
||||||
|
|
||||||
Add FTXUI to your flake inputs:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
{
|
|
||||||
inputs.ftxui.url = "github:ArthurSonzogni/FTXUI";
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Then reference `ftxui.packages.<system>.ftxui` in your outputs.
|
|
||||||
|
|
||||||
<div class="section_buttons">
|
|
||||||
|
|
||||||
| Previous |
|
|
||||||
|:------------------|
|
|
||||||
| [Getting Started](getting-started.html) |
|
|
||||||
|
|
||||||
</div>
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
@page installation_opensuse openSUSE
|
|
||||||
|
|
||||||
## openSUSE Package (Unofficial)
|
|
||||||
|
|
||||||
FTXUI seems to be available from the `devel:libraries:c_c++` repository.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
sudo zypper addrepo https://download.opensuse.org/repositories/devel:libraries:c_c++/openSUSE_Leap_$releasever/devel:libraries:c_c++.repo
|
|
||||||
sudo zypper install ftxui
|
|
||||||
```
|
|
||||||
|
|
||||||
See <https://build.opensuse.org/package/show/devel:libraries:c_c++/ftxui> for details.
|
|
||||||
|
|
||||||
> [!note]
|
|
||||||
> This is an **unofficial** package. That means it is not maintained by the FTXUI
|
|
||||||
> team, but by the community.
|
|
||||||
|
|
||||||
--
|
|
||||||
|
|
||||||
> [!note]
|
|
||||||
> The FTXUI author is not very knowledgeable about openSUSE. This page has been
|
|
||||||
> mostly generated by AI. If you have any suggestions to improve it, please open
|
|
||||||
> a PR.
|
|
||||||
|
|
||||||
|
|
||||||
<div class="section_buttons">
|
|
||||||
|
|
||||||
| Previous |
|
|
||||||
|:------------------|
|
|
||||||
| [Getting Started](getting-started.html) |
|
|
||||||
|
|
||||||
</div>
|
|
||||||
@@ -1,74 +1,15 @@
|
|||||||
@page installation_vcpkg Vcpkg
|
@page installation_vcpkg Vcpkg
|
||||||
@tableofcontents
|
@tableofcontents
|
||||||
|
|
||||||
# Vcpkg Package
|
## Vcpkg Package
|
||||||
|
|
||||||
FTXUI is available in the [Vcpkg registry](https://vcpkg.link/ports/ftxui)
|
FTXUI is available in the Vcpkg registry:
|
||||||
|
|
||||||
To use it, you can add the following to your `vcpkg.json`:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"name": "your-project",
|
|
||||||
"version-string": "0.1.0",
|
|
||||||
"dependencies": [
|
|
||||||
{
|
|
||||||
"name": "ftxui",
|
|
||||||
"version>=": "6.1.9"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
# Install FTXUI using Vcpkg
|
|
||||||
```bash
|
|
||||||
vcpkg install --triplet x64-linux # or x64-windows / arm64-osx etc.
|
|
||||||
```
|
|
||||||
|
|
||||||
# Configure your build system.
|
|
||||||
If you are using CMake, you can use the following in your `CMakeLists.txt`:
|
|
||||||
|
|
||||||
**CMakeLists.txt**
|
|
||||||
```cmake
|
|
||||||
cmake_minimum_required(VERSION 3.15)
|
|
||||||
project(my_project)
|
|
||||||
|
|
||||||
# Make sure vcpkg toolchain file is passed at configure time
|
|
||||||
find_package(ftxui CONFIG REQUIRED)
|
|
||||||
|
|
||||||
add_executable(main main.cpp)
|
|
||||||
target_link_libraries(main
|
|
||||||
PRIVATE ftxui::screen
|
|
||||||
PRIVATE ftxui::dom
|
|
||||||
PRIVATE ftxui::component
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
**main.cpp**
|
|
||||||
```cpp
|
|
||||||
#include <ftxui/component/screen_interactive.hpp>
|
|
||||||
#include <ftxui/component/component.hpp>
|
|
||||||
#include <ftxui/component/component_options.hpp>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
using namespace ftxui;
|
|
||||||
|
|
||||||
auto screen = ScreenInteractive::TerminalOutput();
|
|
||||||
auto button = Button("Click me", [] { std::cout << "Clicked!\n"; });
|
|
||||||
|
|
||||||
screen.Loop(button);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**Configure and build the project**
|
|
||||||
```bash
|
|
||||||
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake
|
|
||||||
cmake --build build
|
|
||||||
./build/main
|
|
||||||
```
|
|
||||||
|
|
||||||
|
- https://vcpkg.link/ports/ftxui
|
||||||
|
|
||||||
|
## TODO
|
||||||
|
|
||||||
|
This page is incomplete. If you use FTXUI with Vcpkg, please help improve this page by contributing working configuration examples.
|
||||||
|
|
||||||
<div class="section_buttons">
|
<div class="section_buttons">
|
||||||
|
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
@page installation_xmake XMake
|
|
||||||
@tableofcontents
|
|
||||||
|
|
||||||
## XMake Package (Unofficial)
|
|
||||||
|
|
||||||
FTXUI is available in the [xmake-repo](https://github.com/xmake-io/xmake-repo/blob/dev/packages/f/ftxui/xmake.lua)
|
|
||||||
|
|
||||||
Example `xmake.lua` snippet:
|
|
||||||
|
|
||||||
```lua
|
|
||||||
add_requires("ftxui", {system = false})
|
|
||||||
|
|
||||||
target("demo")
|
|
||||||
set_kind("binary")
|
|
||||||
add_files("src/*.cpp")
|
|
||||||
add_packages("ftxui")
|
|
||||||
```
|
|
||||||
|
|
||||||
Refer to the [XMake documentation](https://xmake.io) for further options.
|
|
||||||
|
|
||||||
> [!note]
|
|
||||||
> This is an **unofficial** package. That means it is not maintained by the FTXUI
|
|
||||||
> team, but by the community.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
> [!note]
|
|
||||||
> The FTXUI author is not very knowledgeable about openSUSE. This page has been
|
|
||||||
> mostly generated by AI. If you have any suggestions to improve it, please open
|
|
||||||
> a PR.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
<div class="section_buttons">
|
|
||||||
|
|
||||||
| Previous |
|
|
||||||
|:------------------|
|
|
||||||
| [Getting Started](getting-started.html) |
|
|
||||||
|
|
||||||
</div>
|
|
||||||
@@ -14,7 +14,7 @@ A `ftxui::Component` is a shared pointer to a `ftxui::ComponentBase`. The latter
|
|||||||
- `ftxui::ComponentBase::Render()`: How to render the interface.
|
- `ftxui::ComponentBase::Render()`: How to render the interface.
|
||||||
- `ftxui::ComponentBase::OnEvent()`: How to react to events.
|
- `ftxui::ComponentBase::OnEvent()`: How to react to events.
|
||||||
- `ftxui::ComponentBase::Add()`: Construct a parent/child relationship
|
- `ftxui::ComponentBase::Add()`: Construct a parent/child relationship
|
||||||
between two components. The tree of components is used to define how to
|
between two components. The tree of component is used to define how to
|
||||||
navigate using the keyboard.
|
navigate using the keyboard.
|
||||||
|
|
||||||
`ftxui::Element` are used to render a single frame.
|
`ftxui::Element` are used to render a single frame.
|
||||||
@@ -45,7 +45,7 @@ Produced by: `ftxui::Input()` from "ftxui/component/component.hpp"
|
|||||||
|
|
||||||
## Filtered input
|
## Filtered input
|
||||||
|
|
||||||
One can filter out the characters received by the input component, using
|
On can filter out the characters received by the input component, using
|
||||||
`ftxui::CatchEvent`.
|
`ftxui::CatchEvent`.
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
@@ -123,8 +123,8 @@ Produced by: `ftxui::Radiobox()` from "ftxui/component/component.hpp"
|
|||||||
|
|
||||||
# Dropdown {#component-dropdown}
|
# Dropdown {#component-dropdown}
|
||||||
|
|
||||||
A drop-down menu is a component that, when opened, displays a list of elements
|
A drop down menu is a component that when checked display a list of element for
|
||||||
for the user to select from.
|
the user to select one.
|
||||||
|
|
||||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2component_2dropdown_8cpp-example.html):
|
[Example](https://arthursonzogni.github.io/FTXUI/examples_2component_2dropdown_8cpp-example.html):
|
||||||
|
|
||||||
@@ -204,12 +204,12 @@ component = component
|
|||||||
|
|
||||||
# Collapsible {#component-collapsible}
|
# Collapsible {#component-collapsible}
|
||||||
|
|
||||||
Useful for visual elements whose visibility can be toggled on or off by the
|
Useful for visual elements whose visibility can be toggle on/off by the user.
|
||||||
user. Essentially, this is the combination of the `ftxui::Checkbox()` and
|
Essentially, this the combination of the `ftxui::Checkbox()` and
|
||||||
`ftxui::Maybe()` components.
|
`ftxui::Maybe()` components.
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
auto collapsible = Collapsible("Show more", inner_element);
|
auto collabsible = Collapsible("Show more", inner_element);
|
||||||
```
|
```
|
||||||
|
|
||||||
# Maybe {#component-maybe}
|
# Maybe {#component-maybe}
|
||||||
@@ -245,7 +245,7 @@ component = component
|
|||||||
|
|
||||||
Produced by: `ftxui::Container::Horizontal()` from
|
Produced by: `ftxui::Container::Horizontal()` from
|
||||||
"ftxui/component/component.hpp". It displays a list of components horizontally
|
"ftxui/component/component.hpp". It displays a list of components horizontally
|
||||||
and handles keyboard/mouse navigation.
|
and handle keyboard/mouse navigation.
|
||||||
|
|
||||||
## Vertical {#component-vertical}
|
## Vertical {#component-vertical}
|
||||||
|
|
||||||
@@ -256,8 +256,8 @@ and handles keyboard/mouse navigation.
|
|||||||
## Tab {#component-tab}
|
## Tab {#component-tab}
|
||||||
|
|
||||||
Produced by: `ftxui::Container::Tab()` from
|
Produced by: `ftxui::Container::Tab()` from
|
||||||
"ftxui/component/component.hpp". It takes a list of components and displays
|
"ftxui/component/component.hpp". It take a list of component and display only
|
||||||
only one of them. This is useful for implementing a tab bar.
|
one of them. This is useful for implementing a tab bar.
|
||||||
|
|
||||||
[Vertical](https://arthursonzogni.github.io/FTXUI/examples_2component_2tab_vertical_8cpp-example.html):
|
[Vertical](https://arthursonzogni.github.io/FTXUI/examples_2component_2tab_vertical_8cpp-example.html):
|
||||||
|
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ Code:
|
|||||||
border(gauge(0.5))
|
border(gauge(0.5))
|
||||||
```
|
```
|
||||||
|
|
||||||
Terminal output:
|
Teminal output:
|
||||||
```bash
|
```bash
|
||||||
┌────────────────────────────────────────────────────────────────────────────┐
|
┌────────────────────────────────────────────────────────────────────────────┐
|
||||||
│██████████████████████████████████████ │
|
│██████████████████████████████████████ │
|
||||||
@@ -407,7 +407,7 @@ Checkout this
|
|||||||
and the associated
|
and the associated
|
||||||
[demo](https://arthursonzogni.github.io/FTXUI/examples/?file=component/flexbox).
|
[demo](https://arthursonzogni.github.io/FTXUI/examples/?file=component/flexbox).
|
||||||
|
|
||||||
Element can also become flexible using the `ftxui::flex` decorator.
|
Element can also become flexible using the the `ftxui::flex` decorator.
|
||||||
|
|
||||||
Code:
|
Code:
|
||||||
```cpp
|
```cpp
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# ftxui {#ftxui}
|
# Modules {#modules}
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|||||||
@@ -1,58 +0,0 @@
|
|||||||
# POSIX Piped Input in FTXUI
|
|
||||||
|
|
||||||
> [!WARNING]
|
|
||||||
> This feature works only on Linux and macOS. It is not supported on
|
|
||||||
> Windows and WebAssembly.
|
|
||||||
|
|
||||||
## What is a POSIX Pipe?
|
|
||||||
|
|
||||||
A POSIX pipe is a way for two separate programs to communicate. One program sends its output directly as input to another program. Think of it like a one-way tube for data.
|
|
||||||
|
|
||||||
**Example:**
|
|
||||||
|
|
||||||
Imagine you want to list files and then filter them interactively.
|
|
||||||
|
|
||||||
- `ls`: Lists files.
|
|
||||||
- `interactive_grep`: An FTXUI application that filters text and lets you type.
|
|
||||||
|
|
||||||
You can connect them with a pipe (`|`):
|
|
||||||
|
|
||||||
```bash
|
|
||||||
ls -l | interactive_grep
|
|
||||||
```
|
|
||||||
|
|
||||||
Here's what happens:
|
|
||||||
1. `ls -l` lists files with details.
|
|
||||||
2. The `|` sends this list directly to `interactive_grep`.
|
|
||||||
3. `interactive_grep` receives the list and displays it. Because it's an FTXUI app, you can then type to filter the list, even though it received initial data from `ls`.
|
|
||||||
|
|
||||||
## How FTXUI Handles Piped Input
|
|
||||||
|
|
||||||
Now that you understand what a POSIX pipe is, let's look at how FTXUI uses them.
|
|
||||||
|
|
||||||
FTXUI lets your application read data from other programs (like from a pipe) while still allowing you to use your keyboard for interaction. This is useful for interactive command-line tools that process data.
|
|
||||||
|
|
||||||
Normally, FTXUI applications receive all input from `stdin`. However, when FTXUI detects that `stdin` is connected to the output of a pipe (meaning data is being piped into your application), it automatically switches to reading interactive keyboard input from `/dev/tty`. This ensures that your application can still receive user input even while processing piped data.
|
|
||||||
|
|
||||||
This feature is **turned on by default**.
|
|
||||||
|
|
||||||
If your FTXUI application needs to read piped data and also respond to keyboard input, you typically don't need to do anything special:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
auto screen = ScreenInteractive::Fullscreen();
|
|
||||||
// screen.HandlePipedInput(true); // This is enabled by default
|
|
||||||
screen.Loop(component);
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Turning Off Piped Input
|
|
||||||
|
|
||||||
If you don't need this feature, or if it conflicts with your custom input handling, you can turn it off.
|
|
||||||
|
|
||||||
To disable it, call `HandlePipedInput(false)` before starting your application's main loop:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
auto screen = ScreenInteractive::Fullscreen();
|
|
||||||
screen.HandlePipedInput(false); // Turn off piped input handling
|
|
||||||
screen.Loop(component);
|
|
||||||
```
|
|
||||||
@@ -15,11 +15,15 @@ add_subdirectory(component)
|
|||||||
add_subdirectory(dom)
|
add_subdirectory(dom)
|
||||||
|
|
||||||
if (EMSCRIPTEN)
|
if (EMSCRIPTEN)
|
||||||
|
string(APPEND CMAKE_EXE_LINKER_FLAGS " -s ALLOW_MEMORY_GROWTH=1")
|
||||||
|
target_link_options(component PUBLIC "SHELL: -s ALLOW_MEMORY_GROWTH=1")
|
||||||
|
|
||||||
get_property(EXAMPLES GLOBAL PROPERTY FTXUI::EXAMPLES)
|
get_property(EXAMPLES GLOBAL PROPERTY FTXUI::EXAMPLES)
|
||||||
foreach(file
|
foreach(file
|
||||||
"index.html"
|
"index.html"
|
||||||
"index.mjs"
|
"index.mjs"
|
||||||
"index.css"
|
"index.css"
|
||||||
|
"sw.js"
|
||||||
"run_webassembly.py")
|
"run_webassembly.py")
|
||||||
configure_file(${file} ${file})
|
configure_file(${file} ${file})
|
||||||
endforeach(file)
|
endforeach(file)
|
||||||
|
|||||||
@@ -1,64 +1,9 @@
|
|||||||
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
#include "ftxui/component/component.hpp"
|
||||||
// Use of this source code is governed by the MIT license that can be found in
|
#include "ftxui/component/screen_interactive.hpp"
|
||||||
// the LICENSE file.
|
|
||||||
#include <memory> // for shared_ptr, __shared_ptr_access
|
|
||||||
#include <string> // for operator+, to_string
|
|
||||||
|
|
||||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
int main(){
|
||||||
#include "ftxui/component/component.hpp" // for Button, Horizontal, Renderer
|
auto screen = ftxui::ScreenInteractive::Fullscreen();
|
||||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
auto testComponent = ftxui::Renderer([](){return ftxui::text("test Component");});
|
||||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
screen.Loop(testComponent);
|
||||||
#include "ftxui/dom/elements.hpp" // for separator, gauge, text, Element, operator|, vbox, border
|
return 0;
|
||||||
|
|
||||||
using namespace ftxui;
|
|
||||||
|
|
||||||
// This is a helper function to create a button with a custom style.
|
|
||||||
// The style is defined by a lambda function that takes an EntryState and
|
|
||||||
// returns an Element.
|
|
||||||
// We are using `center` to center the text inside the button, then `border` to
|
|
||||||
// add a border around the button, and finally `flex` to make the button fill
|
|
||||||
// the available space.
|
|
||||||
ButtonOption Style() {
|
|
||||||
auto option = ButtonOption::Animated();
|
|
||||||
option.transform = [](const EntryState& s) {
|
|
||||||
auto element = text(s.label);
|
|
||||||
if (s.focused) {
|
|
||||||
element |= bold;
|
|
||||||
}
|
|
||||||
return element | center | borderEmpty | flex;
|
|
||||||
};
|
|
||||||
return option;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
int value = 50;
|
|
||||||
|
|
||||||
// clang-format off
|
|
||||||
auto btn_dec_01 = Button("-1", [&] { value += 1; }, Style());
|
|
||||||
auto btn_inc_01 = Button("+1", [&] { value -= 1; }, Style());
|
|
||||||
auto btn_dec_10 = Button("-10", [&] { value -= 10; }, Style());
|
|
||||||
auto btn_inc_10 = Button("+10", [&] { value += 10; }, Style());
|
|
||||||
// clang-format on
|
|
||||||
|
|
||||||
// The tree of components. This defines how to navigate using the keyboard.
|
|
||||||
// The selected `row` is shared to get a grid layout.
|
|
||||||
int row = 0;
|
|
||||||
auto buttons = Container::Vertical({
|
|
||||||
Container::Horizontal({btn_dec_01, btn_inc_01}, &row) | flex,
|
|
||||||
Container::Horizontal({btn_dec_10, btn_inc_10}, &row) | flex,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Modify the way to render them on screen:
|
|
||||||
auto component = Renderer(buttons, [&] {
|
|
||||||
return vbox({
|
|
||||||
text("value = " + std::to_string(value)),
|
|
||||||
separator(),
|
|
||||||
buttons->Render() | flex,
|
|
||||||
}) |
|
|
||||||
flex | border;
|
|
||||||
});
|
|
||||||
|
|
||||||
auto screen = ScreenInteractive::FitComponent();
|
|
||||||
screen.Loop(component);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,9 +133,8 @@ int main() {
|
|||||||
float dy = 50.f;
|
float dy = 50.f;
|
||||||
ys[x] = int(dy + 20 * cos(dx * 0.14) + 10 * sin(dx * 0.42));
|
ys[x] = int(dy + 20 * cos(dx * 0.14) + 10 * sin(dx * 0.42));
|
||||||
}
|
}
|
||||||
for (int x = 1; x < 99; x++) {
|
for (int x = 1; x < 99; x++)
|
||||||
c.DrawPointLine(x, ys[x], x + 1, ys[x + 1]);
|
c.DrawPointLine(x, ys[x], x + 1, ys[x + 1]);
|
||||||
}
|
|
||||||
|
|
||||||
return canvas(std::move(c));
|
return canvas(std::move(c));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -82,12 +82,10 @@ int main() {
|
|||||||
size(WIDTH, EQUAL, dimx) | size(HEIGHT, EQUAL, dimy) |
|
size(WIDTH, EQUAL, dimx) | size(HEIGHT, EQUAL, dimy) |
|
||||||
bgcolor(Color::HSV(index * 25, 255, 255)) |
|
bgcolor(Color::HSV(index * 25, 255, 255)) |
|
||||||
color(Color::Black);
|
color(Color::Black);
|
||||||
if (element_xflex_grow) {
|
if (element_xflex_grow)
|
||||||
element = element | xflex_grow;
|
element = element | xflex_grow;
|
||||||
}
|
if (element_yflex_grow)
|
||||||
if (element_yflex_grow) {
|
|
||||||
element = element | yflex_grow;
|
element = element | yflex_grow;
|
||||||
}
|
|
||||||
return element;
|
return element;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -121,12 +119,10 @@ int main() {
|
|||||||
|
|
||||||
group = group | notflex;
|
group = group | notflex;
|
||||||
|
|
||||||
if (!group_xflex_grow) {
|
if (!group_xflex_grow)
|
||||||
group = hbox(group, filler());
|
group = hbox(group, filler());
|
||||||
}
|
if (!group_yflex_grow)
|
||||||
if (!group_yflex_grow) {
|
|
||||||
group = vbox(group, filler());
|
group = vbox(group, filler());
|
||||||
}
|
|
||||||
|
|
||||||
group = group | flex;
|
group = group | flex;
|
||||||
return group;
|
return group;
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
||||||
// Use of this source code is governed by the MIT license that can be found in
|
// Use of this source code is governed by the MIT license that can be found in
|
||||||
// the LICENSE file.
|
// the LICENSE file.
|
||||||
#include <stddef.h> // for size_t
|
#include <stddef.h> // for size_t
|
||||||
#include <array> // for array
|
#include <array> // for array
|
||||||
#include <atomic> // for atomic
|
#include <atomic> // for atomic
|
||||||
#include <chrono> // for operator""s, chrono_literals
|
#include <chrono> // for operator""s, chrono_literals
|
||||||
#include <cmath> // for sin
|
#include <cmath> // for sin
|
||||||
#include <ftxui/component/loop.hpp>
|
|
||||||
#include <functional> // for ref, reference_wrapper, function
|
#include <functional> // for ref, reference_wrapper, function
|
||||||
#include <memory> // for allocator, shared_ptr, __shared_ptr_access
|
#include <memory> // for allocator, shared_ptr, __shared_ptr_access
|
||||||
#include <string> // for string, basic_string, char_traits, operator+, to_string
|
#include <string> // for string, basic_string, char_traits, operator+, to_string
|
||||||
@@ -270,7 +269,7 @@ int main() {
|
|||||||
auto spinner_tab_renderer = Renderer([&] {
|
auto spinner_tab_renderer = Renderer([&] {
|
||||||
Elements entries;
|
Elements entries;
|
||||||
for (int i = 0; i < 22; ++i) {
|
for (int i = 0; i < 22; ++i) {
|
||||||
entries.push_back(spinner(i, shift / 5) | bold |
|
entries.push_back(spinner(i, shift / 2) | bold |
|
||||||
size(WIDTH, GREATER_THAN, 2) | border);
|
size(WIDTH, GREATER_THAN, 2) | border);
|
||||||
}
|
}
|
||||||
return hflow(std::move(entries));
|
return hflow(std::move(entries));
|
||||||
@@ -513,20 +512,24 @@ int main() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
Loop loop(&screen, main_renderer);
|
std::atomic<bool> refresh_ui_continue = true;
|
||||||
while (!loop.HasQuitted()) {
|
std::thread refresh_ui([&] {
|
||||||
// Update the state of the application.
|
while (refresh_ui_continue) {
|
||||||
shift++;
|
using namespace std::chrono_literals;
|
||||||
|
std::this_thread::sleep_for(0.05s);
|
||||||
|
// The |shift| variable belong to the main thread. `screen.Post(task)`
|
||||||
|
// will execute the update on the thread where |screen| lives (e.g. the
|
||||||
|
// main thread). Using `screen.Post(task)` is threadsafe.
|
||||||
|
screen.Post([&] { shift++; });
|
||||||
|
// After updating the state, request a new frame to be drawn. This is done
|
||||||
|
// by simulating a new "custom" event to be handled.
|
||||||
|
screen.Post(Event::Custom);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Request a new frame to be drawn.
|
screen.Loop(main_renderer);
|
||||||
screen.RequestAnimationFrame();
|
refresh_ui_continue = false;
|
||||||
|
refresh_ui.join();
|
||||||
// Execute events, and draw the next frame.
|
|
||||||
loop.RunOnce();
|
|
||||||
|
|
||||||
// Sleep for a short duration to control the frame rate (60 FPS).
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000 / 60));
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,12 +22,10 @@ MenuEntryOption Colored(ftxui::Color c) {
|
|||||||
option.transform = [c](EntryState state) {
|
option.transform = [c](EntryState state) {
|
||||||
state.label = (state.active ? "> " : " ") + state.label;
|
state.label = (state.active ? "> " : " ") + state.label;
|
||||||
Element e = text(state.label) | color(c);
|
Element e = text(state.label) | color(c);
|
||||||
if (state.focused) {
|
if (state.focused)
|
||||||
e = e | inverted;
|
e = e | inverted;
|
||||||
}
|
if (state.active)
|
||||||
if (state.active) {
|
|
||||||
e = e | bold;
|
e = e | bold;
|
||||||
}
|
|
||||||
return e;
|
return e;
|
||||||
};
|
};
|
||||||
return option;
|
return option;
|
||||||
|
|||||||
@@ -17,9 +17,8 @@ int main() {
|
|||||||
std::vector<std::string> entries;
|
std::vector<std::string> entries;
|
||||||
int selected = 0;
|
int selected = 0;
|
||||||
|
|
||||||
for (int i = 0; i < 30; ++i) {
|
for (int i = 0; i < 30; ++i)
|
||||||
entries.push_back("Entry " + std::to_string(i));
|
entries.push_back("Entry " + std::to_string(i));
|
||||||
}
|
|
||||||
auto radiobox = Menu(&entries, &selected);
|
auto radiobox = Menu(&entries, &selected);
|
||||||
auto renderer = Renderer(radiobox, [&] {
|
auto renderer = Renderer(radiobox, [&] {
|
||||||
return radiobox->Render() | vscroll_indicator | frame |
|
return radiobox->Render() | vscroll_indicator | frame |
|
||||||
|
|||||||
@@ -17,9 +17,8 @@ int main() {
|
|||||||
std::vector<std::string> entries;
|
std::vector<std::string> entries;
|
||||||
int selected = 0;
|
int selected = 0;
|
||||||
|
|
||||||
for (int i = 0; i < 100; ++i) {
|
for (int i = 0; i < 100; ++i)
|
||||||
entries.push_back(std::to_string(i));
|
entries.push_back(std::to_string(i));
|
||||||
}
|
|
||||||
auto radiobox = Menu(&entries, &selected, MenuOption::Horizontal());
|
auto radiobox = Menu(&entries, &selected, MenuOption::Horizontal());
|
||||||
auto renderer = Renderer(
|
auto renderer = Renderer(
|
||||||
radiobox, [&] { return radiobox->Render() | hscroll_indicator | frame; });
|
radiobox, [&] { return radiobox->Render() | hscroll_indicator | frame; });
|
||||||
|
|||||||
@@ -116,12 +116,10 @@ Component VMenu1(std::vector<std::string>* entries, int* selected) {
|
|||||||
option.entries_option.transform = [](EntryState state) {
|
option.entries_option.transform = [](EntryState state) {
|
||||||
state.label = (state.active ? "> " : " ") + state.label;
|
state.label = (state.active ? "> " : " ") + state.label;
|
||||||
Element e = text(state.label);
|
Element e = text(state.label);
|
||||||
if (state.focused) {
|
if (state.focused)
|
||||||
e = e | bgcolor(Color::Blue);
|
e = e | bgcolor(Color::Blue);
|
||||||
}
|
if (state.active)
|
||||||
if (state.active) {
|
|
||||||
e = e | bold;
|
e = e | bold;
|
||||||
}
|
|
||||||
return e;
|
return e;
|
||||||
};
|
};
|
||||||
return Menu(entries, selected, option);
|
return Menu(entries, selected, option);
|
||||||
@@ -132,12 +130,10 @@ Component VMenu2(std::vector<std::string>* entries, int* selected) {
|
|||||||
option.entries_option.transform = [](EntryState state) {
|
option.entries_option.transform = [](EntryState state) {
|
||||||
state.label += (state.active ? " <" : " ");
|
state.label += (state.active ? " <" : " ");
|
||||||
Element e = hbox(filler(), text(state.label));
|
Element e = hbox(filler(), text(state.label));
|
||||||
if (state.focused) {
|
if (state.focused)
|
||||||
e = e | bgcolor(Color::Red);
|
e = e | bgcolor(Color::Red);
|
||||||
}
|
if (state.active)
|
||||||
if (state.active) {
|
|
||||||
e = e | bold;
|
e = e | bold;
|
||||||
}
|
|
||||||
return e;
|
return e;
|
||||||
};
|
};
|
||||||
return Menu(entries, selected, option);
|
return Menu(entries, selected, option);
|
||||||
@@ -148,16 +144,13 @@ Component VMenu3(std::vector<std::string>* entries, int* selected) {
|
|||||||
option.entries_option.transform = [](EntryState state) {
|
option.entries_option.transform = [](EntryState state) {
|
||||||
Element e = state.active ? text("[" + state.label + "]")
|
Element e = state.active ? text("[" + state.label + "]")
|
||||||
: text(" " + state.label + " ");
|
: text(" " + state.label + " ");
|
||||||
if (state.focused) {
|
if (state.focused)
|
||||||
e = e | bold;
|
e = e | bold;
|
||||||
}
|
|
||||||
|
|
||||||
if (state.focused) {
|
if (state.focused)
|
||||||
e = e | color(Color::Blue);
|
e = e | color(Color::Blue);
|
||||||
}
|
if (state.active)
|
||||||
if (state.active) {
|
|
||||||
e = e | bold;
|
e = e | bold;
|
||||||
}
|
|
||||||
return e;
|
return e;
|
||||||
};
|
};
|
||||||
return Menu(entries, selected, option);
|
return Menu(entries, selected, option);
|
||||||
@@ -252,12 +245,10 @@ Component HMenu5(std::vector<std::string>* entries, int* selected) {
|
|||||||
animation::easing::ElasticOut);
|
animation::easing::ElasticOut);
|
||||||
option.entries_option.transform = [](EntryState state) {
|
option.entries_option.transform = [](EntryState state) {
|
||||||
Element e = text(state.label) | hcenter | flex;
|
Element e = text(state.label) | hcenter | flex;
|
||||||
if (state.active && state.focused) {
|
if (state.active && state.focused)
|
||||||
e = e | bold;
|
e = e | bold;
|
||||||
}
|
if (!state.focused && !state.active)
|
||||||
if (!state.focused && !state.active) {
|
|
||||||
e = e | dim;
|
e = e | dim;
|
||||||
}
|
|
||||||
return e;
|
return e;
|
||||||
};
|
};
|
||||||
option.underline.color_inactive = Color::Default;
|
option.underline.color_inactive = Color::Default;
|
||||||
|
|||||||
@@ -20,9 +20,8 @@ using namespace ftxui;
|
|||||||
Component DummyComponent(int id) {
|
Component DummyComponent(int id) {
|
||||||
return Renderer([id](bool focused) {
|
return Renderer([id](bool focused) {
|
||||||
auto t = text("component " + std::to_string(id));
|
auto t = text("component " + std::to_string(id));
|
||||||
if (focused) {
|
if (focused)
|
||||||
t = t | inverted;
|
t = t | inverted;
|
||||||
}
|
|
||||||
return t;
|
return t;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,8 @@ int main() {
|
|||||||
std::vector<std::string> entries;
|
std::vector<std::string> entries;
|
||||||
int selected = 0;
|
int selected = 0;
|
||||||
|
|
||||||
for (int i = 0; i < 30; ++i) {
|
for (int i = 0; i < 30; ++i)
|
||||||
entries.push_back("RadioBox " + std::to_string(i));
|
entries.push_back("RadioBox " + std::to_string(i));
|
||||||
}
|
|
||||||
auto radiobox = Radiobox(&entries, &selected);
|
auto radiobox = Radiobox(&entries, &selected);
|
||||||
auto renderer = Renderer(radiobox, [&] {
|
auto renderer = Renderer(radiobox, [&] {
|
||||||
return radiobox->Render() | vscroll_indicator | frame |
|
return radiobox->Render() | vscroll_indicator | frame |
|
||||||
|
|||||||
@@ -19,11 +19,10 @@ int main() {
|
|||||||
|
|
||||||
// 1. Example of focusable renderer:
|
// 1. Example of focusable renderer:
|
||||||
auto renderer_focusable = Renderer([](bool focused) {
|
auto renderer_focusable = Renderer([](bool focused) {
|
||||||
if (focused) {
|
if (focused)
|
||||||
return text("FOCUSABLE RENDERER()") | center | bold | border;
|
return text("FOCUSABLE RENDERER()") | center | bold | border;
|
||||||
} else {
|
else
|
||||||
return text(" Focusable renderer() ") | center | border;
|
return text(" Focusable renderer() ") | center | border;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 2. Examples of a non focusable renderer.
|
// 2. Examples of a non focusable renderer.
|
||||||
@@ -34,11 +33,10 @@ int main() {
|
|||||||
// 3. Renderer can wrap other components to redefine their Render() function.
|
// 3. Renderer can wrap other components to redefine their Render() function.
|
||||||
auto button = Button("Wrapped quit button", screen.ExitLoopClosure());
|
auto button = Button("Wrapped quit button", screen.ExitLoopClosure());
|
||||||
auto renderer_wrap = Renderer(button, [&] {
|
auto renderer_wrap = Renderer(button, [&] {
|
||||||
if (button->Focused()) {
|
if (button->Focused())
|
||||||
return button->Render() | bold | color(Color::Red);
|
return button->Render() | bold | color(Color::Red);
|
||||||
} else {
|
else
|
||||||
return button->Render();
|
return button->Render();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Let's renderer everyone:
|
// Let's renderer everyone:
|
||||||
|
|||||||
@@ -32,12 +32,10 @@ int main() {
|
|||||||
|
|
||||||
// Plot a function:
|
// Plot a function:
|
||||||
std::vector<int> ys(100);
|
std::vector<int> ys(100);
|
||||||
for (int x = 0; x < 100; x++) {
|
for (int x = 0; x < 100; x++)
|
||||||
ys[x] = int(80 + 20 * cos(x * 0.2));
|
ys[x] = int(80 + 20 * cos(x * 0.2));
|
||||||
}
|
for (int x = 0; x < 99; x++)
|
||||||
for (int x = 0; x < 99; x++) {
|
|
||||||
c.DrawPointLine(x, ys[x], x + 1, ys[x + 1], Color::Red);
|
c.DrawPointLine(x, ys[x], x + 1, ys[x + 1], Color::Red);
|
||||||
}
|
|
||||||
|
|
||||||
auto document = canvas(&c) | border;
|
auto document = canvas(&c) | border;
|
||||||
|
|
||||||
|
|||||||
@@ -86,9 +86,8 @@ int main() {
|
|||||||
|
|
||||||
auto render = [&]() {
|
auto render = [&]() {
|
||||||
std::vector<Element> entries;
|
std::vector<Element> entries;
|
||||||
for (auto& task : displayed_task) {
|
for (auto& task : displayed_task)
|
||||||
entries.push_back(renderTask(task));
|
entries.push_back(renderTask(task));
|
||||||
}
|
|
||||||
|
|
||||||
return vbox({
|
return vbox({
|
||||||
// List of tasks.
|
// List of tasks.
|
||||||
@@ -139,9 +138,8 @@ int main() {
|
|||||||
std::this_thread::sleep_for(0.01s);
|
std::this_thread::sleep_for(0.01s);
|
||||||
|
|
||||||
// Exit
|
// Exit
|
||||||
if (nb_active + nb_queued == 0) {
|
if (nb_active + nb_queued == 0)
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
// Update the model for the next frame.
|
// Update the model for the next frame.
|
||||||
updateModel();
|
updateModel();
|
||||||
|
|||||||
@@ -21,9 +21,8 @@ int main() {
|
|||||||
for (int index = 0; index < 200; ++index) {
|
for (int index = 0; index < 200; ++index) {
|
||||||
std::vector<Element> entries;
|
std::vector<Element> entries;
|
||||||
for (int i = 0; i < 23; ++i) {
|
for (int i = 0; i < 23; ++i) {
|
||||||
if (i != 0) {
|
if (i != 0)
|
||||||
entries.push_back(separator());
|
entries.push_back(separator());
|
||||||
}
|
|
||||||
entries.push_back( //
|
entries.push_back( //
|
||||||
hbox({
|
hbox({
|
||||||
text(std::to_string(i)) | size(WIDTH, EQUAL, 2),
|
text(std::to_string(i)) | size(WIDTH, EQUAL, 2),
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ if ("serviceWorker" in navigator && !window.crossOriginIsolated) {
|
|||||||
const url_sw = new URL("./sw.js", location.href);
|
const url_sw = new URL("./sw.js", location.href);
|
||||||
const registration = await navigator.serviceWorker.register(url_sw);
|
const registration = await navigator.serviceWorker.register(url_sw);
|
||||||
window.location.reload(); // Reload to ensure the COOP/COEP headers are set.
|
window.location.reload(); // Reload to ensure the COOP/COEP headers are set.
|
||||||
}
|
}
|
||||||
|
|
||||||
const example_list = "@EXAMPLES@".split(";");
|
const example_list = "@EXAMPLES@".split(";");
|
||||||
const url_search_params = new URLSearchParams(window.location.search);
|
const url_search_params = new URLSearchParams(window.location.search);
|
||||||
@@ -55,7 +55,7 @@ const stdout = code => {
|
|||||||
const stderr = code => {
|
const stderr = code => {
|
||||||
if (code == 0 || code == 10) {
|
if (code == 0 || code == 10) {
|
||||||
console.error(String.fromCodePoint(...stderr_buffer));
|
console.error(String.fromCodePoint(...stderr_buffer));
|
||||||
stderr_buffer.length = 0;
|
stderr_buffer = [];
|
||||||
} else {
|
} else {
|
||||||
stderr_buffer.push(code)
|
stderr_buffer.push(code)
|
||||||
}
|
}
|
||||||
@@ -89,6 +89,9 @@ window.Module = {
|
|||||||
const resize_observer = new ResizeObserver(resize_handler);
|
const resize_observer = new ResizeObserver(resize_handler);
|
||||||
resize_observer.observe(term_element);
|
resize_observer.observe(term_element);
|
||||||
resize_handler();
|
resize_handler();
|
||||||
|
|
||||||
|
// Disable scrollbar
|
||||||
|
//term.write('\x1b[?47h')
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -8,21 +8,11 @@
|
|||||||
#include <functional> // for function
|
#include <functional> // for function
|
||||||
|
|
||||||
namespace ftxui::animation {
|
namespace ftxui::animation {
|
||||||
/// @brief RequestAnimationFrame is a function that requests a new frame to be
|
// Components who haven't completed their animation can call this function to
|
||||||
/// drawn in the next animation cycle.
|
// request a new frame to be drawn later.
|
||||||
///
|
//
|
||||||
/// @note This function is typically called by components that need to
|
// When there is no new events and no animations to complete, no new frame is
|
||||||
/// update their state or appearance over time, such as animations or
|
// drawn.
|
||||||
/// transitions. This is useful when the change doesn't depend depend on the
|
|
||||||
/// events seen by the terminal, but rather on the passage of time.
|
|
||||||
///
|
|
||||||
/// Components who haven't completed their animation can call this function to
|
|
||||||
/// request a new frame to be drawn later.
|
|
||||||
///
|
|
||||||
/// When there is no new events and no animations to complete, no new frame is
|
|
||||||
/// drawn.
|
|
||||||
///
|
|
||||||
/// @ingroup component
|
|
||||||
void RequestAnimationFrame();
|
void RequestAnimationFrame();
|
||||||
|
|
||||||
using Clock = std::chrono::steady_clock;
|
using Clock = std::chrono::steady_clock;
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
|
|
||||||
class CapturedMouseInterface {
|
class CapturedMouseInterface {
|
||||||
public:
|
public:
|
||||||
CapturedMouseInterface() = default;
|
CapturedMouseInterface() = default;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
#include <memory> // for make_shared, shared_ptr
|
#include <memory> // for make_shared, shared_ptr
|
||||||
#include <utility> // for forward
|
#include <utility> // for forward
|
||||||
|
|
||||||
#include <ftxui/util/warn_windows_macro.hpp>
|
|
||||||
#include "ftxui/component/component_base.hpp" // for Component, Components
|
#include "ftxui/component/component_base.hpp" // for Component, Components
|
||||||
#include "ftxui/component/component_options.hpp" // for ButtonOption, CheckboxOption, MenuOption
|
#include "ftxui/component/component_options.hpp" // for ButtonOption, CheckboxOption, MenuOption
|
||||||
#include "ftxui/dom/elements.hpp" // for Element
|
#include "ftxui/dom/elements.hpp" // for Element
|
||||||
|
|||||||
@@ -9,9 +9,8 @@
|
|||||||
#include <ftxui/dom/direction.hpp> // for Direction, Direction::Left, Direction::Right, Direction::Down
|
#include <ftxui/dom/direction.hpp> // for Direction, Direction::Left, Direction::Right, Direction::Down
|
||||||
#include <ftxui/dom/elements.hpp> // for Element, separator
|
#include <ftxui/dom/elements.hpp> // for Element, separator
|
||||||
#include <ftxui/util/ref.hpp> // for Ref, ConstRef, StringRef
|
#include <ftxui/util/ref.hpp> // for Ref, ConstRef, StringRef
|
||||||
#include <ftxui/util/warn_windows_macro.hpp>
|
#include <functional> // for function
|
||||||
#include <functional> // for function
|
#include <string> // for string
|
||||||
#include <string> // for string
|
|
||||||
|
|
||||||
#include "ftxui/component/component_base.hpp" // for Component
|
#include "ftxui/component/component_base.hpp" // for Component
|
||||||
#include "ftxui/screen/color.hpp" // for Color, Color::GrayDark, Color::White
|
#include "ftxui/screen/color.hpp" // for Color, Color::GrayDark, Color::White
|
||||||
@@ -28,8 +27,6 @@ struct EntryState {
|
|||||||
int index; ///< Index of the entry when applicable or -1.
|
int index; ///< Index of the entry when applicable or -1.
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Option for the underline effect.
|
|
||||||
/// @ingroup component
|
|
||||||
struct UnderlineOption {
|
struct UnderlineOption {
|
||||||
bool enabled = false;
|
bool enabled = false;
|
||||||
|
|
||||||
@@ -233,8 +230,7 @@ struct SliderOption {
|
|||||||
std::function<void()> on_change; ///> Called when `value` is updated.
|
std::function<void()> on_change; ///> Called when `value` is updated.
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief State passed to the `Window` component's render function.
|
// Parameter pack used by `WindowOptions::render`.
|
||||||
/// @ingroup component
|
|
||||||
struct WindowRenderState {
|
struct WindowRenderState {
|
||||||
Element inner; ///< The element wrapped inside this window.
|
Element inner; ///< The element wrapped inside this window.
|
||||||
const std::string& title; ///< The title of the window.
|
const std::string& title; ///< The title of the window.
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ class ComponentBase;
|
|||||||
///
|
///
|
||||||
/// Useful documentation about xterm specification:
|
/// Useful documentation about xterm specification:
|
||||||
/// https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
|
/// https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
|
||||||
///
|
|
||||||
/// @ingroup component
|
|
||||||
struct Event {
|
struct Event {
|
||||||
// --- Constructor section ---------------------------------------------------
|
// --- Constructor section ---------------------------------------------------
|
||||||
static Event Character(std::string);
|
static Event Character(std::string);
|
||||||
|
|||||||
@@ -14,45 +14,6 @@ class ComponentBase;
|
|||||||
using Component = std::shared_ptr<ComponentBase>;
|
using Component = std::shared_ptr<ComponentBase>;
|
||||||
class ScreenInteractive;
|
class ScreenInteractive;
|
||||||
|
|
||||||
/// @brief Loop is a class that manages the event loop for a component.
|
|
||||||
///
|
|
||||||
/// It is responsible for running the component, handling events, and
|
|
||||||
/// updating the screen.
|
|
||||||
///
|
|
||||||
/// The Loop class is designed to be used with a ScreenInteractive object,
|
|
||||||
/// which represents the terminal screen.
|
|
||||||
///
|
|
||||||
/// **Example**
|
|
||||||
/// ```cpp
|
|
||||||
/// #include <ftxui/component/component.hpp>
|
|
||||||
/// #include <ftxui/component/screen_interactive.hpp>
|
|
||||||
/// #include <ftxui/component/loop.hpp>
|
|
||||||
///
|
|
||||||
/// int main() {
|
|
||||||
/// auto screen = ftxui::ScreenInteractive::TerminalOutput();
|
|
||||||
/// auto component = ftxui::Button("Click me", [] { ... });
|
|
||||||
///
|
|
||||||
/// ftxui::Loop loop(screen.get(), component);
|
|
||||||
///
|
|
||||||
/// // Either
|
|
||||||
/// loop.Run(); // Blocking until the component quits.
|
|
||||||
///
|
|
||||||
/// // Or
|
|
||||||
/// loop.RunOnce(); // Non-blocking, returns immediately.
|
|
||||||
///
|
|
||||||
/// // Or
|
|
||||||
/// loop.RunOnceBlocking(); // Blocking until handling one event.
|
|
||||||
///
|
|
||||||
/// // Or in a loop:
|
|
||||||
/// while (!loop.HasQuitted()) {
|
|
||||||
/// loop.RunOnce();
|
|
||||||
///
|
|
||||||
/// // Do something else like running a different library loop function.
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// @ingroup component
|
|
||||||
class Loop {
|
class Loop {
|
||||||
public:
|
public:
|
||||||
Loop(ScreenInteractive* screen, Component component);
|
Loop(ScreenInteractive* screen, Component component);
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#ifndef FTXUI_COMPONENT_RECEIVER_HPP_
|
#ifndef FTXUI_COMPONENT_RECEIVER_HPP_
|
||||||
#define FTXUI_COMPONENT_RECEIVER_HPP_
|
#define FTXUI_COMPONENT_RECEIVER_HPP_
|
||||||
|
|
||||||
#include <ftxui/util/warn_windows_macro.h>
|
|
||||||
#include <algorithm> // for copy, max
|
#include <algorithm> // for copy, max
|
||||||
#include <atomic> // for atomic, __atomic_base
|
#include <atomic> // for atomic, __atomic_base
|
||||||
#include <condition_variable> // for condition_variable
|
#include <condition_variable> // for condition_variable
|
||||||
@@ -15,8 +14,6 @@
|
|||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
|
|
||||||
// Deprecated
|
|
||||||
//
|
|
||||||
// Usage:
|
// Usage:
|
||||||
//
|
//
|
||||||
// Initialization:
|
// Initialization:
|
||||||
@@ -42,24 +39,17 @@ namespace ftxui {
|
|||||||
// Receiver::Receive() returns true when there are no more senders.
|
// Receiver::Receive() returns true when there are no more senders.
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
// Deprecated:
|
|
||||||
template<class T> class SenderImpl;
|
template<class T> class SenderImpl;
|
||||||
// Deprecated:
|
|
||||||
template<class T> class ReceiverImpl;
|
template<class T> class ReceiverImpl;
|
||||||
// Deprecated:
|
|
||||||
|
|
||||||
// Deprecated:
|
|
||||||
template<class T> using Sender = std::unique_ptr<SenderImpl<T>>;
|
template<class T> using Sender = std::unique_ptr<SenderImpl<T>>;
|
||||||
// Deprecated:
|
|
||||||
template<class T> using Receiver = std::unique_ptr<ReceiverImpl<T>>;
|
template<class T> using Receiver = std::unique_ptr<ReceiverImpl<T>>;
|
||||||
// Deprecated:
|
|
||||||
template<class T> Receiver<T> MakeReceiver();
|
template<class T> Receiver<T> MakeReceiver();
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
// ---- Implementation part ----
|
// ---- Implementation part ----
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
// Deprecated:
|
|
||||||
class SenderImpl {
|
class SenderImpl {
|
||||||
public:
|
public:
|
||||||
SenderImpl(const SenderImpl&) = delete;
|
SenderImpl(const SenderImpl&) = delete;
|
||||||
|
|||||||
@@ -4,10 +4,13 @@
|
|||||||
#ifndef FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
|
#ifndef FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
|
||||||
#define FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
|
#define FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
|
||||||
|
|
||||||
#include <atomic> // for atomic
|
#include <atomic> // for atomic
|
||||||
#include <functional> // for function
|
#include <ftxui/component/receiver.hpp> // for Receiver, Sender
|
||||||
#include <memory> // for shared_ptr
|
#include <functional> // for function
|
||||||
#include <string> // for string
|
#include <memory> // for shared_ptr
|
||||||
|
#include <string> // for string
|
||||||
|
#include <thread> // for thread
|
||||||
|
#include <variant> // for variant
|
||||||
|
|
||||||
#include "ftxui/component/animation.hpp" // for TimePoint
|
#include "ftxui/component/animation.hpp" // for TimePoint
|
||||||
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
|
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
|
||||||
@@ -24,14 +27,6 @@ struct Event;
|
|||||||
using Component = std::shared_ptr<ComponentBase>;
|
using Component = std::shared_ptr<ComponentBase>;
|
||||||
class ScreenInteractivePrivate;
|
class ScreenInteractivePrivate;
|
||||||
|
|
||||||
namespace task {
|
|
||||||
class TaskRunner;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @brief ScreenInteractive is a `Screen` that can handle events, run a main
|
|
||||||
/// loop, and manage components.
|
|
||||||
///
|
|
||||||
/// @ingroup component
|
|
||||||
class ScreenInteractive : public Screen {
|
class ScreenInteractive : public Screen {
|
||||||
public:
|
public:
|
||||||
// Constructors:
|
// Constructors:
|
||||||
@@ -42,12 +37,8 @@ class ScreenInteractive : public Screen {
|
|||||||
static ScreenInteractive FitComponent();
|
static ScreenInteractive FitComponent();
|
||||||
static ScreenInteractive TerminalOutput();
|
static ScreenInteractive TerminalOutput();
|
||||||
|
|
||||||
// Destructor.
|
|
||||||
~ScreenInteractive() override;
|
|
||||||
|
|
||||||
// Options. Must be called before Loop().
|
// Options. Must be called before Loop().
|
||||||
void TrackMouse(bool enable = true);
|
void TrackMouse(bool enable = true);
|
||||||
void HandlePipedInput(bool enable = true);
|
|
||||||
|
|
||||||
// Return the currently active screen, nullptr if none.
|
// Return the currently active screen, nullptr if none.
|
||||||
static ScreenInteractive* Active();
|
static ScreenInteractive* Active();
|
||||||
@@ -101,14 +92,8 @@ class ScreenInteractive : public Screen {
|
|||||||
void Draw(Component component);
|
void Draw(Component component);
|
||||||
void ResetCursorPosition();
|
void ResetCursorPosition();
|
||||||
|
|
||||||
void InstallPipedInputHandling();
|
|
||||||
|
|
||||||
void Signal(int signal);
|
void Signal(int signal);
|
||||||
|
|
||||||
void FetchTerminalEvents();
|
|
||||||
|
|
||||||
void PostAnimationTask();
|
|
||||||
|
|
||||||
ScreenInteractive* suspended_screen_ = nullptr;
|
ScreenInteractive* suspended_screen_ = nullptr;
|
||||||
enum class Dimension {
|
enum class Dimension {
|
||||||
FitComponent,
|
FitComponent,
|
||||||
@@ -116,27 +101,30 @@ class ScreenInteractive : public Screen {
|
|||||||
Fullscreen,
|
Fullscreen,
|
||||||
TerminalOutput,
|
TerminalOutput,
|
||||||
};
|
};
|
||||||
ScreenInteractive(Dimension dimension,
|
Dimension dimension_ = Dimension::Fixed;
|
||||||
int dimx,
|
bool use_alternative_screen_ = false;
|
||||||
|
ScreenInteractive(int dimx,
|
||||||
int dimy,
|
int dimy,
|
||||||
|
Dimension dimension,
|
||||||
bool use_alternative_screen);
|
bool use_alternative_screen);
|
||||||
|
|
||||||
const Dimension dimension_;
|
|
||||||
const bool use_alternative_screen_;
|
|
||||||
|
|
||||||
bool track_mouse_ = true;
|
bool track_mouse_ = true;
|
||||||
|
|
||||||
|
Sender<Task> task_sender_;
|
||||||
|
Receiver<Task> task_receiver_;
|
||||||
|
|
||||||
std::string set_cursor_position;
|
std::string set_cursor_position;
|
||||||
std::string reset_cursor_position;
|
std::string reset_cursor_position;
|
||||||
|
|
||||||
std::atomic<bool> quit_{false};
|
std::atomic<bool> quit_{false};
|
||||||
|
std::thread event_listener_;
|
||||||
|
std::thread animation_listener_;
|
||||||
bool animation_requested_ = false;
|
bool animation_requested_ = false;
|
||||||
animation::TimePoint previous_animation_time_;
|
animation::TimePoint previous_animation_time_;
|
||||||
|
|
||||||
int cursor_x_ = 1;
|
int cursor_x_ = 1;
|
||||||
int cursor_y_ = 1;
|
int cursor_y_ = 1;
|
||||||
|
|
||||||
std::uint64_t frame_count_ = 0;
|
|
||||||
bool mouse_captured = false;
|
bool mouse_captured = false;
|
||||||
bool previous_frame_resized_ = false;
|
bool previous_frame_resized_ = false;
|
||||||
|
|
||||||
@@ -145,9 +133,6 @@ class ScreenInteractive : public Screen {
|
|||||||
bool force_handle_ctrl_c_ = true;
|
bool force_handle_ctrl_c_ = true;
|
||||||
bool force_handle_ctrl_z_ = true;
|
bool force_handle_ctrl_z_ = true;
|
||||||
|
|
||||||
// Piped input handling state (POSIX only)
|
|
||||||
bool handle_piped_input_ = true;
|
|
||||||
|
|
||||||
// The style of the cursor to restore on exit.
|
// The style of the cursor to restore on exit.
|
||||||
int cursor_reset_shape_ = 1;
|
int cursor_reset_shape_ = 1;
|
||||||
|
|
||||||
@@ -167,14 +152,8 @@ class ScreenInteractive : public Screen {
|
|||||||
std::unique_ptr<Selection> selection_;
|
std::unique_ptr<Selection> selection_;
|
||||||
std::function<void()> selection_on_change_;
|
std::function<void()> selection_on_change_;
|
||||||
|
|
||||||
// PIMPL private implementation idiom (Pimpl).
|
|
||||||
struct Internal;
|
|
||||||
std::unique_ptr<Internal> internal_;
|
|
||||||
|
|
||||||
friend class Loop;
|
friend class Loop;
|
||||||
|
|
||||||
Component component_;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
class Private {
|
class Private {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -20,21 +20,6 @@
|
|||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
|
|
||||||
/// @brief Canvas is a drawable buffer associated with drawing operations.
|
|
||||||
///
|
|
||||||
/// Canvas is a drawable area that can be used to create complex graphics. It
|
|
||||||
/// supports drawing points, lines, circles, ellipses, text, and images using
|
|
||||||
/// braille, block, or normal characters.
|
|
||||||
///
|
|
||||||
/// Note: A terminal contains cells. A cells is a unit of:
|
|
||||||
/// - 2x4 braille characters (1x1 pixel)
|
|
||||||
/// - 2x2 block characters (2x2 pixels)
|
|
||||||
/// - 2x4 normal characters (2x4 pixels)
|
|
||||||
///
|
|
||||||
/// You need to multiply the x coordinate by 2 and the y coordinate by 4 to
|
|
||||||
/// get the correct position in the terminal.
|
|
||||||
///
|
|
||||||
/// @ingroup dom
|
|
||||||
struct Canvas {
|
struct Canvas {
|
||||||
public:
|
public:
|
||||||
Canvas() = default;
|
Canvas() = default;
|
||||||
|
|||||||
@@ -5,11 +5,6 @@
|
|||||||
#define FTXUI_DOM_DIRECTION_HPP
|
#define FTXUI_DOM_DIRECTION_HPP
|
||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
|
|
||||||
/// @brief Direction is an enumeration that represents the four cardinal
|
|
||||||
/// directions.
|
|
||||||
///
|
|
||||||
/// @ingroup dom
|
|
||||||
enum class Direction {
|
enum class Direction {
|
||||||
Up = 0,
|
Up = 0,
|
||||||
Down = 1,
|
Down = 1,
|
||||||
|
|||||||
@@ -24,14 +24,6 @@ using Elements = std::vector<Element>;
|
|||||||
using Decorator = std::function<Element(Element)>;
|
using Decorator = std::function<Element(Element)>;
|
||||||
using GraphFunction = std::function<std::vector<int>(int, int)>;
|
using GraphFunction = std::function<std::vector<int>(int, int)>;
|
||||||
|
|
||||||
/// @brief BorderStyle is an enumeration that represents the different styles
|
|
||||||
/// of borders that can be applied to elements in the terminal UI.
|
|
||||||
///
|
|
||||||
/// BorderStyle is an enumeration that represents the different styles of
|
|
||||||
/// borders that can be applied to elements in the terminal UI.
|
|
||||||
/// It is used to define the visual appearance of borders around elements,
|
|
||||||
/// such as windows, frames, or separators.
|
|
||||||
/// @ingroup dom
|
|
||||||
enum BorderStyle {
|
enum BorderStyle {
|
||||||
LIGHT,
|
LIGHT,
|
||||||
DASHED,
|
DASHED,
|
||||||
|
|||||||
@@ -12,18 +12,6 @@
|
|||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
|
|
||||||
/// @brief FlexboxConfig is a configuration structure that defines the layout
|
|
||||||
/// properties for a flexbox container.
|
|
||||||
//
|
|
||||||
/// It allows you to specify the direction of the flex items, whether they
|
|
||||||
/// should wrap, how they should be justified along the main axis, and how
|
|
||||||
/// they should be aligned along the cross axis.
|
|
||||||
/// It also includes properties for gaps between flex items in both the
|
|
||||||
/// main and cross axes.
|
|
||||||
/// This structure is used to configure the layout behavior of flexbox
|
|
||||||
/// containers in a terminal user interface.
|
|
||||||
///
|
|
||||||
/// @ingroup dom
|
|
||||||
struct FlexboxConfig {
|
struct FlexboxConfig {
|
||||||
/// This establishes the main-axis, thus defining the direction flex items are
|
/// This establishes the main-axis, thus defining the direction flex items are
|
||||||
/// placed in the flex container. Flexbox is (aside wrapping) single-direction
|
/// placed in the flex container. Flexbox is (aside wrapping) single-direction
|
||||||
|
|||||||
@@ -27,15 +27,8 @@ namespace ftxui {
|
|||||||
/// LinearGradient(Color::Red, Color::Blue);
|
/// LinearGradient(Color::Red, Color::Blue);
|
||||||
/// LinearGradient(45, Color::Red, Color::Blue);
|
/// LinearGradient(45, Color::Red, Color::Blue);
|
||||||
/// ```
|
/// ```
|
||||||
///
|
|
||||||
/// @ingroup dom
|
|
||||||
struct LinearGradient {
|
struct LinearGradient {
|
||||||
float angle = 0.f;
|
float angle = 0.f;
|
||||||
|
|
||||||
/// A stop is a color at a specific position in the gradient.
|
|
||||||
/// The position is a value between 0.0 and 1.0,
|
|
||||||
/// where 0.0 is the start of the gradient
|
|
||||||
/// and 1.0 is the end of the gradient.
|
|
||||||
struct Stop {
|
struct Stop {
|
||||||
Color color = Color::Default;
|
Color color = Color::Default;
|
||||||
std::optional<float> position;
|
std::optional<float> position;
|
||||||
|
|||||||
@@ -20,20 +20,6 @@ class Screen;
|
|||||||
using Element = std::shared_ptr<Node>;
|
using Element = std::shared_ptr<Node>;
|
||||||
using Elements = std::vector<Element>;
|
using Elements = std::vector<Element>;
|
||||||
|
|
||||||
/// @brief Node is the base class for all elements in the DOM tree.
|
|
||||||
///
|
|
||||||
/// It represents a single node in the document object model (DOM) and provides
|
|
||||||
/// the basic structure for layout and rendering.
|
|
||||||
/// It contains methods for computing layout requirements, setting the box
|
|
||||||
/// dimensions, selecting content, rendering to the screen, and checking the
|
|
||||||
/// layout status.
|
|
||||||
/// It typically contains child elements, which are also instances of Node.
|
|
||||||
///
|
|
||||||
/// Users are expected to derive from this class to create custom elements.
|
|
||||||
///
|
|
||||||
/// A list of builtin elements can be found in the `elements.hpp` file.
|
|
||||||
///
|
|
||||||
/// @ingroup dom
|
|
||||||
class Node {
|
class Node {
|
||||||
public:
|
public:
|
||||||
Node();
|
Node();
|
||||||
|
|||||||
@@ -10,11 +10,6 @@
|
|||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
class Node;
|
class Node;
|
||||||
|
|
||||||
/// @brief Requirement is a structure that defines the layout requirements for a
|
|
||||||
/// Node in the terminal user interface.
|
|
||||||
///
|
|
||||||
/// It specifies the minimum size required to fully draw the element,
|
|
||||||
/// @ingroup dom
|
|
||||||
struct Requirement {
|
struct Requirement {
|
||||||
// The required size to fully draw the element.
|
// The required size to fully draw the element.
|
||||||
int min_x = 0;
|
int min_x = 0;
|
||||||
|
|||||||
@@ -13,12 +13,7 @@
|
|||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
|
|
||||||
/// @brief Represents a selection in a terminal user interface.
|
/// @brief Represent a selection in the terminal.
|
||||||
///
|
|
||||||
/// Selection is a class that represents the two endpoints of a selection in a
|
|
||||||
/// terminal user interface.
|
|
||||||
///
|
|
||||||
/// @ingroup dom
|
|
||||||
class Selection {
|
class Selection {
|
||||||
public:
|
public:
|
||||||
Selection(); // Empty selection.
|
Selection(); // Empty selection.
|
||||||
|
|||||||
@@ -11,28 +11,28 @@
|
|||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
|
|
||||||
|
// Usage:
|
||||||
|
//
|
||||||
|
// Initialization:
|
||||||
|
// ---------------
|
||||||
|
//
|
||||||
|
// auto table = Table({
|
||||||
|
// {"X", "Y"},
|
||||||
|
// {"-1", "1"},
|
||||||
|
// {"+0", "0"},
|
||||||
|
// {"+1", "1"},
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// table.SelectAll().Border(LIGHT);
|
||||||
|
//
|
||||||
|
// table.SelectRow(1).Border(DOUBLE);
|
||||||
|
// table.SelectRow(1).SeparatorInternal(Light);
|
||||||
|
//
|
||||||
|
// std::move(table).Element();
|
||||||
|
|
||||||
class Table;
|
class Table;
|
||||||
class TableSelection;
|
class TableSelection;
|
||||||
|
|
||||||
/// @brief Table is a utility to draw tables.
|
|
||||||
///
|
|
||||||
/// **example**
|
|
||||||
/// ```cpp
|
|
||||||
/// auto table = Table({
|
|
||||||
/// {"X", "Y"},
|
|
||||||
/// {"-1", "1"},
|
|
||||||
/// {"+0", "0"},
|
|
||||||
/// {"+1", "1"},
|
|
||||||
/// });
|
|
||||||
///
|
|
||||||
/// table.SelectAll().Border(LIGHT);
|
|
||||||
/// table.SelectRow(1).Border(DOUBLE);
|
|
||||||
/// table.SelectRow(1).SeparatorInternal(LIGHT);
|
|
||||||
///
|
|
||||||
/// std::move(table).Render();
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// @ingroup dom
|
|
||||||
class Table {
|
class Table {
|
||||||
public:
|
public:
|
||||||
Table();
|
Table();
|
||||||
|
|||||||
@@ -6,13 +6,6 @@
|
|||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
|
|
||||||
/// @brief Box is a structure that represents a rectangular area in a 2D space.
|
|
||||||
///
|
|
||||||
/// It is defined by its minimum and maximum coordinates along the x and y axes.
|
|
||||||
/// Note that the coordinates are inclusive, meaning that the box includes both
|
|
||||||
/// the minimum and maximum values.
|
|
||||||
///
|
|
||||||
/// @ingroup screen
|
|
||||||
struct Box {
|
struct Box {
|
||||||
int x_min = 0;
|
int x_min = 0;
|
||||||
int x_max = 0;
|
int x_max = 0;
|
||||||
|
|||||||
@@ -15,9 +15,7 @@
|
|||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
|
|
||||||
/// @brief Color is a class that represents a color in the terminal user
|
/// @brief A class representing terminal colors.
|
||||||
/// interface.
|
|
||||||
///
|
|
||||||
/// @ingroup screen
|
/// @ingroup screen
|
||||||
class Color {
|
class Color {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -9,10 +9,6 @@
|
|||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
|
|
||||||
/// @brief ColorInfo is a structure that contains information about the terminal
|
|
||||||
/// color palette.
|
|
||||||
///
|
|
||||||
/// @ingroup screen
|
|
||||||
struct ColorInfo {
|
struct ColorInfo {
|
||||||
const char* name;
|
const char* name;
|
||||||
uint8_t index_256;
|
uint8_t index_256;
|
||||||
|
|||||||
@@ -20,9 +20,6 @@ class Image {
|
|||||||
Image() = delete;
|
Image() = delete;
|
||||||
Image(int dimx, int dimy);
|
Image(int dimx, int dimy);
|
||||||
|
|
||||||
// Destructor:
|
|
||||||
virtual ~Image() = default;
|
|
||||||
|
|
||||||
// Access a character in the grid at a given position.
|
// Access a character in the grid at a given position.
|
||||||
std::string& at(int x, int y);
|
std::string& at(int x, int y);
|
||||||
const std::string& at(int x, int y) const;
|
const std::string& at(int x, int y) const;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include "ftxui/screen/image.hpp" // for Pixel, Image
|
#include "ftxui/screen/image.hpp" // for Pixel, Image
|
||||||
#include "ftxui/screen/terminal.hpp" // for Dimensions
|
#include "ftxui/screen/terminal.hpp" // for Dimensions
|
||||||
|
#include "ftxui/util/autoreset.hpp" // for AutoReset
|
||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
|
|
||||||
@@ -30,9 +31,6 @@ class Screen : public Image {
|
|||||||
static Screen Create(Dimensions dimension);
|
static Screen Create(Dimensions dimension);
|
||||||
static Screen Create(Dimensions width, Dimensions height);
|
static Screen Create(Dimensions width, Dimensions height);
|
||||||
|
|
||||||
// Destructor:
|
|
||||||
~Screen() override = default;
|
|
||||||
|
|
||||||
std::string ToString() const;
|
std::string ToString() const;
|
||||||
|
|
||||||
// Print the Screen on to the terminal.
|
// Print the Screen on to the terminal.
|
||||||
|
|||||||
@@ -5,9 +5,6 @@
|
|||||||
#define FTXUI_SCREEN_TERMINAL_HPP
|
#define FTXUI_SCREEN_TERMINAL_HPP
|
||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
|
|
||||||
/// @brief Dimensions is a structure that represents the size of the terminal
|
|
||||||
/// @ingroup screen
|
|
||||||
struct Dimensions {
|
struct Dimensions {
|
||||||
int dimx;
|
int dimx;
|
||||||
int dimy;
|
int dimy;
|
||||||
@@ -17,9 +14,6 @@ namespace Terminal {
|
|||||||
Dimensions Size();
|
Dimensions Size();
|
||||||
void SetFallbackSize(const Dimensions& fallbackSize);
|
void SetFallbackSize(const Dimensions& fallbackSize);
|
||||||
|
|
||||||
/// @brief Color is an enumeration that represents the color support of the
|
|
||||||
/// terminal.
|
|
||||||
/// @ingroup screen
|
|
||||||
enum Color {
|
enum Color {
|
||||||
Palette1,
|
Palette1,
|
||||||
Palette16,
|
Palette16,
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
// Copyright 2025 Arthur Sonzogni. All rights reserved.
|
|
||||||
// Use of this source code is governed by the MIT license that can be found in
|
|
||||||
// the LICENSE file.
|
|
||||||
|
|
||||||
#ifndef FTXUI_UTIL_WARN_WINDOWS_MACRO_H_
|
|
||||||
#define FTXUI_UTIL_WARN_WINDOWS_MACRO_H_
|
|
||||||
|
|
||||||
#ifdef min
|
|
||||||
#error \
|
|
||||||
"The macro 'min' is defined, which conflicts with the standard C++ library and FTXUI. This is often caused by including <windows.h>. To fix this, add '#define NOMINMAX' before including <windows.h>, or pass '/DNOMINMAX' as a compiler flag."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef max
|
|
||||||
#error \
|
|
||||||
"The macro 'max' is defined, which conflicts with the standard C++ library and FTXUI. This is often caused by including <windows.h>. To fix this, add '#define NOMINMAX' before including <windows.h>, or pass '/DNOMINMAX' as a compiler flag."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // FTXUI_UTIL_WARN_WINDOWS_MACRO_H_
|
|
||||||
@@ -1,16 +1,18 @@
|
|||||||
/// @module ftxui.component
|
/**
|
||||||
/// @brief Module file for FTXUI component operations.
|
* @file component.cppm
|
||||||
|
* @brief Module file for FTXUI component operations.
|
||||||
|
*/
|
||||||
|
|
||||||
export module ftxui.component;
|
export module ftxui.component;
|
||||||
|
|
||||||
export import ftxui.component.animation;
|
export import ftxui.component.Animation;
|
||||||
export import ftxui.component.captured_mouse;
|
export import ftxui.component.CapturedMouse;
|
||||||
export import ftxui.component.component;
|
export import ftxui.component.Component;
|
||||||
export import ftxui.component.component_base;
|
export import ftxui.component.ComponentBase;
|
||||||
export import ftxui.component.component_options;
|
export import ftxui.component.ComponentOptions;
|
||||||
export import ftxui.component.event;
|
export import ftxui.component.Event;
|
||||||
export import ftxui.component.loop;
|
export import ftxui.component.Loop;
|
||||||
export import ftxui.component.mouse;
|
export import ftxui.component.Mouse;
|
||||||
export import ftxui.component.receiver;
|
export import ftxui.component.Receiver;
|
||||||
export import ftxui.component.screen_interactive;
|
export import ftxui.component.ScreenInteractive;
|
||||||
export import ftxui.component.task;
|
export import ftxui.component.Task;
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
/// @module ftxui.component.animation
|
/**
|
||||||
/// @brief C++20 module interface for the Animation namespace of the Component module.
|
* @file Animation.cppm
|
||||||
///
|
* @brief Module file for the Animation namespace of the Component module
|
||||||
|
*/
|
||||||
|
|
||||||
module;
|
module;
|
||||||
|
|
||||||
#include <ftxui/component/animation.hpp>
|
#include <ftxui/component/animation.hpp>
|
||||||
|
|
||||||
export module ftxui.component.animation;
|
export module ftxui.component.Animation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @namespace ftxui::animation
|
* @namespace ftxui::animation
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
/// @module ftxui.component.captured_mouse
|
/**
|
||||||
/// @brief Module file for the CapturedMouseInterface class of the Component module
|
* @file CapturedMouse.cppm
|
||||||
|
* @brief Module file for the CapturedMouseInterface class of the Component module
|
||||||
|
*/
|
||||||
|
|
||||||
module;
|
module;
|
||||||
|
|
||||||
#include <ftxui/component/captured_mouse.hpp>
|
#include <ftxui/component/captured_mouse.hpp>
|
||||||
|
|
||||||
export module ftxui.component.captured_mouse;
|
export module ftxui.component.CapturedMouse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @namespace ftxui
|
* @namespace ftxui
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
/// @module ftxui.component.component
|
/**
|
||||||
/// @brief Module file for the Component classes of the Component module
|
* @file Component.cppm
|
||||||
|
* @brief Module file for the Component classes of the Component module
|
||||||
|
*/
|
||||||
|
|
||||||
module;
|
module;
|
||||||
|
|
||||||
#include <ftxui/component/component.hpp>
|
#include <ftxui/component/component.hpp>
|
||||||
|
|
||||||
export module ftxui.component.component;
|
export module ftxui.component.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @namespace ftxui
|
* @namespace ftxui
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
/// @module ftxui.component.component_base
|
/**
|
||||||
/// @brief Module file for the ComponentBase class of the Component module
|
* @file ComponentBase.cppm
|
||||||
|
* @brief Module file for the ComponentBase class of the Component module
|
||||||
|
*/
|
||||||
|
|
||||||
module;
|
module;
|
||||||
|
|
||||||
#include <ftxui/component/component_base.hpp>
|
#include <ftxui/component/component_base.hpp>
|
||||||
|
|
||||||
export module ftxui.component.component_base;
|
export module ftxui.component.ComponentBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @namespace ftxui
|
* @namespace ftxui
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
/// @module ftxui.component.component_options
|
/**
|
||||||
/// @brief Module file for options for the Component class of the Component module
|
* @file ComponentOptions.cppm
|
||||||
|
* @brief Module file for options for the Component class of the Component module
|
||||||
|
*/
|
||||||
|
|
||||||
module;
|
module;
|
||||||
|
|
||||||
#include <ftxui/component/component_options.hpp>
|
#include <ftxui/component/component_options.hpp>
|
||||||
|
|
||||||
export module ftxui.component.component_options;
|
export module ftxui.component.ComponentOptions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @namespace ftxui
|
* @namespace ftxui
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
/// @module ftxui.component.event
|
/**
|
||||||
/// @brief Module file for the Event struct of the Component module
|
* @file Event.cppm
|
||||||
|
* @brief Module file for the Event struct of the Component module
|
||||||
|
*/
|
||||||
|
|
||||||
module;
|
module;
|
||||||
|
|
||||||
#include <ftxui/component/event.hpp>
|
#include <ftxui/component/event.hpp>
|
||||||
|
|
||||||
export module ftxui.component.event;
|
export module ftxui.component.Event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @namespace ftxui
|
* @namespace ftxui
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
/// @module ftxui.component.loop
|
/**
|
||||||
/// @brief Module file for the Loop class of the Component module
|
* @file Loop.cppm
|
||||||
|
* @brief Module file for the Loop class of the Component module
|
||||||
|
*/
|
||||||
|
|
||||||
module;
|
module;
|
||||||
|
|
||||||
#include <ftxui/component/loop.hpp>
|
#include <ftxui/component/loop.hpp>
|
||||||
|
|
||||||
export module ftxui.component.loop;
|
export module ftxui.component.Loop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @namespace ftxui
|
* @namespace ftxui
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
/// @module ftxui.component.mouse
|
/**
|
||||||
/// @brief Module file for the Mouse struct of the Component module
|
* @file Mouse.cppm
|
||||||
|
* @brief Module file for the Mouse struct of the Component module
|
||||||
|
*/
|
||||||
|
|
||||||
module;
|
module;
|
||||||
|
|
||||||
#include <ftxui/component/mouse.hpp>
|
#include <ftxui/component/mouse.hpp>
|
||||||
|
|
||||||
export module ftxui.component.mouse;
|
export module ftxui.component.Mouse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @namespace ftxui
|
* @namespace ftxui
|
||||||
@@ -1,26 +1,22 @@
|
|||||||
/// @module ftxui.component.receiver
|
/**
|
||||||
/// @brief Module file for the Receiver class of the Component module
|
* @file Receiver.cppm
|
||||||
|
* @brief Module file for the Receiver class of the Component module
|
||||||
|
*/
|
||||||
|
|
||||||
module;
|
module;
|
||||||
|
|
||||||
#include <ftxui/component/receiver.hpp>
|
#include <ftxui/component/receiver.hpp>
|
||||||
|
|
||||||
export module ftxui.component.receiver;
|
export module ftxui.component.Receiver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @namespace ftxui
|
* @namespace ftxui
|
||||||
* @brief The FTXUI ftxui:: namespace
|
* @brief The FTXUI ftxui:: namespace
|
||||||
*/
|
*/
|
||||||
export namespace ftxui {
|
export namespace ftxui {
|
||||||
// Deprecated:
|
|
||||||
using ftxui::SenderImpl;
|
using ftxui::SenderImpl;
|
||||||
// Deprecated:
|
|
||||||
using ftxui::ReceiverImpl;
|
using ftxui::ReceiverImpl;
|
||||||
// Deprecated:
|
|
||||||
using ftxui::Sender;
|
using ftxui::Sender;
|
||||||
// Deprecated:
|
|
||||||
using ftxui::Receiver;
|
using ftxui::Receiver;
|
||||||
// Deprecated:
|
|
||||||
using ftxui::MakeReceiver;
|
using ftxui::MakeReceiver;
|
||||||
// Deprecated:
|
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
/// @module ftxui.component.screen_interactive
|
/**
|
||||||
/// @brief Module file for the ScreenInteractive class of the Component module
|
* @file ScreenInteractive.cppm
|
||||||
|
* @brief Module file for the ScreenInteractive class of the Component module
|
||||||
|
*/
|
||||||
|
|
||||||
module;
|
module;
|
||||||
|
|
||||||
#include <ftxui/component/screen_interactive.hpp>
|
#include <ftxui/component/screen_interactive.hpp>
|
||||||
|
|
||||||
export module ftxui.component.screen_interactive;
|
export module ftxui.component.ScreenInteractive;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @namespace ftxui
|
* @namespace ftxui
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
/// @module ftxui.component.task
|
/**
|
||||||
/// @brief Module file for the Task class of the Component module
|
* @file Task.cppm
|
||||||
|
* @brief Module file for the Task class of the Component module
|
||||||
|
*/
|
||||||
|
|
||||||
module;
|
module;
|
||||||
|
|
||||||
#include <ftxui/component/task.hpp>
|
#include <ftxui/component/task.hpp>
|
||||||
|
|
||||||
export module ftxui.component.task;
|
export module ftxui.component.Task;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @namespace ftxui
|
* @namespace ftxui
|
||||||
@@ -139,6 +139,7 @@ class ButtonBase : public ComponentBase, public ButtonOption {
|
|||||||
private:
|
private:
|
||||||
bool mouse_hover_ = false;
|
bool mouse_hover_ = false;
|
||||||
Box box_;
|
Box box_;
|
||||||
|
ButtonOption option_;
|
||||||
float animation_background_ = 0;
|
float animation_background_ = 0;
|
||||||
float animation_foreground_ = 0;
|
float animation_foreground_ = 0;
|
||||||
animation::Animator animator_background_ =
|
animation::Animator animator_background_ =
|
||||||
|
|||||||
@@ -12,11 +12,11 @@
|
|||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
|
|
||||||
/// @brief A collapsible component. It displays a checkbox with an arrow. Once
|
/// @brief A collapsible component. It display a checkbox with an arrow. Once
|
||||||
/// activated, the child is displayed.
|
/// activated, the children is displayed.
|
||||||
/// @param label The label of the checkbox.
|
/// @param label The label of the checkbox.
|
||||||
/// @param child The child to display.
|
/// @param child The children to display.
|
||||||
/// @param show Hold the state about whether the child is displayed or not.
|
/// @param show Hold the state about whether the children is displayed or not.
|
||||||
///
|
///
|
||||||
/// ### Example
|
/// ### Example
|
||||||
/// ```cpp
|
/// ```cpp
|
||||||
|
|||||||
@@ -35,22 +35,26 @@ ComponentBase::~ComponentBase() {
|
|||||||
/// @brief Return the parent ComponentBase, or nul if any.
|
/// @brief Return the parent ComponentBase, or nul if any.
|
||||||
/// @see Detach
|
/// @see Detach
|
||||||
/// @see Parent
|
/// @see Parent
|
||||||
|
/// @ingroup component
|
||||||
ComponentBase* ComponentBase::Parent() const {
|
ComponentBase* ComponentBase::Parent() const {
|
||||||
return parent_;
|
return parent_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Access the child at index `i`.
|
/// @brief Access the child at index `i`.
|
||||||
|
/// @ingroup component
|
||||||
Component& ComponentBase::ChildAt(size_t i) {
|
Component& ComponentBase::ChildAt(size_t i) {
|
||||||
assert(i < ChildCount()); // NOLINT
|
assert(i < ChildCount()); // NOLINT
|
||||||
return children_[i];
|
return children_[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Returns the number of children.
|
/// @brief Returns the number of children.
|
||||||
|
/// @ingroup component
|
||||||
size_t ComponentBase::ChildCount() const {
|
size_t ComponentBase::ChildCount() const {
|
||||||
return children_.size();
|
return children_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Return index of the component in its parent. -1 if no parent.
|
/// @brief Return index of the component in its parent. -1 if no parent.
|
||||||
|
/// @ingroup component
|
||||||
int ComponentBase::Index() const {
|
int ComponentBase::Index() const {
|
||||||
if (parent_ == nullptr) {
|
if (parent_ == nullptr) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -67,6 +71,7 @@ int ComponentBase::Index() const {
|
|||||||
|
|
||||||
/// @brief Add a child.
|
/// @brief Add a child.
|
||||||
/// @@param child The child to be attached.
|
/// @@param child The child to be attached.
|
||||||
|
/// @ingroup component
|
||||||
void ComponentBase::Add(Component child) {
|
void ComponentBase::Add(Component child) {
|
||||||
child->Detach();
|
child->Detach();
|
||||||
child->parent_ = this;
|
child->parent_ = this;
|
||||||
@@ -76,6 +81,7 @@ void ComponentBase::Add(Component child) {
|
|||||||
/// @brief Detach this child from its parent.
|
/// @brief Detach this child from its parent.
|
||||||
/// @see Detach
|
/// @see Detach
|
||||||
/// @see Parent
|
/// @see Parent
|
||||||
|
/// @ingroup component
|
||||||
void ComponentBase::Detach() {
|
void ComponentBase::Detach() {
|
||||||
if (parent_ == nullptr) {
|
if (parent_ == nullptr) {
|
||||||
return;
|
return;
|
||||||
@@ -91,6 +97,7 @@ void ComponentBase::Detach() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Remove all children.
|
/// @brief Remove all children.
|
||||||
|
/// @ingroup component
|
||||||
void ComponentBase::DetachAllChildren() {
|
void ComponentBase::DetachAllChildren() {
|
||||||
while (!children_.empty()) {
|
while (!children_.empty()) {
|
||||||
children_[0]->Detach();
|
children_[0]->Detach();
|
||||||
@@ -100,6 +107,7 @@ void ComponentBase::DetachAllChildren() {
|
|||||||
/// @brief Draw the component.
|
/// @brief Draw the component.
|
||||||
/// Build a ftxui::Element to be drawn on the ftxui::Screen representing this
|
/// Build a ftxui::Element to be drawn on the ftxui::Screen representing this
|
||||||
/// ftxui::ComponentBase. Please override OnRender() to modify the rendering.
|
/// ftxui::ComponentBase. Please override OnRender() to modify the rendering.
|
||||||
|
/// @ingroup component
|
||||||
Element ComponentBase::Render() {
|
Element ComponentBase::Render() {
|
||||||
// Some users might call `ComponentBase::Render()` from
|
// Some users might call `ComponentBase::Render()` from
|
||||||
// `T::OnRender()`. To avoid infinite recursion, we use a flag.
|
// `T::OnRender()`. To avoid infinite recursion, we use a flag.
|
||||||
@@ -135,6 +143,7 @@ Element ComponentBase::Render() {
|
|||||||
/// @brief Draw the component.
|
/// @brief Draw the component.
|
||||||
/// Build a ftxui::Element to be drawn on the ftxi::Screen representing this
|
/// Build a ftxui::Element to be drawn on the ftxi::Screen representing this
|
||||||
/// ftxui::ComponentBase. This function is means to be overridden.
|
/// ftxui::ComponentBase. This function is means to be overridden.
|
||||||
|
/// @ingroup component
|
||||||
Element ComponentBase::OnRender() {
|
Element ComponentBase::OnRender() {
|
||||||
if (children_.size() == 1) {
|
if (children_.size() == 1) {
|
||||||
return children_.front()->Render();
|
return children_.front()->Render();
|
||||||
@@ -148,6 +157,7 @@ Element ComponentBase::OnRender() {
|
|||||||
/// @return True when the event has been handled.
|
/// @return True when the event has been handled.
|
||||||
/// The default implementation called OnEvent on every child until one return
|
/// The default implementation called OnEvent on every child until one return
|
||||||
/// true. If none returns true, return false.
|
/// true. If none returns true, return false.
|
||||||
|
/// @ingroup component
|
||||||
bool ComponentBase::OnEvent(Event event) { // NOLINT
|
bool ComponentBase::OnEvent(Event event) { // NOLINT
|
||||||
for (Component& child : children_) { // NOLINT
|
for (Component& child : children_) { // NOLINT
|
||||||
if (child->OnEvent(event)) {
|
if (child->OnEvent(event)) {
|
||||||
@@ -160,6 +170,7 @@ bool ComponentBase::OnEvent(Event event) { // NOLINT
|
|||||||
/// @brief Called in response to an animation event.
|
/// @brief Called in response to an animation event.
|
||||||
/// @param params the parameters of the animation
|
/// @param params the parameters of the animation
|
||||||
/// The default implementation dispatch the event to every child.
|
/// The default implementation dispatch the event to every child.
|
||||||
|
/// @ingroup component
|
||||||
void ComponentBase::OnAnimation(animation::Params& params) {
|
void ComponentBase::OnAnimation(animation::Params& params) {
|
||||||
for (const Component& child : children_) {
|
for (const Component& child : children_) {
|
||||||
child->OnAnimation(params);
|
child->OnAnimation(params);
|
||||||
@@ -168,6 +179,7 @@ void ComponentBase::OnAnimation(animation::Params& params) {
|
|||||||
|
|
||||||
/// @brief Return the currently Active child.
|
/// @brief Return the currently Active child.
|
||||||
/// @return the currently Active child.
|
/// @return the currently Active child.
|
||||||
|
/// @ingroup component
|
||||||
Component ComponentBase::ActiveChild() {
|
Component ComponentBase::ActiveChild() {
|
||||||
for (auto& child : children_) {
|
for (auto& child : children_) {
|
||||||
if (child->Focusable()) {
|
if (child->Focusable()) {
|
||||||
@@ -180,6 +192,7 @@ Component ComponentBase::ActiveChild() {
|
|||||||
/// @brief Return true when the component contains focusable elements.
|
/// @brief Return true when the component contains focusable elements.
|
||||||
/// The non focusable Components will be skipped when navigating using the
|
/// The non focusable Components will be skipped when navigating using the
|
||||||
/// keyboard.
|
/// keyboard.
|
||||||
|
/// @ingroup component
|
||||||
bool ComponentBase::Focusable() const {
|
bool ComponentBase::Focusable() const {
|
||||||
for (const Component& child : children_) { // NOLINT
|
for (const Component& child : children_) { // NOLINT
|
||||||
if (child->Focusable()) {
|
if (child->Focusable()) {
|
||||||
@@ -190,6 +203,7 @@ bool ComponentBase::Focusable() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Returns if the element if the currently active child of its parent.
|
/// @brief Returns if the element if the currently active child of its parent.
|
||||||
|
/// @ingroup component
|
||||||
bool ComponentBase::Active() const {
|
bool ComponentBase::Active() const {
|
||||||
return parent_ == nullptr || parent_->ActiveChild().get() == this;
|
return parent_ == nullptr || parent_->ActiveChild().get() == this;
|
||||||
}
|
}
|
||||||
@@ -198,6 +212,7 @@ bool ComponentBase::Active() const {
|
|||||||
/// True when the ComponentBase is focused by the user. An element is Focused
|
/// True when the ComponentBase is focused by the user. An element is Focused
|
||||||
/// when it is with all its ancestors the ActiveChild() of their parents, and it
|
/// when it is with all its ancestors the ActiveChild() of their parents, and it
|
||||||
/// Focusable().
|
/// Focusable().
|
||||||
|
/// @ingroup component
|
||||||
bool ComponentBase::Focused() const {
|
bool ComponentBase::Focused() const {
|
||||||
const auto* current = this;
|
const auto* current = this;
|
||||||
while (current && current->Active()) {
|
while (current && current->Active()) {
|
||||||
@@ -208,15 +223,18 @@ bool ComponentBase::Focused() const {
|
|||||||
|
|
||||||
/// @brief Make the |child| to be the "active" one.
|
/// @brief Make the |child| to be the "active" one.
|
||||||
/// @param child the child to become active.
|
/// @param child the child to become active.
|
||||||
|
/// @ingroup component
|
||||||
void ComponentBase::SetActiveChild([[maybe_unused]] ComponentBase* child) {}
|
void ComponentBase::SetActiveChild([[maybe_unused]] ComponentBase* child) {}
|
||||||
|
|
||||||
/// @brief Make the |child| to be the "active" one.
|
/// @brief Make the |child| to be the "active" one.
|
||||||
/// @param child the child to become active.
|
/// @param child the child to become active.
|
||||||
|
/// @ingroup component
|
||||||
void ComponentBase::SetActiveChild(Component child) { // NOLINT
|
void ComponentBase::SetActiveChild(Component child) { // NOLINT
|
||||||
SetActiveChild(child.get());
|
SetActiveChild(child.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Configure all the ancestors to give focus to this component.
|
/// @brief Configure all the ancestors to give focus to this component.
|
||||||
|
/// @ingroup component
|
||||||
void ComponentBase::TakeFocus() {
|
void ComponentBase::TakeFocus() {
|
||||||
ComponentBase* child = this;
|
ComponentBase* child = this;
|
||||||
while (ComponentBase* parent = child->parent_) {
|
while (ComponentBase* parent = child->parent_) {
|
||||||
@@ -228,6 +246,7 @@ void ComponentBase::TakeFocus() {
|
|||||||
/// @brief Take the CapturedMouse if available. There is only one component of
|
/// @brief Take the CapturedMouse if available. There is only one component of
|
||||||
/// them. It represents a component taking priority over others.
|
/// them. It represents a component taking priority over others.
|
||||||
/// @param event The event
|
/// @param event The event
|
||||||
|
/// @ingroup component
|
||||||
CapturedMouse ComponentBase::CaptureMouse(const Event& event) { // NOLINT
|
CapturedMouse ComponentBase::CaptureMouse(const Event& event) { // NOLINT
|
||||||
if (event.screen_) {
|
if (event.screen_) {
|
||||||
return event.screen_->CaptureMouse();
|
return event.screen_->CaptureMouse();
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
// Use of this source code is governed by the MIT license that can be found in
|
// Use of this source code is governed by the MIT license that can be found in
|
||||||
// the LICENSE file.
|
// the LICENSE file.
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <ftxui/component/event.hpp>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "ftxui/component/component.hpp"
|
#include "ftxui/component/component.hpp"
|
||||||
#include "ftxui/component/terminal_input_parser.hpp"
|
#include "ftxui/component/terminal_input_parser.hpp"
|
||||||
@@ -23,9 +22,8 @@ bool GeneratorBool(const char*& data, size_t& size) {
|
|||||||
|
|
||||||
std::string GeneratorString(const char*& data, size_t& size) {
|
std::string GeneratorString(const char*& data, size_t& size) {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
while (index < size && data[index]) {
|
while (index < size && data[index])
|
||||||
++index;
|
++index;
|
||||||
}
|
|
||||||
|
|
||||||
auto out = std::string(data, data + index);
|
auto out = std::string(data, data + index);
|
||||||
data += index;
|
data += index;
|
||||||
@@ -41,9 +39,8 @@ std::string GeneratorString(const char*& data, size_t& size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int GeneratorInt(const char* data, size_t size) {
|
int GeneratorInt(const char* data, size_t size) {
|
||||||
if (size == 0) {
|
if (size == 0)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
auto out = int(data[0]);
|
auto out = int(data[0]);
|
||||||
data++;
|
data++;
|
||||||
size--;
|
size--;
|
||||||
@@ -115,9 +112,8 @@ Components GeneratorComponents(const char*& data, size_t& size, int depth);
|
|||||||
Component GeneratorComponent(const char*& data, size_t& size, int depth) {
|
Component GeneratorComponent(const char*& data, size_t& size, int depth) {
|
||||||
depth--;
|
depth--;
|
||||||
int value = GeneratorInt(data, size);
|
int value = GeneratorInt(data, size);
|
||||||
if (depth <= 0) {
|
if (depth <= 0)
|
||||||
return Button(GeneratorString(data, size), [] {});
|
return Button(GeneratorString(data, size), [] {});
|
||||||
}
|
|
||||||
|
|
||||||
constexpr int value_max = 19;
|
constexpr int value_max = 19;
|
||||||
value = (value % value_max + value_max) % value_max;
|
value = (value % value_max + value_max) % value_max;
|
||||||
@@ -216,17 +212,16 @@ extern "C" int LLVMFuzzerTestOneInput(const char* data, size_t size) {
|
|||||||
auto screen =
|
auto screen =
|
||||||
Screen::Create(Dimension::Fixed(width), Dimension::Fixed(height));
|
Screen::Create(Dimension::Fixed(width), Dimension::Fixed(height));
|
||||||
|
|
||||||
// Generate some events.
|
auto event_receiver = MakeReceiver<Task>();
|
||||||
std::vector<Event> events;
|
{
|
||||||
auto parser =
|
auto parser = TerminalInputParser(event_receiver->MakeSender());
|
||||||
TerminalInputParser([&](const Event& event) { events.push_back(event); });
|
for (size_t i = 0; i < size; ++i)
|
||||||
|
parser.Add(data[i]);
|
||||||
for (size_t i = 0; i < size; ++i) {
|
|
||||||
parser.Add(data[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& event : events) {
|
Task event;
|
||||||
component->OnEvent(event);
|
while (event_receiver->Receive(&event)) {
|
||||||
|
component->OnEvent(std::get<Event>(event));
|
||||||
auto document = component->Render();
|
auto document = component->Render();
|
||||||
Render(screen, document);
|
Render(screen, document);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ namespace ftxui {
|
|||||||
/// @params _active The color when the component is active.
|
/// @params _active The color when the component is active.
|
||||||
/// @params _duration The duration of the animation.
|
/// @params _duration The duration of the animation.
|
||||||
/// @params _function The easing function of the animation.
|
/// @params _function The easing function of the animation.
|
||||||
|
/// @ingroup component
|
||||||
void AnimatedColorOption::Set(Color _inactive,
|
void AnimatedColorOption::Set(Color _inactive,
|
||||||
Color _active,
|
Color _active,
|
||||||
animation::Duration _duration,
|
animation::Duration _duration,
|
||||||
@@ -31,6 +32,7 @@ void AnimatedColorOption::Set(Color _inactive,
|
|||||||
/// @brief Set how the underline should animate.
|
/// @brief Set how the underline should animate.
|
||||||
/// @param d The duration of the animation.
|
/// @param d The duration of the animation.
|
||||||
/// @param f The easing function of the animation.
|
/// @param f The easing function of the animation.
|
||||||
|
/// @ingroup component
|
||||||
void UnderlineOption::SetAnimation(animation::Duration d,
|
void UnderlineOption::SetAnimation(animation::Duration d,
|
||||||
animation::easing::Function f) {
|
animation::easing::Function f) {
|
||||||
SetAnimationDuration(d);
|
SetAnimationDuration(d);
|
||||||
@@ -39,6 +41,7 @@ void UnderlineOption::SetAnimation(animation::Duration d,
|
|||||||
|
|
||||||
/// @brief Set how the underline should animate.
|
/// @brief Set how the underline should animate.
|
||||||
/// @param d The duration of the animation.
|
/// @param d The duration of the animation.
|
||||||
|
/// @ingroup component
|
||||||
void UnderlineOption::SetAnimationDuration(animation::Duration d) {
|
void UnderlineOption::SetAnimationDuration(animation::Duration d) {
|
||||||
leader_duration = d;
|
leader_duration = d;
|
||||||
follower_duration = d;
|
follower_duration = d;
|
||||||
@@ -46,6 +49,7 @@ void UnderlineOption::SetAnimationDuration(animation::Duration d) {
|
|||||||
|
|
||||||
/// @brief Set how the underline should animate.
|
/// @brief Set how the underline should animate.
|
||||||
/// @param f The easing function of the animation.
|
/// @param f The easing function of the animation.
|
||||||
|
/// @ingroup component
|
||||||
void UnderlineOption::SetAnimationFunction(animation::easing::Function f) {
|
void UnderlineOption::SetAnimationFunction(animation::easing::Function f) {
|
||||||
leader_function = f;
|
leader_function = f;
|
||||||
follower_function = std::move(f);
|
follower_function = std::move(f);
|
||||||
@@ -56,6 +60,7 @@ void UnderlineOption::SetAnimationFunction(animation::easing::Function f) {
|
|||||||
/// follower.
|
/// follower.
|
||||||
/// @param f_leader The duration of the animation for the leader.
|
/// @param f_leader The duration of the animation for the leader.
|
||||||
/// @param f_follower The duration of the animation for the follower.
|
/// @param f_follower The duration of the animation for the follower.
|
||||||
|
/// @ingroup component
|
||||||
void UnderlineOption::SetAnimationFunction(
|
void UnderlineOption::SetAnimationFunction(
|
||||||
animation::easing::Function f_leader,
|
animation::easing::Function f_leader,
|
||||||
animation::easing::Function f_follower) {
|
animation::easing::Function f_follower) {
|
||||||
@@ -63,8 +68,9 @@ void UnderlineOption::SetAnimationFunction(
|
|||||||
follower_function = std::move(f_follower);
|
follower_function = std::move(f_follower);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Standard options for a horizontal menu.
|
/// @brief Standard options for an horizontal menu.
|
||||||
/// This can be useful to implement a tab bar.
|
/// This can be useful to implement a tab bar.
|
||||||
|
/// @ingroup component
|
||||||
// static
|
// static
|
||||||
MenuOption MenuOption::Horizontal() {
|
MenuOption MenuOption::Horizontal() {
|
||||||
MenuOption option;
|
MenuOption option;
|
||||||
@@ -89,6 +95,7 @@ MenuOption MenuOption::Horizontal() {
|
|||||||
|
|
||||||
/// @brief Standard options for an animated horizontal menu.
|
/// @brief Standard options for an animated horizontal menu.
|
||||||
/// This can be useful to implement a tab bar.
|
/// This can be useful to implement a tab bar.
|
||||||
|
/// @ingroup component
|
||||||
// static
|
// static
|
||||||
MenuOption MenuOption::HorizontalAnimated() {
|
MenuOption MenuOption::HorizontalAnimated() {
|
||||||
auto option = Horizontal();
|
auto option = Horizontal();
|
||||||
@@ -98,6 +105,7 @@ MenuOption MenuOption::HorizontalAnimated() {
|
|||||||
|
|
||||||
/// @brief Standard options for a vertical menu.
|
/// @brief Standard options for a vertical menu.
|
||||||
/// This can be useful to implement a list of selectable items.
|
/// This can be useful to implement a list of selectable items.
|
||||||
|
/// @ingroup component
|
||||||
// static
|
// static
|
||||||
MenuOption MenuOption::Vertical() {
|
MenuOption MenuOption::Vertical() {
|
||||||
MenuOption option;
|
MenuOption option;
|
||||||
@@ -119,6 +127,7 @@ MenuOption MenuOption::Vertical() {
|
|||||||
|
|
||||||
/// @brief Standard options for an animated vertical menu.
|
/// @brief Standard options for an animated vertical menu.
|
||||||
/// This can be useful to implement a list of selectable items.
|
/// This can be useful to implement a list of selectable items.
|
||||||
|
/// @ingroup component
|
||||||
// static
|
// static
|
||||||
MenuOption MenuOption::VerticalAnimated() {
|
MenuOption MenuOption::VerticalAnimated() {
|
||||||
auto option = MenuOption::Vertical();
|
auto option = MenuOption::Vertical();
|
||||||
@@ -139,8 +148,9 @@ MenuOption MenuOption::VerticalAnimated() {
|
|||||||
return option;
|
return option;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Standard options for a horizontal menu with some separator.
|
/// @brief Standard options for a horitontal menu with some separator.
|
||||||
/// This can be useful to implement a tab bar.
|
/// This can be useful to implement a tab bar.
|
||||||
|
/// @ingroup component
|
||||||
// static
|
// static
|
||||||
MenuOption MenuOption::Toggle() {
|
MenuOption MenuOption::Toggle() {
|
||||||
auto option = MenuOption::Horizontal();
|
auto option = MenuOption::Horizontal();
|
||||||
@@ -149,6 +159,7 @@ MenuOption MenuOption::Toggle() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Create a ButtonOption, highlighted using [] characters.
|
/// @brief Create a ButtonOption, highlighted using [] characters.
|
||||||
|
/// @ingroup component
|
||||||
// static
|
// static
|
||||||
ButtonOption ButtonOption::Ascii() {
|
ButtonOption ButtonOption::Ascii() {
|
||||||
ButtonOption option;
|
ButtonOption option;
|
||||||
@@ -161,6 +172,7 @@ ButtonOption ButtonOption::Ascii() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Create a ButtonOption, inverted when focused.
|
/// @brief Create a ButtonOption, inverted when focused.
|
||||||
|
/// @ingroup component
|
||||||
// static
|
// static
|
||||||
ButtonOption ButtonOption::Simple() {
|
ButtonOption ButtonOption::Simple() {
|
||||||
ButtonOption option;
|
ButtonOption option;
|
||||||
@@ -176,6 +188,7 @@ ButtonOption ButtonOption::Simple() {
|
|||||||
|
|
||||||
/// @brief Create a ButtonOption. The button is shown using a border, inverted
|
/// @brief Create a ButtonOption. The button is shown using a border, inverted
|
||||||
/// when focused. This is the current default.
|
/// when focused. This is the current default.
|
||||||
|
/// @ingroup component
|
||||||
ButtonOption ButtonOption::Border() {
|
ButtonOption ButtonOption::Border() {
|
||||||
ButtonOption option;
|
ButtonOption option;
|
||||||
option.transform = [](const EntryState& s) {
|
option.transform = [](const EntryState& s) {
|
||||||
@@ -192,6 +205,7 @@ ButtonOption ButtonOption::Border() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Create a ButtonOption, using animated colors.
|
/// @brief Create a ButtonOption, using animated colors.
|
||||||
|
/// @ingroup component
|
||||||
// static
|
// static
|
||||||
ButtonOption ButtonOption::Animated() {
|
ButtonOption ButtonOption::Animated() {
|
||||||
return Animated(Color::Black, Color::GrayLight, //
|
return Animated(Color::Black, Color::GrayLight, //
|
||||||
@@ -199,6 +213,7 @@ ButtonOption ButtonOption::Animated() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Create a ButtonOption, using animated colors.
|
/// @brief Create a ButtonOption, using animated colors.
|
||||||
|
/// @ingroup component
|
||||||
// static
|
// static
|
||||||
ButtonOption ButtonOption::Animated(Color color) {
|
ButtonOption ButtonOption::Animated(Color color) {
|
||||||
return ButtonOption::Animated(
|
return ButtonOption::Animated(
|
||||||
@@ -209,6 +224,7 @@ ButtonOption ButtonOption::Animated(Color color) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Create a ButtonOption, using animated colors.
|
/// @brief Create a ButtonOption, using animated colors.
|
||||||
|
/// @ingroup component
|
||||||
// static
|
// static
|
||||||
ButtonOption ButtonOption::Animated(Color background, Color foreground) {
|
ButtonOption ButtonOption::Animated(Color background, Color foreground) {
|
||||||
// NOLINTBEGIN
|
// NOLINTBEGIN
|
||||||
@@ -221,6 +237,7 @@ ButtonOption ButtonOption::Animated(Color background, Color foreground) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Create a ButtonOption, using animated colors.
|
/// @brief Create a ButtonOption, using animated colors.
|
||||||
|
/// @ingroup component
|
||||||
// static
|
// static
|
||||||
ButtonOption ButtonOption::Animated(Color background,
|
ButtonOption ButtonOption::Animated(Color background,
|
||||||
Color foreground,
|
Color foreground,
|
||||||
@@ -240,6 +257,7 @@ ButtonOption ButtonOption::Animated(Color background,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Option for standard Checkbox.
|
/// @brief Option for standard Checkbox.
|
||||||
|
/// @ingroup component
|
||||||
// static
|
// static
|
||||||
CheckboxOption CheckboxOption::Simple() {
|
CheckboxOption CheckboxOption::Simple() {
|
||||||
auto option = CheckboxOption();
|
auto option = CheckboxOption();
|
||||||
@@ -264,6 +282,7 @@ CheckboxOption CheckboxOption::Simple() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Option for standard Radiobox
|
/// @brief Option for standard Radiobox
|
||||||
|
/// @ingroup component
|
||||||
// static
|
// static
|
||||||
RadioboxOption RadioboxOption::Simple() {
|
RadioboxOption RadioboxOption::Simple() {
|
||||||
auto option = RadioboxOption();
|
auto option = RadioboxOption();
|
||||||
@@ -288,6 +307,7 @@ RadioboxOption RadioboxOption::Simple() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Standard options for the input component.
|
/// @brief Standard options for the input component.
|
||||||
|
/// @ingroup component
|
||||||
// static
|
// static
|
||||||
InputOption InputOption::Default() {
|
InputOption InputOption::Default() {
|
||||||
InputOption option;
|
InputOption option;
|
||||||
@@ -310,6 +330,7 @@ InputOption InputOption::Default() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Standard options for a more beautiful input component.
|
/// @brief Standard options for a more beautiful input component.
|
||||||
|
/// @ingroup component
|
||||||
// static
|
// static
|
||||||
InputOption InputOption::Spacious() {
|
InputOption InputOption::Spacious() {
|
||||||
InputOption option;
|
InputOption option;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ namespace ftxui {
|
|||||||
|
|
||||||
/// @brief An event corresponding to a given typed character.
|
/// @brief An event corresponding to a given typed character.
|
||||||
/// @param input The character typed by the user.
|
/// @param input The character typed by the user.
|
||||||
|
/// @ingroup component
|
||||||
// static
|
// static
|
||||||
Event Event::Character(std::string input) {
|
Event Event::Character(std::string input) {
|
||||||
Event event;
|
Event event;
|
||||||
@@ -34,6 +35,7 @@ Event Event::Character(std::string input) {
|
|||||||
|
|
||||||
/// @brief An event corresponding to a given typed character.
|
/// @brief An event corresponding to a given typed character.
|
||||||
/// @param c The character typed by the user.
|
/// @param c The character typed by the user.
|
||||||
|
/// @ingroup component
|
||||||
// static
|
// static
|
||||||
Event Event::Character(char c) {
|
Event Event::Character(char c) {
|
||||||
return Event::Character(std::string{c});
|
return Event::Character(std::string{c});
|
||||||
@@ -41,6 +43,7 @@ Event Event::Character(char c) {
|
|||||||
|
|
||||||
/// @brief An event corresponding to a given typed character.
|
/// @brief An event corresponding to a given typed character.
|
||||||
/// @param c The character typed by the user.
|
/// @param c The character typed by the user.
|
||||||
|
/// @ingroup component
|
||||||
// static
|
// static
|
||||||
Event Event::Character(wchar_t c) {
|
Event Event::Character(wchar_t c) {
|
||||||
return Event::Character(to_string(std::wstring{c}));
|
return Event::Character(to_string(std::wstring{c}));
|
||||||
@@ -49,6 +52,7 @@ Event Event::Character(wchar_t c) {
|
|||||||
/// @brief An event corresponding to a given typed character.
|
/// @brief An event corresponding to a given typed character.
|
||||||
/// @param input The sequence of character send by the terminal.
|
/// @param input The sequence of character send by the terminal.
|
||||||
/// @param mouse The mouse state.
|
/// @param mouse The mouse state.
|
||||||
|
/// @ingroup component
|
||||||
// static
|
// static
|
||||||
Event Event::Mouse(std::string input, struct Mouse mouse) {
|
Event Event::Mouse(std::string input, struct Mouse mouse) {
|
||||||
Event event;
|
Event event;
|
||||||
@@ -70,6 +74,7 @@ Event Event::CursorShape(std::string input, int shape) {
|
|||||||
|
|
||||||
/// @brief An custom event whose meaning is defined by the user of the library.
|
/// @brief An custom event whose meaning is defined by the user of the library.
|
||||||
/// @param input An arbitrary sequence of character defined by the developer.
|
/// @param input An arbitrary sequence of character defined by the developer.
|
||||||
|
/// @ingroup component
|
||||||
// static
|
// static
|
||||||
Event Event::Special(std::string input) {
|
Event Event::Special(std::string input) {
|
||||||
Event event;
|
Event event;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ namespace ftxui {
|
|||||||
|
|
||||||
/// @brief A Loop is a wrapper around a Component and a ScreenInteractive.
|
/// @brief A Loop is a wrapper around a Component and a ScreenInteractive.
|
||||||
/// It is used to run a Component in a terminal.
|
/// It is used to run a Component in a terminal.
|
||||||
|
/// @ingroup component
|
||||||
/// @see Component, ScreenInteractive.
|
/// @see Component, ScreenInteractive.
|
||||||
/// @see ScreenInteractive::Loop().
|
/// @see ScreenInteractive::Loop().
|
||||||
/// @see ScreenInteractive::ExitLoop().
|
/// @see ScreenInteractive::ExitLoop().
|
||||||
@@ -27,6 +28,7 @@ Loop::~Loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Whether the loop has quitted.
|
/// @brief Whether the loop has quitted.
|
||||||
|
/// @ingroup component
|
||||||
bool Loop::HasQuitted() {
|
bool Loop::HasQuitted() {
|
||||||
return screen_->HasQuitted();
|
return screen_->HasQuitted();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace ftxui {
|
|||||||
|
|
||||||
/// @brief Decorate a component |child|. It is shown only when |show| returns
|
/// @brief Decorate a component |child|. It is shown only when |show| returns
|
||||||
/// true.
|
/// true.
|
||||||
/// @param child the component to decorate.
|
/// @param child the compoenent to decorate.
|
||||||
/// @param show a function returning whether |child| should shown.
|
/// @param show a function returning whether |child| should shown.
|
||||||
/// @ingroup component
|
/// @ingroup component
|
||||||
Component Maybe(Component child, std::function<bool()> show) {
|
Component Maybe(Component child, std::function<bool()> show) {
|
||||||
@@ -61,7 +61,7 @@ ComponentDecorator Maybe(std::function<bool()> show) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Decorate a component |child|. It is shown only when |show| is true.
|
/// @brief Decorate a component |child|. It is shown only when |show| is true.
|
||||||
/// @param child the component to decorate.
|
/// @param child the compoennt to decorate.
|
||||||
/// @param show a boolean. |child| is shown when |show| is true.
|
/// @param show a boolean. |child| is shown when |show| is true.
|
||||||
/// @ingroup component
|
/// @ingroup component
|
||||||
///
|
///
|
||||||
|
|||||||
81
src/ftxui/component/receiver_test.cpp
Normal file
81
src/ftxui/component/receiver_test.cpp
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
||||||
|
// Use of this source code is governed by the MIT license that can be found in
|
||||||
|
// the LICENSE file.
|
||||||
|
#include <thread> // for thread
|
||||||
|
#include <utility> // for move
|
||||||
|
|
||||||
|
#include "ftxui/component/receiver.hpp"
|
||||||
|
#include "gtest/gtest.h" // for AssertionResult, Message, Test, TestPartResult, EXPECT_EQ, EXPECT_TRUE, EXPECT_FALSE, TEST
|
||||||
|
|
||||||
|
// NOLINTBEGIN
|
||||||
|
namespace ftxui {
|
||||||
|
|
||||||
|
TEST(Receiver, Basic) {
|
||||||
|
auto receiver = MakeReceiver<char>();
|
||||||
|
auto sender = receiver->MakeSender();
|
||||||
|
|
||||||
|
sender->Send('a');
|
||||||
|
sender->Send('b');
|
||||||
|
sender->Send('c');
|
||||||
|
sender.reset();
|
||||||
|
|
||||||
|
char a, b, c, d;
|
||||||
|
EXPECT_TRUE(receiver->Receive(&a));
|
||||||
|
EXPECT_TRUE(receiver->Receive(&b));
|
||||||
|
EXPECT_TRUE(receiver->Receive(&c));
|
||||||
|
EXPECT_FALSE(receiver->Receive(&d));
|
||||||
|
|
||||||
|
EXPECT_EQ(a, 'a');
|
||||||
|
EXPECT_EQ(b, 'b');
|
||||||
|
EXPECT_EQ(c, 'c');
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Receiver, BasicWithThread) {
|
||||||
|
auto r1 = MakeReceiver<char>();
|
||||||
|
auto r2 = MakeReceiver<char>();
|
||||||
|
auto r3 = MakeReceiver<char>();
|
||||||
|
|
||||||
|
auto s1 = r1->MakeSender();
|
||||||
|
auto s2 = r2->MakeSender();
|
||||||
|
auto s3 = r3->MakeSender();
|
||||||
|
|
||||||
|
auto s1_bis = r1->MakeSender();
|
||||||
|
|
||||||
|
auto stream = [](Receiver<char> receiver, Sender<char> sender) {
|
||||||
|
char c;
|
||||||
|
while (receiver->Receive(&c))
|
||||||
|
sender->Send(c);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Convert data from a different thread.
|
||||||
|
auto t12 = std::thread(stream, std::move(r1), std::move(s2));
|
||||||
|
auto t23 = std::thread(stream, std::move(r2), std::move(s3));
|
||||||
|
|
||||||
|
// Send some data.
|
||||||
|
s1->Send('1');
|
||||||
|
s1_bis->Send('2');
|
||||||
|
s1->Send('3');
|
||||||
|
s1_bis->Send('4');
|
||||||
|
|
||||||
|
// Close the stream.
|
||||||
|
s1.reset();
|
||||||
|
s1_bis.reset();
|
||||||
|
|
||||||
|
char c;
|
||||||
|
EXPECT_TRUE(r3->Receive(&c));
|
||||||
|
EXPECT_EQ(c, '1');
|
||||||
|
EXPECT_TRUE(r3->Receive(&c));
|
||||||
|
EXPECT_EQ(c, '2');
|
||||||
|
EXPECT_TRUE(r3->Receive(&c));
|
||||||
|
EXPECT_EQ(c, '3');
|
||||||
|
EXPECT_TRUE(r3->Receive(&c));
|
||||||
|
EXPECT_EQ(c, '4');
|
||||||
|
EXPECT_FALSE(r3->Receive(&c));
|
||||||
|
|
||||||
|
// Thread will end at the end of the stream.
|
||||||
|
t12.join();
|
||||||
|
t23.join();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace ftxui
|
||||||
|
// NOLINTEND
|
||||||
@@ -17,22 +17,24 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stack> // for stack
|
#include <stack> // for stack
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread> // for thread, sleep_for
|
#include <thread> // for thread, sleep_for
|
||||||
#include <tuple> // for _Swallow_assign, ignore
|
#include <tuple> // for _Swallow_assign, ignore
|
||||||
#include <utility> // for move, swap
|
#include <type_traits> // for decay_t
|
||||||
#include <variant> // for visit, variant
|
#include <utility> // for move, swap
|
||||||
#include <vector> // for vector
|
#include <variant> // for visit, variant
|
||||||
|
#include <vector> // for vector
|
||||||
#include "ftxui/component/animation.hpp" // for TimePoint, Clock, Duration, Params, RequestAnimationFrame
|
#include "ftxui/component/animation.hpp" // for TimePoint, Clock, Duration, Params, RequestAnimationFrame
|
||||||
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse, CapturedMouseInterface
|
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse, CapturedMouseInterface
|
||||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||||
#include "ftxui/component/event.hpp" // for Event
|
#include "ftxui/component/event.hpp" // for Event
|
||||||
#include "ftxui/component/loop.hpp" // for Loop
|
#include "ftxui/component/loop.hpp" // for Loop
|
||||||
#include "ftxui/component/task_runner.hpp"
|
#include "ftxui/component/receiver.hpp" // for ReceiverImpl, Sender, MakeReceiver, SenderImpl, Receiver
|
||||||
#include "ftxui/component/terminal_input_parser.hpp" // for TerminalInputParser
|
#include "ftxui/component/terminal_input_parser.hpp" // for TerminalInputParser
|
||||||
#include "ftxui/dom/node.hpp" // for Node, Render
|
#include "ftxui/dom/node.hpp" // for Node, Render
|
||||||
|
#include "ftxui/dom/requirement.hpp" // for Requirement
|
||||||
|
#include "ftxui/screen/pixel.hpp" // for Pixel
|
||||||
#include "ftxui/screen/terminal.hpp" // for Dimensions, Size
|
#include "ftxui/screen/terminal.hpp" // for Dimensions, Size
|
||||||
#include "ftxui/screen/util.hpp" // for util::clamp
|
#include "ftxui/screen/util.hpp" // for util::clamp
|
||||||
#include "ftxui/util/autoreset.hpp" // for AutoReset
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#define DEFINE_CONSOLEV2_PROPERTIES
|
#define DEFINE_CONSOLEV2_PROPERTIES
|
||||||
@@ -45,11 +47,9 @@
|
|||||||
#error Must be compiled in UNICODE mode
|
#error Must be compiled in UNICODE mode
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/select.h> // for select, FD_ISSET, FD_SET, FD_ZERO, fd_set, timeval
|
#include <sys/select.h> // for select, FD_ISSET, FD_SET, FD_ZERO, fd_set, timeval
|
||||||
#include <termios.h> // for tcsetattr, termios, tcgetattr, TCSANOW, cc_t, ECHO, ICANON, VMIN, VTIME
|
#include <termios.h> // for tcsetattr, termios, tcgetattr, TCSANOW, cc_t, ECHO, ICANON, VMIN, VTIME
|
||||||
#include <unistd.h> // for STDIN_FILENO, read
|
#include <unistd.h> // for STDIN_FILENO, read
|
||||||
#include <cerrno>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Quick exit is missing in standard CLang headers
|
// Quick exit is missing in standard CLang headers
|
||||||
@@ -59,20 +59,6 @@
|
|||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
|
|
||||||
struct ScreenInteractive::Internal {
|
|
||||||
// Convert char to Event.
|
|
||||||
TerminalInputParser terminal_input_parser;
|
|
||||||
|
|
||||||
task::TaskRunner task_runner;
|
|
||||||
|
|
||||||
// The last time a character was received.
|
|
||||||
std::chrono::time_point<std::chrono::steady_clock> last_char_time =
|
|
||||||
std::chrono::steady_clock::now();
|
|
||||||
|
|
||||||
explicit Internal(std::function<void(Event)> out)
|
|
||||||
: terminal_input_parser(std::move(out)) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace animation {
|
namespace animation {
|
||||||
void RequestAnimationFrame() {
|
void RequestAnimationFrame() {
|
||||||
auto* screen = ScreenInteractive::Active();
|
auto* screen = ScreenInteractive::Active();
|
||||||
@@ -96,9 +82,73 @@ constexpr int timeout_milliseconds = 20;
|
|||||||
timeout_milliseconds * 1000;
|
timeout_milliseconds * 1000;
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
|
||||||
|
void EventListener(std::atomic<bool>* quit, Sender<Task> out) {
|
||||||
|
auto console = GetStdHandle(STD_INPUT_HANDLE);
|
||||||
|
auto parser = TerminalInputParser(out->Clone());
|
||||||
|
while (!*quit) {
|
||||||
|
// Throttle ReadConsoleInput by waiting 250ms, this wait function will
|
||||||
|
// return if there is input in the console.
|
||||||
|
auto wait_result = WaitForSingleObject(console, timeout_milliseconds);
|
||||||
|
if (wait_result == WAIT_TIMEOUT) {
|
||||||
|
parser.Timeout(timeout_milliseconds);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD number_of_events = 0;
|
||||||
|
if (!GetNumberOfConsoleInputEvents(console, &number_of_events))
|
||||||
|
continue;
|
||||||
|
if (number_of_events <= 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
std::vector<INPUT_RECORD> records{number_of_events};
|
||||||
|
DWORD number_of_events_read = 0;
|
||||||
|
ReadConsoleInput(console, records.data(), (DWORD)records.size(),
|
||||||
|
&number_of_events_read);
|
||||||
|
records.resize(number_of_events_read);
|
||||||
|
|
||||||
|
for (const auto& r : records) {
|
||||||
|
switch (r.EventType) {
|
||||||
|
case KEY_EVENT: {
|
||||||
|
auto key_event = r.Event.KeyEvent;
|
||||||
|
// ignore UP key events
|
||||||
|
if (key_event.bKeyDown == FALSE)
|
||||||
|
continue;
|
||||||
|
std::wstring wstring;
|
||||||
|
wstring += key_event.uChar.UnicodeChar;
|
||||||
|
for (auto it : to_string(wstring)) {
|
||||||
|
parser.Add(it);
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case WINDOW_BUFFER_SIZE_EVENT:
|
||||||
|
out->Send(Event::Special({0}));
|
||||||
|
break;
|
||||||
|
case MENU_EVENT:
|
||||||
|
case FOCUS_EVENT:
|
||||||
|
case MOUSE_EVENT:
|
||||||
|
// TODO(mauve): Implement later.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#elif defined(__EMSCRIPTEN__)
|
#elif defined(__EMSCRIPTEN__)
|
||||||
#include <emscripten.h>
|
#include <emscripten.h>
|
||||||
|
|
||||||
|
// Read char from the terminal.
|
||||||
|
void EventListener(std::atomic<bool>* quit, Sender<Task> out) {
|
||||||
|
auto parser = TerminalInputParser(std::move(out));
|
||||||
|
|
||||||
|
char c;
|
||||||
|
while (!*quit) {
|
||||||
|
while (read(STDIN_FILENO, &c, 1), c)
|
||||||
|
parser.Add(c);
|
||||||
|
|
||||||
|
emscripten_sleep(1);
|
||||||
|
parser.Timeout(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
EMSCRIPTEN_KEEPALIVE
|
EMSCRIPTEN_KEEPALIVE
|
||||||
void ftxui_on_resize(int columns, int rows) {
|
void ftxui_on_resize(int columns, int rows) {
|
||||||
@@ -112,8 +162,8 @@ void ftxui_on_resize(int columns, int rows) {
|
|||||||
|
|
||||||
#else // POSIX (Linux & Mac)
|
#else // POSIX (Linux & Mac)
|
||||||
|
|
||||||
int CheckStdinReady() {
|
int CheckStdinReady(int usec_timeout) {
|
||||||
timeval tv = {0, 0}; // NOLINT
|
timeval tv = {0, usec_timeout}; // NOLINT
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
FD_ZERO(&fds); // NOLINT
|
FD_ZERO(&fds); // NOLINT
|
||||||
FD_SET(STDIN_FILENO, &fds); // NOLINT
|
FD_SET(STDIN_FILENO, &fds); // NOLINT
|
||||||
@@ -121,6 +171,24 @@ int CheckStdinReady() {
|
|||||||
return FD_ISSET(STDIN_FILENO, &fds); // NOLINT
|
return FD_ISSET(STDIN_FILENO, &fds); // NOLINT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read char from the terminal.
|
||||||
|
void EventListener(std::atomic<bool>* quit, Sender<Task> out) {
|
||||||
|
auto parser = TerminalInputParser(std::move(out));
|
||||||
|
|
||||||
|
while (!*quit) {
|
||||||
|
if (!CheckStdinReady(timeout_microseconds)) {
|
||||||
|
parser.Timeout(timeout_milliseconds);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t buffer_size = 100;
|
||||||
|
std::array<char, buffer_size> buffer; // NOLINT;
|
||||||
|
size_t l = read(fileno(stdin), buffer.data(), buffer_size); // NOLINT
|
||||||
|
for (size_t i = 0; i < l; ++i) {
|
||||||
|
parser.Add(buffer[i]); // NOLINT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::stack<Closure> on_exit_functions; // NOLINT
|
std::stack<Closure> on_exit_functions; // NOLINT
|
||||||
@@ -267,29 +335,38 @@ class CapturedMouseImpl : public CapturedMouseInterface {
|
|||||||
std::function<void(void)> callback_;
|
std::function<void(void)> callback_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void AnimationListener(std::atomic<bool>* quit, Sender<Task> out) {
|
||||||
|
// Animation at around 60fps.
|
||||||
|
const auto time_delta = std::chrono::milliseconds(15);
|
||||||
|
while (!*quit) {
|
||||||
|
out->Send(AnimationTask());
|
||||||
|
std::this_thread::sleep_for(time_delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
ScreenInteractive::ScreenInteractive(Dimension dimension,
|
ScreenInteractive::ScreenInteractive(int dimx,
|
||||||
int dimx,
|
|
||||||
int dimy,
|
int dimy,
|
||||||
|
Dimension dimension,
|
||||||
bool use_alternative_screen)
|
bool use_alternative_screen)
|
||||||
: Screen(dimx, dimy),
|
: Screen(dimx, dimy),
|
||||||
dimension_(dimension),
|
dimension_(dimension),
|
||||||
use_alternative_screen_(use_alternative_screen) {
|
use_alternative_screen_(use_alternative_screen) {
|
||||||
internal_ = std::make_unique<Internal>(
|
task_receiver_ = MakeReceiver<Task>();
|
||||||
[&](Event event) { PostEvent(std::move(event)); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
ScreenInteractive ScreenInteractive::FixedSize(int dimx, int dimy) {
|
ScreenInteractive ScreenInteractive::FixedSize(int dimx, int dimy) {
|
||||||
return {
|
return {
|
||||||
Dimension::Fixed,
|
|
||||||
dimx,
|
dimx,
|
||||||
dimy,
|
dimy,
|
||||||
/*use_alternative_screen=*/false,
|
Dimension::Fixed,
|
||||||
|
false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @ingroup component
|
||||||
/// Create a ScreenInteractive taking the full terminal size. This is using the
|
/// Create a ScreenInteractive taking the full terminal size. This is using the
|
||||||
/// alternate screen buffer to avoid messing with the terminal content.
|
/// alternate screen buffer to avoid messing with the terminal content.
|
||||||
/// @note This is the same as `ScreenInteractive::FullscreenAlternateScreen()`
|
/// @note This is the same as `ScreenInteractive::FullscreenAlternateScreen()`
|
||||||
@@ -298,61 +375,54 @@ ScreenInteractive ScreenInteractive::Fullscreen() {
|
|||||||
return FullscreenAlternateScreen();
|
return FullscreenAlternateScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @ingroup component
|
||||||
/// Create a ScreenInteractive taking the full terminal size. The primary screen
|
/// Create a ScreenInteractive taking the full terminal size. The primary screen
|
||||||
/// buffer is being used. It means if the terminal is resized, the previous
|
/// buffer is being used. It means if the terminal is resized, the previous
|
||||||
/// content might mess up with the terminal content.
|
/// content might mess up with the terminal content.
|
||||||
// static
|
// static
|
||||||
ScreenInteractive ScreenInteractive::FullscreenPrimaryScreen() {
|
ScreenInteractive ScreenInteractive::FullscreenPrimaryScreen() {
|
||||||
auto terminal = Terminal::Size();
|
|
||||||
return {
|
return {
|
||||||
|
0,
|
||||||
|
0,
|
||||||
Dimension::Fullscreen,
|
Dimension::Fullscreen,
|
||||||
terminal.dimx,
|
|
||||||
terminal.dimy,
|
|
||||||
/*use_alternative_screen=*/false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a ScreenInteractive taking the full terminal size. This is using the
|
|
||||||
/// alternate screen buffer to avoid messing with the terminal content.
|
|
||||||
// static
|
|
||||||
ScreenInteractive ScreenInteractive::FullscreenAlternateScreen() {
|
|
||||||
auto terminal = Terminal::Size();
|
|
||||||
return {
|
|
||||||
Dimension::Fullscreen,
|
|
||||||
terminal.dimx,
|
|
||||||
terminal.dimy,
|
|
||||||
/*use_alternative_screen=*/true,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a ScreenInteractive whose width match the terminal output width and
|
|
||||||
/// the height matches the component being drawn.
|
|
||||||
// static
|
|
||||||
ScreenInteractive ScreenInteractive::TerminalOutput() {
|
|
||||||
auto terminal = Terminal::Size();
|
|
||||||
return {
|
|
||||||
Dimension::TerminalOutput,
|
|
||||||
terminal.dimx,
|
|
||||||
terminal.dimy, // Best guess.
|
|
||||||
/*use_alternative_screen=*/false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
ScreenInteractive::~ScreenInteractive() = default;
|
|
||||||
|
|
||||||
/// Create a ScreenInteractive whose width and height match the component being
|
|
||||||
/// drawn.
|
|
||||||
// static
|
|
||||||
ScreenInteractive ScreenInteractive::FitComponent() {
|
|
||||||
auto terminal = Terminal::Size();
|
|
||||||
return {
|
|
||||||
Dimension::FitComponent,
|
|
||||||
terminal.dimx, // Best guess.
|
|
||||||
terminal.dimy, // Best guess.
|
|
||||||
false,
|
false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @ingroup component
|
||||||
|
/// Create a ScreenInteractive taking the full terminal size. This is using the
|
||||||
|
/// alternate screen buffer to avoid messing with the terminal content.
|
||||||
|
// static
|
||||||
|
ScreenInteractive ScreenInteractive::FullscreenAlternateScreen() {
|
||||||
|
return {
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
Dimension::Fullscreen,
|
||||||
|
true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
ScreenInteractive ScreenInteractive::TerminalOutput() {
|
||||||
|
return {
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
Dimension::TerminalOutput,
|
||||||
|
false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
ScreenInteractive ScreenInteractive::FitComponent() {
|
||||||
|
return {
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
Dimension::FitComponent,
|
||||||
|
false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @ingroup component
|
||||||
/// @brief Set whether mouse is tracked and events reported.
|
/// @brief Set whether mouse is tracked and events reported.
|
||||||
/// called outside of the main loop. E.g `ScreenInteractive::Loop(...)`.
|
/// called outside of the main loop. E.g `ScreenInteractive::Loop(...)`.
|
||||||
/// @param enable Whether to enable mouse event tracking.
|
/// @param enable Whether to enable mouse event tracking.
|
||||||
@@ -372,28 +442,22 @@ void ScreenInteractive::TrackMouse(bool enable) {
|
|||||||
track_mouse_ = enable;
|
track_mouse_ = enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Enable or disable automatic piped input handling.
|
|
||||||
/// When enabled, FTXUI will detect piped input and redirect stdin from /dev/tty
|
|
||||||
/// for keyboard input, allowing applications to read piped data while still
|
|
||||||
/// receiving interactive keyboard events.
|
|
||||||
/// @param enable Whether to enable piped input handling. Default is true.
|
|
||||||
/// @note This must be called before Loop().
|
|
||||||
/// @note This feature is enabled by default.
|
|
||||||
/// @note This feature is only available on POSIX systems (Linux/macOS).
|
|
||||||
void ScreenInteractive::HandlePipedInput(bool enable) {
|
|
||||||
handle_piped_input_ = enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @brief Add a task to the main loop.
|
/// @brief Add a task to the main loop.
|
||||||
/// It will be executed later, after every other scheduled tasks.
|
/// It will be executed later, after every other scheduled tasks.
|
||||||
|
/// @ingroup component
|
||||||
void ScreenInteractive::Post(Task task) {
|
void ScreenInteractive::Post(Task task) {
|
||||||
internal_->task_runner.PostTask([this, task = std::move(task)]() mutable {
|
// Task/Events sent toward inactive screen or screen waiting to become
|
||||||
HandleTask(component_, task);
|
// inactive are dropped.
|
||||||
});
|
if (!task_sender_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
task_sender_->Send(std::move(task));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Add an event to the main loop.
|
/// @brief Add an event to the main loop.
|
||||||
/// It will be executed later, after every other scheduled events.
|
/// It will be executed later, after every other scheduled events.
|
||||||
|
/// @ingroup component
|
||||||
void ScreenInteractive::PostEvent(Event event) {
|
void ScreenInteractive::PostEvent(Event event) {
|
||||||
Post(event);
|
Post(event);
|
||||||
}
|
}
|
||||||
@@ -415,6 +479,7 @@ void ScreenInteractive::RequestAnimationFrame() {
|
|||||||
/// @brief Try to get the unique lock about behing able to capture the mouse.
|
/// @brief Try to get the unique lock about behing able to capture the mouse.
|
||||||
/// @return A unique lock if the mouse is not already captured, otherwise a
|
/// @return A unique lock if the mouse is not already captured, otherwise a
|
||||||
/// null.
|
/// null.
|
||||||
|
/// @ingroup component
|
||||||
CapturedMouse ScreenInteractive::CaptureMouse() {
|
CapturedMouse ScreenInteractive::CaptureMouse() {
|
||||||
if (mouse_captured) {
|
if (mouse_captured) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -426,14 +491,16 @@ CapturedMouse ScreenInteractive::CaptureMouse() {
|
|||||||
|
|
||||||
/// @brief Execute the main loop.
|
/// @brief Execute the main loop.
|
||||||
/// @param component The component to draw.
|
/// @param component The component to draw.
|
||||||
|
/// @ingroup component
|
||||||
void ScreenInteractive::Loop(Component component) { // NOLINT
|
void ScreenInteractive::Loop(Component component) { // NOLINT
|
||||||
class Loop loop(this, std::move(component));
|
class Loop loop(this, std::move(component));
|
||||||
loop.Run();
|
loop.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Return whether the main loop has been quit.
|
/// @brief Return whether the main loop has been quit.
|
||||||
|
/// @ingroup component
|
||||||
bool ScreenInteractive::HasQuitted() {
|
bool ScreenInteractive::HasQuitted() {
|
||||||
return quit_;
|
return task_receiver_->HasQuitted();
|
||||||
}
|
}
|
||||||
|
|
||||||
// private
|
// private
|
||||||
@@ -590,15 +657,7 @@ void ScreenInteractive::Install() {
|
|||||||
|
|
||||||
SetConsoleMode(stdin_handle, in_mode);
|
SetConsoleMode(stdin_handle, in_mode);
|
||||||
SetConsoleMode(stdout_handle, out_mode);
|
SetConsoleMode(stdout_handle, out_mode);
|
||||||
#else // POSIX (Linux & Mac)
|
#else
|
||||||
// #if defined(__EMSCRIPTEN__)
|
|
||||||
//// Reading stdin isn't blocking.
|
|
||||||
// int flags = fcntl(0, F_GETFL, 0);
|
|
||||||
// fcntl(0, F_SETFL, flags | O_NONBLOCK);
|
|
||||||
|
|
||||||
//// Restore the terminal configuration on exit.
|
|
||||||
// on_exit_functions.emplace([flags] { fcntl(0, F_SETFL, flags); });
|
|
||||||
// #endif
|
|
||||||
for (const int signal : {SIGWINCH, SIGTSTP}) {
|
for (const int signal : {SIGWINCH, SIGTSTP}) {
|
||||||
InstallSignalHandler(signal);
|
InstallSignalHandler(signal);
|
||||||
}
|
}
|
||||||
@@ -670,102 +729,41 @@ void ScreenInteractive::Install() {
|
|||||||
// ensure it is fully applied:
|
// ensure it is fully applied:
|
||||||
Flush();
|
Flush();
|
||||||
|
|
||||||
// Redirect the true terminal to stdin, so that we can read keyboard input
|
|
||||||
// directly from stdin, even if the input is piped from a file or another
|
|
||||||
// process.
|
|
||||||
//
|
|
||||||
// TODO: Instead of redirecting stdin, we could define the file descriptor to
|
|
||||||
// read from, and use it in the TerminalInputParser.
|
|
||||||
InstallPipedInputHandling();
|
|
||||||
|
|
||||||
quit_ = false;
|
quit_ = false;
|
||||||
|
task_sender_ = task_receiver_->MakeSender();
|
||||||
PostAnimationTask();
|
event_listener_ =
|
||||||
}
|
std::thread(&EventListener, &quit_, task_receiver_->MakeSender());
|
||||||
|
animation_listener_ =
|
||||||
void ScreenInteractive::InstallPipedInputHandling() {
|
std::thread(&AnimationListener, &quit_, task_receiver_->MakeSender());
|
||||||
#if !defined(_WIN32) && !defined(__EMSCRIPTEN__)
|
|
||||||
// Handle piped input redirection if explicitly enabled by the application.
|
|
||||||
// This allows applications to read data from stdin while still receiving
|
|
||||||
// keyboard input from the terminal for interactive use.
|
|
||||||
if (!handle_piped_input_) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If stdin is a terminal, we don't need to redirect it.
|
|
||||||
if (isatty(STDIN_FILENO)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save the current stdin so we can restore it later.
|
|
||||||
int original_fd = dup(STDIN_FILENO);
|
|
||||||
if (original_fd < 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Redirect stdin to the controlling terminal for keyboard input.
|
|
||||||
if (std::freopen("/dev/tty", "r", stdin) == nullptr) {
|
|
||||||
// Failed to open /dev/tty (containers, headless systems, etc.)
|
|
||||||
// Clean up and continue without redirection
|
|
||||||
close(original_fd);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restore the original stdin file descriptor on exit.
|
|
||||||
on_exit_functions.emplace([=] {
|
|
||||||
dup2(original_fd, STDIN_FILENO);
|
|
||||||
close(original_fd);
|
|
||||||
});
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// private
|
// private
|
||||||
void ScreenInteractive::Uninstall() {
|
void ScreenInteractive::Uninstall() {
|
||||||
ExitNow();
|
ExitNow();
|
||||||
|
event_listener_.join();
|
||||||
|
animation_listener_.join();
|
||||||
OnExit();
|
OnExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// private
|
// private
|
||||||
// NOLINTNEXTLINE
|
// NOLINTNEXTLINE
|
||||||
void ScreenInteractive::RunOnceBlocking(Component component) {
|
void ScreenInteractive::RunOnceBlocking(Component component) {
|
||||||
// Set FPS to 60 at most.
|
ExecuteSignalHandlers();
|
||||||
const auto time_per_frame = std::chrono::microseconds(16666); // 1s / 60fps
|
Task task;
|
||||||
|
if (task_receiver_->Receive(&task)) {
|
||||||
auto time = std::chrono::steady_clock::now();
|
HandleTask(component, task);
|
||||||
size_t executed_task = internal_->task_runner.ExecutedTasks();
|
|
||||||
|
|
||||||
// Wait for at least one task to execute.
|
|
||||||
while (executed_task == internal_->task_runner.ExecutedTasks() &&
|
|
||||||
!HasQuitted()) {
|
|
||||||
RunOnce(component);
|
|
||||||
|
|
||||||
const auto now = std::chrono::steady_clock::now();
|
|
||||||
const auto delta = now - time;
|
|
||||||
time = now;
|
|
||||||
|
|
||||||
if (delta < time_per_frame) {
|
|
||||||
const auto sleep_duration = time_per_frame - delta;
|
|
||||||
std::this_thread::sleep_for(sleep_duration);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
RunOnce(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
// private
|
// private
|
||||||
void ScreenInteractive::RunOnce(Component component) {
|
void ScreenInteractive::RunOnce(Component component) {
|
||||||
AutoReset set_component(&component_, component);
|
Task task;
|
||||||
ExecuteSignalHandlers();
|
while (task_receiver_->ReceiveNonBlocking(&task)) {
|
||||||
FetchTerminalEvents();
|
HandleTask(component, task);
|
||||||
|
ExecuteSignalHandlers();
|
||||||
// Execute the pending tasks from the queue.
|
|
||||||
const size_t executed_task = internal_->task_runner.ExecutedTasks();
|
|
||||||
internal_->task_runner.RunUntilIdle();
|
|
||||||
// If no executed task, we can return early without redrawing the screen.
|
|
||||||
if (executed_task == internal_->task_runner.ExecutedTasks()) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
Draw(std::move(component));
|
||||||
ExecuteSignalHandlers();
|
|
||||||
Draw(component);
|
|
||||||
|
|
||||||
if (selection_data_previous_ != selection_data_) {
|
if (selection_data_previous_ != selection_data_) {
|
||||||
selection_data_previous_ = selection_data_;
|
selection_data_previous_ = selection_data_;
|
||||||
@@ -786,7 +784,6 @@ void ScreenInteractive::HandleTask(Component component, Task& task) {
|
|||||||
// clang-format off
|
// clang-format off
|
||||||
// Handle Event.
|
// Handle Event.
|
||||||
if constexpr (std::is_same_v<T, Event>) {
|
if constexpr (std::is_same_v<T, Event>) {
|
||||||
|
|
||||||
if (arg.is_cursor_position()) {
|
if (arg.is_cursor_position()) {
|
||||||
cursor_x_ = arg.cursor_x();
|
cursor_x_ = arg.cursor_x();
|
||||||
cursor_y_ = arg.cursor_y();
|
cursor_y_ = arg.cursor_y();
|
||||||
@@ -933,7 +930,7 @@ void ScreenInteractive::Draw(Component component) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool resized = frame_count_ == 0 || (dimx != dimx_) || (dimy != dimy_);
|
const bool resized = (dimx != dimx_) || (dimy != dimy_);
|
||||||
ResetCursorPosition();
|
ResetCursorPosition();
|
||||||
std::cout << ResetPosition(/*clear=*/resized);
|
std::cout << ResetPosition(/*clear=*/resized);
|
||||||
|
|
||||||
@@ -1016,7 +1013,6 @@ void ScreenInteractive::Draw(Component component) {
|
|||||||
Flush();
|
Flush();
|
||||||
Clear();
|
Clear();
|
||||||
frame_valid_ = true;
|
frame_valid_ = true;
|
||||||
frame_count_++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// private
|
// private
|
||||||
@@ -1026,11 +1022,13 @@ void ScreenInteractive::ResetCursorPosition() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Return a function to exit the main loop.
|
/// @brief Return a function to exit the main loop.
|
||||||
|
/// @ingroup component
|
||||||
Closure ScreenInteractive::ExitLoopClosure() {
|
Closure ScreenInteractive::ExitLoopClosure() {
|
||||||
return [this] { Exit(); };
|
return [this] { Exit(); };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Exit the main loop.
|
/// @brief Exit the main loop.
|
||||||
|
/// @ingroup component
|
||||||
void ScreenInteractive::Exit() {
|
void ScreenInteractive::Exit() {
|
||||||
Post([this] { ExitNow(); });
|
Post([this] { ExitNow(); });
|
||||||
}
|
}
|
||||||
@@ -1038,6 +1036,7 @@ void ScreenInteractive::Exit() {
|
|||||||
// private:
|
// private:
|
||||||
void ScreenInteractive::ExitNow() {
|
void ScreenInteractive::ExitNow() {
|
||||||
quit_ = true;
|
quit_ = true;
|
||||||
|
task_sender_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
// private:
|
// private:
|
||||||
@@ -1070,118 +1069,6 @@ void ScreenInteractive::Signal(int signal) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenInteractive::FetchTerminalEvents() {
|
|
||||||
#if defined(_WIN32)
|
|
||||||
auto get_input_records = [&]() -> std::vector<INPUT_RECORD> {
|
|
||||||
// Check if there is input in the console.
|
|
||||||
auto console = GetStdHandle(STD_INPUT_HANDLE);
|
|
||||||
DWORD number_of_events = 0;
|
|
||||||
if (!GetNumberOfConsoleInputEvents(console, &number_of_events)) {
|
|
||||||
return std::vector<INPUT_RECORD>();
|
|
||||||
}
|
|
||||||
if (number_of_events <= 0) {
|
|
||||||
// No input, return.
|
|
||||||
return std::vector<INPUT_RECORD>();
|
|
||||||
}
|
|
||||||
// Read the input events.
|
|
||||||
std::vector<INPUT_RECORD> records(number_of_events);
|
|
||||||
DWORD number_of_events_read = 0;
|
|
||||||
if (!ReadConsoleInput(console, records.data(), (DWORD)records.size(),
|
|
||||||
&number_of_events_read)) {
|
|
||||||
return std::vector<INPUT_RECORD>();
|
|
||||||
}
|
|
||||||
records.resize(number_of_events_read);
|
|
||||||
return records;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto records = get_input_records();
|
|
||||||
if (records.size() == 0) {
|
|
||||||
const auto timeout =
|
|
||||||
std::chrono::steady_clock::now() - internal_->last_char_time;
|
|
||||||
const size_t timeout_microseconds =
|
|
||||||
std::chrono::duration_cast<std::chrono::microseconds>(timeout).count();
|
|
||||||
internal_->terminal_input_parser.Timeout(timeout_microseconds);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
internal_->last_char_time = std::chrono::steady_clock::now();
|
|
||||||
|
|
||||||
// Convert the input events to FTXUI events.
|
|
||||||
// For each event, we call the terminal input parser to convert it to
|
|
||||||
// Event.
|
|
||||||
for (const auto& r : records) {
|
|
||||||
switch (r.EventType) {
|
|
||||||
case KEY_EVENT: {
|
|
||||||
auto key_event = r.Event.KeyEvent;
|
|
||||||
// ignore UP key events
|
|
||||||
if (key_event.bKeyDown == FALSE) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
std::wstring wstring;
|
|
||||||
wstring += key_event.uChar.UnicodeChar;
|
|
||||||
for (auto it : to_string(wstring)) {
|
|
||||||
internal_->terminal_input_parser.Add(it);
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
case WINDOW_BUFFER_SIZE_EVENT:
|
|
||||||
Post(Event::Special({0}));
|
|
||||||
break;
|
|
||||||
case MENU_EVENT:
|
|
||||||
case FOCUS_EVENT:
|
|
||||||
case MOUSE_EVENT:
|
|
||||||
// TODO(mauve): Implement later.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#elif defined(__EMSCRIPTEN__)
|
|
||||||
// Read chars from the terminal.
|
|
||||||
// We configured it to be non blocking.
|
|
||||||
std::array<char, 128> out{};
|
|
||||||
size_t l = read(STDIN_FILENO, out.data(), out.size());
|
|
||||||
if (l == 0) {
|
|
||||||
const auto timeout =
|
|
||||||
std::chrono::steady_clock::now() - internal_->last_char_time;
|
|
||||||
const size_t timeout_microseconds =
|
|
||||||
std::chrono::duration_cast<std::chrono::microseconds>(timeout).count();
|
|
||||||
internal_->terminal_input_parser.Timeout(timeout_microseconds);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
internal_->last_char_time = std::chrono::steady_clock::now();
|
|
||||||
|
|
||||||
// Convert the chars to events.
|
|
||||||
for (size_t i = 0; i < l; ++i) {
|
|
||||||
internal_->terminal_input_parser.Add(out[i]);
|
|
||||||
}
|
|
||||||
#else // POSIX (Linux & Mac)
|
|
||||||
if (!CheckStdinReady()) {
|
|
||||||
const auto timeout =
|
|
||||||
std::chrono::steady_clock::now() - internal_->last_char_time;
|
|
||||||
const size_t timeout_ms =
|
|
||||||
std::chrono::duration_cast<std::chrono::milliseconds>(timeout).count();
|
|
||||||
internal_->terminal_input_parser.Timeout(timeout_ms);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
internal_->last_char_time = std::chrono::steady_clock::now();
|
|
||||||
|
|
||||||
// Read chars from the terminal.
|
|
||||||
std::array<char, 128> out{};
|
|
||||||
size_t l = read(fileno(stdin), out.data(), out.size());
|
|
||||||
|
|
||||||
// Convert the chars to events.
|
|
||||||
for (size_t i = 0; i < l; ++i) {
|
|
||||||
internal_->terminal_input_parser.Add(out[i]);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScreenInteractive::PostAnimationTask() {
|
|
||||||
Post(AnimationTask());
|
|
||||||
|
|
||||||
// Repeat the animation task every 15ms. This correspond to a frame rate
|
|
||||||
// of around 66fps.
|
|
||||||
internal_->task_runner.PostDelayedTask([this] { PostAnimationTask(); },
|
|
||||||
std::chrono::milliseconds(15));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ScreenInteractive::SelectionData::operator==(
|
bool ScreenInteractive::SelectionData::operator==(
|
||||||
const ScreenInteractive::SelectionData& other) const {
|
const ScreenInteractive::SelectionData& other) const {
|
||||||
if (empty && other.empty) {
|
if (empty && other.empty) {
|
||||||
|
|||||||
@@ -1,220 +0,0 @@
|
|||||||
// Copyright 2025 Arthur Sonzogni. All rights reserved.
|
|
||||||
// Use of this source code is governed by the MIT license that can be found in
|
|
||||||
// the LICENSE file.
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
#include "ftxui/component/component.hpp"
|
|
||||||
#include "ftxui/component/screen_interactive.hpp"
|
|
||||||
#include "ftxui/dom/elements.hpp"
|
|
||||||
|
|
||||||
#if !defined(_WIN32) && !defined(__EMSCRIPTEN__)
|
|
||||||
|
|
||||||
namespace ftxui {
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
// Test fixture for piped input functionality
|
|
||||||
class PipedInputTest : public ::testing::Test {
|
|
||||||
protected:
|
|
||||||
void SetUp() override {
|
|
||||||
// Save original stdin for restoration
|
|
||||||
original_stdin_ = dup(STDIN_FILENO);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TearDown() override {
|
|
||||||
// Restore original stdin
|
|
||||||
if (original_stdin_ >= 0) {
|
|
||||||
dup2(original_stdin_, STDIN_FILENO);
|
|
||||||
close(original_stdin_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a pipe and redirect stdin to read from it
|
|
||||||
void SetupPipedStdin() {
|
|
||||||
if (pipe(pipe_fds_) == 0) {
|
|
||||||
dup2(pipe_fds_[0], STDIN_FILENO);
|
|
||||||
close(pipe_fds_[0]);
|
|
||||||
// Keep write end open for writing test data
|
|
||||||
piped_stdin_setup_ = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write test data to the piped stdin
|
|
||||||
void WriteToPipedStdin(const std::string& data) {
|
|
||||||
if (piped_stdin_setup_) {
|
|
||||||
write(pipe_fds_[1], data.c_str(), data.length());
|
|
||||||
close(pipe_fds_[1]); // Close write end to signal EOF
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if /dev/tty is available (not available in some CI environments)
|
|
||||||
bool IsTtyAvailable() {
|
|
||||||
struct stat st;
|
|
||||||
return stat("/dev/tty", &st) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
int original_stdin_ = -1;
|
|
||||||
int pipe_fds_[2] = {-1, -1};
|
|
||||||
bool piped_stdin_setup_ = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_F(PipedInputTest, DefaultBehaviorEnabled) {
|
|
||||||
// Test that HandlePipedInput is enabled by default
|
|
||||||
if (!IsTtyAvailable()) {
|
|
||||||
GTEST_SKIP() << "/dev/tty not available in this environment";
|
|
||||||
}
|
|
||||||
|
|
||||||
auto screen = ScreenInteractive::TerminalOutput();
|
|
||||||
auto component = Renderer([] { return text("test"); });
|
|
||||||
|
|
||||||
SetupPipedStdin();
|
|
||||||
WriteToPipedStdin("test data\n");
|
|
||||||
|
|
||||||
// Install should redirect stdin since HandlePipedInput is on by default
|
|
||||||
screen.Install();
|
|
||||||
|
|
||||||
// Stdin should be the tty
|
|
||||||
EXPECT_TRUE(isatty(STDIN_FILENO));
|
|
||||||
|
|
||||||
screen.Uninstall();
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(PipedInputTest, ExplicitlyDisabled) {
|
|
||||||
// Test that explicitly disabling works
|
|
||||||
auto screen = ScreenInteractive::TerminalOutput();
|
|
||||||
screen.HandlePipedInput(false);
|
|
||||||
auto component = Renderer([] { return text("test"); });
|
|
||||||
|
|
||||||
SetupPipedStdin();
|
|
||||||
WriteToPipedStdin("test data\n");
|
|
||||||
|
|
||||||
screen.Install();
|
|
||||||
|
|
||||||
// Stdin should still be the pipe since feature is disabled
|
|
||||||
EXPECT_FALSE(isatty(STDIN_FILENO));
|
|
||||||
|
|
||||||
screen.Uninstall();
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(PipedInputTest, ExplicitlyEnabled) {
|
|
||||||
if (!IsTtyAvailable()) {
|
|
||||||
GTEST_SKIP() << "/dev/tty not available in this environment";
|
|
||||||
}
|
|
||||||
|
|
||||||
auto screen = ScreenInteractive::TerminalOutput();
|
|
||||||
screen.HandlePipedInput(true); // Explicitly enable
|
|
||||||
auto component = Renderer([] { return text("test"); });
|
|
||||||
|
|
||||||
SetupPipedStdin();
|
|
||||||
WriteToPipedStdin("test data\n");
|
|
||||||
|
|
||||||
// Before install: stdin should be piped
|
|
||||||
EXPECT_FALSE(isatty(STDIN_FILENO));
|
|
||||||
|
|
||||||
screen.Install();
|
|
||||||
|
|
||||||
// After install with piped input handling: stdin should be redirected to tty
|
|
||||||
EXPECT_TRUE(isatty(STDIN_FILENO));
|
|
||||||
|
|
||||||
screen.Uninstall();
|
|
||||||
|
|
||||||
// After uninstall: stdin should be restored to original state
|
|
||||||
// Note: This will be the pipe we set up, so it should be non-tty
|
|
||||||
EXPECT_FALSE(isatty(STDIN_FILENO));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(PipedInputTest, NormalStdinUnchanged) {
|
|
||||||
// Test that normal stdin (not piped) is not affected
|
|
||||||
auto screen = ScreenInteractive::TerminalOutput();
|
|
||||||
auto component = Renderer([] { return text("test"); });
|
|
||||||
|
|
||||||
// Don't setup piped stdin - use normal stdin
|
|
||||||
bool original_isatty = isatty(STDIN_FILENO);
|
|
||||||
|
|
||||||
screen.Install();
|
|
||||||
|
|
||||||
// Stdin should remain unchanged
|
|
||||||
EXPECT_EQ(original_isatty, isatty(STDIN_FILENO));
|
|
||||||
|
|
||||||
screen.Uninstall();
|
|
||||||
|
|
||||||
// Stdin should still be unchanged
|
|
||||||
EXPECT_EQ(original_isatty, isatty(STDIN_FILENO));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(PipedInputTest, MultipleInstallUninstallCycles) {
|
|
||||||
if (!IsTtyAvailable()) {
|
|
||||||
GTEST_SKIP() << "/dev/tty not available in this environment";
|
|
||||||
}
|
|
||||||
|
|
||||||
auto screen = ScreenInteractive::TerminalOutput();
|
|
||||||
auto component = Renderer([] { return text("test"); });
|
|
||||||
|
|
||||||
SetupPipedStdin();
|
|
||||||
WriteToPipedStdin("test data\n");
|
|
||||||
|
|
||||||
// First cycle
|
|
||||||
screen.Install();
|
|
||||||
EXPECT_TRUE(isatty(STDIN_FILENO));
|
|
||||||
screen.Uninstall();
|
|
||||||
EXPECT_FALSE(isatty(STDIN_FILENO));
|
|
||||||
|
|
||||||
// Second cycle should work the same
|
|
||||||
screen.Install();
|
|
||||||
EXPECT_TRUE(isatty(STDIN_FILENO));
|
|
||||||
screen.Uninstall();
|
|
||||||
EXPECT_FALSE(isatty(STDIN_FILENO));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(PipedInputTest, HandlePipedInputMethodBehavior) {
|
|
||||||
auto screen = ScreenInteractive::TerminalOutput();
|
|
||||||
|
|
||||||
// Test method can be called multiple times
|
|
||||||
screen.HandlePipedInput(true);
|
|
||||||
screen.HandlePipedInput(false);
|
|
||||||
screen.HandlePipedInput(true);
|
|
||||||
|
|
||||||
// Should be enabled after last call
|
|
||||||
SetupPipedStdin();
|
|
||||||
WriteToPipedStdin("test data\n");
|
|
||||||
|
|
||||||
if (IsTtyAvailable()) {
|
|
||||||
screen.Install();
|
|
||||||
EXPECT_TRUE(isatty(STDIN_FILENO));
|
|
||||||
screen.Uninstall();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test the graceful fallback when /dev/tty is not available
|
|
||||||
// This test simulates environments like containers where /dev/tty might not exist
|
|
||||||
TEST_F(PipedInputTest, GracefulFallbackWhenTtyUnavailable) {
|
|
||||||
auto screen = ScreenInteractive::TerminalOutput();
|
|
||||||
auto component = Renderer([] { return text("test"); });
|
|
||||||
|
|
||||||
SetupPipedStdin();
|
|
||||||
WriteToPipedStdin("test data\n");
|
|
||||||
|
|
||||||
// This test doesn't directly mock /dev/tty unavailability since that's hard to do
|
|
||||||
// in a unit test environment, but the code path handles freopen() failure gracefully
|
|
||||||
screen.Install();
|
|
||||||
|
|
||||||
// The behavior depends on whether /dev/tty is available
|
|
||||||
// If available, stdin gets redirected; if not, it remains piped
|
|
||||||
// Both behaviors are correct
|
|
||||||
|
|
||||||
screen.Uninstall();
|
|
||||||
|
|
||||||
// After uninstall, stdin should be restored
|
|
||||||
EXPECT_FALSE(isatty(STDIN_FILENO)); // Should still be our test pipe
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
} // namespace ftxui
|
|
||||||
|
|
||||||
#endif // !defined(_WIN32) && !defined(__EMSCRIPTEN__)
|
|
||||||
@@ -10,58 +10,9 @@
|
|||||||
#include "ftxui/component/screen_interactive.hpp"
|
#include "ftxui/component/screen_interactive.hpp"
|
||||||
#include "ftxui/dom/elements.hpp" // for text, Element
|
#include "ftxui/dom/elements.hpp" // for text, Element
|
||||||
|
|
||||||
#if defined(__unix__)
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <array>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <ftxui/component/loop.hpp>
|
|
||||||
#include <string>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
#if defined(__unix__)
|
|
||||||
|
|
||||||
// Capture the standard output (stdout) to a string.
|
|
||||||
class StdCapture {
|
|
||||||
public:
|
|
||||||
explicit StdCapture(std::string* captured) : captured_(captured) {
|
|
||||||
if (pipe(pipefd_) != 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
old_stdout_ = dup(fileno(stdout));
|
|
||||||
fflush(stdout);
|
|
||||||
dup2(pipefd_[1], fileno(stdout));
|
|
||||||
close(pipefd_[1]); // Close the write end in the parent
|
|
||||||
}
|
|
||||||
|
|
||||||
~StdCapture() {
|
|
||||||
fflush(stdout);
|
|
||||||
dup2(old_stdout_, fileno(stdout));
|
|
||||||
close(old_stdout_);
|
|
||||||
|
|
||||||
char buffer[1024];
|
|
||||||
ssize_t count;
|
|
||||||
while ((count = read(pipefd_[0], buffer, sizeof(buffer))) > 0) {
|
|
||||||
captured_->append(buffer, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
close(pipefd_[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
StdCapture(const StdCapture&) = delete;
|
|
||||||
StdCapture& operator=(const StdCapture&) = delete;
|
|
||||||
|
|
||||||
private:
|
|
||||||
int pipefd_[2]{-1, -1};
|
|
||||||
int old_stdout_{-1};
|
|
||||||
std::string* const captured_;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool TestSignal(int signal) {
|
bool TestSignal(int signal) {
|
||||||
int called = 0;
|
int called = 0;
|
||||||
// The tree of components. This defines how to navigate using the keyboard.
|
// The tree of components. This defines how to navigate using the keyboard.
|
||||||
@@ -180,66 +131,4 @@ TEST(ScreenInteractive, CtrlC_NotForced) {
|
|||||||
ASSERT_GE(ctrl_c_count, 50);
|
ASSERT_GE(ctrl_c_count, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regression test for:
|
|
||||||
// https://github.com/ArthurSonzogni/FTXUI/pull/1064/files
|
|
||||||
TEST(ScreenInteractive, FixedSizeInitialFrame) {
|
|
||||||
#if defined(__unix__)
|
|
||||||
std::string output;
|
|
||||||
{
|
|
||||||
auto capture = StdCapture(&output);
|
|
||||||
|
|
||||||
auto screen = ScreenInteractive::FixedSize(2, 2);
|
|
||||||
auto component = Renderer([&] { return text("AB"); });
|
|
||||||
|
|
||||||
Loop loop(&screen, component);
|
|
||||||
loop.RunOnce();
|
|
||||||
}
|
|
||||||
using namespace std::string_view_literals;
|
|
||||||
|
|
||||||
auto expected =
|
|
||||||
// Install the ScreenInteractive.
|
|
||||||
"\0" // Flush stdout.
|
|
||||||
"\x1BP$q q" // Set cursor shape to 1 (block).
|
|
||||||
"\x1B\\" // Reset cursor position.
|
|
||||||
"\x1B[?7l" // Disable line wrapping.
|
|
||||||
"\x1B[?1000h" // Enable mouse tracking.
|
|
||||||
"\x1B[?1003h" // Enable mouse motion tracking.
|
|
||||||
"\x1B[?1015h" // Enable mouse wheel tracking.
|
|
||||||
"\x1B[?1006h" // Enable SGR mouse tracking.
|
|
||||||
"\0" // Flush stdout.
|
|
||||||
|
|
||||||
// Reset the screen.
|
|
||||||
"\r" // Reset cursor position.
|
|
||||||
"\x1B[2K" // Clear the line.
|
|
||||||
"\x1B[1A" // Move cursor up one line.
|
|
||||||
"\x1B[2K" // Clear the line.
|
|
||||||
|
|
||||||
// Print the document.
|
|
||||||
"AB\r\n" // Print "AB" and move to the next line.
|
|
||||||
" " // Print two spaces to fill the line.
|
|
||||||
|
|
||||||
// Set cursor position.
|
|
||||||
"\x1B[1D" // Move cursor left one character.
|
|
||||||
"\x1B[?25l" // Hide cursor.
|
|
||||||
|
|
||||||
// Flush
|
|
||||||
"\0" // Flush stdout.
|
|
||||||
|
|
||||||
// Uninstall the ScreenInteractive.
|
|
||||||
"\x1B[1C" // Move cursor right one character.
|
|
||||||
"\x1B[?1006l" // Disable SGR mouse tracking.
|
|
||||||
"\x1B[?1015l" // Disable mouse wheel tracking.
|
|
||||||
"\x1B[?1003l" // Disable mouse motion tracking.
|
|
||||||
"\x1B[?1000l" // Disable mouse tracking.
|
|
||||||
"\x1B[?7h" // Enable line wrapping.
|
|
||||||
"\x1B[?25h" // Show cursor.
|
|
||||||
"\x1B[1 q" // Set cursor shape to 1 (block).
|
|
||||||
"\0" // Flush stdout.
|
|
||||||
|
|
||||||
// Skip one line to avoid the prompt to be printed over the last drawing.
|
|
||||||
"\r\n"sv;
|
|
||||||
ASSERT_EQ(expected, output);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace ftxui
|
} // namespace ftxui
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
// Copyright 2024 Arthur Sonzogni. All rights reserved.
|
|
||||||
// Use of this source code is governed by the MIT license that can be found in
|
|
||||||
// the LICENSE file.
|
|
||||||
#include "ftxui/component/task_internal.hpp"
|
|
||||||
|
|
||||||
namespace ftxui::task {
|
|
||||||
bool PendingTask::operator<(const PendingTask& other) const {
|
|
||||||
if (!time && !other.time) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!time) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!other.time) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return time.value() > other.time.value();
|
|
||||||
}
|
|
||||||
} // namespace ftxui::task
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
// Copyright 2024 Arthur Sonzogni. All rights reserved.
|
|
||||||
// Use of this source code is governed by the MIT license that can be found in
|
|
||||||
// the LICENSE file.
|
|
||||||
#ifndef TASK_HPP
|
|
||||||
#define TASK_HPP
|
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <functional>
|
|
||||||
#include <optional>
|
|
||||||
|
|
||||||
namespace ftxui::task {
|
|
||||||
|
|
||||||
/// A task represents a unit of work.
|
|
||||||
using Task = std::function<void()>;
|
|
||||||
|
|
||||||
/// A PendingTask represents a task that is scheduled to be executed at a
|
|
||||||
/// specific time, or as soon as possible.
|
|
||||||
struct PendingTask {
|
|
||||||
// Immediate task:
|
|
||||||
PendingTask(Task t) : task(std::move(t)) {} // NOLINT
|
|
||||||
|
|
||||||
// Delayed task with a duration
|
|
||||||
PendingTask(Task t, std::chrono::steady_clock::duration duration)
|
|
||||||
: task(std::move(t)), time(std::chrono::steady_clock::now() + duration) {}
|
|
||||||
|
|
||||||
/// The task to be executed.
|
|
||||||
Task task;
|
|
||||||
|
|
||||||
/// The time when the task should be executed. If the time is empty, the task
|
|
||||||
/// should be executed as soon as possible.
|
|
||||||
std::optional<std::chrono::steady_clock::time_point> time;
|
|
||||||
|
|
||||||
/// Compare two PendingTasks by their time.
|
|
||||||
/// If both tasks have no time, they are considered equal.
|
|
||||||
bool operator<(const PendingTask& other) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ftxui::task
|
|
||||||
|
|
||||||
#endif // TASK_HPP_
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
// Copyright 2024 Arthur Sonzogni. All rights reserved.
|
|
||||||
// Use of this source code is governed by the MIT license that can be found in
|
|
||||||
// the LICENSE file.
|
|
||||||
#include "ftxui/component/task_queue.hpp"
|
|
||||||
|
|
||||||
namespace ftxui::task {
|
|
||||||
|
|
||||||
auto TaskQueue::PostTask(PendingTask task) -> void {
|
|
||||||
if (!task.time) {
|
|
||||||
immediate_tasks_.push(task);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (task.time.value() < std::chrono::steady_clock::now()) {
|
|
||||||
immediate_tasks_.push(task);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
delayed_tasks_.push(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto TaskQueue::Get() -> MaybeTask {
|
|
||||||
// Attempt to execute a task immediately.
|
|
||||||
if (!immediate_tasks_.empty()) {
|
|
||||||
auto task = immediate_tasks_.front();
|
|
||||||
immediate_tasks_.pop();
|
|
||||||
return task.task;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move all tasks that can be executed to the immediate queue.
|
|
||||||
auto now = std::chrono::steady_clock::now();
|
|
||||||
while (!delayed_tasks_.empty() && delayed_tasks_.top().time.value() <= now) {
|
|
||||||
immediate_tasks_.push(delayed_tasks_.top());
|
|
||||||
delayed_tasks_.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attempt to execute a task immediately.
|
|
||||||
if (!immediate_tasks_.empty()) {
|
|
||||||
auto task = immediate_tasks_.front();
|
|
||||||
immediate_tasks_.pop();
|
|
||||||
return task.task;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there are no tasks to execute, return the delay until the next task.
|
|
||||||
if (!delayed_tasks_.empty()) {
|
|
||||||
return delayed_tasks_.top().time.value() - now;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there are no tasks to execute, return the maximum duration.
|
|
||||||
return std::monostate{};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace ftxui::task
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
// Copyright 2024 Arthur Sonzogni. All rights reserved.
|
|
||||||
// Use of this source code is governed by the MIT license that can be found in
|
|
||||||
// the LICENSE file.
|
|
||||||
#ifndef TASK_QUEUE_HPP
|
|
||||||
#define TASK_QUEUE_HPP
|
|
||||||
|
|
||||||
#include <queue>
|
|
||||||
#include <variant>
|
|
||||||
|
|
||||||
#include "ftxui/component/task_internal.hpp" // for PendingTask, Task
|
|
||||||
|
|
||||||
namespace ftxui::task {
|
|
||||||
|
|
||||||
/// A task queue that schedules tasks to be executed in the future. Tasks can be
|
|
||||||
/// scheduled to be executed immediately, or after a certain duration.
|
|
||||||
/// - The tasks are executed in the order they were scheduled.
|
|
||||||
/// - If multiple tasks are scheduled to be executed at the same time, they are
|
|
||||||
/// executed in the order they were scheduled.
|
|
||||||
/// - If a task is scheduled to be executed in the past, it is executed
|
|
||||||
/// immediately.
|
|
||||||
struct TaskQueue {
|
|
||||||
auto PostTask(PendingTask task) -> void;
|
|
||||||
|
|
||||||
using MaybeTask =
|
|
||||||
std::variant<Task, std::chrono::steady_clock::duration, std::monostate>;
|
|
||||||
auto Get() -> MaybeTask;
|
|
||||||
|
|
||||||
bool HasImmediateTasks() const { return !immediate_tasks_.empty(); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::queue<PendingTask> immediate_tasks_;
|
|
||||||
std::priority_queue<PendingTask> delayed_tasks_;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ftxui::task
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
// Copyright 2024 Arthur Sonzogni. All rights reserved.
|
|
||||||
// Use of this source code is governed by the MIT license that can be found in
|
|
||||||
// the LICENSE file.
|
|
||||||
#include "ftxui/component/task_runner.hpp"
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
namespace ftxui::task {
|
|
||||||
|
|
||||||
static thread_local TaskRunner* current_task_runner = nullptr; // NOLINT
|
|
||||||
|
|
||||||
TaskRunner::TaskRunner() {
|
|
||||||
assert(!previous_task_runner_);
|
|
||||||
previous_task_runner_ = current_task_runner;
|
|
||||||
current_task_runner = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
TaskRunner::~TaskRunner() {
|
|
||||||
current_task_runner = previous_task_runner_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// static
|
|
||||||
auto TaskRunner::Current() -> TaskRunner* {
|
|
||||||
assert(current_task_runner);
|
|
||||||
return current_task_runner;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto TaskRunner::PostTask(Task task) -> void {
|
|
||||||
queue_.PostTask(PendingTask{std::move(task)});
|
|
||||||
}
|
|
||||||
|
|
||||||
auto TaskRunner::PostDelayedTask(Task task,
|
|
||||||
std::chrono::steady_clock::duration duration)
|
|
||||||
-> void {
|
|
||||||
queue_.PostTask(PendingTask{std::move(task), duration});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Runs the tasks in the queue.
|
|
||||||
auto TaskRunner::RunUntilIdle()
|
|
||||||
-> std::optional<std::chrono::steady_clock::duration> {
|
|
||||||
while (true) {
|
|
||||||
auto maybe_task = queue_.Get();
|
|
||||||
if (std::holds_alternative<std::monostate>(maybe_task)) {
|
|
||||||
// No more tasks to execute, exit the loop.
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (std::holds_alternative<Task>(maybe_task)) {
|
|
||||||
executed_tasks_++;
|
|
||||||
std::get<Task>(maybe_task)();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (std::holds_alternative<std::chrono::steady_clock::duration>(
|
|
||||||
maybe_task)) {
|
|
||||||
return std::get<std::chrono::steady_clock::duration>(maybe_task);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto TaskRunner::Run() -> void {
|
|
||||||
while (true) {
|
|
||||||
auto duration = RunUntilIdle();
|
|
||||||
if (!duration) {
|
|
||||||
// No more tasks to execute, exit the loop.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sleep for the duration until the next task can be executed.
|
|
||||||
std::this_thread::sleep_for(duration.value());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace ftxui::task
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
// Copyright 2024 Arthur Sonzogni. All rights reserved.
|
|
||||||
// Use of this source code is governed by the MIT license that can be found in
|
|
||||||
// the LICENSE file.
|
|
||||||
#ifndef TASK_RUNNER_HPP
|
|
||||||
#define TASK_RUNNER_HPP
|
|
||||||
|
|
||||||
#include "ftxui/component/task_internal.hpp"
|
|
||||||
#include "ftxui/component/task_queue.hpp"
|
|
||||||
|
|
||||||
namespace ftxui::task {
|
|
||||||
|
|
||||||
class TaskRunner {
|
|
||||||
public:
|
|
||||||
TaskRunner();
|
|
||||||
~TaskRunner();
|
|
||||||
|
|
||||||
// Returns the task runner for the current thread.
|
|
||||||
static auto Current() -> TaskRunner*;
|
|
||||||
|
|
||||||
/// Schedules a task to be executed immediately.
|
|
||||||
auto PostTask(Task task) -> void;
|
|
||||||
|
|
||||||
/// Schedules a task to be executed after a certain duration.
|
|
||||||
auto PostDelayedTask(Task task, std::chrono::steady_clock::duration duration)
|
|
||||||
-> void;
|
|
||||||
|
|
||||||
/// Runs the tasks in the queue, return the delay until the next delayed task
|
|
||||||
/// can be executed.
|
|
||||||
auto RunUntilIdle() -> std::optional<std::chrono::steady_clock::duration>;
|
|
||||||
|
|
||||||
// Runs the tasks in the queue, blocking until all tasks are executed.
|
|
||||||
auto Run() -> void;
|
|
||||||
|
|
||||||
bool HasImmediateTasks() const { return queue_.HasImmediateTasks(); }
|
|
||||||
|
|
||||||
size_t ExecutedTasks() const { return executed_tasks_; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
TaskRunner* previous_task_runner_ = nullptr;
|
|
||||||
TaskQueue queue_;
|
|
||||||
size_t executed_tasks_ = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ftxui::task
|
|
||||||
|
|
||||||
#endif // TASK_RUNNER_HPP
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
// Copyright 2024 Arthur Sonzogni. All rights reserved.
|
|
||||||
// Use of this source code is governed by the MIT license that can be found in
|
|
||||||
// the LICENSE file.
|
|
||||||
// Copyright 2024 Arthur Sonzogni. All rights reserved.
|
|
||||||
// Use of this source code is governed by the MIT license that can be found in
|
|
||||||
// the LICENSE file.
|
|
||||||
#include "ftxui/component/task_internal.hpp"
|
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
#include <thread> // for sleep_for
|
|
||||||
#include "ftxui/component/task_runner.hpp"
|
|
||||||
|
|
||||||
namespace ftxui::task {
|
|
||||||
|
|
||||||
TEST(TaskTest, Basic) {
|
|
||||||
std::vector<int> values;
|
|
||||||
|
|
||||||
auto task_1 = [&values] { values.push_back(1); };
|
|
||||||
auto task_2 = [&values] { values.push_back(2); };
|
|
||||||
auto task_3 = [&values] { values.push_back(3); };
|
|
||||||
|
|
||||||
auto runner = TaskRunner();
|
|
||||||
|
|
||||||
runner.PostTask(task_1);
|
|
||||||
runner.PostTask(task_2);
|
|
||||||
runner.PostTask(task_3);
|
|
||||||
while (true) {
|
|
||||||
auto duration = runner.RunUntilIdle();
|
|
||||||
if (!duration) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
std::this_thread::sleep_for(duration.value());
|
|
||||||
}
|
|
||||||
|
|
||||||
EXPECT_EQ(values, (std::vector<int>{1, 2, 3}));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(TaskTest, PostedWithinTask) {
|
|
||||||
std::vector<int> values;
|
|
||||||
|
|
||||||
auto task_1 = [&values] {
|
|
||||||
values.push_back(1);
|
|
||||||
auto task_2 = [&values] { values.push_back(5); };
|
|
||||||
TaskRunner::Current()->PostTask(std::move(task_2));
|
|
||||||
values.push_back(2);
|
|
||||||
};
|
|
||||||
|
|
||||||
auto task_2 = [&values] {
|
|
||||||
values.push_back(3);
|
|
||||||
auto task_2 = [&values] { values.push_back(6); };
|
|
||||||
TaskRunner::Current()->PostTask(std::move(task_2));
|
|
||||||
values.push_back(4);
|
|
||||||
};
|
|
||||||
|
|
||||||
auto runner = TaskRunner();
|
|
||||||
|
|
||||||
runner.PostTask(task_1);
|
|
||||||
runner.PostTask(task_2);
|
|
||||||
while (true) {
|
|
||||||
auto duration = runner.RunUntilIdle();
|
|
||||||
if (!duration) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
std::this_thread::sleep_for(duration.value());
|
|
||||||
}
|
|
||||||
|
|
||||||
EXPECT_EQ(values, (std::vector<int>{1, 2, 3, 4, 5, 6}));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(TaskTest, RunDelayedTask) {
|
|
||||||
std::vector<int> values;
|
|
||||||
|
|
||||||
auto task_1 = [&values] { values.push_back(1); };
|
|
||||||
auto task_2 = [&values] { values.push_back(2); };
|
|
||||||
auto task_3 = [&values] { values.push_back(3); };
|
|
||||||
|
|
||||||
auto runner = TaskRunner();
|
|
||||||
|
|
||||||
runner.PostDelayedTask(task_3, std::chrono::milliseconds(300));
|
|
||||||
runner.PostDelayedTask(task_1, std::chrono::milliseconds(100));
|
|
||||||
runner.PostDelayedTask(task_2, std::chrono::milliseconds(200));
|
|
||||||
while (true) {
|
|
||||||
auto duration = runner.RunUntilIdle();
|
|
||||||
if (!duration) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
std::this_thread::sleep_for(duration.value());
|
|
||||||
}
|
|
||||||
|
|
||||||
EXPECT_EQ(values, (std::vector<int>{1, 2, 3}));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace ftxui::task
|
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include <cstdint> // for uint32_t
|
#include <cstdint> // for uint32_t
|
||||||
#include <ftxui/component/mouse.hpp> // for Mouse, Mouse::Button, Mouse::Motion
|
#include <ftxui/component/mouse.hpp> // for Mouse, Mouse::Button, Mouse::Motion
|
||||||
#include <functional> // for std::function
|
#include <ftxui/component/receiver.hpp> // for SenderImpl, Sender
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory> // for unique_ptr, allocator
|
#include <memory> // for unique_ptr, allocator
|
||||||
#include <utility> // for move
|
#include <utility> // for move
|
||||||
@@ -90,7 +90,7 @@ const std::map<std::string, std::string> g_uniformize = {
|
|||||||
{"\x1B[X", "\x1B[24~"}, // F12
|
{"\x1B[X", "\x1B[24~"}, // F12
|
||||||
};
|
};
|
||||||
|
|
||||||
TerminalInputParser::TerminalInputParser(std::function<void(Event)> out)
|
TerminalInputParser::TerminalInputParser(Sender<Task> out)
|
||||||
: out_(std::move(out)) {}
|
: out_(std::move(out)) {}
|
||||||
|
|
||||||
void TerminalInputParser::Timeout(int time) {
|
void TerminalInputParser::Timeout(int time) {
|
||||||
@@ -131,7 +131,7 @@ void TerminalInputParser::Send(TerminalInputParser::Output output) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
case CHARACTER:
|
case CHARACTER:
|
||||||
out_(Event::Character(std::move(pending_)));
|
out_->Send(Event::Character(std::move(pending_)));
|
||||||
pending_.clear();
|
pending_.clear();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -140,25 +140,25 @@ void TerminalInputParser::Send(TerminalInputParser::Output output) {
|
|||||||
if (it != g_uniformize.end()) {
|
if (it != g_uniformize.end()) {
|
||||||
pending_ = it->second;
|
pending_ = it->second;
|
||||||
}
|
}
|
||||||
out_(Event::Special(std::move(pending_)));
|
out_->Send(Event::Special(std::move(pending_)));
|
||||||
pending_.clear();
|
pending_.clear();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case MOUSE:
|
case MOUSE:
|
||||||
out_(Event::Mouse(std::move(pending_), output.mouse)); // NOLINT
|
out_->Send(Event::Mouse(std::move(pending_), output.mouse)); // NOLINT
|
||||||
pending_.clear();
|
pending_.clear();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case CURSOR_POSITION:
|
case CURSOR_POSITION:
|
||||||
out_(Event::CursorPosition(std::move(pending_), // NOLINT
|
out_->Send(Event::CursorPosition(std::move(pending_), // NOLINT
|
||||||
output.cursor.x, // NOLINT
|
output.cursor.x, // NOLINT
|
||||||
output.cursor.y)); // NOLINT
|
output.cursor.y)); // NOLINT
|
||||||
pending_.clear();
|
pending_.clear();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case CURSOR_SHAPE:
|
case CURSOR_SHAPE:
|
||||||
out_(Event::CursorShape(std::move(pending_), output.cursor_shape));
|
out_->Send(Event::CursorShape(std::move(pending_), output.cursor_shape));
|
||||||
pending_.clear();
|
pending_.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user