mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-12-16 01:48:56 +08:00
Compare commits
24 Commits
a86d8f32d7
...
copilot/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac93764bbf | ||
|
|
c0cb3e84cc | ||
|
|
f21fcc1995 | ||
|
|
f7ac35ed35 | ||
|
|
fba510ec02 | ||
|
|
775ad9ce5e | ||
|
|
f5785fd3b4 | ||
|
|
853d87e917 | ||
|
|
11f7132886 | ||
|
|
346f751527 | ||
|
|
e56ff89cf3 | ||
|
|
21b24a1b78 | ||
|
|
bfd07ba309 | ||
|
|
d20b84f720 | ||
|
|
0dde21f09e | ||
|
|
40e1fac3d4 | ||
|
|
8ef18ab647 | ||
|
|
994915dbb9 | ||
|
|
3b359e8cd7 | ||
|
|
1073ba414d | ||
|
|
b78b97056b | ||
|
|
68fc9b1212 | ||
|
|
6440a88dc6 | ||
|
|
14da21b0ee |
2
.bazelrc
2
.bazelrc
@@ -1,3 +1,5 @@
|
||||
common --enable_bzlmod
|
||||
|
||||
build --features=layering_check
|
||||
build --enable_bzlmod
|
||||
|
||||
|
||||
@@ -2,3 +2,6 @@
|
||||
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
|
||||
BasedOnStyle: Chromium
|
||||
Standard: Cpp11
|
||||
|
||||
InsertBraces: true
|
||||
InsertNewlineAtEOF: true
|
||||
|
||||
12
BUILD.bazel
12
BUILD.bazel
@@ -13,7 +13,6 @@ load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
|
||||
load(":bazel/ftxui.bzl", "ftxui_cc_library")
|
||||
load(":bazel/ftxui.bzl", "generate_examples")
|
||||
load(":bazel/ftxui.bzl", "windows_copts")
|
||||
load(":bazel/ftxui.bzl", "pthread_linkopts")
|
||||
|
||||
# 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
|
||||
@@ -159,6 +158,12 @@ ftxui_cc_library(
|
||||
"src/ftxui/component/resizable_split.cpp",
|
||||
"src/ftxui/component/screen_interactive.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.hpp",
|
||||
"src/ftxui/component/util.cpp",
|
||||
@@ -170,6 +175,9 @@ ftxui_cc_library(
|
||||
# Private header from ftxui:screen.
|
||||
"src/ftxui/screen/string_internal.hpp",
|
||||
"src/ftxui/screen/util.hpp",
|
||||
|
||||
# Private header.
|
||||
"include/ftxui/util/warn_windows_macro.hpp",
|
||||
],
|
||||
hdrs = [
|
||||
"include/ftxui/component/animation.hpp",
|
||||
@@ -184,7 +192,6 @@ ftxui_cc_library(
|
||||
"include/ftxui/component/screen_interactive.hpp",
|
||||
"include/ftxui/component/task.hpp",
|
||||
],
|
||||
linkopts = pthread_linkopts(),
|
||||
deps = [
|
||||
":dom",
|
||||
":screen",
|
||||
@@ -207,7 +214,6 @@ cc_test(
|
||||
"src/ftxui/component/menu_test.cpp",
|
||||
"src/ftxui/component/modal_test.cpp",
|
||||
"src/ftxui/component/radiobox_test.cpp",
|
||||
"src/ftxui/component/receiver_test.cpp",
|
||||
"src/ftxui/component/resizable_split_test.cpp",
|
||||
"src/ftxui/component/slider_test.cpp",
|
||||
"src/ftxui/component/terminal_input_parser_test.cpp",
|
||||
|
||||
@@ -24,6 +24,13 @@ Next
|
||||
import ftxui.util;
|
||||
```
|
||||
Thanks @mikomikotaishi for PR #1015.
|
||||
- Remove dependency on 'pthread'.
|
||||
|
||||
### Component
|
||||
- Fix ScreenInteractive::FixedSize screen stomps on the preceding terminal
|
||||
output. Thanks @zozowell in #1064.
|
||||
- Fix vertical `ftxui::Slider`. The "up" key was previously decreasing the
|
||||
value. Thanks @its-pablo in #1093 for reporting the issue.
|
||||
|
||||
|
||||
6.1.9 (2025-05-07)
|
||||
|
||||
@@ -144,26 +144,20 @@ add_library(component
|
||||
src/ftxui/component/resizable_split.cpp
|
||||
src/ftxui/component/screen_interactive.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.hpp
|
||||
src/ftxui/component/util.cpp
|
||||
src/ftxui/component/window.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(dom
|
||||
PUBLIC screen
|
||||
)
|
||||
|
||||
target_link_libraries(component
|
||||
PUBLIC dom
|
||||
)
|
||||
|
||||
if (NOT EMSCRIPTEN)
|
||||
find_package(Threads)
|
||||
target_link_libraries(component
|
||||
PUBLIC Threads::Threads
|
||||
)
|
||||
endif()
|
||||
target_link_libraries(dom PUBLIC screen)
|
||||
target_link_libraries(component PUBLIC dom)
|
||||
|
||||
include(cmake/ftxui_set_options.cmake)
|
||||
ftxui_set_options(screen)
|
||||
@@ -184,8 +178,8 @@ include(cmake/ftxui_install.cmake)
|
||||
include(cmake/ftxui_package.cmake)
|
||||
include(cmake/ftxui_modules.cmake)
|
||||
|
||||
add_subdirectory(doc)
|
||||
add_subdirectory(examples)
|
||||
add_subdirectory(doc)
|
||||
|
||||
# You can generate ./examples_modules/ by running
|
||||
# ./tools/generate_examples_modules.sh
|
||||
|
||||
11
README.md
11
README.md
@@ -1,3 +1,4 @@
|
||||
|
||||
<p align="center">
|
||||
<img src="https://github.com/ArthurSonzogni/FTXUI/assets/4759106/6925b6da-0a7e-49d9-883c-c890e1f36007" alt="Demo image"></img>
|
||||
<br/>
|
||||
@@ -18,7 +19,7 @@
|
||||
<br/>
|
||||
<a href="https://arthursonzogni.github.io/FTXUI/">Documentation</a> ·
|
||||
<a href="https://github.com/ArthurSonzogni/FTXUI/issues">Report a Bug</a> ·
|
||||
<a href="https://arthursonzogni.github.io/FTXUI/examples.html">Examples</a> .
|
||||
<a href="https://arthursonzogni.github.io/FTXUI/examples/">Examples</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>
|
||||
|
||||
@@ -50,8 +51,9 @@ 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)
|
||||
- [Ubuntu package](https://launchpad.net/ubuntu/+source/ftxui)
|
||||
- [Arch Linux](https://aur.archlinux.org/packages/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)
|
||||
- [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)
|
||||
- [Nix](https://github.com/ArthurSonzogni/FTXUI/blob/main/flake.nix)
|
||||
* Good practices: documentation, tests, fuzzers, performance tests, automated CI, automated packaging, etc...
|
||||
|
||||
## Documentation
|
||||
@@ -361,6 +363,8 @@ Feel free to add your projects here:
|
||||
- [FTB - tertminal file browser](https://github.com/Cyxuan0311/FTB)
|
||||
- [openJuice](https://github.com/mikomikotaishi/openJuice)
|
||||
- [SHOOT!](https://github.com/ShingZhanho/ENGG1340-Project-25Spring)
|
||||
- [VerifySN (Fast Hash Tool)](https://github.com/d06i/verifySN)
|
||||
- [tic-tac-toe](https://github.com/birland/tic-tac-toe)
|
||||
|
||||
### [cpp-best-practices/game_jam](https://github.com/cpp-best-practices/game_jam)
|
||||
|
||||
@@ -430,6 +434,7 @@ If you don't, FTXUI may be used from the following packages:
|
||||
- [Ubuntu package](https://launchpad.net/ubuntu/+source/ftxui),
|
||||
- [Arch Linux](https://aur.archlinux.org/packages/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)
|
||||
|
||||
|
||||
|
||||
@@ -43,16 +43,6 @@ def windows_copts():
|
||||
"//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(
|
||||
name,
|
||||
srcs = [],
|
||||
|
||||
1
build/_deps/googlebenchmark-src
Submodule
1
build/_deps/googlebenchmark-src
Submodule
Submodule build/_deps/googlebenchmark-src added at 015d1a091a
42
build/_deps/googlebenchmark-subbuild/CMakeLists.txt
Normal file
42
build/_deps/googlebenchmark-subbuild/CMakeLists.txt
Normal file
@@ -0,0 +1,42 @@
|
||||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
# file Copyright.txt or https://cmake.org/licensing for details.
|
||||
|
||||
cmake_minimum_required(VERSION 3.31.6)
|
||||
|
||||
# Reject any attempt to use a toolchain file. We must not use one because
|
||||
# we could be downloading it here. If the CMAKE_TOOLCHAIN_FILE environment
|
||||
# variable is set, the cache variable will have been initialized from it.
|
||||
unset(CMAKE_TOOLCHAIN_FILE CACHE)
|
||||
unset(ENV{CMAKE_TOOLCHAIN_FILE})
|
||||
|
||||
# We name the project and the target for the ExternalProject_Add() call
|
||||
# to something that will highlight to the user what we are working on if
|
||||
# something goes wrong and an error message is produced.
|
||||
|
||||
project(googlebenchmark-populate NONE)
|
||||
|
||||
|
||||
# Pass through things we've already detected in the main project to avoid
|
||||
# paying the cost of redetecting them again in ExternalProject_Add()
|
||||
set(GIT_EXECUTABLE [==[/usr/bin/git]==])
|
||||
set(GIT_VERSION_STRING [==[2.51.0]==])
|
||||
set_property(GLOBAL PROPERTY _CMAKE_FindGit_GIT_EXECUTABLE_VERSION
|
||||
[==[/usr/bin/git;2.51.0]==]
|
||||
)
|
||||
|
||||
|
||||
include(ExternalProject)
|
||||
ExternalProject_Add(googlebenchmark-populate
|
||||
"UPDATE_DISCONNECTED" "False" "GIT_REPOSITORY" "https://github.com/google/benchmark" "EXTERNALPROJECT_INTERNAL_ARGUMENT_SEPARATOR" "GIT_TAG" "015d1a091af6937488242b70121858bce8fd40e9" "GIT_PROGRESS" "TRUE"
|
||||
SOURCE_DIR "/home/runner/work/FTXUI/FTXUI/build/_deps/googlebenchmark-src"
|
||||
BINARY_DIR "/home/runner/work/FTXUI/FTXUI/build/_deps/googlebenchmark-build"
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
TEST_COMMAND ""
|
||||
USES_TERMINAL_DOWNLOAD YES
|
||||
USES_TERMINAL_UPDATE YES
|
||||
USES_TERMINAL_PATCH YES
|
||||
)
|
||||
|
||||
|
||||
1
build/_deps/googletest-src
Submodule
1
build/_deps/googletest-src
Submodule
Submodule build/_deps/googletest-src added at 23ef29555e
42
build/_deps/googletest-subbuild/CMakeLists.txt
Normal file
42
build/_deps/googletest-subbuild/CMakeLists.txt
Normal file
@@ -0,0 +1,42 @@
|
||||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
# file Copyright.txt or https://cmake.org/licensing for details.
|
||||
|
||||
cmake_minimum_required(VERSION 3.31.6)
|
||||
|
||||
# Reject any attempt to use a toolchain file. We must not use one because
|
||||
# we could be downloading it here. If the CMAKE_TOOLCHAIN_FILE environment
|
||||
# variable is set, the cache variable will have been initialized from it.
|
||||
unset(CMAKE_TOOLCHAIN_FILE CACHE)
|
||||
unset(ENV{CMAKE_TOOLCHAIN_FILE})
|
||||
|
||||
# We name the project and the target for the ExternalProject_Add() call
|
||||
# to something that will highlight to the user what we are working on if
|
||||
# something goes wrong and an error message is produced.
|
||||
|
||||
project(googletest-populate NONE)
|
||||
|
||||
|
||||
# Pass through things we've already detected in the main project to avoid
|
||||
# paying the cost of redetecting them again in ExternalProject_Add()
|
||||
set(GIT_EXECUTABLE [==[/usr/bin/git]==])
|
||||
set(GIT_VERSION_STRING [==[2.51.0]==])
|
||||
set_property(GLOBAL PROPERTY _CMAKE_FindGit_GIT_EXECUTABLE_VERSION
|
||||
[==[/usr/bin/git;2.51.0]==]
|
||||
)
|
||||
|
||||
|
||||
include(ExternalProject)
|
||||
ExternalProject_Add(googletest-populate
|
||||
"UPDATE_DISCONNECTED" "False" "GIT_REPOSITORY" "https://github.com/google/googletest" "EXTERNALPROJECT_INTERNAL_ARGUMENT_SEPARATOR" "GIT_TAG" "23ef29555ef4789f555f1ba8c51b4c52975f0907" "GIT_PROGRESS" "TRUE"
|
||||
SOURCE_DIR "/home/runner/work/FTXUI/FTXUI/build/_deps/googletest-src"
|
||||
BINARY_DIR "/home/runner/work/FTXUI/FTXUI/build/_deps/googletest-build"
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
TEST_COMMAND ""
|
||||
USES_TERMINAL_DOWNLOAD YES
|
||||
USES_TERMINAL_UPDATE YES
|
||||
USES_TERMINAL_PATCH YES
|
||||
)
|
||||
|
||||
|
||||
@@ -11,6 +11,9 @@ include(CMakePackageConfigHelpers)
|
||||
install(
|
||||
TARGETS screen dom component
|
||||
EXPORT ftxui-targets
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
||||
)
|
||||
|
||||
install(
|
||||
|
||||
@@ -6,6 +6,7 @@ add_library(ftxui-modules)
|
||||
|
||||
target_sources(ftxui-modules
|
||||
PUBLIC FILE_SET CXX_MODULES FILES
|
||||
src/ftxui/ftxui.cppm
|
||||
src/ftxui/component.cppm
|
||||
src/ftxui/component/animation.cppm
|
||||
src/ftxui/component/captured_mouse.cppm
|
||||
|
||||
@@ -101,6 +101,5 @@ endfunction()
|
||||
|
||||
if (EMSCRIPTEN)
|
||||
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")
|
||||
endif()
|
||||
|
||||
@@ -19,11 +19,10 @@ add_executable(ftxui-tests
|
||||
src/ftxui/component/menu_test.cpp
|
||||
src/ftxui/component/modal_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/screen_interactive_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/toggle_test.cpp
|
||||
src/ftxui/dom/blink_test.cpp
|
||||
@@ -51,6 +50,7 @@ add_executable(ftxui-tests
|
||||
src/ftxui/dom/vbox_test.cpp
|
||||
src/ftxui/screen/color_test.cpp
|
||||
src/ftxui/screen/string_test.cpp
|
||||
src/ftxui/util/ref_test.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(ftxui-tests
|
||||
|
||||
@@ -12,8 +12,24 @@ FTXUI experimentally supports
|
||||
compilation times and improve code organization. Each header has a
|
||||
corresponding module.
|
||||
|
||||
**Example with CMake and Ninja**
|
||||
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;
|
||||
@@ -26,23 +42,30 @@ int main() {
|
||||
}
|
||||
```
|
||||
|
||||
```sh
|
||||
cmake \
|
||||
-DCMAKE_GENERATOR=Ninja \
|
||||
-DFTXUI_BUILD_MODULES=ON \
|
||||
..
|
||||
Note, the `ftxui` convenience module which simply pulls together all the modules:
|
||||
|
||||
ninja
|
||||
```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
|
||||
)
|
||||
```
|
||||
> [!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
|
||||
headers to provide a more convenient interface. The following modules
|
||||
are available:
|
||||
|
||||
- `ftxui`
|
||||
|
||||
@@ -16,6 +16,11 @@ This page serves as an entry point for the available integration methods.
|
||||
- @subpage installation_vcpkg
|
||||
- @subpage installation_conan
|
||||
- @subpage installation_manual
|
||||
- @subpage installation_nix
|
||||
- @subpage installation_debian
|
||||
- @subpage installation_arch
|
||||
- @subpage installation_opensuse
|
||||
- @subpage installation_xmake
|
||||
|
||||
## Next Steps
|
||||
|
||||
|
||||
34
doc/installation_arch.md
Normal file
34
doc/installation_arch.md
Normal file
@@ -0,0 +1,34 @@
|
||||
@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>
|
||||
@@ -1,20 +1,104 @@
|
||||
@page installation_conan Conan
|
||||
@tableofcontents
|
||||
|
||||
## Conan Package
|
||||
FTXUI can be easily obtained and integrated into your project using the Conan package manager.
|
||||
|
||||
Unofficial support for FTXUI exists on Conan Center:
|
||||
## Prerequisites
|
||||
|
||||
- https://conan.io/center/recipes/ftxui
|
||||
First, ensure that Conan is installed on your system. If not, you can install it via pip:
|
||||
|
||||
## TODO
|
||||
```powershell
|
||||
pip install conan
|
||||
```
|
||||
Conan often works in tandem with CMake, so you will need to have CMake installed as well. Once you have confirmed both Conan and CMake are installed, create a project directory, for example, `ftxui-demo`:
|
||||
|
||||
This page is incomplete. If you use FTXUI with Conan and can provide a minimal working setup, feel free to contribute.
|
||||
```powershell
|
||||
mkdir C:\ftxui-demo
|
||||
cd C:\ftxui-demo
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
After ensuring your environment is set up correctly, create a Conan configuration file `conanfile.txt`. This file is used to declare your project's dependencies. The community-maintained package for FTXUI can be found on [Conan Center](https://conan.io/center/recipes/ftxui).
|
||||
|
||||
> [!note]
|
||||
> This is an unofficial build script. This means it is not maintained by the FTXUI
|
||||
> team but by the community. The package maintainer appears to actively update it
|
||||
> to the latest releases. Many thanks to the maintainer for their work!
|
||||
|
||||
@todo If you are familiar with the process, please consider adding an "official" build script to Conan Center.
|
||||
This could be a GitHub Action that automatically updates Conan Center upon new releases.
|
||||
|
||||
```ini
|
||||
[requires]
|
||||
ftxui/6.0.2
|
||||
|
||||
[generators]
|
||||
CMakeDeps
|
||||
CMakeToolchain
|
||||
|
||||
[layout]
|
||||
cmake_layout
|
||||
```
|
||||
|
||||
## Install Dependencies and Build
|
||||
|
||||
Once configured, run the following command to install FTXUI and its dependencies:
|
||||
|
||||
```powershell
|
||||
conan install . --output-folder=build --build=missing
|
||||
```
|
||||
|
||||
This will download and install `ftxui/6.0.2` along with all its dependencies from Conan's remote repositories.
|
||||
|
||||
After the installation completes, you can test it by creating a `demo.cpp` file in your project directory:
|
||||
|
||||
```cpp
|
||||
#include <ftxui/screen/screen.hpp>
|
||||
#include <ftxui/dom/elements.hpp>
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
auto document = hbox({
|
||||
text(" Hello "),
|
||||
text("FTXUI ") | bold | color(Color::Red),
|
||||
text(" world! ")
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
std::cout << screen.ToString() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
If the test is successful, you can then create a `CMakeLists.txt` file in the project directory:
|
||||
|
||||
```cmake
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
project(ftxui-demo)
|
||||
|
||||
# Set the C++ standard
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
# Find the FTXUI package installed via Conan
|
||||
find_package(ftxui CONFIG REQUIRED)
|
||||
|
||||
# Create the executable
|
||||
add_executable(demo demo.cpp)
|
||||
|
||||
# Link the executable to the FTXUI library
|
||||
target_link_libraries(demo PRIVATE ftxui::component)
|
||||
```
|
||||
|
||||
@todo 考虑到中国多数地区使用Conan很有可能遇到各种网络问题,我想做一个定制的版本说明,但是我对conan的了解有限再加上没有找到合适的资料,因此这个计划短暂的被搁置了,如果您知道方法,欢迎在[中文版本](xiaoditx.girhub.io/public/docs/ftxui%E4%B8%AD%E6%96%87%E7%BF%BB%E8%AF%91/installation/conan/)的下方留下评论以提醒我
|
||||
|
||||
---
|
||||
|
||||
<div class="section_buttons">
|
||||
|
||||
|
||||
| Previous |
|
||||
|:------------------|
|
||||
| [Getting Started](getting-started.html) |
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
42
doc/installation_debian.md
Normal file
42
doc/installation_debian.md
Normal file
@@ -0,0 +1,42 @@
|
||||
@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>
|
||||
35
doc/installation_manual.md
Normal file
35
doc/installation_manual.md
Normal file
@@ -0,0 +1,35 @@
|
||||
@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>
|
||||
38
doc/installation_nix.md
Normal file
38
doc/installation_nix.md
Normal file
@@ -0,0 +1,38 @@
|
||||
@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>
|
||||
32
doc/installation_opensuse.md
Normal file
32
doc/installation_opensuse.md
Normal file
@@ -0,0 +1,32 @@
|
||||
@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,15 +1,74 @@
|
||||
@page installation_vcpkg Vcpkg
|
||||
@tableofcontents
|
||||
|
||||
## Vcpkg Package
|
||||
# Vcpkg Package
|
||||
|
||||
FTXUI is available in the Vcpkg registry:
|
||||
FTXUI is available in the [Vcpkg registry](https://vcpkg.link/ports/ftxui)
|
||||
|
||||
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">
|
||||
|
||||
|
||||
40
doc/installation_xmake.md
Normal file
40
doc/installation_xmake.md
Normal file
@@ -0,0 +1,40 @@
|
||||
@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>
|
||||
@@ -15,16 +15,14 @@ add_subdirectory(component)
|
||||
add_subdirectory(dom)
|
||||
|
||||
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)
|
||||
foreach(file
|
||||
"index.css"
|
||||
"index.html"
|
||||
"index.mjs"
|
||||
"index.css"
|
||||
"run_webassembly.py"
|
||||
"sw.js"
|
||||
"run_webassembly.py")
|
||||
)
|
||||
configure_file(${file} ${file})
|
||||
endforeach(file)
|
||||
endif()
|
||||
|
||||
@@ -1,9 +1,64 @@
|
||||
#include "ftxui/component/component.hpp"
|
||||
#include "ftxui/component/screen_interactive.hpp"
|
||||
// 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 <memory> // for shared_ptr, __shared_ptr_access
|
||||
#include <string> // for operator+, to_string
|
||||
|
||||
int main(){
|
||||
auto screen = ftxui::ScreenInteractive::Fullscreen();
|
||||
auto testComponent = ftxui::Renderer([](){return ftxui::text("test Component");});
|
||||
screen.Loop(testComponent);
|
||||
return 0;
|
||||
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
||||
#include "ftxui/component/component.hpp" // for Button, Horizontal, Renderer
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/elements.hpp" // for separator, gauge, text, Element, operator|, vbox, border
|
||||
|
||||
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,8 +133,9 @@ int main() {
|
||||
float dy = 50.f;
|
||||
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]);
|
||||
}
|
||||
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
|
||||
@@ -82,10 +82,12 @@ int main() {
|
||||
size(WIDTH, EQUAL, dimx) | size(HEIGHT, EQUAL, dimy) |
|
||||
bgcolor(Color::HSV(index * 25, 255, 255)) |
|
||||
color(Color::Black);
|
||||
if (element_xflex_grow)
|
||||
if (element_xflex_grow) {
|
||||
element = element | xflex_grow;
|
||||
if (element_yflex_grow)
|
||||
}
|
||||
if (element_yflex_grow) {
|
||||
element = element | yflex_grow;
|
||||
}
|
||||
return element;
|
||||
};
|
||||
|
||||
@@ -119,10 +121,12 @@ int main() {
|
||||
|
||||
group = group | notflex;
|
||||
|
||||
if (!group_xflex_grow)
|
||||
if (!group_xflex_grow) {
|
||||
group = hbox(group, filler());
|
||||
if (!group_yflex_grow)
|
||||
}
|
||||
if (!group_yflex_grow) {
|
||||
group = vbox(group, filler());
|
||||
}
|
||||
|
||||
group = group | flex;
|
||||
return group;
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
// 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 <stddef.h> // for size_t
|
||||
#include <array> // for array
|
||||
#include <atomic> // for atomic
|
||||
#include <chrono> // for operator""s, chrono_literals
|
||||
#include <cmath> // for sin
|
||||
#include <stddef.h> // for size_t
|
||||
#include <array> // for array
|
||||
#include <atomic> // for atomic
|
||||
#include <chrono> // for operator""s, chrono_literals
|
||||
#include <cmath> // for sin
|
||||
#include <ftxui/component/loop.hpp>
|
||||
#include <functional> // for ref, reference_wrapper, function
|
||||
#include <memory> // for allocator, shared_ptr, __shared_ptr_access
|
||||
#include <string> // for string, basic_string, char_traits, operator+, to_string
|
||||
@@ -269,7 +270,7 @@ int main() {
|
||||
auto spinner_tab_renderer = Renderer([&] {
|
||||
Elements entries;
|
||||
for (int i = 0; i < 22; ++i) {
|
||||
entries.push_back(spinner(i, shift / 2) | bold |
|
||||
entries.push_back(spinner(i, shift / 5) | bold |
|
||||
size(WIDTH, GREATER_THAN, 2) | border);
|
||||
}
|
||||
return hflow(std::move(entries));
|
||||
@@ -512,24 +513,20 @@ int main() {
|
||||
});
|
||||
});
|
||||
|
||||
std::atomic<bool> refresh_ui_continue = true;
|
||||
std::thread refresh_ui([&] {
|
||||
while (refresh_ui_continue) {
|
||||
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);
|
||||
}
|
||||
});
|
||||
Loop loop(&screen, main_renderer);
|
||||
while (!loop.HasQuitted()) {
|
||||
// Update the state of the application.
|
||||
shift++;
|
||||
|
||||
screen.Loop(main_renderer);
|
||||
refresh_ui_continue = false;
|
||||
refresh_ui.join();
|
||||
// Request a new frame to be drawn.
|
||||
screen.RequestAnimationFrame();
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
@@ -22,10 +22,12 @@ MenuEntryOption Colored(ftxui::Color c) {
|
||||
option.transform = [c](EntryState state) {
|
||||
state.label = (state.active ? "> " : " ") + state.label;
|
||||
Element e = text(state.label) | color(c);
|
||||
if (state.focused)
|
||||
if (state.focused) {
|
||||
e = e | inverted;
|
||||
if (state.active)
|
||||
}
|
||||
if (state.active) {
|
||||
e = e | bold;
|
||||
}
|
||||
return e;
|
||||
};
|
||||
return option;
|
||||
|
||||
@@ -17,8 +17,9 @@ int main() {
|
||||
std::vector<std::string> entries;
|
||||
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));
|
||||
}
|
||||
auto radiobox = Menu(&entries, &selected);
|
||||
auto renderer = Renderer(radiobox, [&] {
|
||||
return radiobox->Render() | vscroll_indicator | frame |
|
||||
|
||||
@@ -17,8 +17,9 @@ int main() {
|
||||
std::vector<std::string> entries;
|
||||
int selected = 0;
|
||||
|
||||
for (int i = 0; i < 100; ++i)
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
entries.push_back(std::to_string(i));
|
||||
}
|
||||
auto radiobox = Menu(&entries, &selected, MenuOption::Horizontal());
|
||||
auto renderer = Renderer(
|
||||
radiobox, [&] { return radiobox->Render() | hscroll_indicator | frame; });
|
||||
|
||||
@@ -116,10 +116,12 @@ Component VMenu1(std::vector<std::string>* entries, int* selected) {
|
||||
option.entries_option.transform = [](EntryState state) {
|
||||
state.label = (state.active ? "> " : " ") + state.label;
|
||||
Element e = text(state.label);
|
||||
if (state.focused)
|
||||
if (state.focused) {
|
||||
e = e | bgcolor(Color::Blue);
|
||||
if (state.active)
|
||||
}
|
||||
if (state.active) {
|
||||
e = e | bold;
|
||||
}
|
||||
return e;
|
||||
};
|
||||
return Menu(entries, selected, option);
|
||||
@@ -130,10 +132,12 @@ Component VMenu2(std::vector<std::string>* entries, int* selected) {
|
||||
option.entries_option.transform = [](EntryState state) {
|
||||
state.label += (state.active ? " <" : " ");
|
||||
Element e = hbox(filler(), text(state.label));
|
||||
if (state.focused)
|
||||
if (state.focused) {
|
||||
e = e | bgcolor(Color::Red);
|
||||
if (state.active)
|
||||
}
|
||||
if (state.active) {
|
||||
e = e | bold;
|
||||
}
|
||||
return e;
|
||||
};
|
||||
return Menu(entries, selected, option);
|
||||
@@ -144,13 +148,16 @@ Component VMenu3(std::vector<std::string>* entries, int* selected) {
|
||||
option.entries_option.transform = [](EntryState state) {
|
||||
Element e = state.active ? text("[" + state.label + "]")
|
||||
: text(" " + state.label + " ");
|
||||
if (state.focused)
|
||||
if (state.focused) {
|
||||
e = e | bold;
|
||||
}
|
||||
|
||||
if (state.focused)
|
||||
if (state.focused) {
|
||||
e = e | color(Color::Blue);
|
||||
if (state.active)
|
||||
}
|
||||
if (state.active) {
|
||||
e = e | bold;
|
||||
}
|
||||
return e;
|
||||
};
|
||||
return Menu(entries, selected, option);
|
||||
@@ -245,10 +252,12 @@ Component HMenu5(std::vector<std::string>* entries, int* selected) {
|
||||
animation::easing::ElasticOut);
|
||||
option.entries_option.transform = [](EntryState state) {
|
||||
Element e = text(state.label) | hcenter | flex;
|
||||
if (state.active && state.focused)
|
||||
if (state.active && state.focused) {
|
||||
e = e | bold;
|
||||
if (!state.focused && !state.active)
|
||||
}
|
||||
if (!state.focused && !state.active) {
|
||||
e = e | dim;
|
||||
}
|
||||
return e;
|
||||
};
|
||||
option.underline.color_inactive = Color::Default;
|
||||
|
||||
@@ -20,8 +20,9 @@ using namespace ftxui;
|
||||
Component DummyComponent(int id) {
|
||||
return Renderer([id](bool focused) {
|
||||
auto t = text("component " + std::to_string(id));
|
||||
if (focused)
|
||||
if (focused) {
|
||||
t = t | inverted;
|
||||
}
|
||||
return t;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,8 +17,9 @@ int main() {
|
||||
std::vector<std::string> entries;
|
||||
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));
|
||||
}
|
||||
auto radiobox = Radiobox(&entries, &selected);
|
||||
auto renderer = Renderer(radiobox, [&] {
|
||||
return radiobox->Render() | vscroll_indicator | frame |
|
||||
|
||||
@@ -19,10 +19,11 @@ int main() {
|
||||
|
||||
// 1. Example of focusable renderer:
|
||||
auto renderer_focusable = Renderer([](bool focused) {
|
||||
if (focused)
|
||||
if (focused) {
|
||||
return text("FOCUSABLE RENDERER()") | center | bold | border;
|
||||
else
|
||||
} else {
|
||||
return text(" Focusable renderer() ") | center | border;
|
||||
}
|
||||
});
|
||||
|
||||
// 2. Examples of a non focusable renderer.
|
||||
@@ -33,10 +34,11 @@ int main() {
|
||||
// 3. Renderer can wrap other components to redefine their Render() function.
|
||||
auto button = Button("Wrapped quit button", screen.ExitLoopClosure());
|
||||
auto renderer_wrap = Renderer(button, [&] {
|
||||
if (button->Focused())
|
||||
if (button->Focused()) {
|
||||
return button->Render() | bold | color(Color::Red);
|
||||
else
|
||||
} else {
|
||||
return button->Render();
|
||||
}
|
||||
});
|
||||
|
||||
// Let's renderer everyone:
|
||||
|
||||
@@ -32,10 +32,12 @@ int main() {
|
||||
|
||||
// Plot a function:
|
||||
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));
|
||||
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);
|
||||
}
|
||||
|
||||
auto document = canvas(&c) | border;
|
||||
|
||||
|
||||
@@ -86,8 +86,9 @@ int main() {
|
||||
|
||||
auto render = [&]() {
|
||||
std::vector<Element> entries;
|
||||
for (auto& task : displayed_task)
|
||||
for (auto& task : displayed_task) {
|
||||
entries.push_back(renderTask(task));
|
||||
}
|
||||
|
||||
return vbox({
|
||||
// List of tasks.
|
||||
@@ -138,8 +139,9 @@ int main() {
|
||||
std::this_thread::sleep_for(0.01s);
|
||||
|
||||
// Exit
|
||||
if (nb_active + nb_queued == 0)
|
||||
if (nb_active + nb_queued == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Update the model for the next frame.
|
||||
updateModel();
|
||||
|
||||
@@ -21,8 +21,9 @@ int main() {
|
||||
for (int index = 0; index < 200; ++index) {
|
||||
std::vector<Element> entries;
|
||||
for (int i = 0; i < 23; ++i) {
|
||||
if (i != 0)
|
||||
if (i != 0) {
|
||||
entries.push_back(separator());
|
||||
}
|
||||
entries.push_back( //
|
||||
hbox({
|
||||
text(std::to_string(i)) | size(WIDTH, EQUAL, 2),
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
@import url(https://fonts.googleapis.com/css?family=Khula:700);
|
||||
|
||||
html {
|
||||
--toc-width: 250px;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color:#EEE;
|
||||
padding:0px;
|
||||
margin:0px;
|
||||
background-color: #EEE;
|
||||
padding: 0px;
|
||||
margin: 0px;
|
||||
font-family: Khula, Helvetica, sans-serif;
|
||||
font-size: 130%;
|
||||
}
|
||||
|
||||
.page {
|
||||
max-width:1300px;
|
||||
max-width: 1300px;
|
||||
margin: auto;
|
||||
padding: 10px;
|
||||
}
|
||||
@@ -20,7 +24,7 @@ a {
|
||||
margin: 0 -.25rem;
|
||||
padding: 0 .25rem;
|
||||
transition: color .3s ease-in-out,
|
||||
box-shadow .3s ease-in-out;
|
||||
box-shadow .3s ease-in-out;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
@@ -30,45 +34,48 @@ a:hover {
|
||||
|
||||
h1 {
|
||||
text-decoration: underline;
|
||||
width:100%;
|
||||
background-color: rgba(100,100,255,0.5);
|
||||
width: 100%;
|
||||
background-color: rgba(100, 100, 255, 0.5);
|
||||
padding: 10px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
|
||||
#selectExample {
|
||||
flex:1;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
#selectExample, #selectExample option {
|
||||
#selectExample,
|
||||
#selectExample option {
|
||||
font-size: 16px;
|
||||
font-family: sans-serif;
|
||||
font-weight: 700;
|
||||
line-height: 1.3;
|
||||
border:0px;
|
||||
border: 0px;
|
||||
background-color: #bbb;
|
||||
color:black;
|
||||
color: black;
|
||||
}
|
||||
|
||||
#selectExample:focus {
|
||||
outline:none;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
#terminal {
|
||||
width:100%;
|
||||
width: 100%;
|
||||
height 500px;
|
||||
height: calc(clamp(200px, 100vh - 300px, 900px));
|
||||
overflow: hidden;
|
||||
border:none;
|
||||
background-color:black;
|
||||
border: none;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
}
|
||||
|
||||
#terminalContainer {
|
||||
overflow: hidden;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0px 2px 10px 0px rgba(0,0,0,0.75),
|
||||
0px 2px 80px 0px rgba(0,0,0,0.50);
|
||||
box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.75),
|
||||
0px 2px 80px 0px rgba(0, 0, 0, 0.50);
|
||||
background-color: black;
|
||||
}
|
||||
|
||||
.fakeButtons {
|
||||
@@ -76,7 +83,7 @@ h1 {
|
||||
width: 10px;
|
||||
border-radius: 50%;
|
||||
border: 1px solid #000;
|
||||
margin:6px;
|
||||
margin: 6px;
|
||||
background-color: #ff3b47;
|
||||
border-color: #9d252b;
|
||||
display: inline-block;
|
||||
@@ -95,13 +102,79 @@ h1 {
|
||||
}
|
||||
|
||||
.fakeMenu {
|
||||
display:flex;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
width:100%;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
height: 25px;
|
||||
background-color: #bbb;
|
||||
color:black;
|
||||
color: black;
|
||||
margin: 0 auto;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.toc-container {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: var(--toc-width);
|
||||
background: white;
|
||||
padding: 0;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
|
||||
.toc-title {
|
||||
font-weight: bold;
|
||||
margin-bottom: 5px;
|
||||
font-size: 0.9em;
|
||||
color: #555;
|
||||
|
||||
position: sticky;
|
||||
transition: position 1.0s ease-in-out;
|
||||
top: 0;
|
||||
z-index: 1;
|
||||
padding: 20px;
|
||||
margin: 0;
|
||||
|
||||
border-bottom: 1px solid #ddd;
|
||||
|
||||
/* Gradient background for the title */
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
|
||||
.toc-item {
|
||||
padding: 3px 8px;
|
||||
margin: 0;
|
||||
cursor: pointer;
|
||||
font-size: 0.85em;
|
||||
border-radius: 3px;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.toc-item:hover {
|
||||
background: #f0f0f0;
|
||||
}
|
||||
|
||||
.toc-item.selected {
|
||||
background: #e0e0e0;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
.toc-container {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.page {
|
||||
margin-left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1025px) {
|
||||
.page {
|
||||
margin-left: calc(var(--toc-width) + 20px);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,13 +9,18 @@
|
||||
<script type="module" src="index.mjs"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="toc-container">
|
||||
<div class="toc-list"></div>
|
||||
</div>
|
||||
<script id="example_script"></script>
|
||||
|
||||
<div class="page">
|
||||
<p>
|
||||
<a href="https://github.com/ArthurSonzogni/FTXUI">FTXUI</a> is a simple
|
||||
functional C++ library for terminal user interface. <br/>
|
||||
This showcases the: <a href="https://github.com/ArthurSonzogni/FTXUI/tree/master/examples">./example/</a> folder. <br/>
|
||||
This showcases the: <a
|
||||
href="https://github.com/ArthurSonzogni/FTXUI/tree/master/examples">./example/</a>
|
||||
folder. See <a id="source">source</a>.
|
||||
</p>
|
||||
|
||||
<div id="terminalContainer">
|
||||
|
||||
@@ -7,7 +7,7 @@ if ("serviceWorker" in navigator && !window.crossOriginIsolated) {
|
||||
const url_sw = new URL("./sw.js", location.href);
|
||||
const registration = await navigator.serviceWorker.register(url_sw);
|
||||
window.location.reload(); // Reload to ensure the COOP/COEP headers are set.
|
||||
}
|
||||
}
|
||||
|
||||
const example_list = "@EXAMPLES@".split(";");
|
||||
const url_search_params = new URLSearchParams(window.location.search);
|
||||
@@ -55,7 +55,7 @@ const stdout = code => {
|
||||
const stderr = code => {
|
||||
if (code == 0 || code == 10) {
|
||||
console.error(String.fromCodePoint(...stderr_buffer));
|
||||
stderr_buffer = [];
|
||||
stderr_buffer.length = 0;
|
||||
} else {
|
||||
stderr_buffer.push(code)
|
||||
}
|
||||
@@ -89,12 +89,72 @@ window.Module = {
|
||||
const resize_observer = new ResizeObserver(resize_handler);
|
||||
resize_observer.observe(term_element);
|
||||
resize_handler();
|
||||
|
||||
// Disable scrollbar
|
||||
//term.write('\x1b[?47h')
|
||||
},
|
||||
};
|
||||
|
||||
const source = document.querySelector("#source");
|
||||
source.href = "https://github.com/ArthurSonzogni/FTXUI/blob/main/examples/" + example + ".cpp";
|
||||
|
||||
const words = example.split('/')
|
||||
words[1] = "ftxui_example_" + words[1] + ".js"
|
||||
document.querySelector("#example_script").src = words.join('/');
|
||||
|
||||
|
||||
// Table of Contents (TOC) for quick navigation.
|
||||
|
||||
// Get select element
|
||||
const selectEl = document.querySelector('select#selectExample');
|
||||
if (!selectEl) {
|
||||
console.error('select#selectExample not found');
|
||||
} else {
|
||||
// Get TOC container
|
||||
const tocContainer = document.querySelector('.toc-container');
|
||||
const tocList = tocContainer.querySelector('.toc-list');
|
||||
|
||||
// Group options by directory
|
||||
const groupedOptions = Array.from(selectEl.options).reduce((acc, option) => {
|
||||
const [dir, file] = option.text.split('/');
|
||||
if (!acc[dir]) {
|
||||
acc[dir] = [];
|
||||
}
|
||||
acc[dir].push({ option, file });
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
// Generate TOC items
|
||||
for (const dir in groupedOptions) {
|
||||
const dirContainer = document.createElement('div');
|
||||
|
||||
const dirHeader = document.createElement('div');
|
||||
dirHeader.textContent = dir;
|
||||
dirHeader.className = 'toc-title';
|
||||
dirContainer.appendChild(dirHeader);
|
||||
|
||||
groupedOptions[dir].forEach(({ option, file }) => {
|
||||
const tocItem = document.createElement('div');
|
||||
tocItem.textContent = file;
|
||||
tocItem.className = 'toc-item';
|
||||
|
||||
if (selectEl.options[selectEl.selectedIndex].value === option.value) {
|
||||
tocItem.classList.add('selected');
|
||||
}
|
||||
|
||||
// Click handler
|
||||
tocItem.addEventListener('click', () => {
|
||||
for(let i=0; i<selectEl.options.length; ++i) {
|
||||
if (selectEl.options[i].value == option.value) {
|
||||
selectEl.selectedIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
history.pushState({}, "", "?file=" + option.value);
|
||||
location.reload();
|
||||
});
|
||||
|
||||
dirContainer.appendChild(tocItem);
|
||||
});
|
||||
|
||||
tocList.appendChild(dirContainer);
|
||||
}
|
||||
}''
|
||||
|
||||
@@ -8,11 +8,21 @@
|
||||
#include <functional> // for function
|
||||
|
||||
namespace ftxui::animation {
|
||||
// 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.
|
||||
/// @brief RequestAnimationFrame is a function that requests a new frame to be
|
||||
/// drawn in the next animation cycle.
|
||||
///
|
||||
/// @note This function is typically called by components that need to
|
||||
/// update their state or appearance over time, such as animations or
|
||||
/// 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();
|
||||
|
||||
using Clock = std::chrono::steady_clock;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <memory>
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
class CapturedMouseInterface {
|
||||
public:
|
||||
CapturedMouseInterface() = default;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <memory> // for make_shared, shared_ptr
|
||||
#include <utility> // for forward
|
||||
|
||||
#include <ftxui/util/warn_windows_macro.hpp>
|
||||
#include "ftxui/component/component_base.hpp" // for Component, Components
|
||||
#include "ftxui/component/component_options.hpp" // for ButtonOption, CheckboxOption, MenuOption
|
||||
#include "ftxui/dom/elements.hpp" // for Element
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
#include <ftxui/dom/direction.hpp> // for Direction, Direction::Left, Direction::Right, Direction::Down
|
||||
#include <ftxui/dom/elements.hpp> // for Element, separator
|
||||
#include <ftxui/util/ref.hpp> // for Ref, ConstRef, StringRef
|
||||
#include <functional> // for function
|
||||
#include <string> // for string
|
||||
#include <ftxui/util/warn_windows_macro.hpp>
|
||||
#include <functional> // for function
|
||||
#include <string> // for string
|
||||
|
||||
#include "ftxui/component/component_base.hpp" // for Component
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::GrayDark, Color::White
|
||||
@@ -27,6 +28,8 @@ struct EntryState {
|
||||
int index; ///< Index of the entry when applicable or -1.
|
||||
};
|
||||
|
||||
/// @brief Option for the underline effect.
|
||||
/// @ingroup component
|
||||
struct UnderlineOption {
|
||||
bool enabled = false;
|
||||
|
||||
@@ -230,7 +233,8 @@ struct SliderOption {
|
||||
std::function<void()> on_change; ///> Called when `value` is updated.
|
||||
};
|
||||
|
||||
// Parameter pack used by `WindowOptions::render`.
|
||||
/// @brief State passed to the `Window` component's render function.
|
||||
/// @ingroup component
|
||||
struct WindowRenderState {
|
||||
Element inner; ///< The element wrapped inside this window.
|
||||
const std::string& title; ///< The title of the window.
|
||||
|
||||
@@ -24,6 +24,8 @@ class ComponentBase;
|
||||
///
|
||||
/// Useful documentation about xterm specification:
|
||||
/// https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
|
||||
///
|
||||
/// @ingroup component
|
||||
struct Event {
|
||||
// --- Constructor section ---------------------------------------------------
|
||||
static Event Character(std::string);
|
||||
|
||||
@@ -14,6 +14,45 @@ class ComponentBase;
|
||||
using Component = std::shared_ptr<ComponentBase>;
|
||||
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 {
|
||||
public:
|
||||
Loop(ScreenInteractive* screen, Component component);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#ifndef FTXUI_COMPONENT_RECEIVER_HPP_
|
||||
#define FTXUI_COMPONENT_RECEIVER_HPP_
|
||||
|
||||
#include <ftxui/util/warn_windows_macro.hpp>
|
||||
#include <algorithm> // for copy, max
|
||||
#include <atomic> // for atomic, __atomic_base
|
||||
#include <condition_variable> // for condition_variable
|
||||
@@ -14,6 +15,8 @@
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
// Deprecated
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// Initialization:
|
||||
@@ -39,17 +42,24 @@ namespace ftxui {
|
||||
// Receiver::Receive() returns true when there are no more senders.
|
||||
|
||||
// clang-format off
|
||||
// Deprecated:
|
||||
template<class T> class SenderImpl;
|
||||
// Deprecated:
|
||||
template<class T> class ReceiverImpl;
|
||||
// Deprecated:
|
||||
|
||||
// Deprecated:
|
||||
template<class T> using Sender = std::unique_ptr<SenderImpl<T>>;
|
||||
// Deprecated:
|
||||
template<class T> using Receiver = std::unique_ptr<ReceiverImpl<T>>;
|
||||
// Deprecated:
|
||||
template<class T> Receiver<T> MakeReceiver();
|
||||
// clang-format on
|
||||
|
||||
// ---- Implementation part ----
|
||||
|
||||
template <class T>
|
||||
// Deprecated:
|
||||
class SenderImpl {
|
||||
public:
|
||||
SenderImpl(const SenderImpl&) = delete;
|
||||
|
||||
@@ -4,13 +4,10 @@
|
||||
#ifndef FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
|
||||
#define FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
|
||||
|
||||
#include <atomic> // for atomic
|
||||
#include <ftxui/component/receiver.hpp> // for Receiver, Sender
|
||||
#include <functional> // for function
|
||||
#include <memory> // for shared_ptr
|
||||
#include <string> // for string
|
||||
#include <thread> // for thread
|
||||
#include <variant> // for variant
|
||||
#include <atomic> // for atomic
|
||||
#include <functional> // for function
|
||||
#include <memory> // for shared_ptr
|
||||
#include <string> // for string
|
||||
|
||||
#include "ftxui/component/animation.hpp" // for TimePoint
|
||||
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
|
||||
@@ -27,6 +24,14 @@ struct Event;
|
||||
using Component = std::shared_ptr<ComponentBase>;
|
||||
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 {
|
||||
public:
|
||||
// Constructors:
|
||||
@@ -37,6 +42,9 @@ class ScreenInteractive : public Screen {
|
||||
static ScreenInteractive FitComponent();
|
||||
static ScreenInteractive TerminalOutput();
|
||||
|
||||
// Destructor.
|
||||
~ScreenInteractive();
|
||||
|
||||
// Options. Must be called before Loop().
|
||||
void TrackMouse(bool enable = true);
|
||||
|
||||
@@ -94,6 +102,10 @@ class ScreenInteractive : public Screen {
|
||||
|
||||
void Signal(int signal);
|
||||
|
||||
void FetchTerminalEvents();
|
||||
|
||||
void PostAnimationTask();
|
||||
|
||||
ScreenInteractive* suspended_screen_ = nullptr;
|
||||
enum class Dimension {
|
||||
FitComponent,
|
||||
@@ -101,30 +113,26 @@ class ScreenInteractive : public Screen {
|
||||
Fullscreen,
|
||||
TerminalOutput,
|
||||
};
|
||||
Dimension dimension_ = Dimension::Fixed;
|
||||
bool use_alternative_screen_ = false;
|
||||
ScreenInteractive(int dimx,
|
||||
ScreenInteractive(Dimension dimension,
|
||||
int dimx,
|
||||
int dimy,
|
||||
Dimension dimension,
|
||||
bool use_alternative_screen);
|
||||
const Dimension dimension_;
|
||||
const bool use_alternative_screen_;
|
||||
|
||||
bool track_mouse_ = true;
|
||||
|
||||
Sender<Task> task_sender_;
|
||||
Receiver<Task> task_receiver_;
|
||||
|
||||
std::string set_cursor_position;
|
||||
std::string reset_cursor_position;
|
||||
|
||||
std::atomic<bool> quit_{false};
|
||||
std::thread event_listener_;
|
||||
std::thread animation_listener_;
|
||||
bool animation_requested_ = false;
|
||||
animation::TimePoint previous_animation_time_;
|
||||
|
||||
int cursor_x_ = 1;
|
||||
int cursor_y_ = 1;
|
||||
|
||||
std::uint64_t frame_count_ = 0;
|
||||
bool mouse_captured = false;
|
||||
bool previous_frame_resized_ = false;
|
||||
|
||||
@@ -152,8 +160,14 @@ class ScreenInteractive : public Screen {
|
||||
std::unique_ptr<Selection> selection_;
|
||||
std::function<void()> selection_on_change_;
|
||||
|
||||
// PIMPL private implementation idiom (Pimpl).
|
||||
struct Internal;
|
||||
std::unique_ptr<Internal> internal_;
|
||||
|
||||
friend class Loop;
|
||||
|
||||
Component component_;
|
||||
|
||||
public:
|
||||
class Private {
|
||||
public:
|
||||
|
||||
@@ -20,6 +20,21 @@
|
||||
|
||||
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 {
|
||||
public:
|
||||
Canvas() = default;
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
#define FTXUI_DOM_DIRECTION_HPP
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
/// @brief Direction is an enumeration that represents the four cardinal
|
||||
/// directions.
|
||||
///
|
||||
/// @ingroup dom
|
||||
enum class Direction {
|
||||
Up = 0,
|
||||
Down = 1,
|
||||
|
||||
@@ -24,6 +24,14 @@ using Elements = std::vector<Element>;
|
||||
using Decorator = std::function<Element(Element)>;
|
||||
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 {
|
||||
LIGHT,
|
||||
DASHED,
|
||||
|
||||
@@ -12,6 +12,18 @@
|
||||
|
||||
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 {
|
||||
/// This establishes the main-axis, thus defining the direction flex items are
|
||||
/// placed in the flex container. Flexbox is (aside wrapping) single-direction
|
||||
|
||||
@@ -27,8 +27,15 @@ namespace ftxui {
|
||||
/// LinearGradient(Color::Red, Color::Blue);
|
||||
/// LinearGradient(45, Color::Red, Color::Blue);
|
||||
/// ```
|
||||
///
|
||||
/// @ingroup dom
|
||||
struct LinearGradient {
|
||||
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 {
|
||||
Color color = Color::Default;
|
||||
std::optional<float> position;
|
||||
|
||||
@@ -20,6 +20,20 @@ class Screen;
|
||||
using Element = std::shared_ptr<Node>;
|
||||
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 {
|
||||
public:
|
||||
Node();
|
||||
|
||||
@@ -10,6 +10,11 @@
|
||||
namespace ftxui {
|
||||
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 {
|
||||
// The required size to fully draw the element.
|
||||
int min_x = 0;
|
||||
|
||||
@@ -13,7 +13,12 @@
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
/// @brief Represent a selection in the terminal.
|
||||
/// @brief Represents a selection in a terminal user interface.
|
||||
///
|
||||
/// Selection is a class that represents the two endpoints of a selection in a
|
||||
/// terminal user interface.
|
||||
///
|
||||
/// @ingroup dom
|
||||
class Selection {
|
||||
public:
|
||||
Selection(); // Empty selection.
|
||||
|
||||
@@ -11,28 +11,28 @@
|
||||
|
||||
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 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 {
|
||||
public:
|
||||
Table();
|
||||
|
||||
@@ -6,6 +6,13 @@
|
||||
|
||||
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 {
|
||||
int x_min = 0;
|
||||
int x_max = 0;
|
||||
|
||||
@@ -15,7 +15,9 @@
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
/// @brief A class representing terminal colors.
|
||||
/// @brief Color is a class that represents a color in the terminal user
|
||||
/// interface.
|
||||
///
|
||||
/// @ingroup screen
|
||||
class Color {
|
||||
public:
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
/// @brief ColorInfo is a structure that contains information about the terminal
|
||||
/// color palette.
|
||||
///
|
||||
/// @ingroup screen
|
||||
struct ColorInfo {
|
||||
const char* name;
|
||||
uint8_t index_256;
|
||||
|
||||
@@ -20,6 +20,9 @@ class Image {
|
||||
Image() = delete;
|
||||
Image(int dimx, int dimy);
|
||||
|
||||
// Destructor:
|
||||
virtual ~Image() = default;
|
||||
|
||||
// Access a character in the grid at a given position.
|
||||
std::string& at(int x, int y);
|
||||
const std::string& at(int x, int y) const;
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
#include "ftxui/screen/image.hpp" // for Pixel, Image
|
||||
#include "ftxui/screen/terminal.hpp" // for Dimensions
|
||||
#include "ftxui/util/autoreset.hpp" // for AutoReset
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
@@ -31,6 +30,9 @@ class Screen : public Image {
|
||||
static Screen Create(Dimensions dimension);
|
||||
static Screen Create(Dimensions width, Dimensions height);
|
||||
|
||||
// Destructor:
|
||||
~Screen() override = default;
|
||||
|
||||
std::string ToString() const;
|
||||
|
||||
// Print the Screen on to the terminal.
|
||||
@@ -58,7 +60,7 @@ class Screen : public Image {
|
||||
BarBlinking = 5,
|
||||
Bar = 6,
|
||||
};
|
||||
Shape shape;
|
||||
Shape shape = Hidden;
|
||||
};
|
||||
|
||||
Cursor cursor() const { return cursor_; }
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
#define FTXUI_SCREEN_TERMINAL_HPP
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
/// @brief Dimensions is a structure that represents the size of the terminal
|
||||
/// @ingroup screen
|
||||
struct Dimensions {
|
||||
int dimx;
|
||||
int dimy;
|
||||
@@ -14,6 +17,9 @@ namespace Terminal {
|
||||
Dimensions Size();
|
||||
void SetFallbackSize(const Dimensions& fallbackSize);
|
||||
|
||||
/// @brief Color is an enumeration that represents the color support of the
|
||||
/// terminal.
|
||||
/// @ingroup screen
|
||||
enum Color {
|
||||
Palette1,
|
||||
Palette16,
|
||||
|
||||
18
include/ftxui/util/warn_windows_macro.hpp
Normal file
18
include/ftxui/util/warn_windows_macro.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
// 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_
|
||||
@@ -139,7 +139,6 @@ class ButtonBase : public ComponentBase, public ButtonOption {
|
||||
private:
|
||||
bool mouse_hover_ = false;
|
||||
Box box_;
|
||||
ButtonOption option_;
|
||||
float animation_background_ = 0;
|
||||
float animation_foreground_ = 0;
|
||||
animation::Animator animator_background_ =
|
||||
|
||||
@@ -35,26 +35,22 @@ ComponentBase::~ComponentBase() {
|
||||
/// @brief Return the parent ComponentBase, or nul if any.
|
||||
/// @see Detach
|
||||
/// @see Parent
|
||||
/// @ingroup component
|
||||
ComponentBase* ComponentBase::Parent() const {
|
||||
return parent_;
|
||||
}
|
||||
|
||||
/// @brief Access the child at index `i`.
|
||||
/// @ingroup component
|
||||
Component& ComponentBase::ChildAt(size_t i) {
|
||||
assert(i < ChildCount()); // NOLINT
|
||||
return children_[i];
|
||||
}
|
||||
|
||||
/// @brief Returns the number of children.
|
||||
/// @ingroup component
|
||||
size_t ComponentBase::ChildCount() const {
|
||||
return children_.size();
|
||||
}
|
||||
|
||||
/// @brief Return index of the component in its parent. -1 if no parent.
|
||||
/// @ingroup component
|
||||
int ComponentBase::Index() const {
|
||||
if (parent_ == nullptr) {
|
||||
return -1;
|
||||
@@ -71,7 +67,6 @@ int ComponentBase::Index() const {
|
||||
|
||||
/// @brief Add a child.
|
||||
/// @@param child The child to be attached.
|
||||
/// @ingroup component
|
||||
void ComponentBase::Add(Component child) {
|
||||
child->Detach();
|
||||
child->parent_ = this;
|
||||
@@ -81,7 +76,6 @@ void ComponentBase::Add(Component child) {
|
||||
/// @brief Detach this child from its parent.
|
||||
/// @see Detach
|
||||
/// @see Parent
|
||||
/// @ingroup component
|
||||
void ComponentBase::Detach() {
|
||||
if (parent_ == nullptr) {
|
||||
return;
|
||||
@@ -97,7 +91,6 @@ void ComponentBase::Detach() {
|
||||
}
|
||||
|
||||
/// @brief Remove all children.
|
||||
/// @ingroup component
|
||||
void ComponentBase::DetachAllChildren() {
|
||||
while (!children_.empty()) {
|
||||
children_[0]->Detach();
|
||||
@@ -107,7 +100,6 @@ void ComponentBase::DetachAllChildren() {
|
||||
/// @brief Draw the component.
|
||||
/// Build a ftxui::Element to be drawn on the ftxui::Screen representing this
|
||||
/// ftxui::ComponentBase. Please override OnRender() to modify the rendering.
|
||||
/// @ingroup component
|
||||
Element ComponentBase::Render() {
|
||||
// Some users might call `ComponentBase::Render()` from
|
||||
// `T::OnRender()`. To avoid infinite recursion, we use a flag.
|
||||
@@ -143,7 +135,6 @@ Element ComponentBase::Render() {
|
||||
/// @brief Draw the component.
|
||||
/// Build a ftxui::Element to be drawn on the ftxi::Screen representing this
|
||||
/// ftxui::ComponentBase. This function is means to be overridden.
|
||||
/// @ingroup component
|
||||
Element ComponentBase::OnRender() {
|
||||
if (children_.size() == 1) {
|
||||
return children_.front()->Render();
|
||||
@@ -157,7 +148,6 @@ Element ComponentBase::OnRender() {
|
||||
/// @return True when the event has been handled.
|
||||
/// The default implementation called OnEvent on every child until one return
|
||||
/// true. If none returns true, return false.
|
||||
/// @ingroup component
|
||||
bool ComponentBase::OnEvent(Event event) { // NOLINT
|
||||
for (Component& child : children_) { // NOLINT
|
||||
if (child->OnEvent(event)) {
|
||||
@@ -170,7 +160,6 @@ bool ComponentBase::OnEvent(Event event) { // NOLINT
|
||||
/// @brief Called in response to an animation event.
|
||||
/// @param params the parameters of the animation
|
||||
/// The default implementation dispatch the event to every child.
|
||||
/// @ingroup component
|
||||
void ComponentBase::OnAnimation(animation::Params& params) {
|
||||
for (const Component& child : children_) {
|
||||
child->OnAnimation(params);
|
||||
@@ -179,7 +168,6 @@ void ComponentBase::OnAnimation(animation::Params& params) {
|
||||
|
||||
/// @brief Return the currently Active child.
|
||||
/// @return the currently Active child.
|
||||
/// @ingroup component
|
||||
Component ComponentBase::ActiveChild() {
|
||||
for (auto& child : children_) {
|
||||
if (child->Focusable()) {
|
||||
@@ -192,7 +180,6 @@ Component ComponentBase::ActiveChild() {
|
||||
/// @brief Return true when the component contains focusable elements.
|
||||
/// The non focusable Components will be skipped when navigating using the
|
||||
/// keyboard.
|
||||
/// @ingroup component
|
||||
bool ComponentBase::Focusable() const {
|
||||
for (const Component& child : children_) { // NOLINT
|
||||
if (child->Focusable()) {
|
||||
@@ -203,7 +190,6 @@ bool ComponentBase::Focusable() const {
|
||||
}
|
||||
|
||||
/// @brief Returns if the element if the currently active child of its parent.
|
||||
/// @ingroup component
|
||||
bool ComponentBase::Active() const {
|
||||
return parent_ == nullptr || parent_->ActiveChild().get() == this;
|
||||
}
|
||||
@@ -212,7 +198,6 @@ bool ComponentBase::Active() const {
|
||||
/// 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
|
||||
/// Focusable().
|
||||
/// @ingroup component
|
||||
bool ComponentBase::Focused() const {
|
||||
const auto* current = this;
|
||||
while (current && current->Active()) {
|
||||
@@ -223,18 +208,15 @@ bool ComponentBase::Focused() const {
|
||||
|
||||
/// @brief Make the |child| to be the "active" one.
|
||||
/// @param child the child to become active.
|
||||
/// @ingroup component
|
||||
void ComponentBase::SetActiveChild([[maybe_unused]] ComponentBase* child) {}
|
||||
|
||||
/// @brief Make the |child| to be the "active" one.
|
||||
/// @param child the child to become active.
|
||||
/// @ingroup component
|
||||
void ComponentBase::SetActiveChild(Component child) { // NOLINT
|
||||
SetActiveChild(child.get());
|
||||
}
|
||||
|
||||
/// @brief Configure all the ancestors to give focus to this component.
|
||||
/// @ingroup component
|
||||
void ComponentBase::TakeFocus() {
|
||||
ComponentBase* child = this;
|
||||
while (ComponentBase* parent = child->parent_) {
|
||||
@@ -246,7 +228,6 @@ void ComponentBase::TakeFocus() {
|
||||
/// @brief Take the CapturedMouse if available. There is only one component of
|
||||
/// them. It represents a component taking priority over others.
|
||||
/// @param event The event
|
||||
/// @ingroup component
|
||||
CapturedMouse ComponentBase::CaptureMouse(const Event& event) { // NOLINT
|
||||
if (event.screen_) {
|
||||
return event.screen_->CaptureMouse();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
||||
#include <cassert>
|
||||
#include <ftxui/component/event.hpp>
|
||||
#include <vector>
|
||||
#include "ftxui/component/component.hpp"
|
||||
#include "ftxui/component/terminal_input_parser.hpp"
|
||||
@@ -22,8 +23,9 @@ bool GeneratorBool(const char*& data, size_t& size) {
|
||||
|
||||
std::string GeneratorString(const char*& data, size_t& size) {
|
||||
int index = 0;
|
||||
while (index < size && data[index])
|
||||
while (index < size && data[index]) {
|
||||
++index;
|
||||
}
|
||||
|
||||
auto out = std::string(data, data + index);
|
||||
data += index;
|
||||
@@ -39,8 +41,9 @@ std::string GeneratorString(const char*& data, size_t& size) {
|
||||
}
|
||||
|
||||
int GeneratorInt(const char* data, size_t size) {
|
||||
if (size == 0)
|
||||
if (size == 0) {
|
||||
return 0;
|
||||
}
|
||||
auto out = int(data[0]);
|
||||
data++;
|
||||
size--;
|
||||
@@ -112,8 +115,9 @@ Components GeneratorComponents(const char*& data, size_t& size, int depth);
|
||||
Component GeneratorComponent(const char*& data, size_t& size, int depth) {
|
||||
depth--;
|
||||
int value = GeneratorInt(data, size);
|
||||
if (depth <= 0)
|
||||
if (depth <= 0) {
|
||||
return Button(GeneratorString(data, size), [] {});
|
||||
}
|
||||
|
||||
constexpr int value_max = 19;
|
||||
value = (value % value_max + value_max) % value_max;
|
||||
@@ -212,16 +216,17 @@ extern "C" int LLVMFuzzerTestOneInput(const char* data, size_t size) {
|
||||
auto screen =
|
||||
Screen::Create(Dimension::Fixed(width), Dimension::Fixed(height));
|
||||
|
||||
auto event_receiver = MakeReceiver<Task>();
|
||||
{
|
||||
auto parser = TerminalInputParser(event_receiver->MakeSender());
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
parser.Add(data[i]);
|
||||
// Generate some events.
|
||||
std::vector<Event> events;
|
||||
auto parser =
|
||||
TerminalInputParser([&](const Event& event) { events.push_back(event); });
|
||||
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
parser.Add(data[i]);
|
||||
}
|
||||
|
||||
Task event;
|
||||
while (event_receiver->Receive(&event)) {
|
||||
component->OnEvent(std::get<Event>(event));
|
||||
for (const auto& event : events) {
|
||||
component->OnEvent(event);
|
||||
auto document = component->Render();
|
||||
Render(screen, document);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ namespace ftxui {
|
||||
/// @params _active The color when the component is active.
|
||||
/// @params _duration The duration of the animation.
|
||||
/// @params _function The easing function of the animation.
|
||||
/// @ingroup component
|
||||
void AnimatedColorOption::Set(Color _inactive,
|
||||
Color _active,
|
||||
animation::Duration _duration,
|
||||
@@ -32,7 +31,6 @@ void AnimatedColorOption::Set(Color _inactive,
|
||||
/// @brief Set how the underline should animate.
|
||||
/// @param d The duration of the animation.
|
||||
/// @param f The easing function of the animation.
|
||||
/// @ingroup component
|
||||
void UnderlineOption::SetAnimation(animation::Duration d,
|
||||
animation::easing::Function f) {
|
||||
SetAnimationDuration(d);
|
||||
@@ -41,7 +39,6 @@ void UnderlineOption::SetAnimation(animation::Duration d,
|
||||
|
||||
/// @brief Set how the underline should animate.
|
||||
/// @param d The duration of the animation.
|
||||
/// @ingroup component
|
||||
void UnderlineOption::SetAnimationDuration(animation::Duration d) {
|
||||
leader_duration = d;
|
||||
follower_duration = d;
|
||||
@@ -49,7 +46,6 @@ void UnderlineOption::SetAnimationDuration(animation::Duration d) {
|
||||
|
||||
/// @brief Set how the underline should animate.
|
||||
/// @param f The easing function of the animation.
|
||||
/// @ingroup component
|
||||
void UnderlineOption::SetAnimationFunction(animation::easing::Function f) {
|
||||
leader_function = f;
|
||||
follower_function = std::move(f);
|
||||
@@ -60,7 +56,6 @@ void UnderlineOption::SetAnimationFunction(animation::easing::Function f) {
|
||||
/// follower.
|
||||
/// @param f_leader The duration of the animation for the leader.
|
||||
/// @param f_follower The duration of the animation for the follower.
|
||||
/// @ingroup component
|
||||
void UnderlineOption::SetAnimationFunction(
|
||||
animation::easing::Function f_leader,
|
||||
animation::easing::Function f_follower) {
|
||||
@@ -70,7 +65,6 @@ void UnderlineOption::SetAnimationFunction(
|
||||
|
||||
/// @brief Standard options for a horizontal menu.
|
||||
/// This can be useful to implement a tab bar.
|
||||
/// @ingroup component
|
||||
// static
|
||||
MenuOption MenuOption::Horizontal() {
|
||||
MenuOption option;
|
||||
@@ -95,7 +89,6 @@ MenuOption MenuOption::Horizontal() {
|
||||
|
||||
/// @brief Standard options for an animated horizontal menu.
|
||||
/// This can be useful to implement a tab bar.
|
||||
/// @ingroup component
|
||||
// static
|
||||
MenuOption MenuOption::HorizontalAnimated() {
|
||||
auto option = Horizontal();
|
||||
@@ -105,7 +98,6 @@ MenuOption MenuOption::HorizontalAnimated() {
|
||||
|
||||
/// @brief Standard options for a vertical menu.
|
||||
/// This can be useful to implement a list of selectable items.
|
||||
/// @ingroup component
|
||||
// static
|
||||
MenuOption MenuOption::Vertical() {
|
||||
MenuOption option;
|
||||
@@ -127,7 +119,6 @@ MenuOption MenuOption::Vertical() {
|
||||
|
||||
/// @brief Standard options for an animated vertical menu.
|
||||
/// This can be useful to implement a list of selectable items.
|
||||
/// @ingroup component
|
||||
// static
|
||||
MenuOption MenuOption::VerticalAnimated() {
|
||||
auto option = MenuOption::Vertical();
|
||||
@@ -150,7 +141,6 @@ MenuOption MenuOption::VerticalAnimated() {
|
||||
|
||||
/// @brief Standard options for a horizontal menu with some separator.
|
||||
/// This can be useful to implement a tab bar.
|
||||
/// @ingroup component
|
||||
// static
|
||||
MenuOption MenuOption::Toggle() {
|
||||
auto option = MenuOption::Horizontal();
|
||||
@@ -159,7 +149,6 @@ MenuOption MenuOption::Toggle() {
|
||||
}
|
||||
|
||||
/// @brief Create a ButtonOption, highlighted using [] characters.
|
||||
/// @ingroup component
|
||||
// static
|
||||
ButtonOption ButtonOption::Ascii() {
|
||||
ButtonOption option;
|
||||
@@ -172,7 +161,6 @@ ButtonOption ButtonOption::Ascii() {
|
||||
}
|
||||
|
||||
/// @brief Create a ButtonOption, inverted when focused.
|
||||
/// @ingroup component
|
||||
// static
|
||||
ButtonOption ButtonOption::Simple() {
|
||||
ButtonOption option;
|
||||
@@ -188,7 +176,6 @@ ButtonOption ButtonOption::Simple() {
|
||||
|
||||
/// @brief Create a ButtonOption. The button is shown using a border, inverted
|
||||
/// when focused. This is the current default.
|
||||
/// @ingroup component
|
||||
ButtonOption ButtonOption::Border() {
|
||||
ButtonOption option;
|
||||
option.transform = [](const EntryState& s) {
|
||||
@@ -205,7 +192,6 @@ ButtonOption ButtonOption::Border() {
|
||||
}
|
||||
|
||||
/// @brief Create a ButtonOption, using animated colors.
|
||||
/// @ingroup component
|
||||
// static
|
||||
ButtonOption ButtonOption::Animated() {
|
||||
return Animated(Color::Black, Color::GrayLight, //
|
||||
@@ -213,7 +199,6 @@ ButtonOption ButtonOption::Animated() {
|
||||
}
|
||||
|
||||
/// @brief Create a ButtonOption, using animated colors.
|
||||
/// @ingroup component
|
||||
// static
|
||||
ButtonOption ButtonOption::Animated(Color color) {
|
||||
return ButtonOption::Animated(
|
||||
@@ -224,7 +209,6 @@ ButtonOption ButtonOption::Animated(Color color) {
|
||||
}
|
||||
|
||||
/// @brief Create a ButtonOption, using animated colors.
|
||||
/// @ingroup component
|
||||
// static
|
||||
ButtonOption ButtonOption::Animated(Color background, Color foreground) {
|
||||
// NOLINTBEGIN
|
||||
@@ -237,7 +221,6 @@ ButtonOption ButtonOption::Animated(Color background, Color foreground) {
|
||||
}
|
||||
|
||||
/// @brief Create a ButtonOption, using animated colors.
|
||||
/// @ingroup component
|
||||
// static
|
||||
ButtonOption ButtonOption::Animated(Color background,
|
||||
Color foreground,
|
||||
@@ -257,7 +240,6 @@ ButtonOption ButtonOption::Animated(Color background,
|
||||
}
|
||||
|
||||
/// @brief Option for standard Checkbox.
|
||||
/// @ingroup component
|
||||
// static
|
||||
CheckboxOption CheckboxOption::Simple() {
|
||||
auto option = CheckboxOption();
|
||||
@@ -282,7 +264,6 @@ CheckboxOption CheckboxOption::Simple() {
|
||||
}
|
||||
|
||||
/// @brief Option for standard Radiobox
|
||||
/// @ingroup component
|
||||
// static
|
||||
RadioboxOption RadioboxOption::Simple() {
|
||||
auto option = RadioboxOption();
|
||||
@@ -307,7 +288,6 @@ RadioboxOption RadioboxOption::Simple() {
|
||||
}
|
||||
|
||||
/// @brief Standard options for the input component.
|
||||
/// @ingroup component
|
||||
// static
|
||||
InputOption InputOption::Default() {
|
||||
InputOption option;
|
||||
@@ -330,7 +310,6 @@ InputOption InputOption::Default() {
|
||||
}
|
||||
|
||||
/// @brief Standard options for a more beautiful input component.
|
||||
/// @ingroup component
|
||||
// static
|
||||
InputOption InputOption::Spacious() {
|
||||
InputOption option;
|
||||
|
||||
@@ -24,7 +24,6 @@ namespace ftxui {
|
||||
|
||||
/// @brief An event corresponding to a given typed character.
|
||||
/// @param input The character typed by the user.
|
||||
/// @ingroup component
|
||||
// static
|
||||
Event Event::Character(std::string input) {
|
||||
Event event;
|
||||
@@ -35,7 +34,6 @@ Event Event::Character(std::string input) {
|
||||
|
||||
/// @brief An event corresponding to a given typed character.
|
||||
/// @param c The character typed by the user.
|
||||
/// @ingroup component
|
||||
// static
|
||||
Event Event::Character(char c) {
|
||||
return Event::Character(std::string{c});
|
||||
@@ -43,7 +41,6 @@ Event Event::Character(char c) {
|
||||
|
||||
/// @brief An event corresponding to a given typed character.
|
||||
/// @param c The character typed by the user.
|
||||
/// @ingroup component
|
||||
// static
|
||||
Event Event::Character(wchar_t c) {
|
||||
return Event::Character(to_string(std::wstring{c}));
|
||||
@@ -52,7 +49,6 @@ Event Event::Character(wchar_t c) {
|
||||
/// @brief An event corresponding to a given typed character.
|
||||
/// @param input The sequence of character send by the terminal.
|
||||
/// @param mouse The mouse state.
|
||||
/// @ingroup component
|
||||
// static
|
||||
Event Event::Mouse(std::string input, struct Mouse mouse) {
|
||||
Event event;
|
||||
@@ -74,7 +70,6 @@ Event Event::CursorShape(std::string input, int shape) {
|
||||
|
||||
/// @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.
|
||||
/// @ingroup component
|
||||
// static
|
||||
Event Event::Special(std::string input) {
|
||||
Event event;
|
||||
|
||||
@@ -11,7 +11,6 @@ namespace ftxui {
|
||||
|
||||
/// @brief A Loop is a wrapper around a Component and a ScreenInteractive.
|
||||
/// It is used to run a Component in a terminal.
|
||||
/// @ingroup component
|
||||
/// @see Component, ScreenInteractive.
|
||||
/// @see ScreenInteractive::Loop().
|
||||
/// @see ScreenInteractive::ExitLoop().
|
||||
@@ -28,7 +27,6 @@ Loop::~Loop() {
|
||||
}
|
||||
|
||||
/// @brief Whether the loop has quitted.
|
||||
/// @ingroup component
|
||||
bool Loop::HasQuitted() {
|
||||
return screen_->HasQuitted();
|
||||
}
|
||||
|
||||
@@ -12,9 +12,15 @@ export module ftxui.component.receiver;
|
||||
* @brief The FTXUI ftxui:: namespace
|
||||
*/
|
||||
export namespace ftxui {
|
||||
// Deprecated:
|
||||
using ftxui::SenderImpl;
|
||||
// Deprecated:
|
||||
using ftxui::ReceiverImpl;
|
||||
// Deprecated:
|
||||
using ftxui::Sender;
|
||||
// Deprecated:
|
||||
using ftxui::Receiver;
|
||||
// Deprecated:
|
||||
using ftxui::MakeReceiver;
|
||||
// Deprecated:
|
||||
}
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
// 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,24 +17,22 @@
|
||||
#include <memory>
|
||||
#include <stack> // for stack
|
||||
#include <string>
|
||||
#include <thread> // for thread, sleep_for
|
||||
#include <tuple> // for _Swallow_assign, ignore
|
||||
#include <type_traits> // for decay_t
|
||||
#include <utility> // for move, swap
|
||||
#include <variant> // for visit, variant
|
||||
#include <vector> // for vector
|
||||
#include <thread> // for thread, sleep_for
|
||||
#include <tuple> // for _Swallow_assign, ignore
|
||||
#include <utility> // for move, swap
|
||||
#include <variant> // for visit, variant
|
||||
#include <vector> // for vector
|
||||
#include "ftxui/component/animation.hpp" // for TimePoint, Clock, Duration, Params, RequestAnimationFrame
|
||||
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse, CapturedMouseInterface
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/event.hpp" // for Event
|
||||
#include "ftxui/component/loop.hpp" // for Loop
|
||||
#include "ftxui/component/receiver.hpp" // for ReceiverImpl, Sender, MakeReceiver, SenderImpl, Receiver
|
||||
#include "ftxui/component/task_runner.hpp"
|
||||
#include "ftxui/component/terminal_input_parser.hpp" // for TerminalInputParser
|
||||
#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/util.hpp" // for util::clamp
|
||||
#include "ftxui/util/autoreset.hpp" // for AutoReset
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define DEFINE_CONSOLEV2_PROPERTIES
|
||||
@@ -47,9 +45,11 @@
|
||||
#error Must be compiled in UNICODE mode
|
||||
#endif
|
||||
#else
|
||||
#include <fcntl.h>
|
||||
#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 <unistd.h> // for STDIN_FILENO, read
|
||||
#include <cerrno>
|
||||
#endif
|
||||
|
||||
// Quick exit is missing in standard CLang headers
|
||||
@@ -59,6 +59,20 @@
|
||||
|
||||
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 {
|
||||
void RequestAnimationFrame() {
|
||||
auto* screen = ScreenInteractive::Active();
|
||||
@@ -82,73 +96,9 @@ constexpr int timeout_milliseconds = 20;
|
||||
timeout_milliseconds * 1000;
|
||||
#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__)
|
||||
#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" {
|
||||
EMSCRIPTEN_KEEPALIVE
|
||||
void ftxui_on_resize(int columns, int rows) {
|
||||
@@ -162,8 +112,8 @@ void ftxui_on_resize(int columns, int rows) {
|
||||
|
||||
#else // POSIX (Linux & Mac)
|
||||
|
||||
int CheckStdinReady(int usec_timeout) {
|
||||
timeval tv = {0, usec_timeout}; // NOLINT
|
||||
int CheckStdinReady() {
|
||||
timeval tv = {0, 0}; // NOLINT
|
||||
fd_set fds;
|
||||
FD_ZERO(&fds); // NOLINT
|
||||
FD_SET(STDIN_FILENO, &fds); // NOLINT
|
||||
@@ -171,24 +121,6 @@ int CheckStdinReady(int usec_timeout) {
|
||||
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
|
||||
|
||||
std::stack<Closure> on_exit_functions; // NOLINT
|
||||
@@ -335,38 +267,29 @@ class CapturedMouseImpl : public CapturedMouseInterface {
|
||||
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
|
||||
|
||||
ScreenInteractive::ScreenInteractive(int dimx,
|
||||
ScreenInteractive::ScreenInteractive(Dimension dimension,
|
||||
int dimx,
|
||||
int dimy,
|
||||
Dimension dimension,
|
||||
bool use_alternative_screen)
|
||||
: Screen(dimx, dimy),
|
||||
dimension_(dimension),
|
||||
use_alternative_screen_(use_alternative_screen) {
|
||||
task_receiver_ = MakeReceiver<Task>();
|
||||
internal_ = std::make_unique<Internal>(
|
||||
[&](Event event) { PostEvent(std::move(event)); });
|
||||
}
|
||||
|
||||
// static
|
||||
ScreenInteractive ScreenInteractive::FixedSize(int dimx, int dimy) {
|
||||
return {
|
||||
Dimension::Fixed,
|
||||
dimx,
|
||||
dimy,
|
||||
Dimension::Fixed,
|
||||
false,
|
||||
/*use_alternative_screen=*/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.
|
||||
/// @note This is the same as `ScreenInteractive::FullscreenAlternateScreen()`
|
||||
@@ -375,54 +298,61 @@ ScreenInteractive ScreenInteractive::Fullscreen() {
|
||||
return FullscreenAlternateScreen();
|
||||
}
|
||||
|
||||
/// @ingroup component
|
||||
/// Create a ScreenInteractive taking the full terminal size. The primary screen
|
||||
/// buffer is being used. It means if the terminal is resized, the previous
|
||||
/// content might mess up with the terminal content.
|
||||
// static
|
||||
ScreenInteractive ScreenInteractive::FullscreenPrimaryScreen() {
|
||||
auto terminal = Terminal::Size();
|
||||
return {
|
||||
0,
|
||||
0,
|
||||
Dimension::Fullscreen,
|
||||
false,
|
||||
terminal.dimx,
|
||||
terminal.dimy,
|
||||
/*use_alternative_screen=*/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() {
|
||||
auto terminal = Terminal::Size();
|
||||
return {
|
||||
0,
|
||||
0,
|
||||
Dimension::Fullscreen,
|
||||
true,
|
||||
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 {
|
||||
0,
|
||||
0,
|
||||
Dimension::TerminalOutput,
|
||||
false,
|
||||
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 {
|
||||
0,
|
||||
0,
|
||||
Dimension::FitComponent,
|
||||
terminal.dimx, // Best guess.
|
||||
terminal.dimy, // Best guess.
|
||||
false,
|
||||
};
|
||||
}
|
||||
|
||||
/// @ingroup component
|
||||
/// @brief Set whether mouse is tracked and events reported.
|
||||
/// called outside of the main loop. E.g `ScreenInteractive::Loop(...)`.
|
||||
/// @param enable Whether to enable mouse event tracking.
|
||||
@@ -444,20 +374,14 @@ void ScreenInteractive::TrackMouse(bool enable) {
|
||||
|
||||
/// @brief Add a task to the main loop.
|
||||
/// It will be executed later, after every other scheduled tasks.
|
||||
/// @ingroup component
|
||||
void ScreenInteractive::Post(Task task) {
|
||||
// Task/Events sent toward inactive screen or screen waiting to become
|
||||
// inactive are dropped.
|
||||
if (!task_sender_) {
|
||||
return;
|
||||
}
|
||||
|
||||
task_sender_->Send(std::move(task));
|
||||
internal_->task_runner.PostTask([this, task = std::move(task)]() mutable {
|
||||
HandleTask(component_, task);
|
||||
});
|
||||
}
|
||||
|
||||
/// @brief Add an event to the main loop.
|
||||
/// It will be executed later, after every other scheduled events.
|
||||
/// @ingroup component
|
||||
void ScreenInteractive::PostEvent(Event event) {
|
||||
Post(event);
|
||||
}
|
||||
@@ -479,7 +403,6 @@ void ScreenInteractive::RequestAnimationFrame() {
|
||||
/// @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
|
||||
/// null.
|
||||
/// @ingroup component
|
||||
CapturedMouse ScreenInteractive::CaptureMouse() {
|
||||
if (mouse_captured) {
|
||||
return nullptr;
|
||||
@@ -491,16 +414,14 @@ CapturedMouse ScreenInteractive::CaptureMouse() {
|
||||
|
||||
/// @brief Execute the main loop.
|
||||
/// @param component The component to draw.
|
||||
/// @ingroup component
|
||||
void ScreenInteractive::Loop(Component component) { // NOLINT
|
||||
class Loop loop(this, std::move(component));
|
||||
loop.Run();
|
||||
}
|
||||
|
||||
/// @brief Return whether the main loop has been quit.
|
||||
/// @ingroup component
|
||||
bool ScreenInteractive::HasQuitted() {
|
||||
return task_receiver_->HasQuitted();
|
||||
return quit_;
|
||||
}
|
||||
|
||||
// private
|
||||
@@ -657,7 +578,15 @@ void ScreenInteractive::Install() {
|
||||
|
||||
SetConsoleMode(stdin_handle, in_mode);
|
||||
SetConsoleMode(stdout_handle, out_mode);
|
||||
#else
|
||||
#else // POSIX (Linux & Mac)
|
||||
// #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}) {
|
||||
InstallSignalHandler(signal);
|
||||
}
|
||||
@@ -730,40 +659,57 @@ void ScreenInteractive::Install() {
|
||||
Flush();
|
||||
|
||||
quit_ = false;
|
||||
task_sender_ = task_receiver_->MakeSender();
|
||||
event_listener_ =
|
||||
std::thread(&EventListener, &quit_, task_receiver_->MakeSender());
|
||||
animation_listener_ =
|
||||
std::thread(&AnimationListener, &quit_, task_receiver_->MakeSender());
|
||||
|
||||
PostAnimationTask();
|
||||
}
|
||||
|
||||
// private
|
||||
void ScreenInteractive::Uninstall() {
|
||||
ExitNow();
|
||||
event_listener_.join();
|
||||
animation_listener_.join();
|
||||
OnExit();
|
||||
}
|
||||
|
||||
// private
|
||||
// NOLINTNEXTLINE
|
||||
void ScreenInteractive::RunOnceBlocking(Component component) {
|
||||
ExecuteSignalHandlers();
|
||||
Task task;
|
||||
if (task_receiver_->Receive(&task)) {
|
||||
HandleTask(component, task);
|
||||
// Set FPS to 60 at most.
|
||||
const auto time_per_frame = std::chrono::microseconds(16666); // 1s / 60fps
|
||||
|
||||
auto time = std::chrono::steady_clock::now();
|
||||
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
|
||||
void ScreenInteractive::RunOnce(Component component) {
|
||||
Task task;
|
||||
while (task_receiver_->ReceiveNonBlocking(&task)) {
|
||||
HandleTask(component, task);
|
||||
ExecuteSignalHandlers();
|
||||
AutoReset set_component(&component_, component);
|
||||
ExecuteSignalHandlers();
|
||||
FetchTerminalEvents();
|
||||
|
||||
// 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_) {
|
||||
selection_data_previous_ = selection_data_;
|
||||
@@ -784,6 +730,7 @@ void ScreenInteractive::HandleTask(Component component, Task& task) {
|
||||
// clang-format off
|
||||
// Handle Event.
|
||||
if constexpr (std::is_same_v<T, Event>) {
|
||||
|
||||
if (arg.is_cursor_position()) {
|
||||
cursor_x_ = arg.cursor_x();
|
||||
cursor_y_ = arg.cursor_y();
|
||||
@@ -930,7 +877,7 @@ void ScreenInteractive::Draw(Component component) {
|
||||
break;
|
||||
}
|
||||
|
||||
const bool resized = (dimx != dimx_) || (dimy != dimy_);
|
||||
const bool resized = frame_count_ == 0 || (dimx != dimx_) || (dimy != dimy_);
|
||||
ResetCursorPosition();
|
||||
std::cout << ResetPosition(/*clear=*/resized);
|
||||
|
||||
@@ -1013,6 +960,7 @@ void ScreenInteractive::Draw(Component component) {
|
||||
Flush();
|
||||
Clear();
|
||||
frame_valid_ = true;
|
||||
frame_count_++;
|
||||
}
|
||||
|
||||
// private
|
||||
@@ -1022,13 +970,11 @@ void ScreenInteractive::ResetCursorPosition() {
|
||||
}
|
||||
|
||||
/// @brief Return a function to exit the main loop.
|
||||
/// @ingroup component
|
||||
Closure ScreenInteractive::ExitLoopClosure() {
|
||||
return [this] { Exit(); };
|
||||
}
|
||||
|
||||
/// @brief Exit the main loop.
|
||||
/// @ingroup component
|
||||
void ScreenInteractive::Exit() {
|
||||
Post([this] { ExitNow(); });
|
||||
}
|
||||
@@ -1036,7 +982,6 @@ void ScreenInteractive::Exit() {
|
||||
// private:
|
||||
void ScreenInteractive::ExitNow() {
|
||||
quit_ = true;
|
||||
task_sender_.reset();
|
||||
}
|
||||
|
||||
// private:
|
||||
@@ -1069,6 +1014,118 @@ void ScreenInteractive::Signal(int signal) {
|
||||
#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==(
|
||||
const ScreenInteractive::SelectionData& other) const {
|
||||
if (empty && other.empty) {
|
||||
|
||||
@@ -10,9 +10,58 @@
|
||||
#include "ftxui/component/screen_interactive.hpp"
|
||||
#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 {
|
||||
#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) {
|
||||
int called = 0;
|
||||
// The tree of components. This defines how to navigate using the keyboard.
|
||||
@@ -131,4 +180,66 @@ TEST(ScreenInteractive, CtrlC_NotForced) {
|
||||
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
|
||||
|
||||
@@ -33,6 +33,20 @@ Decorator flexDirection(Direction direction) {
|
||||
return xflex; // NOT_REACHED()
|
||||
}
|
||||
|
||||
Direction Opposite(Direction d) {
|
||||
switch (d) {
|
||||
case Direction::Up:
|
||||
return Direction::Down;
|
||||
case Direction::Down:
|
||||
return Direction::Up;
|
||||
case Direction::Left:
|
||||
return Direction::Right;
|
||||
case Direction::Right:
|
||||
return Direction::Left;
|
||||
}
|
||||
return d; // NOT_REACHED()
|
||||
}
|
||||
|
||||
template <class T>
|
||||
class SliderBase : public SliderOption<T>, public ComponentBase {
|
||||
public:
|
||||
@@ -47,59 +61,15 @@ class SliderBase : public SliderOption<T>, public ComponentBase {
|
||||
flexDirection(this->direction) | reflect(gauge_box_) | gauge_color;
|
||||
}
|
||||
|
||||
void OnLeft() {
|
||||
switch (this->direction) {
|
||||
case Direction::Right:
|
||||
this->value() -= this->increment();
|
||||
break;
|
||||
case Direction::Left:
|
||||
this->value() += this->increment();
|
||||
break;
|
||||
case Direction::Up:
|
||||
case Direction::Down:
|
||||
break;
|
||||
void OnDirection(Direction pressed) {
|
||||
if (pressed == this->direction) {
|
||||
this->value() += this->increment();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void OnRight() {
|
||||
switch (this->direction) {
|
||||
case Direction::Right:
|
||||
this->value() += this->increment();
|
||||
break;
|
||||
case Direction::Left:
|
||||
this->value() -= this->increment();
|
||||
break;
|
||||
case Direction::Up:
|
||||
case Direction::Down:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OnUp() {
|
||||
switch (this->direction) {
|
||||
case Direction::Up:
|
||||
this->value() -= this->increment();
|
||||
break;
|
||||
case Direction::Down:
|
||||
this->value() += this->increment();
|
||||
break;
|
||||
case Direction::Left:
|
||||
case Direction::Right:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OnDown() {
|
||||
switch (this->direction) {
|
||||
case Direction::Down:
|
||||
this->value() += this->increment();
|
||||
break;
|
||||
case Direction::Up:
|
||||
this->value() -= this->increment();
|
||||
break;
|
||||
case Direction::Left:
|
||||
case Direction::Right:
|
||||
break;
|
||||
if (pressed == Opposite(this->direction)) {
|
||||
this->value() -= this->increment();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,16 +80,16 @@ class SliderBase : public SliderOption<T>, public ComponentBase {
|
||||
|
||||
T old_value = this->value();
|
||||
if (event == Event::ArrowLeft || event == Event::Character('h')) {
|
||||
OnLeft();
|
||||
OnDirection(Direction::Left);
|
||||
}
|
||||
if (event == Event::ArrowRight || event == Event::Character('l')) {
|
||||
OnRight();
|
||||
OnDirection(Direction::Right);
|
||||
}
|
||||
if (event == Event::ArrowUp || event == Event::Character('k')) {
|
||||
OnDown();
|
||||
OnDirection(Direction::Up);
|
||||
}
|
||||
if (event == Event::ArrowDown || event == Event::Character('j')) {
|
||||
OnUp();
|
||||
OnDirection(Direction::Down);
|
||||
}
|
||||
|
||||
this->value() = std::max(this->min(), std::min(this->max(), this->value()));
|
||||
|
||||
19
src/ftxui/component/task.cpp
Normal file
19
src/ftxui/component/task.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
// 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
|
||||
40
src/ftxui/component/task_internal.hpp
Normal file
40
src/ftxui/component/task_internal.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
// 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_
|
||||
53
src/ftxui/component/task_queue.cpp
Normal file
53
src/ftxui/component/task_queue.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
// 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
|
||||
37
src/ftxui/component/task_queue.hpp
Normal file
37
src/ftxui/component/task_queue.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
// 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
|
||||
75
src/ftxui/component/task_runner.cpp
Normal file
75
src/ftxui/component/task_runner.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
// 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
|
||||
46
src/ftxui/component/task_runner.hpp
Normal file
46
src/ftxui/component/task_runner.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
// 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
|
||||
94
src/ftxui/component/task_test.cpp
Normal file
94
src/ftxui/component/task_test.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
// 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 <ftxui/component/mouse.hpp> // for Mouse, Mouse::Button, Mouse::Motion
|
||||
#include <ftxui/component/receiver.hpp> // for SenderImpl, Sender
|
||||
#include <functional> // for std::function
|
||||
#include <map>
|
||||
#include <memory> // for unique_ptr, allocator
|
||||
#include <utility> // for move
|
||||
@@ -90,7 +90,7 @@ const std::map<std::string, std::string> g_uniformize = {
|
||||
{"\x1B[X", "\x1B[24~"}, // F12
|
||||
};
|
||||
|
||||
TerminalInputParser::TerminalInputParser(Sender<Task> out)
|
||||
TerminalInputParser::TerminalInputParser(std::function<void(Event)> out)
|
||||
: out_(std::move(out)) {}
|
||||
|
||||
void TerminalInputParser::Timeout(int time) {
|
||||
@@ -131,7 +131,7 @@ void TerminalInputParser::Send(TerminalInputParser::Output output) {
|
||||
return;
|
||||
|
||||
case CHARACTER:
|
||||
out_->Send(Event::Character(std::move(pending_)));
|
||||
out_(Event::Character(std::move(pending_)));
|
||||
pending_.clear();
|
||||
return;
|
||||
|
||||
@@ -140,25 +140,25 @@ void TerminalInputParser::Send(TerminalInputParser::Output output) {
|
||||
if (it != g_uniformize.end()) {
|
||||
pending_ = it->second;
|
||||
}
|
||||
out_->Send(Event::Special(std::move(pending_)));
|
||||
out_(Event::Special(std::move(pending_)));
|
||||
pending_.clear();
|
||||
}
|
||||
return;
|
||||
|
||||
case MOUSE:
|
||||
out_->Send(Event::Mouse(std::move(pending_), output.mouse)); // NOLINT
|
||||
out_(Event::Mouse(std::move(pending_), output.mouse)); // NOLINT
|
||||
pending_.clear();
|
||||
return;
|
||||
|
||||
case CURSOR_POSITION:
|
||||
out_->Send(Event::CursorPosition(std::move(pending_), // NOLINT
|
||||
output.cursor.x, // NOLINT
|
||||
output.cursor.y)); // NOLINT
|
||||
out_(Event::CursorPosition(std::move(pending_), // NOLINT
|
||||
output.cursor.x, // NOLINT
|
||||
output.cursor.y)); // NOLINT
|
||||
pending_.clear();
|
||||
return;
|
||||
|
||||
case CURSOR_SHAPE:
|
||||
out_->Send(Event::CursorShape(std::move(pending_), output.cursor_shape));
|
||||
out_(Event::CursorShape(std::move(pending_), output.cursor_shape));
|
||||
pending_.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
#ifndef FTXUI_COMPONENT_TERMINAL_INPUT_PARSER
|
||||
#define FTXUI_COMPONENT_TERMINAL_INPUT_PARSER
|
||||
|
||||
#include <functional>
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/mouse.hpp" // for Mouse
|
||||
#include "ftxui/component/receiver.hpp" // for Sender
|
||||
#include "ftxui/component/task.hpp" // for Task
|
||||
#include "ftxui/component/mouse.hpp" // for Mouse
|
||||
|
||||
namespace ftxui {
|
||||
struct Event;
|
||||
@@ -17,7 +16,7 @@ struct Event;
|
||||
// Parse a sequence of |char| accross |time|. Produces |Event|.
|
||||
class TerminalInputParser {
|
||||
public:
|
||||
explicit TerminalInputParser(Sender<Task> out);
|
||||
explicit TerminalInputParser(std::function<void(Event)> out);
|
||||
void Timeout(int time);
|
||||
void Add(char c);
|
||||
|
||||
@@ -62,7 +61,7 @@ class TerminalInputParser {
|
||||
Output ParseMouse(bool altered, bool pressed, std::vector<int> arguments);
|
||||
Output ParseCursorPosition(std::vector<int> arguments);
|
||||
|
||||
Sender<Task> out_;
|
||||
std::function<void(Event)> out_;
|
||||
int position_ = -1;
|
||||
int timeout_ = 0;
|
||||
std::string pending_;
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
||||
#include <ftxui/component/mouse.hpp> // for Mouse, Mouse::Left, Mouse::Middle, Mouse::Pressed, Mouse::Released, Mouse::Right
|
||||
#include <ftxui/component/task.hpp> // for Task
|
||||
#include <functional> // for function
|
||||
#include <initializer_list> // for initializer_list
|
||||
#include <memory> // for allocator, unique_ptr
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/component/event.hpp" // for Event, Event::Return, Event::ArrowDown, Event::ArrowLeft, Event::ArrowRight, Event::ArrowUp, Event::Backspace, Event::End, Event::Home, Event::Custom, Event::Delete, Event::F1, Event::F10, Event::F11, Event::F12, Event::F2, Event::F3, Event::F4, Event::F5, Event::F6, Event::F7, Event::F8, Event::F9, Event::PageDown, Event::PageUp, Event::Tab, Event::TabReverse, Event::Escape
|
||||
#include "ftxui/component/receiver.hpp" // for MakeReceiver, ReceiverImpl
|
||||
#include "ftxui/component/terminal_input_parser.hpp"
|
||||
#include "gtest/gtest.h" // for AssertionResult, Test, Message, TestPartResult, EXPECT_EQ, EXPECT_TRUE, TEST, EXPECT_FALSE
|
||||
|
||||
@@ -17,233 +17,205 @@ namespace ftxui {
|
||||
// Test char |c| to are trivially converted into |Event::Character(c)|.
|
||||
TEST(Event, Character) {
|
||||
std::vector<char> basic_char;
|
||||
for (char c = 'a'; c <= 'z'; ++c)
|
||||
for (char c = 'a'; c <= 'z'; ++c) {
|
||||
basic_char.push_back(c);
|
||||
for (char c = 'A'; c <= 'Z'; ++c)
|
||||
}
|
||||
for (char c = 'A'; c <= 'Z'; ++c) {
|
||||
basic_char.push_back(c);
|
||||
|
||||
auto event_receiver = MakeReceiver<Task>();
|
||||
{
|
||||
auto parser = TerminalInputParser(event_receiver->MakeSender());
|
||||
for (char c : basic_char)
|
||||
parser.Add(c);
|
||||
}
|
||||
|
||||
Task received;
|
||||
std::vector<Event> received_events;
|
||||
auto parser = TerminalInputParser(
|
||||
[&](Event event) { received_events.push_back(std::move(event)); });
|
||||
for (char c : basic_char) {
|
||||
EXPECT_TRUE(event_receiver->Receive(&received));
|
||||
EXPECT_TRUE(std::get<Event>(received).is_character());
|
||||
EXPECT_EQ(c, std::get<Event>(received).character()[0]);
|
||||
parser.Add(c);
|
||||
}
|
||||
EXPECT_FALSE(event_receiver->Receive(&received));
|
||||
|
||||
for (size_t i = 0; i < basic_char.size(); ++i) {
|
||||
EXPECT_TRUE(received_events[i].is_character());
|
||||
EXPECT_EQ(basic_char[i], received_events[i].character()[0]);
|
||||
}
|
||||
EXPECT_EQ(received_events.size(), basic_char.size());
|
||||
}
|
||||
|
||||
TEST(Event, EscapeKeyWithoutWaiting) {
|
||||
auto event_receiver = MakeReceiver<Task>();
|
||||
{
|
||||
auto parser = TerminalInputParser(event_receiver->MakeSender());
|
||||
parser.Add('\x1B');
|
||||
}
|
||||
std::vector<Event> received_events;
|
||||
auto parser = TerminalInputParser(
|
||||
[&](Event event) { received_events.push_back(std::move(event)); });
|
||||
parser.Add('');
|
||||
|
||||
Task received;
|
||||
EXPECT_FALSE(event_receiver->Receive(&received));
|
||||
EXPECT_TRUE(received_events.empty());
|
||||
}
|
||||
|
||||
TEST(Event, EscapeKeyNotEnoughWait) {
|
||||
auto event_receiver = MakeReceiver<Task>();
|
||||
{
|
||||
auto parser = TerminalInputParser(event_receiver->MakeSender());
|
||||
parser.Add('\x1B');
|
||||
parser.Timeout(49);
|
||||
}
|
||||
std::vector<Event> received_events;
|
||||
auto parser = TerminalInputParser(
|
||||
[&](Event event) { received_events.push_back(std::move(event)); });
|
||||
parser.Add('');
|
||||
parser.Timeout(49);
|
||||
|
||||
Task received;
|
||||
EXPECT_FALSE(event_receiver->Receive(&received));
|
||||
EXPECT_TRUE(received_events.empty());
|
||||
}
|
||||
|
||||
TEST(Event, EscapeKeyEnoughWait) {
|
||||
auto event_receiver = MakeReceiver<Task>();
|
||||
{
|
||||
auto parser = TerminalInputParser(event_receiver->MakeSender());
|
||||
parser.Add('\x1B');
|
||||
parser.Timeout(50);
|
||||
}
|
||||
std::vector<Event> received_events;
|
||||
auto parser = TerminalInputParser(
|
||||
[&](Event event) { received_events.push_back(std::move(event)); });
|
||||
parser.Add('');
|
||||
parser.Timeout(50);
|
||||
|
||||
Task received;
|
||||
EXPECT_TRUE(event_receiver->Receive(&received));
|
||||
EXPECT_EQ(std::get<Event>(received), Event::Escape);
|
||||
EXPECT_FALSE(event_receiver->Receive(&received));
|
||||
EXPECT_EQ(1, received_events.size());
|
||||
EXPECT_EQ(received_events[0], Event::Escape);
|
||||
}
|
||||
|
||||
TEST(Event, EscapeFast) {
|
||||
auto event_receiver = MakeReceiver<Task>();
|
||||
{
|
||||
auto parser = TerminalInputParser(event_receiver->MakeSender());
|
||||
parser.Add('\x1B');
|
||||
parser.Add('a');
|
||||
parser.Add('\x1B');
|
||||
parser.Add('b');
|
||||
parser.Timeout(49);
|
||||
}
|
||||
Task received;
|
||||
EXPECT_TRUE(event_receiver->Receive(&received));
|
||||
EXPECT_EQ(std::get<Event>(received), Event::AltA);
|
||||
EXPECT_TRUE(event_receiver->Receive(&received));
|
||||
EXPECT_EQ(std::get<Event>(received), Event::AltB);
|
||||
EXPECT_FALSE(event_receiver->Receive(&received));
|
||||
std::vector<Event> received_events;
|
||||
auto parser = TerminalInputParser(
|
||||
[&](Event event) { received_events.push_back(std::move(event)); });
|
||||
parser.Add('');
|
||||
parser.Add('a');
|
||||
parser.Add('');
|
||||
parser.Add('b');
|
||||
parser.Timeout(49);
|
||||
|
||||
EXPECT_EQ(2, received_events.size());
|
||||
EXPECT_EQ(received_events[0], Event::AltA);
|
||||
EXPECT_EQ(received_events[1], Event::AltB);
|
||||
}
|
||||
|
||||
TEST(Event, MouseLeftClickPressed) {
|
||||
auto event_receiver = MakeReceiver<Task>();
|
||||
{
|
||||
auto parser = TerminalInputParser(event_receiver->MakeSender());
|
||||
parser.Add('\x1B');
|
||||
parser.Add('[');
|
||||
parser.Add('0');
|
||||
parser.Add(';');
|
||||
parser.Add('1');
|
||||
parser.Add('2');
|
||||
parser.Add(';');
|
||||
parser.Add('4');
|
||||
parser.Add('2');
|
||||
parser.Add('M');
|
||||
}
|
||||
std::vector<Event> received_events;
|
||||
auto parser = TerminalInputParser(
|
||||
[&](Event event) { received_events.push_back(std::move(event)); });
|
||||
parser.Add('');
|
||||
parser.Add('[');
|
||||
parser.Add('0');
|
||||
parser.Add(';');
|
||||
parser.Add('1');
|
||||
parser.Add('2');
|
||||
parser.Add(';');
|
||||
parser.Add('4');
|
||||
parser.Add('2');
|
||||
parser.Add('M');
|
||||
|
||||
Task received;
|
||||
EXPECT_TRUE(event_receiver->Receive(&received));
|
||||
EXPECT_TRUE(std::get<Event>(received).is_mouse());
|
||||
EXPECT_EQ(Mouse::Left, std::get<Event>(received).mouse().button);
|
||||
EXPECT_EQ(12, std::get<Event>(received).mouse().x);
|
||||
EXPECT_EQ(42, std::get<Event>(received).mouse().y);
|
||||
EXPECT_EQ(std::get<Event>(received).mouse().motion, Mouse::Pressed);
|
||||
EXPECT_FALSE(event_receiver->Receive(&received));
|
||||
EXPECT_EQ(1, received_events.size());
|
||||
EXPECT_TRUE(received_events[0].is_mouse());
|
||||
EXPECT_EQ(Mouse::Left, received_events[0].mouse().button);
|
||||
EXPECT_EQ(12, received_events[0].mouse().x);
|
||||
EXPECT_EQ(42, received_events[0].mouse().y);
|
||||
EXPECT_EQ(received_events[0].mouse().motion, Mouse::Pressed);
|
||||
}
|
||||
|
||||
TEST(Event, MouseLeftMoved) {
|
||||
auto event_receiver = MakeReceiver<Task>();
|
||||
{
|
||||
auto parser = TerminalInputParser(event_receiver->MakeSender());
|
||||
parser.Add('\x1B');
|
||||
parser.Add('[');
|
||||
parser.Add('3');
|
||||
parser.Add('2');
|
||||
parser.Add(';');
|
||||
parser.Add('1');
|
||||
parser.Add('2');
|
||||
parser.Add(';');
|
||||
parser.Add('4');
|
||||
parser.Add('2');
|
||||
parser.Add('M');
|
||||
}
|
||||
std::vector<Event> received_events;
|
||||
auto parser = TerminalInputParser(
|
||||
[&](Event event) { received_events.push_back(std::move(event)); });
|
||||
parser.Add('');
|
||||
parser.Add('[');
|
||||
parser.Add('3');
|
||||
parser.Add('2');
|
||||
parser.Add(';');
|
||||
parser.Add('1');
|
||||
parser.Add('2');
|
||||
parser.Add(';');
|
||||
parser.Add('4');
|
||||
parser.Add('2');
|
||||
parser.Add('M');
|
||||
|
||||
Task received;
|
||||
EXPECT_TRUE(event_receiver->Receive(&received));
|
||||
EXPECT_TRUE(std::get<Event>(received).is_mouse());
|
||||
EXPECT_EQ(Mouse::Left, std::get<Event>(received).mouse().button);
|
||||
EXPECT_EQ(12, std::get<Event>(received).mouse().x);
|
||||
EXPECT_EQ(42, std::get<Event>(received).mouse().y);
|
||||
EXPECT_EQ(std::get<Event>(received).mouse().motion, Mouse::Moved);
|
||||
EXPECT_FALSE(event_receiver->Receive(&received));
|
||||
EXPECT_EQ(1, received_events.size());
|
||||
EXPECT_TRUE(received_events[0].is_mouse());
|
||||
EXPECT_EQ(Mouse::Left, received_events[0].mouse().button);
|
||||
EXPECT_EQ(12, received_events[0].mouse().x);
|
||||
EXPECT_EQ(42, received_events[0].mouse().y);
|
||||
EXPECT_EQ(received_events[0].mouse().motion, Mouse::Moved);
|
||||
}
|
||||
|
||||
TEST(Event, MouseLeftClickReleased) {
|
||||
auto event_receiver = MakeReceiver<Task>();
|
||||
{
|
||||
auto parser = TerminalInputParser(event_receiver->MakeSender());
|
||||
parser.Add('\x1B');
|
||||
parser.Add('[');
|
||||
parser.Add('0');
|
||||
parser.Add(';');
|
||||
parser.Add('1');
|
||||
parser.Add('2');
|
||||
parser.Add(';');
|
||||
parser.Add('4');
|
||||
parser.Add('2');
|
||||
parser.Add('m');
|
||||
}
|
||||
std::vector<Event> received_events;
|
||||
auto parser = TerminalInputParser(
|
||||
[&](Event event) { received_events.push_back(std::move(event)); });
|
||||
parser.Add('');
|
||||
parser.Add('[');
|
||||
parser.Add('0');
|
||||
parser.Add(';');
|
||||
parser.Add('1');
|
||||
parser.Add('2');
|
||||
parser.Add(';');
|
||||
parser.Add('4');
|
||||
parser.Add('2');
|
||||
parser.Add('m');
|
||||
|
||||
Task received;
|
||||
EXPECT_TRUE(event_receiver->Receive(&received));
|
||||
EXPECT_TRUE(std::get<Event>(received).is_mouse());
|
||||
EXPECT_EQ(Mouse::Left, std::get<Event>(received).mouse().button);
|
||||
EXPECT_EQ(12, std::get<Event>(received).mouse().x);
|
||||
EXPECT_EQ(42, std::get<Event>(received).mouse().y);
|
||||
EXPECT_EQ(std::get<Event>(received).mouse().motion, Mouse::Released);
|
||||
EXPECT_FALSE(event_receiver->Receive(&received));
|
||||
EXPECT_EQ(1, received_events.size());
|
||||
EXPECT_TRUE(received_events[0].is_mouse());
|
||||
EXPECT_EQ(Mouse::Left, received_events[0].mouse().button);
|
||||
EXPECT_EQ(12, received_events[0].mouse().x);
|
||||
EXPECT_EQ(42, received_events[0].mouse().y);
|
||||
EXPECT_EQ(received_events[0].mouse().motion, Mouse::Released);
|
||||
}
|
||||
|
||||
TEST(Event, MouseReporting) {
|
||||
auto event_receiver = MakeReceiver<Task>();
|
||||
{
|
||||
auto parser = TerminalInputParser(event_receiver->MakeSender());
|
||||
parser.Add('\x1B');
|
||||
parser.Add('[');
|
||||
parser.Add('1');
|
||||
parser.Add('2');
|
||||
parser.Add(';');
|
||||
parser.Add('4');
|
||||
parser.Add('2');
|
||||
parser.Add('R');
|
||||
}
|
||||
std::vector<Event> received_events;
|
||||
auto parser = TerminalInputParser(
|
||||
[&](Event event) { received_events.push_back(std::move(event)); });
|
||||
parser.Add('');
|
||||
parser.Add('[');
|
||||
parser.Add('1');
|
||||
parser.Add('2');
|
||||
parser.Add(';');
|
||||
parser.Add('4');
|
||||
parser.Add('2');
|
||||
parser.Add('R');
|
||||
|
||||
Task received;
|
||||
EXPECT_TRUE(event_receiver->Receive(&received));
|
||||
EXPECT_TRUE(std::get<Event>(received).is_cursor_position());
|
||||
EXPECT_EQ(42, std::get<Event>(received).cursor_x());
|
||||
EXPECT_EQ(12, std::get<Event>(received).cursor_y());
|
||||
EXPECT_FALSE(event_receiver->Receive(&received));
|
||||
EXPECT_EQ(1, received_events.size());
|
||||
EXPECT_TRUE(received_events[0].is_cursor_position());
|
||||
EXPECT_EQ(42, received_events[0].cursor_x());
|
||||
EXPECT_EQ(12, received_events[0].cursor_y());
|
||||
}
|
||||
|
||||
TEST(Event, MouseMiddleClick) {
|
||||
auto event_receiver = MakeReceiver<Task>();
|
||||
{
|
||||
auto parser = TerminalInputParser(event_receiver->MakeSender());
|
||||
parser.Add('\x1B');
|
||||
parser.Add('[');
|
||||
parser.Add('3');
|
||||
parser.Add('3');
|
||||
parser.Add(';');
|
||||
parser.Add('1');
|
||||
parser.Add('2');
|
||||
parser.Add(';');
|
||||
parser.Add('4');
|
||||
parser.Add('2');
|
||||
parser.Add('M');
|
||||
}
|
||||
std::vector<Event> received_events;
|
||||
auto parser = TerminalInputParser(
|
||||
[&](Event event) { received_events.push_back(std::move(event)); });
|
||||
parser.Add('');
|
||||
parser.Add('[');
|
||||
parser.Add('3');
|
||||
parser.Add('3');
|
||||
parser.Add(';');
|
||||
parser.Add('1');
|
||||
parser.Add('2');
|
||||
parser.Add(';');
|
||||
parser.Add('4');
|
||||
parser.Add('2');
|
||||
parser.Add('M');
|
||||
|
||||
Task received;
|
||||
EXPECT_TRUE(event_receiver->Receive(&received));
|
||||
EXPECT_TRUE(std::get<Event>(received).is_mouse());
|
||||
EXPECT_EQ(Mouse::Middle, std::get<Event>(received).mouse().button);
|
||||
EXPECT_EQ(12, std::get<Event>(received).mouse().x);
|
||||
EXPECT_EQ(42, std::get<Event>(received).mouse().y);
|
||||
EXPECT_FALSE(event_receiver->Receive(&received));
|
||||
EXPECT_EQ(1, received_events.size());
|
||||
EXPECT_TRUE(received_events[0].is_mouse());
|
||||
EXPECT_EQ(Mouse::Middle, received_events[0].mouse().button);
|
||||
EXPECT_EQ(12, received_events[0].mouse().x);
|
||||
EXPECT_EQ(42, received_events[0].mouse().y);
|
||||
}
|
||||
|
||||
TEST(Event, MouseRightClick) {
|
||||
auto event_receiver = MakeReceiver<Task>();
|
||||
{
|
||||
auto parser = TerminalInputParser(event_receiver->MakeSender());
|
||||
parser.Add('\x1B');
|
||||
parser.Add('[');
|
||||
parser.Add('3');
|
||||
parser.Add('4');
|
||||
parser.Add(';');
|
||||
parser.Add('1');
|
||||
parser.Add('2');
|
||||
parser.Add(';');
|
||||
parser.Add('4');
|
||||
parser.Add('2');
|
||||
parser.Add('M');
|
||||
}
|
||||
std::vector<Event> received_events;
|
||||
auto parser = TerminalInputParser(
|
||||
[&](Event event) { received_events.push_back(std::move(event)); });
|
||||
parser.Add('');
|
||||
parser.Add('[');
|
||||
parser.Add('3');
|
||||
parser.Add('4');
|
||||
parser.Add(';');
|
||||
parser.Add('1');
|
||||
parser.Add('2');
|
||||
parser.Add(';');
|
||||
parser.Add('4');
|
||||
parser.Add('2');
|
||||
parser.Add('M');
|
||||
|
||||
Task received;
|
||||
EXPECT_TRUE(event_receiver->Receive(&received));
|
||||
EXPECT_TRUE(std::get<Event>(received).is_mouse());
|
||||
EXPECT_EQ(Mouse::Right, std::get<Event>(received).mouse().button);
|
||||
EXPECT_EQ(12, std::get<Event>(received).mouse().x);
|
||||
EXPECT_EQ(42, std::get<Event>(received).mouse().y);
|
||||
EXPECT_FALSE(event_receiver->Receive(&received));
|
||||
EXPECT_EQ(1, received_events.size());
|
||||
EXPECT_TRUE(received_events[0].is_mouse());
|
||||
EXPECT_EQ(Mouse::Right, received_events[0].mouse().button);
|
||||
EXPECT_EQ(12, received_events[0].mouse().x);
|
||||
EXPECT_EQ(42, received_events[0].mouse().y);
|
||||
}
|
||||
|
||||
TEST(Event, UTF8) {
|
||||
@@ -313,31 +285,30 @@ TEST(Event, UTF8) {
|
||||
|
||||
};
|
||||
for (auto test : kTestCase) {
|
||||
auto event_receiver = MakeReceiver<Task>();
|
||||
{
|
||||
auto parser = TerminalInputParser(event_receiver->MakeSender());
|
||||
for (auto input : test.input)
|
||||
parser.Add(input);
|
||||
std::vector<Event> received_events;
|
||||
auto parser = TerminalInputParser(
|
||||
[&](Event event) { received_events.push_back(std::move(event)); });
|
||||
for (auto input : test.input) {
|
||||
parser.Add(input);
|
||||
}
|
||||
Task received;
|
||||
|
||||
if (test.valid) {
|
||||
EXPECT_TRUE(event_receiver->Receive(&received));
|
||||
EXPECT_TRUE(std::get<Event>(received).is_character());
|
||||
EXPECT_EQ(1, received_events.size());
|
||||
EXPECT_TRUE(received_events[0].is_character());
|
||||
} else {
|
||||
EXPECT_TRUE(received_events.empty());
|
||||
}
|
||||
EXPECT_FALSE(event_receiver->Receive(&received));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Event, NewLine) {
|
||||
for (char newline : {'\r', '\n'}) {
|
||||
auto event_receiver = MakeReceiver<Task>();
|
||||
{
|
||||
auto parser = TerminalInputParser(event_receiver->MakeSender());
|
||||
parser.Add(newline);
|
||||
}
|
||||
Task received;
|
||||
EXPECT_TRUE(event_receiver->Receive(&received));
|
||||
EXPECT_TRUE(std::get<Event>(received) == Event::Return);
|
||||
std::vector<Event> received_events;
|
||||
auto parser = TerminalInputParser(
|
||||
[&](Event event) { received_events.push_back(std::move(event)); });
|
||||
parser.Add(newline);
|
||||
EXPECT_EQ(1, received_events.size());
|
||||
EXPECT_TRUE(received_events[0] == Event::Return);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,8 +319,9 @@ TEST(Event, Control) {
|
||||
};
|
||||
std::vector<TestCase> cases;
|
||||
for (int i = 0; i < 32; ++i) {
|
||||
if (i == 8 || i == 13 || i == 24 || i == 26 || i == 27)
|
||||
if (i == 8 || i == 13 || i == 24 || i == 26 || i == 27) {
|
||||
continue;
|
||||
}
|
||||
cases.push_back({char(i), false});
|
||||
}
|
||||
cases.push_back({char(24), false});
|
||||
@@ -357,17 +329,16 @@ TEST(Event, Control) {
|
||||
cases.push_back({char(127), false});
|
||||
|
||||
for (auto test : cases) {
|
||||
auto event_receiver = MakeReceiver<Task>();
|
||||
{
|
||||
auto parser = TerminalInputParser(event_receiver->MakeSender());
|
||||
parser.Add(test.input);
|
||||
}
|
||||
Task received;
|
||||
std::vector<Event> received_events;
|
||||
auto parser = TerminalInputParser(
|
||||
[&](Event event) { received_events.push_back(std::move(event)); });
|
||||
parser.Add(test.input);
|
||||
|
||||
if (test.cancel) {
|
||||
EXPECT_FALSE(event_receiver->Receive(&received));
|
||||
EXPECT_TRUE(received_events.empty());
|
||||
} else {
|
||||
EXPECT_TRUE(event_receiver->Receive(&received));
|
||||
EXPECT_EQ(std::get<Event>(received), Event::Special({test.input}));
|
||||
EXPECT_EQ(1, received_events.size());
|
||||
EXPECT_EQ(received_events[0], Event::Special({test.input}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -375,8 +346,9 @@ TEST(Event, Control) {
|
||||
TEST(Event, Special) {
|
||||
auto str = [](std::string input) {
|
||||
std::vector<unsigned char> output;
|
||||
for (auto it : input)
|
||||
for (auto it : input) {
|
||||
output.push_back(it);
|
||||
}
|
||||
return output;
|
||||
};
|
||||
|
||||
@@ -385,10 +357,12 @@ TEST(Event, Special) {
|
||||
Event expected;
|
||||
} kTestCase[] = {
|
||||
// Arrow (default cursor mode)
|
||||
{str("\x1B[A"), Event::ArrowUp}, {str("\x1B[B"), Event::ArrowDown},
|
||||
{str("\x1B[C"), Event::ArrowRight}, {str("\x1B[D"), Event::ArrowLeft},
|
||||
{str("\x1B[H"), Event::Home}, {str("\x1B[F"), Event::End},
|
||||
/*
|
||||
{str("[A"), Event::ArrowUp},
|
||||
{str("[B"), Event::ArrowDown},
|
||||
{str("[C"), Event::ArrowRight},
|
||||
{str("[D"), Event::ArrowLeft},
|
||||
{str("[H"), Event::Home},
|
||||
{str("[F"), Event::End},
|
||||
|
||||
// Arrow (application cursor mode)
|
||||
{str("\x1BOA"), Event::ArrowUp},
|
||||
@@ -469,45 +443,38 @@ TEST(Event, Special) {
|
||||
|
||||
// Custom:
|
||||
{{0}, Event::Custom},
|
||||
*/
|
||||
};
|
||||
|
||||
for (auto test : kTestCase) {
|
||||
auto event_receiver = MakeReceiver<Task>();
|
||||
{
|
||||
auto parser = TerminalInputParser(event_receiver->MakeSender());
|
||||
for (auto input : test.input) {
|
||||
parser.Add(input);
|
||||
}
|
||||
std::vector<Event> received_events;
|
||||
auto parser = TerminalInputParser(
|
||||
[&](Event event) { received_events.push_back(std::move(event)); });
|
||||
for (auto input : test.input) {
|
||||
parser.Add(input);
|
||||
}
|
||||
Task received;
|
||||
EXPECT_TRUE(event_receiver->Receive(&received));
|
||||
EXPECT_EQ(std::get<Event>(received), test.expected);
|
||||
EXPECT_FALSE(event_receiver->Receive(&received));
|
||||
EXPECT_EQ(1, received_events.size());
|
||||
EXPECT_EQ(received_events[0], test.expected);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Event, DeviceControlString) {
|
||||
auto event_receiver = MakeReceiver<Task>();
|
||||
{
|
||||
auto parser = TerminalInputParser(event_receiver->MakeSender());
|
||||
parser.Add(27); // ESC
|
||||
parser.Add(80); // P
|
||||
parser.Add(49); // 1
|
||||
parser.Add(36); // $
|
||||
parser.Add(114); // r
|
||||
parser.Add(49); // 1
|
||||
parser.Add(32); // SP
|
||||
parser.Add(113); // q
|
||||
parser.Add(27); // ESC
|
||||
parser.Add(92); // (backslash)
|
||||
}
|
||||
std::vector<Event> received_events;
|
||||
auto parser = TerminalInputParser(
|
||||
[&](Event event) { received_events.push_back(std::move(event)); });
|
||||
parser.Add(27); // ESC
|
||||
parser.Add(80); // P
|
||||
parser.Add(49); // 1
|
||||
parser.Add(36); // $
|
||||
parser.Add(114); // r
|
||||
parser.Add(49); // 1
|
||||
parser.Add(32); // SP
|
||||
parser.Add(113); // q
|
||||
parser.Add(27); // ESC
|
||||
parser.Add(92); // (backslash)
|
||||
|
||||
Task received;
|
||||
EXPECT_TRUE(event_receiver->Receive(&received));
|
||||
EXPECT_TRUE(std::get<Event>(received).is_cursor_shape());
|
||||
EXPECT_EQ(1, std::get<Event>(received).cursor_shape());
|
||||
EXPECT_FALSE(event_receiver->Receive(&received));
|
||||
EXPECT_EQ(1, received_events.size());
|
||||
EXPECT_TRUE(received_events[0].is_cursor_shape());
|
||||
EXPECT_EQ(1, received_events[0].cursor_shape());
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
// Copyright 2021 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 <cstddef>
|
||||
#include <ftxui/component/event.hpp>
|
||||
#include "ftxui/component/terminal_input_parser.hpp"
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const char* data, size_t size) {
|
||||
using namespace ftxui;
|
||||
auto event_receiver = MakeReceiver<Task>();
|
||||
{
|
||||
auto parser = TerminalInputParser(event_receiver->MakeSender());
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
parser.Add(data[i]);
|
||||
}
|
||||
auto parser = TerminalInputParser([&](Event) {});
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
parser.Add(data[i]);
|
||||
}
|
||||
|
||||
Task received;
|
||||
while (event_receiver->Receive(&received)) {
|
||||
// Do nothing.
|
||||
}
|
||||
return 0; // Non-zero return values are reserved for future use.
|
||||
}
|
||||
|
||||
@@ -6,42 +6,36 @@
|
||||
namespace ftxui {
|
||||
|
||||
/// @brief Set the flexbox direction.
|
||||
/// @ingroup dom
|
||||
FlexboxConfig& FlexboxConfig::Set(FlexboxConfig::Direction d) {
|
||||
this->direction = d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// @brief Set the flexbox wrap.
|
||||
/// @ingroup dom
|
||||
FlexboxConfig& FlexboxConfig::Set(FlexboxConfig::Wrap w) {
|
||||
this->wrap = w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// @brief Set the flexbox justify content.
|
||||
/// @ingroup dom
|
||||
FlexboxConfig& FlexboxConfig::Set(FlexboxConfig::JustifyContent j) {
|
||||
this->justify_content = j;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// @brief Set the flexbox align items.
|
||||
/// @ingroup dom
|
||||
FlexboxConfig& FlexboxConfig::Set(FlexboxConfig::AlignItems a) {
|
||||
this->align_items = a;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// @brief Set the flexbox align content.
|
||||
/// @ingroup dom
|
||||
FlexboxConfig& FlexboxConfig::Set(FlexboxConfig::AlignContent a) {
|
||||
this->align_content = a;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// @brief Set the flexbox flex direction.
|
||||
/// @ingroup dom
|
||||
FlexboxConfig& FlexboxConfig::SetGap(int x, int y) {
|
||||
this->gap_x = x;
|
||||
this->gap_y = y;
|
||||
|
||||
@@ -189,13 +189,11 @@ class LinearGradientColor : public NodeDecorator {
|
||||
/// .Stop(Color::Green, 0.5)
|
||||
/// .Stop(Color::Blue, 1.0);;
|
||||
/// ```
|
||||
/// @ingroup dom
|
||||
LinearGradient::LinearGradient() = default;
|
||||
|
||||
/// @brief Build a gradient with two colors.
|
||||
/// @param begin The color at the beginning of the gradient.
|
||||
/// @param end The color at the end of the gradient.
|
||||
/// @ingroup dom
|
||||
LinearGradient::LinearGradient(Color begin, Color end)
|
||||
: LinearGradient(0, begin, end) {}
|
||||
|
||||
@@ -203,7 +201,6 @@ LinearGradient::LinearGradient(Color begin, Color end)
|
||||
/// @param a The angle of the gradient.
|
||||
/// @param begin The color at the beginning of the gradient.
|
||||
/// @param end The color at the end of the gradient.
|
||||
/// @ingroup dom
|
||||
LinearGradient::LinearGradient(float a, Color begin, Color end) : angle(a) {
|
||||
stops.push_back({begin, {}});
|
||||
stops.push_back({end, {}});
|
||||
@@ -212,7 +209,6 @@ LinearGradient::LinearGradient(float a, Color begin, Color end) : angle(a) {
|
||||
/// @brief Set the angle of the gradient.
|
||||
/// @param a The angle of the gradient.
|
||||
/// @return The gradient.
|
||||
/// @ingroup dom
|
||||
LinearGradient& LinearGradient::Angle(float a) {
|
||||
angle = a;
|
||||
return *this;
|
||||
@@ -221,7 +217,6 @@ LinearGradient& LinearGradient::Angle(float a) {
|
||||
/// @brief Add a color stop to the gradient.
|
||||
/// @param c The color of the stop.
|
||||
/// @param p The position of the stop.
|
||||
/// @return The gradient.
|
||||
LinearGradient& LinearGradient::Stop(Color c, float p) {
|
||||
stops.push_back({c, p});
|
||||
return *this;
|
||||
@@ -230,7 +225,6 @@ LinearGradient& LinearGradient::Stop(Color c, float p) {
|
||||
/// @brief Add a color stop to the gradient.
|
||||
/// @param c The color of the stop.
|
||||
/// @return The gradient.
|
||||
/// @ingroup dom
|
||||
/// @note The position of the stop is interpolated from nearby stops.
|
||||
LinearGradient& LinearGradient::Stop(Color c) {
|
||||
stops.push_back({c, {}});
|
||||
|
||||
@@ -17,7 +17,6 @@ Node::Node(Elements children) : children_(std::move(children)) {}
|
||||
Node::~Node() = default;
|
||||
|
||||
/// @brief Compute how much space an element needs.
|
||||
/// @ingroup dom
|
||||
void Node::ComputeRequirement() {
|
||||
if (children_.empty()) {
|
||||
return;
|
||||
@@ -39,13 +38,11 @@ void Node::ComputeRequirement() {
|
||||
}
|
||||
|
||||
/// @brief Assign a position and a dimension to an element for drawing.
|
||||
/// @ingroup dom
|
||||
void Node::SetBox(Box box) {
|
||||
box_ = box;
|
||||
}
|
||||
|
||||
/// @brief Compute the selection of an element.
|
||||
/// @ingroup dom
|
||||
void Node::Select(Selection& selection) {
|
||||
// If this Node box_ doesn't intersect with the selection, then no selection.
|
||||
if (Box::Intersection(selection.GetBox(), box_).IsEmpty()) {
|
||||
@@ -59,7 +56,6 @@ void Node::Select(Selection& selection) {
|
||||
}
|
||||
|
||||
/// @brief Display an element on a ftxui::Screen.
|
||||
/// @ingroup dom
|
||||
void Node::Render(Screen& screen) {
|
||||
for (auto& child : children_) {
|
||||
child->Render(screen);
|
||||
|
||||
@@ -81,7 +81,7 @@ class Size : public Node {
|
||||
} // namespace
|
||||
|
||||
/// @brief Apply a constraint on the size of an element.
|
||||
/// @param direction Whether the WIDTH of the HEIGHT of the element must be
|
||||
/// @param direction Whether the WIDTH or the HEIGHT of the element must be
|
||||
/// constrained.
|
||||
/// @param constraint The type of constaint.
|
||||
/// @param value The value.
|
||||
|
||||
@@ -44,14 +44,12 @@ void Order(int& a, int& b) {
|
||||
} // namespace
|
||||
|
||||
/// @brief Create an empty table.
|
||||
/// @ingroup dom
|
||||
Table::Table() {
|
||||
Initialize({});
|
||||
}
|
||||
|
||||
/// @brief Create a table from a vector of vector of string.
|
||||
/// @param input The input data.
|
||||
/// @ingroup dom
|
||||
Table::Table(std::vector<std::vector<std::string>> input) {
|
||||
std::vector<std::vector<Element>> output;
|
||||
output.reserve(input.size());
|
||||
@@ -68,14 +66,12 @@ Table::Table(std::vector<std::vector<std::string>> input) {
|
||||
|
||||
/// @brief Create a table from a vector of vector of Element
|
||||
/// @param input The input elements.
|
||||
/// @ingroup dom
|
||||
Table::Table(std::vector<std::vector<Element>> input) {
|
||||
Initialize(std::move(input));
|
||||
}
|
||||
|
||||
// @brief Create a table from a list of list of string.
|
||||
// @param init The input data.
|
||||
// @ingroup dom
|
||||
Table::Table(std::initializer_list<std::vector<std::string>> init) {
|
||||
std::vector<std::vector<Element>> input;
|
||||
for (const auto& row : init) {
|
||||
@@ -139,7 +135,6 @@ void Table::Initialize(std::vector<std::vector<Element>> input) {
|
||||
/// @brief Select a row of the table.
|
||||
/// @param index The index of the row to select.
|
||||
/// @note You can use negative index to select from the end.
|
||||
/// @ingroup dom
|
||||
TableSelection Table::SelectRow(int index) {
|
||||
return SelectRectangle(0, -1, index, index);
|
||||
}
|
||||
@@ -148,7 +143,6 @@ TableSelection Table::SelectRow(int index) {
|
||||
/// @param row_min The first row to select.
|
||||
/// @param row_max The last row to select.
|
||||
/// @note You can use negative index to select from the end.
|
||||
/// @ingroup dom
|
||||
TableSelection Table::SelectRows(int row_min, int row_max) {
|
||||
return SelectRectangle(0, -1, row_min, row_max);
|
||||
}
|
||||
@@ -156,7 +150,6 @@ TableSelection Table::SelectRows(int row_min, int row_max) {
|
||||
/// @brief Select a column of the table.
|
||||
/// @param index The index of the column to select.
|
||||
/// @note You can use negative index to select from the end.
|
||||
/// @ingroup dom
|
||||
TableSelection Table::SelectColumn(int index) {
|
||||
return SelectRectangle(index, index, 0, -1);
|
||||
}
|
||||
@@ -165,7 +158,6 @@ TableSelection Table::SelectColumn(int index) {
|
||||
/// @param column_min The first column to select.
|
||||
/// @param column_max The last column to select.
|
||||
/// @note You can use negative index to select from the end.
|
||||
/// @ingroup dom
|
||||
TableSelection Table::SelectColumns(int column_min, int column_max) {
|
||||
return SelectRectangle(column_min, column_max, 0, -1);
|
||||
}
|
||||
@@ -174,7 +166,6 @@ TableSelection Table::SelectColumns(int column_min, int column_max) {
|
||||
/// @param column The column of the cell to select.
|
||||
/// @param row The row of the cell to select.
|
||||
/// @note You can use negative index to select from the end.
|
||||
/// @ingroup dom
|
||||
TableSelection Table::SelectCell(int column, int row) {
|
||||
return SelectRectangle(column, column, row, row);
|
||||
}
|
||||
@@ -185,7 +176,6 @@ TableSelection Table::SelectCell(int column, int row) {
|
||||
/// @param row_min The first row to select.
|
||||
/// @param row_max The last row to select.
|
||||
/// @note You can use negative index to select from the end.
|
||||
/// @ingroup dom
|
||||
TableSelection Table::SelectRectangle(int column_min,
|
||||
int column_max,
|
||||
int row_min,
|
||||
@@ -207,7 +197,6 @@ TableSelection Table::SelectRectangle(int column_min,
|
||||
}
|
||||
|
||||
/// @brief Select all the table.
|
||||
/// @ingroup dom
|
||||
TableSelection Table::SelectAll() {
|
||||
TableSelection output; // NOLINT
|
||||
output.table_ = this;
|
||||
@@ -220,7 +209,6 @@ TableSelection Table::SelectAll() {
|
||||
|
||||
/// @brief Render the table.
|
||||
/// @return The rendered table. This is an element you can draw.
|
||||
/// @ingroup dom
|
||||
Element Table::Render() {
|
||||
for (int y = 0; y < dim_y_; ++y) {
|
||||
for (int x = 0; x < dim_x_; ++x) {
|
||||
@@ -250,7 +238,6 @@ Element Table::Render() {
|
||||
/// @brief Apply the `decorator` to the selection.
|
||||
/// This decorate both the cells, the lines and the corners.
|
||||
/// @param decorator The decorator to apply.
|
||||
/// @ingroup dom
|
||||
// NOLINTNEXTLINE
|
||||
void TableSelection::Decorate(Decorator decorator) {
|
||||
for (int y = y_min_; y <= y_max_; ++y) {
|
||||
@@ -264,7 +251,6 @@ void TableSelection::Decorate(Decorator decorator) {
|
||||
/// @brief Apply the `decorator` to the selection.
|
||||
/// @param decorator The decorator to apply.
|
||||
/// This decorate only the cells.
|
||||
/// @ingroup dom
|
||||
// NOLINTNEXTLINE
|
||||
void TableSelection::DecorateCells(Decorator decorator) {
|
||||
for (int y = y_min_; y <= y_max_; ++y) {
|
||||
@@ -282,7 +268,6 @@ void TableSelection::DecorateCells(Decorator decorator) {
|
||||
/// @param decorator The decorator to apply.
|
||||
/// @param modulo The modulo of the lines to decorate.
|
||||
/// @param shift The shift of the lines to decorate.
|
||||
/// @ingroup dom
|
||||
// NOLINTNEXTLINE
|
||||
void TableSelection::DecorateAlternateColumn(Decorator decorator,
|
||||
int modulo,
|
||||
@@ -302,7 +287,6 @@ void TableSelection::DecorateAlternateColumn(Decorator decorator,
|
||||
/// @param decorator The decorator to apply.
|
||||
/// @param modulo The modulo of the lines to decorate.
|
||||
/// @param shift The shift of the lines to decorate.
|
||||
/// @ingroup dom
|
||||
// NOLINTNEXTLINE
|
||||
void TableSelection::DecorateAlternateRow(Decorator decorator,
|
||||
int modulo,
|
||||
@@ -322,7 +306,6 @@ void TableSelection::DecorateAlternateRow(Decorator decorator,
|
||||
/// @param decorator The decorator to apply.
|
||||
/// @param modulo The modulo of the corners to decorate.
|
||||
/// @param shift The shift of the corners to decorate.
|
||||
/// @ingroup dom
|
||||
// NOLINTNEXTLINE
|
||||
void TableSelection::DecorateCellsAlternateColumn(Decorator decorator,
|
||||
int modulo,
|
||||
@@ -342,7 +325,6 @@ void TableSelection::DecorateCellsAlternateColumn(Decorator decorator,
|
||||
/// @param decorator The decorator to apply.
|
||||
/// @param modulo The modulo of the corners to decorate.
|
||||
/// @param shift The shift of the corners to decorate.
|
||||
/// @ingroup dom
|
||||
// NOLINTNEXTLINE
|
||||
void TableSelection::DecorateCellsAlternateRow(Decorator decorator,
|
||||
int modulo,
|
||||
@@ -359,7 +341,6 @@ void TableSelection::DecorateCellsAlternateRow(Decorator decorator,
|
||||
|
||||
/// @brief Apply a `border` around the selection.
|
||||
/// @param border The border style to apply.
|
||||
/// @ingroup dom
|
||||
void TableSelection::Border(BorderStyle border) {
|
||||
BorderLeft(border);
|
||||
BorderRight(border);
|
||||
@@ -378,7 +359,6 @@ void TableSelection::Border(BorderStyle border) {
|
||||
|
||||
/// @brief Draw some separator lines in the selection.
|
||||
/// @param border The border style to apply.
|
||||
/// @ingroup dom
|
||||
void TableSelection::Separator(BorderStyle border) {
|
||||
for (int y = y_min_ + 1; y <= y_max_ - 1; ++y) {
|
||||
for (int x = x_min_ + 1; x <= x_max_ - 1; ++x) {
|
||||
@@ -394,7 +374,6 @@ void TableSelection::Separator(BorderStyle border) {
|
||||
|
||||
/// @brief Draw some vertical separator lines in the selection.
|
||||
/// @param border The border style to apply.
|
||||
/// @ingroup dom
|
||||
void TableSelection::SeparatorVertical(BorderStyle border) {
|
||||
for (int y = y_min_ + 1; y <= y_max_ - 1; ++y) {
|
||||
for (int x = x_min_ + 1; x <= x_max_ - 1; ++x) {
|
||||
@@ -408,7 +387,6 @@ void TableSelection::SeparatorVertical(BorderStyle border) {
|
||||
|
||||
/// @brief Draw some horizontal separator lines in the selection.
|
||||
/// @param border The border style to apply.
|
||||
/// @ingroup dom
|
||||
void TableSelection::SeparatorHorizontal(BorderStyle border) {
|
||||
for (int y = y_min_ + 1; y <= y_max_ - 1; ++y) {
|
||||
for (int x = x_min_ + 1; x <= x_max_ - 1; ++x) {
|
||||
@@ -422,7 +400,6 @@ void TableSelection::SeparatorHorizontal(BorderStyle border) {
|
||||
|
||||
/// @brief Draw some separator lines to the left side of the selection.
|
||||
/// @param border The border style to apply.
|
||||
/// @ingroup dom
|
||||
void TableSelection::BorderLeft(BorderStyle border) {
|
||||
for (int y = y_min_; y <= y_max_; y++) {
|
||||
table_->elements_[y][x_min_] =
|
||||
@@ -432,7 +409,6 @@ void TableSelection::BorderLeft(BorderStyle border) {
|
||||
|
||||
/// @brief Draw some separator lines to the right side of the selection.
|
||||
/// @param border The border style to apply.
|
||||
/// @ingroup dom
|
||||
void TableSelection::BorderRight(BorderStyle border) {
|
||||
for (int y = y_min_; y <= y_max_; y++) {
|
||||
table_->elements_[y][x_max_] =
|
||||
@@ -442,7 +418,6 @@ void TableSelection::BorderRight(BorderStyle border) {
|
||||
|
||||
/// @brief Draw some separator lines to the top side of the selection.
|
||||
/// @param border The border style to apply.
|
||||
/// @ingroup dom
|
||||
void TableSelection::BorderTop(BorderStyle border) {
|
||||
for (int x = x_min_; x <= x_max_; x++) {
|
||||
table_->elements_[y_min_][x] =
|
||||
@@ -452,7 +427,6 @@ void TableSelection::BorderTop(BorderStyle border) {
|
||||
|
||||
/// @brief Draw some separator lines to the bottom side of the selection.
|
||||
/// @param border The border style to apply.
|
||||
/// @ingroup dom
|
||||
void TableSelection::BorderBottom(BorderStyle border) {
|
||||
for (int x = x_min_; x <= x_max_; x++) {
|
||||
table_->elements_[y_max_][x] =
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
namespace ftxui {
|
||||
/// @return the biggest Box contained in both |a| and |b|.
|
||||
/// @ingroup screen
|
||||
// static
|
||||
Box Box::Intersection(Box a, Box b) {
|
||||
return Box{
|
||||
@@ -19,7 +18,6 @@ Box Box::Intersection(Box a, Box b) {
|
||||
}
|
||||
|
||||
/// @return the smallest Box containing both |a| and |b|.
|
||||
/// @ingroup screen
|
||||
// static
|
||||
Box Box::Union(Box a, Box b) {
|
||||
return Box{
|
||||
@@ -33,7 +31,6 @@ Box Box::Union(Box a, Box b) {
|
||||
/// Shift the box by (x,y).
|
||||
/// @param x horizontal shift.
|
||||
/// @param y vertical shift.
|
||||
/// @ingroup screen
|
||||
void Box::Shift(int x, int y) {
|
||||
x_min += x;
|
||||
x_max += x;
|
||||
@@ -42,7 +39,6 @@ void Box::Shift(int x, int y) {
|
||||
}
|
||||
|
||||
/// @return whether (x,y) is contained inside the box.
|
||||
/// @ingroup screen
|
||||
bool Box::Contain(int x, int y) const {
|
||||
return x_min <= x && //
|
||||
x_max >= x && //
|
||||
@@ -51,20 +47,17 @@ bool Box::Contain(int x, int y) const {
|
||||
}
|
||||
|
||||
/// @return whether the box is empty.
|
||||
/// @ingroup screen
|
||||
bool Box::IsEmpty() const {
|
||||
return x_min > x_max || y_min > y_max;
|
||||
}
|
||||
|
||||
/// @return whether |other| is the same as |this|
|
||||
/// @ingroup screen
|
||||
bool Box::operator==(const Box& other) const {
|
||||
return (x_min == other.x_min) && (x_max == other.x_max) &&
|
||||
(y_min == other.y_min) && (y_max == other.y_max);
|
||||
}
|
||||
|
||||
/// @return whether |other| and |this| are different.
|
||||
/// @ingroup screen
|
||||
bool Box::operator!=(const Box& other) const {
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
@@ -74,20 +74,16 @@ std::string Color::Print(bool is_background_color) const {
|
||||
}
|
||||
|
||||
/// @brief Build a transparent color.
|
||||
/// @ingroup screen
|
||||
Color::Color() = default;
|
||||
|
||||
/// @brief Build a transparent color.
|
||||
/// @ingroup screen
|
||||
Color::Color(Palette1 /*value*/) : Color() {}
|
||||
|
||||
/// @brief Build a color using the Palette16 colors.
|
||||
/// @ingroup screen
|
||||
Color::Color(Palette16 index)
|
||||
: type_(ColorType::Palette16), red_(index), alpha_(255) {}
|
||||
|
||||
/// @brief Build a color using Palette256 colors.
|
||||
/// @ingroup screen
|
||||
Color::Color(Palette256 index)
|
||||
: type_(ColorType::Palette256), red_(index), alpha_(255) {
|
||||
if (Terminal::ColorSupport() >= Terminal::Color::Palette256) {
|
||||
@@ -104,7 +100,6 @@ Color::Color(Palette256 index)
|
||||
/// @param green The quantity of green [0,255]
|
||||
/// @param blue The quantity of blue [0,255]
|
||||
/// @param alpha The quantity of alpha [0,255]
|
||||
/// @ingroup screen
|
||||
Color::Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
|
||||
: type_(ColorType::TrueColor),
|
||||
red_(red),
|
||||
@@ -148,7 +143,6 @@ Color::Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
|
||||
/// @param red The quantity of red [0,255]
|
||||
/// @param green The quantity of green [0,255]
|
||||
/// @param blue The quantity of blue [0,255]
|
||||
/// @ingroup screen
|
||||
// static
|
||||
Color Color::RGB(uint8_t red, uint8_t green, uint8_t blue) {
|
||||
return RGBA(red, green, blue, 255);
|
||||
@@ -160,7 +154,6 @@ Color Color::RGB(uint8_t red, uint8_t green, uint8_t blue) {
|
||||
/// @param green The quantity of green [0,255]
|
||||
/// @param blue The quantity of blue [0,255]
|
||||
/// @param alpha The quantity of alpha [0,255]
|
||||
/// @ingroup screen
|
||||
/// @see Color::RGB
|
||||
// static
|
||||
Color Color::RGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) {
|
||||
@@ -174,7 +167,6 @@ Color Color::RGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) {
|
||||
/// @param s The "colorfulness" [0,255].
|
||||
/// @param v The "Lightness" [0,255]
|
||||
/// @param alpha The quantity of alpha [0,255]
|
||||
/// @ingroup screen
|
||||
// static
|
||||
Color Color::HSVA(uint8_t h, uint8_t s, uint8_t v, uint8_t alpha) {
|
||||
uint8_t region = h / 43; // NOLINT
|
||||
@@ -202,7 +194,6 @@ Color Color::HSVA(uint8_t h, uint8_t s, uint8_t v, uint8_t alpha) {
|
||||
/// @param h The hue of the color [0,255]
|
||||
/// @param s The "colorfulness" [0,255].
|
||||
/// @param v The "Lightness" [0,255]
|
||||
/// @ingroup screen
|
||||
// static
|
||||
Color Color::HSV(uint8_t h, uint8_t s, uint8_t v) {
|
||||
return HSVA(h, s, v, 255);
|
||||
|
||||
@@ -47,8 +47,9 @@ namespace {
|
||||
#if defined(_WIN32)
|
||||
void WindowsEmulateVT100Terminal() {
|
||||
static bool done = false;
|
||||
if (done)
|
||||
if (done) {
|
||||
return;
|
||||
}
|
||||
done = true;
|
||||
|
||||
// Enable VT processing on stdout and stdin
|
||||
|
||||
@@ -1284,8 +1284,9 @@ bool IsCombining(uint32_t ucs) {
|
||||
}
|
||||
|
||||
bool IsFullWidth(uint32_t ucs) {
|
||||
if (ucs < 0x0300) // Quick path: // NOLINT
|
||||
if (ucs < 0x0300) { // Quick path: // NOLINT
|
||||
return false;
|
||||
}
|
||||
|
||||
return Bisearch(ucs, g_full_width_characters);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2024 Arthur Sonzogni. All rights reserved.
|
||||
// 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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user