mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-09 21:57:36 +08:00
Compare commits
49 Commits
v6.0.0
...
HarryPehko
Author | SHA1 | Date | |
---|---|---|---|
![]() |
dad2eaaa28 | ||
![]() |
5c3e3151a5 | ||
![]() |
143b24c6a5 | ||
![]() |
40e1fac3d4 | ||
![]() |
8ef18ab647 | ||
![]() |
994915dbb9 | ||
![]() |
3b359e8cd7 | ||
![]() |
1073ba414d | ||
![]() |
b78b97056b | ||
![]() |
68fc9b1212 | ||
![]() |
6440a88dc6 | ||
![]() |
14da21b0ee | ||
![]() |
a86d8f32d7 | ||
![]() |
3367c3a005 | ||
![]() |
44dcd41b5e | ||
![]() |
96d817217c | ||
![]() |
bbe6d1e0a3 | ||
![]() |
b65bbce9bb | ||
![]() |
fe86d06595 | ||
![]() |
ba81d364cf | ||
![]() |
a8eda59d98 | ||
![]() |
2f0afe7b14 | ||
![]() |
cde284e747 | ||
![]() |
deae56888a | ||
![]() |
50467783a6 | ||
![]() |
d178bc1a95 | ||
![]() |
22576bae6b | ||
![]() |
08b8a3b28f | ||
![]() |
5cfed50702 | ||
![]() |
b307a175ed | ||
![]() |
4604adb502 | ||
![]() |
add5f40d31 | ||
![]() |
805db9bdea | ||
![]() |
784f53fd7e | ||
![]() |
799d8a267e | ||
![]() |
f4513702b0 | ||
![]() |
ba6716c6e1 | ||
![]() |
694fa6bf5c | ||
![]() |
625915b52c | ||
![]() |
2d4c114008 | ||
![]() |
aa80d8bac9 | ||
![]() |
bcdcf70348 | ||
![]() |
4231c4903b | ||
![]() |
10d73d365f | ||
![]() |
07fd3e685a | ||
![]() |
09eb2f7fb0 | ||
![]() |
1144e13125 | ||
![]() |
4ba7dd2c5e | ||
![]() |
ee24bec3ba |
9
.bazelrc
Normal file
9
.bazelrc
Normal file
@@ -0,0 +1,9 @@
|
||||
common --enable_bzlmod
|
||||
|
||||
build --features=layering_check
|
||||
build --enable_bzlmod
|
||||
|
||||
build --enable_platform_specific_config
|
||||
build:linux --cxxopt=-std=c++20
|
||||
build:macos --cxxopt=-std=c++20
|
||||
build:windows --cxxopt=-std:c++20
|
9
.bcr/README.md
Normal file
9
.bcr/README.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# Bazel Central Registry
|
||||
|
||||
When the ruleset is released, we want it to be published to the
|
||||
Bazel Central Registry automatically:
|
||||
<https://registry.bazel.build>
|
||||
|
||||
This folder contains configuration files to automate the publish step.
|
||||
See <https://github.com/bazel-contrib/publish-to-bcr/blob/main/templates/README.md>
|
||||
for authoritative documentation about these files.
|
16
.bcr/metadata.template.json
Normal file
16
.bcr/metadata.template.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"homepage": "https://github.com/ArthurSonzogni/FTXUI",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "Arthur Sonzogni",
|
||||
"email": "sonzogniarthur@gmail.com",
|
||||
"github": "ArthurSonzogni",
|
||||
"github_user_id": 4759106
|
||||
}
|
||||
],
|
||||
"repository": [
|
||||
"github:ArthurSonzogni/FTXUI"
|
||||
],
|
||||
"versions": [],
|
||||
"yanked_versions": {}
|
||||
}
|
36
.bcr/presubmit.yml
Normal file
36
.bcr/presubmit.yml
Normal file
@@ -0,0 +1,36 @@
|
||||
matrix:
|
||||
bazel:
|
||||
- 7.x
|
||||
- 8.x
|
||||
- rolling
|
||||
unix_platform:
|
||||
- debian11
|
||||
- ubuntu2204
|
||||
- macos
|
||||
- macos_arm64
|
||||
win_platform:
|
||||
- windows
|
||||
|
||||
tasks:
|
||||
|
||||
unix_test:
|
||||
name: Verify build targets on Unix
|
||||
platform: ${{ unix_platform }}
|
||||
bazel: ${{ bazel }}
|
||||
build_flags:
|
||||
- --cxxopt=-std=c++20
|
||||
build_targets:
|
||||
- '@ftxui//:dom'
|
||||
- '@ftxui//:component'
|
||||
- '@ftxui//:screen'
|
||||
|
||||
windows_test:
|
||||
name: Verify build targets
|
||||
platform: ${{ win_platform }}
|
||||
bazel: ${{ bazel }}
|
||||
build_flags:
|
||||
- --cxxopt=/std:c++20
|
||||
build_targets:
|
||||
- '@ftxui//:dom'
|
||||
- '@ftxui//:component'
|
||||
- '@ftxui//:screen'
|
5
.bcr/source.template.json
Normal file
5
.bcr/source.template.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"integrity": "",
|
||||
"strip_prefix": "",
|
||||
"url": "https://github.com/ArthurSonzogni/FTXUI/releases/download/{TAG}/source.tar.gz"
|
||||
}
|
@@ -2,3 +2,6 @@
|
||||
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
|
||||
BasedOnStyle: Chromium
|
||||
Standard: Cpp11
|
||||
|
||||
InsertBraces: true
|
||||
InsertNewlineAtEOF: true
|
||||
|
174
.github/workflows/build.yaml
vendored
174
.github/workflows/build.yaml
vendored
@@ -1,17 +1,63 @@
|
||||
name: Build
|
||||
|
||||
on:
|
||||
create:
|
||||
# On new commits to main:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
# On pull requests:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: "Tests"
|
||||
|
||||
test_bazel:
|
||||
name: "Bazel, ${{ matrix.cxx }}, ${{ matrix.os }}"
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
cxx: g++
|
||||
cc: gcc
|
||||
|
||||
- os: ubuntu-latest
|
||||
cxx: clang++
|
||||
cc: clang
|
||||
|
||||
- os: macos-latest
|
||||
cxx: g++
|
||||
cc: gcc
|
||||
|
||||
- os: macos-latest
|
||||
cxx: clang++
|
||||
cc: clang
|
||||
|
||||
- os: windows-latest
|
||||
cxx: cl
|
||||
cc: cl
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: "Checkout repository"
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: "Build with Bazel"
|
||||
env:
|
||||
CC: ${{ matrix.cc }}
|
||||
CXX: ${{ matrix.cxx }}
|
||||
run: bazel build ...
|
||||
|
||||
- name: "Tests with Bazel"
|
||||
env:
|
||||
CC: ${{ matrix.cc }}
|
||||
CXX: ${{ matrix.cxx }}
|
||||
run: bazel test --test_output=all ...
|
||||
|
||||
test_cmake:
|
||||
name: "CMake, ${{ matrix.compiler }}, ${{ matrix.os }}"
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@@ -104,7 +150,7 @@ jobs:
|
||||
--gcov-executable '${{ matrix.gcov_executable }}';
|
||||
|
||||
- name: Windows - Test and coverage
|
||||
if: runner.os == 'Windows' && false
|
||||
if: runner.os == 'Windows'
|
||||
working-directory: ./build
|
||||
run: >
|
||||
OpenCppCoverage.exe
|
||||
@@ -120,118 +166,46 @@ jobs:
|
||||
name: ${{ runner.os }}-coverage
|
||||
files: ./build/coverage.xml
|
||||
|
||||
# Create a release on new v* tags
|
||||
release:
|
||||
needs: test
|
||||
if: ${{ github.event_name == 'create' && startsWith(github.ref, 'refs/tags/v') }}
|
||||
name: "Create release"
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
steps:
|
||||
- name: "Create release"
|
||||
uses: softprops/action-gh-release@v1
|
||||
id: create_release
|
||||
with:
|
||||
draft: true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
# Build artifact for the release
|
||||
package:
|
||||
name: "Build packages"
|
||||
needs: release
|
||||
test_modules:
|
||||
name: "Test modules"
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
asset_path: build/ftxui*Linux*
|
||||
- os: macos-latest
|
||||
asset_path: build/ftxui*Darwin*
|
||||
- os: windows-latest
|
||||
asset_path: build/ftxui*Win64*
|
||||
compiler: llvm
|
||||
# TODO add gcc / msvc
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Get number of CPU cores
|
||||
uses: SimenB/github-actions-cpu-cores@v1
|
||||
id: cpu-cores
|
||||
|
||||
- name: "Checkout repository"
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: "Install cmake"
|
||||
uses: lukka/get-cmake@latest
|
||||
- name: "Setup Cpp"
|
||||
uses: aminya/setup-cpp@v1
|
||||
with:
|
||||
compiler: ${{ matrix.compiler }}
|
||||
vcvarsall: ${{ contains(matrix.os, 'windows' )}}
|
||||
cmake: true
|
||||
ninja: true
|
||||
clangtidy: false
|
||||
cppcheck: false
|
||||
opencppcoverage: false
|
||||
|
||||
- name: "Build packages"
|
||||
- name: "Generate ./examples_modules"
|
||||
run: >
|
||||
./tools/generate_examples_modules.sh
|
||||
|
||||
- name: "Build modules"
|
||||
run: >
|
||||
mkdir build;
|
||||
cd build;
|
||||
cmake ..
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
-DCMAKE_BUILD_PARALLEL_LEVEL=${{ steps.cpu-cores.outputs.count }}
|
||||
-DCMAKE_GENERATOR=Ninja
|
||||
-DFTXUI_BUILD_MODULES=ON
|
||||
-DFTXUI_BUILD_EXAMPLES=ON
|
||||
-DCMAKE_BUILD_TYPE=Debug
|
||||
-DFTXUI_BUILD_DOCS=OFF
|
||||
-DFTXUI_BUILD_EXAMPLES=OFF
|
||||
-DFTXUI_BUILD_TESTS=OFF
|
||||
-DFTXUI_BUILD_TESTS_FUZZER=OFF
|
||||
-DFTXUI_ENABLE_INSTALL=ON
|
||||
-DFTXUI_DEV_WARNINGS=ON ;
|
||||
cmake --build . --target package;
|
||||
|
||||
- uses: shogo82148/actions-upload-release-asset@v1
|
||||
with:
|
||||
upload_url: ${{ needs.release.outputs.upload_url }}
|
||||
asset_path: ${{ matrix.asset_path }}
|
||||
overwrite: true
|
||||
|
||||
documentation:
|
||||
if: github.ref == 'refs/heads/main'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: "Checkout repository"
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: "Install cmake"
|
||||
uses: lukka/get-cmake@latest
|
||||
|
||||
- name: "Install emsdk"
|
||||
uses: mymindstorm/setup-emsdk@v7
|
||||
|
||||
- name: "Install Doxygen/Graphviz"
|
||||
run: >
|
||||
sudo apt-get update;
|
||||
sudo apt-get install doxygen graphviz;
|
||||
|
||||
- name: "Build documentation"
|
||||
run: >
|
||||
mkdir build;
|
||||
cd build;
|
||||
emcmake cmake ..
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
-DFTXUI_BUILD_DOCS=ON
|
||||
-DFTXUI_BUILD_EXAMPLES=ON
|
||||
-DFTXUI_BUILD_TESTS=OFF
|
||||
-DFTXUI_BUILD_TESTS_FUZZER=OFF
|
||||
-DFTXUI_ENABLE_INSTALL=OFF
|
||||
-DFTXUI_DEV_WARNINGS=ON ;
|
||||
cmake --build . --target doc;
|
||||
cmake --build . ;
|
||||
rsync -amv
|
||||
--include='*/'
|
||||
--include='*.html'
|
||||
--include='*.css'
|
||||
--include='*.mjs'
|
||||
--include='*.js'
|
||||
--include='*.wasm'
|
||||
--exclude='*'
|
||||
examples
|
||||
doc/doxygen/html;
|
||||
|
||||
- name: "Deploy"
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: build/doc/doxygen/html/
|
||||
enable_jekyll: false
|
||||
allow_empty_commit: false
|
||||
force_orphan: true
|
||||
publish_branch: gh-pages
|
||||
cmake --build .
|
||||
|
65
.github/workflows/documentation.yaml
vendored
Normal file
65
.github/workflows/documentation.yaml
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
name: Documentation
|
||||
|
||||
on:
|
||||
# On new commits to main:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
documentation:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: "Checkout repository"
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: "Install cmake"
|
||||
uses: lukka/get-cmake@latest
|
||||
|
||||
- name: "Install emsdk"
|
||||
uses: mymindstorm/setup-emsdk@v7
|
||||
|
||||
- name: "Install Doxygen"
|
||||
uses: ssciwr/doxygen-install@v1
|
||||
with:
|
||||
version: '1.12.0'
|
||||
|
||||
- name: "Install Graphviz"
|
||||
run: >
|
||||
sudo apt-get update;
|
||||
sudo apt-get install graphviz;
|
||||
|
||||
- name: "Build documentation"
|
||||
run: >
|
||||
mkdir build;
|
||||
cd build;
|
||||
emcmake cmake ..
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
-DFTXUI_BUILD_DOCS=ON
|
||||
-DFTXUI_BUILD_EXAMPLES=ON
|
||||
-DFTXUI_BUILD_TESTS=OFF
|
||||
-DFTXUI_BUILD_TESTS_FUZZER=OFF
|
||||
-DFTXUI_ENABLE_INSTALL=OFF
|
||||
-DFTXUI_DEV_WARNINGS=OFF;
|
||||
cmake --build . --target doc;
|
||||
cmake --build . ;
|
||||
rsync -amv
|
||||
--include='*/'
|
||||
--include='*.html'
|
||||
--include='*.css'
|
||||
--include='*.mjs'
|
||||
--include='*.js'
|
||||
--include='*.wasm'
|
||||
--exclude='*'
|
||||
examples
|
||||
doc/doxygen/html;
|
||||
|
||||
- name: "Deploy"
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: build/doc/doxygen/html/
|
||||
enable_jekyll: false
|
||||
allow_empty_commit: false
|
||||
force_orphan: true
|
||||
publish_branch: gh-pages
|
24
.github/workflows/publish.yaml
vendored
Normal file
24
.github/workflows/publish.yaml
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
name: "Publish to Bazel Central Registry"
|
||||
|
||||
on:
|
||||
# Manual kick-off (you type the tag)
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag_name:
|
||||
description: "Tag to publish"
|
||||
required: true
|
||||
type: string
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
uses: bazel-contrib/publish-to-bcr/.github/workflows/publish.yaml@v0.0.4
|
||||
with:
|
||||
tag_name: ${{ github.event.inputs.tag_name }}
|
||||
registry_fork: ArthurSonzogni/bazel-central-registry
|
||||
attest: false
|
||||
|
||||
secrets:
|
||||
publish_token: ${{ secrets.PUBLISH_TOKEN }}
|
100
.github/workflows/release.yaml
vendored
Normal file
100
.github/workflows/release.yaml
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
# On push to a tag:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
# On manual trigger:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
# Needed to mint attestations
|
||||
id-token: write
|
||||
attestations: write
|
||||
# Needed to upload release assets
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: "Create release"
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
steps:
|
||||
- name: "Create release"
|
||||
uses: softprops/action-gh-release@v1
|
||||
id: create_release
|
||||
with:
|
||||
draft: true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
# Build artifact for the release
|
||||
package_compiled:
|
||||
name: "Build packages"
|
||||
needs: release
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
asset_path: build/ftxui*Linux*
|
||||
- os: macos-latest
|
||||
asset_path: build/ftxui*Darwin*
|
||||
- os: windows-latest
|
||||
asset_path: build/ftxui*Win64*
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Get number of CPU cores
|
||||
uses: SimenB/github-actions-cpu-cores@v1
|
||||
id: cpu-cores
|
||||
|
||||
- name: "Checkout repository"
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: "Install cmake"
|
||||
uses: lukka/get-cmake@latest
|
||||
|
||||
- name: "Build packages"
|
||||
run: >
|
||||
mkdir build;
|
||||
cd build;
|
||||
cmake ..
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
-DCMAKE_BUILD_PARALLEL_LEVEL=${{ steps.cpu-cores.outputs.count }}
|
||||
-DFTXUI_BUILD_DOCS=OFF
|
||||
-DFTXUI_BUILD_EXAMPLES=OFF
|
||||
-DFTXUI_BUILD_TESTS=OFF
|
||||
-DFTXUI_BUILD_TESTS_FUZZER=OFF
|
||||
-DFTXUI_ENABLE_INSTALL=ON
|
||||
-DFTXUI_DEV_WARNINGS=ON ;
|
||||
cmake --build . --target package;
|
||||
|
||||
- uses: shogo82148/actions-upload-release-asset@v1
|
||||
with:
|
||||
upload_url: ${{ needs.release.outputs.upload_url }}
|
||||
asset_path: ${{ matrix.asset_path }}
|
||||
overwrite: true
|
||||
|
||||
# Build "source" artifact for the release. This is the same as the github
|
||||
# "source" archive, but with a stable URL. This is useful for the Bazel
|
||||
# Central Repository.
|
||||
package_source:
|
||||
name: "Build source package"
|
||||
needs: release
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: "Checkout repository"
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: "Create source package"
|
||||
run: >
|
||||
git archive --format=tar.gz -o source.tar.gz HEAD
|
||||
|
||||
- name: "Upload source package"
|
||||
uses: shogo82148/actions-upload-release-asset@v1
|
||||
with:
|
||||
upload_url: ${{ needs.release.outputs.upload_url }}
|
||||
asset_path: source.tar.gz
|
||||
overwrite: true
|
11
.gitignore
vendored
11
.gitignore
vendored
@@ -20,6 +20,10 @@ out/
|
||||
!flake.nix
|
||||
!ftxui.pc.in
|
||||
!iwyu.imp
|
||||
!WORKSPACE.bazel
|
||||
!BUILD.bazel
|
||||
!MODULE.bazel
|
||||
!.bazelrc
|
||||
|
||||
# .github directory:
|
||||
!.github/**/*.yaml
|
||||
@@ -29,6 +33,10 @@ out/
|
||||
!cmake/**/*.in
|
||||
!cmake/**/*.cmake
|
||||
|
||||
# bazel directory:
|
||||
!bazel/**/*.bzl
|
||||
!.bcr/*
|
||||
|
||||
# doc directory:
|
||||
!doc/**/Doxyfile.in
|
||||
!doc/**/*.txt
|
||||
@@ -36,6 +44,7 @@ out/
|
||||
!doc/**/*.html
|
||||
!doc/**/*.xml
|
||||
!doc/**/*.md
|
||||
!doc/*.md
|
||||
|
||||
# examples directory:
|
||||
!examples/**/*.cpp
|
||||
@@ -54,8 +63,10 @@ out/
|
||||
!include/ftxui/**/*.cpp
|
||||
|
||||
# src directory:
|
||||
!src/ftxui/*.cppm
|
||||
!src/ftxui/**/*.hpp
|
||||
!src/ftxui/**/*.cpp
|
||||
!src/ftxui/**/*.cppm
|
||||
|
||||
# tools directory:
|
||||
!tools/**/*.sh
|
||||
|
274
BUILD.bazel
Normal file
274
BUILD.bazel
Normal file
@@ -0,0 +1,274 @@
|
||||
# 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.
|
||||
|
||||
# TODO:
|
||||
# - Build benchmark.
|
||||
# - Build fuzzers.
|
||||
# - Build documentation.
|
||||
# - Enable the two tests timing out.
|
||||
# - Support WebAssembly
|
||||
|
||||
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")
|
||||
|
||||
# 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
|
||||
# component.
|
||||
# ┌component──┐
|
||||
# │┌dom──────┐│
|
||||
# ││┌screen─┐││
|
||||
# └┴┴───────┴┴┘
|
||||
alias(name = "ftxui", actual = ":component")
|
||||
|
||||
# @ftxui:screen is a module that provides a screen buffer and color management
|
||||
# for terminal applications. A screen is a 2D array of cells, each cell can
|
||||
# contain a glyph, a color, and other attributes. The library also provides
|
||||
# functions to manipulate the screen.
|
||||
ftxui_cc_library(
|
||||
name = "screen",
|
||||
srcs = [
|
||||
"src/ftxui/screen/box.cpp",
|
||||
"src/ftxui/screen/color.cpp",
|
||||
"src/ftxui/screen/color_info.cpp",
|
||||
"src/ftxui/screen/image.cpp",
|
||||
"src/ftxui/screen/screen.cpp",
|
||||
"src/ftxui/screen/string.cpp",
|
||||
"src/ftxui/screen/string_internal.hpp",
|
||||
"src/ftxui/screen/terminal.cpp",
|
||||
"src/ftxui/screen/util.hpp",
|
||||
],
|
||||
hdrs = [
|
||||
"include/ftxui/screen/box.hpp",
|
||||
"include/ftxui/screen/color.hpp",
|
||||
"include/ftxui/screen/color_info.hpp",
|
||||
"include/ftxui/screen/deprecated.hpp",
|
||||
"include/ftxui/screen/image.hpp",
|
||||
"include/ftxui/screen/pixel.hpp",
|
||||
"include/ftxui/screen/screen.hpp",
|
||||
"include/ftxui/screen/string.hpp",
|
||||
"include/ftxui/screen/terminal.hpp",
|
||||
"include/ftxui/util/autoreset.hpp",
|
||||
"include/ftxui/util/ref.hpp",
|
||||
],
|
||||
)
|
||||
|
||||
# @ftxui:dom is a library that provides a way to create and manipulate a
|
||||
# "document" that can be rendered to a screen. The document is a tree of nodes.
|
||||
# Nodes can be text, layouts, or various decorators. Users needs to compose
|
||||
# nodes to create a document. A document is responsive to the size of the
|
||||
# screen.
|
||||
ftxui_cc_library(
|
||||
name = "dom",
|
||||
srcs = [
|
||||
"src/ftxui/dom/automerge.cpp",
|
||||
"src/ftxui/dom/blink.cpp",
|
||||
"src/ftxui/dom/bold.cpp",
|
||||
"src/ftxui/dom/border.cpp",
|
||||
"src/ftxui/dom/box_helper.cpp",
|
||||
"src/ftxui/dom/box_helper.hpp",
|
||||
"src/ftxui/dom/canvas.cpp",
|
||||
"src/ftxui/dom/clear_under.cpp",
|
||||
"src/ftxui/dom/color.cpp",
|
||||
"src/ftxui/dom/composite_decorator.cpp",
|
||||
"src/ftxui/dom/dbox.cpp",
|
||||
"src/ftxui/dom/dim.cpp",
|
||||
"src/ftxui/dom/flex.cpp",
|
||||
"src/ftxui/dom/flexbox.cpp",
|
||||
"src/ftxui/dom/flexbox_config.cpp",
|
||||
"src/ftxui/dom/flexbox_helper.cpp",
|
||||
"src/ftxui/dom/flexbox_helper.hpp",
|
||||
"src/ftxui/dom/focus.cpp",
|
||||
"src/ftxui/dom/frame.cpp",
|
||||
"src/ftxui/dom/gauge.cpp",
|
||||
"src/ftxui/dom/graph.cpp",
|
||||
"src/ftxui/dom/gridbox.cpp",
|
||||
"src/ftxui/dom/hbox.cpp",
|
||||
"src/ftxui/dom/hyperlink.cpp",
|
||||
"src/ftxui/dom/inverted.cpp",
|
||||
"src/ftxui/dom/italic.cpp",
|
||||
"src/ftxui/dom/linear_gradient.cpp",
|
||||
"src/ftxui/dom/node.cpp",
|
||||
"src/ftxui/dom/node_decorator.cpp",
|
||||
"src/ftxui/dom/node_decorator.hpp",
|
||||
"src/ftxui/dom/paragraph.cpp",
|
||||
"src/ftxui/dom/reflect.cpp",
|
||||
"src/ftxui/dom/scroll_indicator.cpp",
|
||||
"src/ftxui/dom/selection.cpp",
|
||||
"src/ftxui/dom/selection_style.cpp",
|
||||
"src/ftxui/dom/separator.cpp",
|
||||
"src/ftxui/dom/size.cpp",
|
||||
"src/ftxui/dom/spinner.cpp",
|
||||
"src/ftxui/dom/strikethrough.cpp",
|
||||
"src/ftxui/dom/table.cpp",
|
||||
"src/ftxui/dom/text.cpp",
|
||||
"src/ftxui/dom/underlined.cpp",
|
||||
"src/ftxui/dom/underlined_double.cpp",
|
||||
"src/ftxui/dom/util.cpp",
|
||||
"src/ftxui/dom/vbox.cpp",
|
||||
],
|
||||
hdrs = [
|
||||
"include/ftxui/dom/canvas.hpp",
|
||||
"include/ftxui/dom/deprecated.hpp",
|
||||
"include/ftxui/dom/direction.hpp",
|
||||
"include/ftxui/dom/elements.hpp",
|
||||
"include/ftxui/dom/flexbox_config.hpp",
|
||||
"include/ftxui/dom/linear_gradient.hpp",
|
||||
"include/ftxui/dom/node.hpp",
|
||||
"include/ftxui/dom/requirement.hpp",
|
||||
"include/ftxui/dom/selection.hpp",
|
||||
"include/ftxui/dom/table.hpp",
|
||||
"include/ftxui/dom/take_any_args.hpp",
|
||||
],
|
||||
deps = [":screen"],
|
||||
)
|
||||
|
||||
# @ftxui:component is a library to create "dynamic" component renderering and
|
||||
# updating a ftxui::dom document on the screen. It is a higher level API than
|
||||
# ftxui:dom.
|
||||
#
|
||||
# The module is required if your program needs to respond to user input. It
|
||||
# defines a set of ftxui::Component. These components can be utilized to
|
||||
# navigate using the arrow keys and/or cursor. There are several builtin widgets
|
||||
# like checkbox/inputbox/etc to interact with. You can combine them, or even
|
||||
# define your own custom components.
|
||||
ftxui_cc_library(
|
||||
name = "component",
|
||||
srcs = [
|
||||
"src/ftxui/component/animation.cpp",
|
||||
"src/ftxui/component/button.cpp",
|
||||
"src/ftxui/component/catch_event.cpp",
|
||||
"src/ftxui/component/checkbox.cpp",
|
||||
"src/ftxui/component/collapsible.cpp",
|
||||
"src/ftxui/component/component.cpp",
|
||||
"src/ftxui/component/component_options.cpp",
|
||||
"src/ftxui/component/container.cpp",
|
||||
"src/ftxui/component/dropdown.cpp",
|
||||
"src/ftxui/component/event.cpp",
|
||||
"src/ftxui/component/hoverable.cpp",
|
||||
"src/ftxui/component/input.cpp",
|
||||
"src/ftxui/component/loop.cpp",
|
||||
"src/ftxui/component/maybe.cpp",
|
||||
"src/ftxui/component/menu.cpp",
|
||||
"src/ftxui/component/modal.cpp",
|
||||
"src/ftxui/component/radiobox.cpp",
|
||||
"src/ftxui/component/renderer.cpp",
|
||||
"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",
|
||||
|
||||
|
||||
# Private header from ftxui:dom.
|
||||
"src/ftxui/dom/node_decorator.hpp",
|
||||
|
||||
# Private header from ftxui:screen.
|
||||
"src/ftxui/screen/string_internal.hpp",
|
||||
"src/ftxui/screen/util.hpp",
|
||||
],
|
||||
hdrs = [
|
||||
"include/ftxui/component/animation.hpp",
|
||||
"include/ftxui/component/captured_mouse.hpp",
|
||||
"include/ftxui/component/component.hpp",
|
||||
"include/ftxui/component/component_base.hpp",
|
||||
"include/ftxui/component/component_options.hpp",
|
||||
"include/ftxui/component/event.hpp",
|
||||
"include/ftxui/component/loop.hpp",
|
||||
"include/ftxui/component/mouse.hpp",
|
||||
"include/ftxui/component/receiver.hpp",
|
||||
"include/ftxui/component/screen_interactive.hpp",
|
||||
"include/ftxui/component/task.hpp",
|
||||
],
|
||||
deps = [
|
||||
":dom",
|
||||
":screen",
|
||||
],
|
||||
)
|
||||
|
||||
# FTXUI's tests
|
||||
cc_test(
|
||||
name = "tests",
|
||||
testonly = True,
|
||||
srcs = [
|
||||
"src/ftxui/component/animation_test.cpp",
|
||||
"src/ftxui/component/button_test.cpp",
|
||||
"src/ftxui/component/collapsible_test.cpp",
|
||||
"src/ftxui/component/component_test.cpp",
|
||||
"src/ftxui/component/container_test.cpp",
|
||||
"src/ftxui/component/dropdown_test.cpp",
|
||||
"src/ftxui/component/hoverable_test.cpp",
|
||||
"src/ftxui/component/input_test.cpp",
|
||||
"src/ftxui/component/menu_test.cpp",
|
||||
"src/ftxui/component/modal_test.cpp",
|
||||
"src/ftxui/component/radiobox_test.cpp",
|
||||
"src/ftxui/component/resizable_split_test.cpp",
|
||||
"src/ftxui/component/slider_test.cpp",
|
||||
"src/ftxui/component/terminal_input_parser_test.cpp",
|
||||
"src/ftxui/component/toggle_test.cpp",
|
||||
"src/ftxui/dom/blink_test.cpp",
|
||||
"src/ftxui/dom/bold_test.cpp",
|
||||
"src/ftxui/dom/border_test.cpp",
|
||||
"src/ftxui/dom/canvas_test.cpp",
|
||||
"src/ftxui/dom/color_test.cpp",
|
||||
"src/ftxui/dom/dbox_test.cpp",
|
||||
"src/ftxui/dom/dim_test.cpp",
|
||||
"src/ftxui/dom/flexbox_helper_test.cpp",
|
||||
"src/ftxui/dom/flexbox_test.cpp",
|
||||
"src/ftxui/dom/gauge_test.cpp",
|
||||
"src/ftxui/dom/gridbox_test.cpp",
|
||||
"src/ftxui/dom/hbox_test.cpp",
|
||||
"src/ftxui/dom/hyperlink_test.cpp",
|
||||
"src/ftxui/dom/italic_test.cpp",
|
||||
"src/ftxui/dom/linear_gradient_test.cpp",
|
||||
"src/ftxui/dom/scroll_indicator_test.cpp",
|
||||
"src/ftxui/dom/separator_test.cpp",
|
||||
"src/ftxui/dom/spinner_test.cpp",
|
||||
"src/ftxui/dom/table_test.cpp",
|
||||
"src/ftxui/dom/text_test.cpp",
|
||||
"src/ftxui/dom/underlined_test.cpp",
|
||||
"src/ftxui/dom/vbox_test.cpp",
|
||||
"src/ftxui/screen/color_test.cpp",
|
||||
"src/ftxui/screen/string_test.cpp",
|
||||
"src/ftxui/util/ref_test.cpp",
|
||||
|
||||
# Private header from ftxui:screen for string_test.cpp.
|
||||
"src/ftxui/screen/string_internal.hpp",
|
||||
|
||||
# Private header from ftxui::component for
|
||||
# terminal_input_parser_test.cpp.
|
||||
"src/ftxui/component/terminal_input_parser.hpp",
|
||||
|
||||
# Private header from ftxui::dom for
|
||||
# flexbox_helper_test.cpp.
|
||||
"src/ftxui/dom/flexbox_helper.hpp",
|
||||
|
||||
# TODO: Enable the two tests timing out with Bazel:
|
||||
# - "src/ftxui/component/screen_interactive_test.cpp",
|
||||
# - "src/ftxui/dom/selection_test.cpp",
|
||||
],
|
||||
includes = [
|
||||
"include",
|
||||
"src",
|
||||
],
|
||||
copts = windows_copts(),
|
||||
deps = [
|
||||
":screen",
|
||||
":dom",
|
||||
":component",
|
||||
"@googletest//:gtest",
|
||||
"@googletest//:gtest_main",
|
||||
],
|
||||
)
|
||||
|
||||
generate_examples()
|
100
CHANGELOG.md
100
CHANGELOG.md
@@ -1,8 +1,100 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
current (development)
|
||||
---------------------
|
||||
Next
|
||||
====
|
||||
|
||||
### Doc
|
||||
- Fix broken Doxygen output. See @markmandel in #1029.
|
||||
- Use Doxygen awesome. Add our own theme.
|
||||
- Break the documentation into several pages.
|
||||
|
||||
### Build
|
||||
- Feature: Support C++20 modules.
|
||||
This requires:
|
||||
- Using the Ninja or MSVC generator
|
||||
- A recent Clang/GCC/MSVC compiler.
|
||||
- Cmake 3.28 or higher.
|
||||
Usage:
|
||||
```cpp
|
||||
import ftxui;
|
||||
import ftxui.component;
|
||||
import ftxui.dom;
|
||||
import ftxui.screen;
|
||||
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.
|
||||
|
||||
|
||||
6.1.9 (2025-05-07)
|
||||
------------
|
||||
|
||||
### Build
|
||||
If all goes well (pending), ftxui should appear in the Bazel central repository.
|
||||
It can be imported into your project using the following lines:
|
||||
|
||||
**MODULE.bazel**
|
||||
```bazel
|
||||
bazel_dep(name = "ftxui", version = "6.1.9")
|
||||
```
|
||||
|
||||
Thanks @robinlinden and @kcc for the reviews.
|
||||
|
||||
### dom
|
||||
- Bugfix: Restore the `dbox` behavior from ftxui 5.0.0. To apply bgcolor
|
||||
blending between the two layers, a new `dboxBlend` will be added.
|
||||
|
||||
6.1.8 (2025-05-01)
|
||||
------------------
|
||||
|
||||
### Build
|
||||
- Feature: Support `bazel` build system. See #1032.
|
||||
Proposed by Kostya Serebryany @kcc
|
||||
|
||||
**BUILD.bazel**
|
||||
```bazel
|
||||
deps = [
|
||||
// Depend on the whole library:
|
||||
"@ftxui//:ftxui",
|
||||
|
||||
// Choose a specific submodule:
|
||||
"@ftxui//:component",
|
||||
"@ftxui//:dom",
|
||||
"@ftxui//:screen",
|
||||
]
|
||||
```
|
||||
|
||||
### Component
|
||||
- Bugfix: Fix a crash with ResizeableSplit. See #1023.
|
||||
- Clamp screen size to terminal size.
|
||||
- Disallow `ResizeableSplit` with negative size.
|
||||
|
||||
### Dom
|
||||
- Bugfix: Disallow specifying a negative size constraint. See #1023.
|
||||
|
||||
|
||||
6.0.2 (2025-03-30)
|
||||
-----
|
||||
|
||||
### Component
|
||||
- BugFix: Fix major crash on Windows affecting all components. See #1020
|
||||
- BugFix: Fix focusRelative.
|
||||
|
||||
6.0.1 (2025-03-28)
|
||||
-----
|
||||
|
||||
Same as v6.0.0.
|
||||
|
||||
Due to a problem tag v6.0.0 was replaced. This isn't a good practice and affect
|
||||
developers that started using it in the short timeframe. Submitting a new
|
||||
release with the same content is the best way to fix this.
|
||||
|
||||
See #1017 and #1019.
|
||||
|
||||
6.0.0 (2025-03-23)
|
||||
-----
|
||||
@@ -74,6 +166,10 @@ current (development)
|
||||
- See `selectionStyleReset` decorator.
|
||||
- Breaking change: Change how "focus"/"select" are handled. This fixes the
|
||||
behavior.
|
||||
- Breaking change: `Component::OnRender()` becomes the method to override to
|
||||
render a component. This replaces `Component::Render()` that is still in use
|
||||
to call the rendering method on the children. This change allows to fix a
|
||||
couple of issues around focus handling.
|
||||
|
||||
### Screen
|
||||
- Feature: Add `Box::IsEmpty()`.
|
||||
|
@@ -1,20 +1,26 @@
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
option(FTXUI_BUILD_DOCS "Set to ON to build docs" OFF)
|
||||
option(FTXUI_BUILD_EXAMPLES "Set to ON to build examples" OFF)
|
||||
option(FTXUI_BUILD_MODULES "Build the C++20 modules" OFF)
|
||||
option(FTXUI_BUILD_TESTS "Set to ON to build tests" OFF)
|
||||
option(FTXUI_BUILD_TESTS_FUZZER "Set to ON to enable fuzzing" OFF)
|
||||
option(FTXUI_CLANG_TIDY "Execute clang-tidy" OFF)
|
||||
option(FTXUI_DEV_WARNINGS "Enable more compiler warnings and warnings as errors" OFF)
|
||||
option(FTXUI_ENABLE_COVERAGE "Execute code coverage" OFF)
|
||||
option(FTXUI_ENABLE_INSTALL "Generate the install target" ON)
|
||||
option(FTXUI_QUIET "Set to ON for FTXUI to be quiet" OFF)
|
||||
|
||||
if (FTXUI_BUILD_MODULES)
|
||||
cmake_minimum_required(VERSION 3.28.2)
|
||||
else()
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
endif()
|
||||
|
||||
project(ftxui
|
||||
LANGUAGES CXX
|
||||
VERSION 6.0.0
|
||||
VERSION 6.1.9
|
||||
DESCRIPTION "C++ Functional Terminal User Interface."
|
||||
)
|
||||
|
||||
option(FTXUI_QUIET "Set to ON for FTXUI to be quiet" OFF)
|
||||
option(FTXUI_BUILD_EXAMPLES "Set to ON to build examples" OFF)
|
||||
option(FTXUI_BUILD_DOCS "Set to ON to build docs" OFF)
|
||||
option(FTXUI_BUILD_TESTS "Set to ON to build tests" OFF)
|
||||
option(FTXUI_BUILD_TESTS_FUZZER "Set to ON to enable fuzzing" OFF)
|
||||
option(FTXUI_ENABLE_INSTALL "Generate the install target" ON)
|
||||
option(FTXUI_CLANG_TIDY "Execute clang-tidy" OFF)
|
||||
option(FTXUI_ENABLE_COVERAGE "Execute code coverage" OFF)
|
||||
option(FTXUI_DEV_WARNINGS "Enable more compiler warnings and warnings as errors" OFF)
|
||||
|
||||
set(FTXUI_MICROSOFT_TERMINAL_FALLBACK_HELP_TEXT "On windows, assume the \
|
||||
terminal used will be one of Microsoft and use a set of reasonnable fallback \
|
||||
@@ -138,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)
|
||||
@@ -176,6 +176,13 @@ include(cmake/iwyu.cmake)
|
||||
include(cmake/ftxui_export.cmake)
|
||||
include(cmake/ftxui_install.cmake)
|
||||
include(cmake/ftxui_package.cmake)
|
||||
include(cmake/ftxui_modules.cmake)
|
||||
|
||||
add_subdirectory(examples)
|
||||
add_subdirectory(doc)
|
||||
add_subdirectory(examples)
|
||||
|
||||
# You can generate ./examples_modules/ by running
|
||||
# ./tools/generate_examples_modules.sh
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/examples_modules/CMakeLists.txt")
|
||||
add_subdirectory(examples_modules)
|
||||
endif()
|
||||
|
13
MODULE.bazel
Normal file
13
MODULE.bazel
Normal file
@@ -0,0 +1,13 @@
|
||||
# FTXUI module.
|
||||
module(
|
||||
name = "ftxui",
|
||||
version = "6.1.9",
|
||||
compatibility_level = 6,
|
||||
)
|
||||
|
||||
# Build dependencies.
|
||||
bazel_dep(name = "rules_cc", version = "0.1.1")
|
||||
bazel_dep(name = "platforms", version = "0.0.10")
|
||||
|
||||
# Test dependencies.
|
||||
bazel_dep(name = "googletest", version = "1.14.0.bcr.1", dev_dependency = True)
|
85
README.md
85
README.md
@@ -18,7 +18,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>
|
||||
|
||||
@@ -39,18 +39,30 @@ A simple cross-platform C++ library for terminal based user interfaces!
|
||||
* Support for [UTF8](https://en.wikipedia.org/wiki/UTF-8) and [fullwidth chars](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) (→ 测试)
|
||||
* Support for animations. [Demo 1](https://arthursonzogni.github.io/FTXUI/examples/?file=component/menu_underline_animated_gallery), [Demo 2](https://arthursonzogni.github.io/FTXUI/examples/?file=component/button_style)
|
||||
* Support for drawing. [Demo](https://arthursonzogni.github.io/FTXUI/examples/?file=component/canvas_animated)
|
||||
* No dependencies
|
||||
* No dependencies.
|
||||
* [C++20 Module support](https://arthursonzogni.github.io/FTXUI/cpp20-modules.html)
|
||||
* **Cross platform**: Linux/MacOS (main target), WebAssembly, Windows (Thanks to contributors!).
|
||||
* Learn by [examples](#documentation), and [tutorials](#documentation)
|
||||
* Multiple packages: CMake [FetchContent]([https://bewagner.net/programming/2020/05/02/cmake-fetchcontent/](https://cmake.org/cmake/help/latest/module/FetchContent.html)) (preferred), vcpkg, pkgbuild, conan.
|
||||
* Multiple packages:
|
||||
- CMake [FetchContent]([https://bewagner.net/programming/2020/05/02/cmake-fetchcontent/](https://cmake.org/cmake/help/latest/module/FetchContent.html)) (preferred)
|
||||
- [Bazel](https://registry.bazel.build/modules/ftxui)
|
||||
- [vcpkg](https://vcpkg.link/ports/ftxui)
|
||||
- [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)
|
||||
- [Nix](https://github.com/ArthurSonzogni/FTXUI/blob/main/flake.nix)
|
||||
* Good practices: documentation, tests, fuzzers, performance tests, automated CI, automated packaging, etc...
|
||||
|
||||
## Documentation
|
||||
|
||||
- [Starter example project](https://github.com/ArthurSonzogni/ftxui-starter)
|
||||
- [Starter CMake](https://github.com/ArthurSonzogni/ftxui-starter)
|
||||
- [Starter Bazel](https://github.com/ArthurSonzogni/ftxui-bazel)
|
||||
- [Documentation](https://arthursonzogni.github.io/FTXUI/)
|
||||
- [Examples (WebAssembly)](https://arthursonzogni.github.io/FTXUI/examples/)
|
||||
- [Build using CMake](https://arthursonzogni.github.io/FTXUI/#build-cmake)
|
||||
- [Build using Bazel](https://arthursonzogni.github.io/FTXUI/#build-bazel)
|
||||
|
||||
## Example
|
||||
~~~cpp
|
||||
@@ -86,7 +98,7 @@ Element can be arranged together:
|
||||
- inside a grid with `gridbox`
|
||||
- wrap along one direction using the `flexbox`.
|
||||
|
||||
Element can become flexible using the the `flex` decorator.
|
||||
Element can become flexible using the `flex` decorator.
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2dom_2vbox_hbox_8cpp-example.html) using `hbox`, `vbox` and `filler`.
|
||||
|
||||
@@ -348,6 +360,8 @@ Feel free to add your projects here:
|
||||
- [terminal-rain](https://github.com/Oakamoore/terminal-rain)
|
||||
- [keywords](https://github.com/Oakamoore/keywords) ([Play web version :heart:](https://oakamoore.itch.io/keywords))
|
||||
- [FTB - tertminal file browser](https://github.com/Cyxuan0311/FTB)
|
||||
- [openJuice](https://github.com/mikomikotaishi/openJuice)
|
||||
- [SHOOT!](https://github.com/ShingZhanho/ENGG1340-Project-25Spring)
|
||||
|
||||
### [cpp-best-practices/game_jam](https://github.com/cpp-best-practices/game_jam)
|
||||
|
||||
@@ -364,38 +378,71 @@ Several games using the FTXUI have been made during the Game Jam:
|
||||
- [smoothlife](https://github.com/cpp-best-practices/game_jam/blob/main/Jam1_April_2022/smoothlife.md)
|
||||
- [Consu](https://github.com/cpp-best-practices/game_jam/blob/main/Jam1_April_2022/consu.md)
|
||||
|
||||
## Utilization
|
||||
|
||||
|
||||
## Build using CMake
|
||||
|
||||
It is **highly** recommended to use CMake FetchContent to depend on FTXUI so you may specify which commit you would like to depend on.
|
||||
```cmake
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(ftxui
|
||||
GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
|
||||
GIT_TAG v6.0.0
|
||||
GIT_TAG v6.1.9
|
||||
)
|
||||
FetchContent_MakeAvailable(ftxui)
|
||||
|
||||
FetchContent_GetProperties(ftxui)
|
||||
if(NOT ftxui_POPULATED)
|
||||
FetchContent_Populate(ftxui)
|
||||
add_subdirectory(${ftxui_SOURCE_DIR} ${ftxui_BINARY_DIR} EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
target_link_libraries(your_target PRIVATE
|
||||
# Chose a submodule
|
||||
ftxui::component
|
||||
ftxui::dom
|
||||
ftxui::screen
|
||||
)
|
||||
```
|
||||
|
||||
# Build using Bazel
|
||||
|
||||
**MODULE.bazel**
|
||||
```starlark
|
||||
bazel_dep(
|
||||
name = "ftxui",
|
||||
version = "v6.1.9",
|
||||
)
|
||||
```
|
||||
|
||||
**BUILD.bazel**
|
||||
```starlark
|
||||
cc_binary(
|
||||
name = "your_target",
|
||||
srcs = ["your_source.cc"],
|
||||
deps = [
|
||||
"@ftxui//:ftxui_component",
|
||||
"@ftxui//:ftxui_dom",
|
||||
"@ftxui//:ftxui_screen",
|
||||
],
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
# Build with something else:
|
||||
If you don't, FTXUI may be used from the following packages:
|
||||
- [vcpkg](https://vcpkgx.com/details.html?package=ftxui)
|
||||
- [Arch Linux PKGBUILD](https://aur.archlinux.org/packages/ftxui-git/).
|
||||
- [conan.io](https://conan.io/center/ftxui)
|
||||
- [openSUSE](https://build.opensuse.org/package/show/devel:libraries:c_c++/ftxui)
|
||||
-
|
||||
- CMake [FetchContent]([https://bewagner.net/programming/2020/05/02/cmake-fetchcontent/](https://cmake.org/cmake/help/latest/module/FetchContent.html)) (preferred),
|
||||
- [Bazel](https://registry.bazel.build/modules/ftxui),
|
||||
- [vcpkg](https://vcpkg.link/ports/ftxui),
|
||||
- [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),
|
||||
[Nix](https://github.com/ArthurSonzogni/FTXUI/blob/main/flake.nix),
|
||||
[](https://repology.org/project/libftxui/versions)
|
||||
|
||||
|
||||
If you choose to build and link FTXUI yourself, `ftxui-component` must be first in the linking order relative to the other FTXUI libraries, i.e.
|
||||
```bash
|
||||
g++ . . . -lftxui-component -lftxui-dom -lftxui-screen . . .
|
||||
```
|
||||
|
||||
|
||||
To build FTXUI with modules, check [documentation](https://arthursonzogni.github.io/FTXUI/cpp20-modules.html)
|
||||
|
||||
## Contributors
|
||||
|
||||
|
4
WORKSPACE.bazel
Normal file
4
WORKSPACE.bazel
Normal file
@@ -0,0 +1,4 @@
|
||||
# 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.
|
||||
workspace(name = "ftxui")
|
94
bazel/ftxui.bzl
Normal file
94
bazel/ftxui.bzl
Normal file
@@ -0,0 +1,94 @@
|
||||
# ftxui_common.bzl
|
||||
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
load("@rules_cc//cc:defs.bzl", "cc_binary")
|
||||
|
||||
# Microsoft terminal is a bit buggy ¯\_(ツ)_/¯ and MSVC uses bad defaults.
|
||||
def windows_copts():
|
||||
MSVC_COPTS = [
|
||||
# Microsoft Visual Studio must decode sources files as UTF-8.
|
||||
"/utf-8",
|
||||
|
||||
# Microsoft Visual Studio must interpret the codepoint using unicode.
|
||||
"/DUNICODE",
|
||||
"/D_UNICODE",
|
||||
|
||||
# Fallback for Microsoft Terminal.
|
||||
# This
|
||||
# - Replace missing font symbols by others.
|
||||
# - Reduce screen position pooling frequency to deals against a Microsoft
|
||||
# race condition. This was fixed in 2020, but clients never not updated.
|
||||
# - https://github.com/microsoft/terminal/pull/7583
|
||||
# - https://github.com/ArthurSonzogni/FTXUI/issues/136
|
||||
"/DFTXUI_MICROSOFT_TERMINAL_FALLBACK",
|
||||
]
|
||||
|
||||
WINDOWS_COPTS = [
|
||||
# Fallback for Microsoft Terminal.
|
||||
# This
|
||||
# - Replace missing font symbols by others.
|
||||
# - Reduce screen position pooling frequency to deals against a Microsoft
|
||||
# race condition. This was fixed in 2020, but clients are still using
|
||||
# old versions.
|
||||
# - https://github.com/microsoft/terminal/pull/7583
|
||||
# - https://github.com/ArthurSonzogni/FTXUI/issues/136
|
||||
"-DFTXUI_MICROSOFT_TERMINAL_FALLBACK",
|
||||
];
|
||||
|
||||
return select({
|
||||
# MSVC:
|
||||
"@rules_cc//cc/compiler:msvc-cl": MSVC_COPTS,
|
||||
"@rules_cc//cc/compiler:clang-cl": MSVC_COPTS,
|
||||
"@platforms//os:windows": WINDOWS_COPTS,
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
def ftxui_cc_library(
|
||||
name,
|
||||
srcs = [],
|
||||
hdrs = [],
|
||||
linkopts = [],
|
||||
deps = []):
|
||||
|
||||
cc_library(
|
||||
name = name,
|
||||
srcs = srcs,
|
||||
hdrs = hdrs,
|
||||
linkopts = linkopts,
|
||||
deps = deps,
|
||||
strip_include_prefix = "",
|
||||
include_prefix = "",
|
||||
includes = [
|
||||
"include",
|
||||
"src",
|
||||
],
|
||||
copts = windows_copts(),
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
# Compile all the examples in the examples/ directory.
|
||||
# This is useful to check the Bazel is always synchronized against CMake
|
||||
# definitions.
|
||||
def generate_examples():
|
||||
cpp_files = native.glob(["examples/**/*.cpp"])
|
||||
|
||||
for src in cpp_files:
|
||||
# Skip failing examples due to the color_info_sorted_2d.ipp dependency.
|
||||
if src == "examples/component/homescreen.cpp" or \
|
||||
src == "examples/dom/color_info_palette256.cpp" or \
|
||||
src == "examples/dom/color_gallery.cpp":
|
||||
continue
|
||||
|
||||
# Turn "examples/component/button.cpp" → "example_component_button"
|
||||
name = src.replace("/", "_").replace(".cpp", "")
|
||||
|
||||
cc_binary(
|
||||
name = name,
|
||||
srcs = [src],
|
||||
deps = [
|
||||
":component",
|
||||
":dom",
|
||||
":screen",
|
||||
],
|
||||
copts = windows_copts(),
|
||||
)
|
@@ -5,13 +5,14 @@ function(ftxui_message msg)
|
||||
endfunction()
|
||||
|
||||
ftxui_message("┌─ FTXUI options ─────────────────────")
|
||||
ftxui_message("│ FTXUI_ENABLE_INSTALL : ${FTXUI_ENABLE_INSTALL}")
|
||||
ftxui_message("│ FTXUI_BUILD_EXAMPLES : ${FTXUI_BUILD_EXAMPLES}")
|
||||
ftxui_message("│ FTXUI_QUIET : ${FTXUI_QUIET}")
|
||||
ftxui_message("│ FTXUI_BUILD_DOCS : ${FTXUI_BUILD_DOCS}")
|
||||
ftxui_message("│ FTXUI_BUILD_EXAMPLES : ${FTXUI_BUILD_EXAMPLES}")
|
||||
ftxui_message("│ FTXUI_BUILD_MODULES : ${FTXUI_BUILD_MODULES}")
|
||||
ftxui_message("│ FTXUI_BUILD_TESTS : ${FTXUI_BUILD_TESTS}")
|
||||
ftxui_message("│ FTXUI_BUILD_TESTS_FUZZER : ${FTXUI_BUILD_TESTS_FUZZER}")
|
||||
ftxui_message("│ FTXUI_ENABLE_COVERAGE : ${FTXUI_ENABLE_COVERAGE}")
|
||||
ftxui_message("│ FTXUI_DEV_WARNINGS : ${FTXUI_DEV_WARNINGS}")
|
||||
ftxui_message("│ FTXUI_CLANG_TIDY : ${FTXUI_CLANG_TIDY}")
|
||||
ftxui_message("│ FTXUI_DEV_WARNINGS : ${FTXUI_DEV_WARNINGS}")
|
||||
ftxui_message("│ FTXUI_ENABLE_COVERAGE : ${FTXUI_ENABLE_COVERAGE}")
|
||||
ftxui_message("│ FTXUI_ENABLE_INSTALL : ${FTXUI_ENABLE_INSTALL}")
|
||||
ftxui_message("│ FTXUI_QUIET : ${FTXUI_QUIET}")
|
||||
ftxui_message("└─────────────────────────────────────")
|
||||
|
83
cmake/ftxui_modules.cmake
Normal file
83
cmake/ftxui_modules.cmake
Normal file
@@ -0,0 +1,83 @@
|
||||
if (NOT FTXUI_BUILD_MODULES)
|
||||
return()
|
||||
endif()
|
||||
|
||||
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
|
||||
src/ftxui/component/component.cppm
|
||||
src/ftxui/component/component_base.cppm
|
||||
src/ftxui/component/component_options.cppm
|
||||
src/ftxui/component/event.cppm
|
||||
src/ftxui/component/loop.cppm
|
||||
src/ftxui/component/mouse.cppm
|
||||
src/ftxui/component/receiver.cppm
|
||||
src/ftxui/component/screen_interactive.cppm
|
||||
src/ftxui/component/task.cppm
|
||||
src/ftxui/dom.cppm
|
||||
src/ftxui/dom/canvas.cppm
|
||||
src/ftxui/dom/deprecated.cppm
|
||||
src/ftxui/dom/direction.cppm
|
||||
src/ftxui/dom/elements.cppm
|
||||
src/ftxui/dom/flexbox_config.cppm
|
||||
src/ftxui/dom/linear_gradient.cppm
|
||||
src/ftxui/dom/node.cppm
|
||||
src/ftxui/dom/requirement.cppm
|
||||
src/ftxui/dom/selection.cppm
|
||||
src/ftxui/dom/table.cppm
|
||||
src/ftxui/screen.cppm
|
||||
src/ftxui/screen/box.cppm
|
||||
src/ftxui/screen/color.cppm
|
||||
src/ftxui/screen/color_info.cppm
|
||||
src/ftxui/screen/deprecated.cppm
|
||||
src/ftxui/screen/image.cppm
|
||||
src/ftxui/screen/pixel.cppm
|
||||
src/ftxui/screen/screen.cppm
|
||||
src/ftxui/screen/string.cppm
|
||||
src/ftxui/screen/terminal.cppm
|
||||
src/ftxui/util.cppm
|
||||
src/ftxui/util/autoreset.cppm
|
||||
src/ftxui/util/ref.cppm
|
||||
)
|
||||
|
||||
target_link_libraries(ftxui-modules
|
||||
PUBLIC
|
||||
ftxui::screen
|
||||
ftxui::dom
|
||||
ftxui::component
|
||||
)
|
||||
|
||||
target_compile_features(ftxui-modules PUBLIC cxx_std_20)
|
||||
# TODO: Explain why this is needed.
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
target_compile_options(ftxui-modules PUBLIC -fmodules-ts)
|
||||
endif ()
|
||||
|
||||
add_library(ftxui::modules ALIAS ftxui-modules)
|
||||
|
||||
if(FTXUI_ENABLE_INSTALL)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
install(TARGETS ftxui-modules
|
||||
EXPORT ftxui-targets
|
||||
FILE_SET CXX_MODULES
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ftxui
|
||||
FILE_SET HEADERS
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ftxui
|
||||
INCLUDES
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ftxui
|
||||
)
|
||||
install(EXPORT ftxui-targets
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ftxui
|
||||
CXX_MODULES_DIRECTORY ${CMAKE_INSTALL_LIBDIR}/cmake/ftxui
|
||||
)
|
||||
install(FILES my_package-config.cmake
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ftxui
|
||||
)
|
||||
endif()
|
@@ -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
|
||||
|
@@ -8,13 +8,63 @@ if (NOT DOXYGEN_FOUND)
|
||||
return()
|
||||
endif()
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
doxygen-awesome-css
|
||||
GIT_REPOSITORY https://github.com/jothepro/doxygen-awesome-css.git
|
||||
GIT_TAG v2.3.4
|
||||
|
||||
)
|
||||
FetchContent_MakeAvailable(doxygen-awesome-css)
|
||||
FetchContent_GetProperties(doxygen-awesome-css SOURCE_DIR AWESOME_CSS_DIR)
|
||||
|
||||
# Generate example list for documentation
|
||||
set(EXAMPLE_LIST "${CMAKE_CURRENT_BINARY_DIR}/example_list.md")
|
||||
file(WRITE ${EXAMPLE_LIST} "# Examples")
|
||||
set(DOM_EXAMPLES "")
|
||||
set(COMPONENT_EXAMPLES "")
|
||||
|
||||
get_property(EXAMPLES GLOBAL PROPERTY FTXUI::EXAMPLES)
|
||||
foreach(EXAMPLE IN LISTS EXAMPLES)
|
||||
file(APPEND ${EXAMPLE_LIST} "\n@example examples/${EXAMPLE}.cpp")
|
||||
endforeach(EXAMPLE IN LISTS EXAMPLES)
|
||||
|
||||
foreach(example IN LISTS EXAMPLES)
|
||||
if(example MATCHES "^dom/.*")
|
||||
list(APPEND DOM_EXAMPLES "${example}")
|
||||
elseif(example MATCHES "^component/.*")
|
||||
list(APPEND COMPONENT_EXAMPLES "${example}")
|
||||
else()
|
||||
message(ERROR "Unknown example '${example}'")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
macro(write_example_list file title page examples)
|
||||
file(WRITE "${file}" "@page ${page} ${title}\n")
|
||||
file(APPEND "${file}" "@tableofcontents\n")
|
||||
|
||||
foreach(example IN LISTS ${examples})
|
||||
get_filename_component(name "${example}" NAME_WE)
|
||||
file(APPEND "${file}" "# ${name}\n")
|
||||
|
||||
# Add a markdown to the demo. URL example:
|
||||
# https://arthursonzogni.github.io/FTXUI/examples/?file=component/canvas_animated
|
||||
file(APPEND "${file}" "[Demo](https://arthursonzogni.github.io/FTXUI/examples/?file=${example})\n")
|
||||
|
||||
file(APPEND "${file}" "@include examples/${example}.cpp\n")
|
||||
file(APPEND "${file}" "\n")
|
||||
endforeach()
|
||||
|
||||
# Reference to the examples
|
||||
foreach(example IN LISTS ${examples})
|
||||
get_filename_component(name "${example}" NAME_WE)
|
||||
file(APPEND "${file}" "@example examples/${example}.cpp\n")
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
write_example_list("${CMAKE_CURRENT_BINARY_DIR}/dom_examples.md"
|
||||
"Example"
|
||||
module-dom-examples
|
||||
DOM_EXAMPLES)
|
||||
write_example_list("${CMAKE_CURRENT_BINARY_DIR}/component_examples.md"
|
||||
"Example"
|
||||
module-component-examples
|
||||
COMPONENT_EXAMPLES)
|
||||
|
||||
configure_file(Doxyfile.in Doxyfile @ONLY)
|
||||
|
||||
|
1052
doc/Doxyfile.in
1052
doc/Doxyfile.in
File diff suppressed because it is too large
Load Diff
@@ -1,44 +1,56 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<doxygenlayout version="1.0">
|
||||
<!-- Generated by doxygen 1.12.0 -->
|
||||
<!-- Navigation index tabs for HTML output -->
|
||||
<navindex>
|
||||
<tab type="mainpage" visible="yes" title="Tutorial"/>
|
||||
<tab type="examples" visible="yes" title="" intro=""/>
|
||||
<tab type="filelist" visible="yes" title=""/>
|
||||
|
||||
<tab type="pages" visible="no" title="" intro=""/>
|
||||
<tab type="modules" visible="yes" title="" intro=""/>
|
||||
<tab type="mainpage" visible="no" title=""/>
|
||||
<tab type="pages" visible="yes" title="Pages" intro=""/>
|
||||
<tab type="topics" visible="yes" title="Reference" intro=""/>
|
||||
<tab type="modules" visible="yes" title="" intro="">
|
||||
<tab type="modulelist" visible="yes" title="" intro=""/>
|
||||
<tab type="modulemembers" visible="yes" title="" intro=""/>
|
||||
</tab>
|
||||
<tab type="namespaces" visible="yes" title="">
|
||||
<tab type="namespacelist" visible="yes" title="" intro=""/>
|
||||
<tab type="namespacemembers" visible="yes" title="" intro=""/>
|
||||
</tab>
|
||||
<tab type="interfaces" visible="no" title="">
|
||||
<tab type="concepts" visible="yes" title="">
|
||||
</tab>
|
||||
<tab type="interfaces" visible="yes" title="">
|
||||
<tab type="interfacelist" visible="yes" title="" intro=""/>
|
||||
<tab type="interfaceindex" visible="$ALPHABETICAL_INDEX" title=""/>
|
||||
<tab type="interfaceindex" visible="$ALPHABETICAL_INDEX" title=""/>
|
||||
<tab type="interfacehierarchy" visible="yes" title="" intro=""/>
|
||||
</tab>
|
||||
<tab type="classes" visible="no" title="">
|
||||
<tab type="classes" visible="yes" title="">
|
||||
<tab type="classlist" visible="yes" title="" intro=""/>
|
||||
<tab type="classindex" visible="$ALPHABETICAL_INDEX" title=""/>
|
||||
<tab type="classindex" visible="$ALPHABETICAL_INDEX" title=""/>
|
||||
<tab type="hierarchy" visible="yes" title="" intro=""/>
|
||||
<tab type="classmembers" visible="yes" title="" intro=""/>
|
||||
</tab>
|
||||
<tab type="structs" visible="no" title="">
|
||||
<tab type="structs" visible="yes" title="">
|
||||
<tab type="structlist" visible="yes" title="" intro=""/>
|
||||
<tab type="structindex" visible="$ALPHABETICAL_INDEX" title=""/>
|
||||
<tab type="structindex" visible="$ALPHABETICAL_INDEX" title=""/>
|
||||
</tab>
|
||||
<tab type="exceptions" visible="no" title="">
|
||||
<tab type="exceptions" visible="yes" title="">
|
||||
<tab type="exceptionlist" visible="yes" title="" intro=""/>
|
||||
<tab type="exceptionindex" visible="$ALPHABETICAL_INDEX" title=""/>
|
||||
<tab type="exceptionindex" visible="$ALPHABETICAL_INDEX" title=""/>
|
||||
<tab type="exceptionhierarchy" visible="yes" title="" intro=""/>
|
||||
</tab>
|
||||
|
||||
<tab type="files" visible="yes" title="">
|
||||
<tab type="filelist" visible="yes" title="" intro=""/>
|
||||
<tab type="globals" visible="yes" title="" intro=""/>
|
||||
</tab>
|
||||
|
||||
<tab type="examples" visible="yes" title="" intro=""/>
|
||||
</navindex>
|
||||
|
||||
<!-- Layout definition for a class page -->
|
||||
<class>
|
||||
<briefdescription visible="yes"/>
|
||||
<includes visible="$SHOW_INCLUDE_FILES"/>
|
||||
<inheritancegraph visible="$CLASS_GRAPH"/>
|
||||
<collaborationgraph visible="$COLLABORATION_GRAPH"/>
|
||||
<includes visible="$SHOW_HEADERFILE"/>
|
||||
<inheritancegraph visible="yes"/>
|
||||
<collaborationgraph visible="yes"/>
|
||||
<memberdecl>
|
||||
<nestedclasses visible="yes" title=""/>
|
||||
<publictypes title=""/>
|
||||
@@ -96,19 +108,20 @@
|
||||
<namespace>
|
||||
<briefdescription visible="yes"/>
|
||||
<memberdecl>
|
||||
<functions title=""/>
|
||||
<enums title=""/>
|
||||
<typedefs title=""/>
|
||||
<classes visible="yes" title=""/>
|
||||
<structs visible="yes" title=""/>
|
||||
|
||||
<nestednamespaces visible="yes" title=""/>
|
||||
<constantgroups visible="yes" title=""/>
|
||||
<interfaces visible="yes" title=""/>
|
||||
<classes visible="yes" title=""/>
|
||||
<concepts visible="yes" title=""/>
|
||||
<structs visible="yes" title=""/>
|
||||
<exceptions visible="yes" title=""/>
|
||||
<typedefs title=""/>
|
||||
<sequences title=""/>
|
||||
<dictionaries title=""/>
|
||||
<enums title=""/>
|
||||
<functions title=""/>
|
||||
<variables title=""/>
|
||||
<properties title=""/>
|
||||
<membergroups visible="yes"/>
|
||||
</memberdecl>
|
||||
<detaileddescription title=""/>
|
||||
@@ -120,16 +133,26 @@
|
||||
<enums title=""/>
|
||||
<functions title=""/>
|
||||
<variables title=""/>
|
||||
<properties title=""/>
|
||||
</memberdef>
|
||||
<authorsection visible="yes"/>
|
||||
</namespace>
|
||||
|
||||
<!-- Layout definition for a concept page -->
|
||||
<concept>
|
||||
<briefdescription visible="yes"/>
|
||||
<includes visible="$SHOW_HEADERFILE"/>
|
||||
<definition visible="yes" title=""/>
|
||||
<detaileddescription title=""/>
|
||||
<authorsection visible="yes"/>
|
||||
</concept>
|
||||
|
||||
<!-- Layout definition for a file page -->
|
||||
<file>
|
||||
<briefdescription visible="yes"/>
|
||||
<includes visible="$SHOW_INCLUDE_FILES"/>
|
||||
<includegraph visible="$INCLUDE_GRAPH"/>
|
||||
<includedbygraph visible="$INCLUDED_BY_GRAPH"/>
|
||||
<includegraph visible="yes"/>
|
||||
<includedbygraph visible="yes"/>
|
||||
<sourcelink visible="yes"/>
|
||||
<memberdecl>
|
||||
<interfaces visible="yes" title=""/>
|
||||
@@ -137,6 +160,7 @@
|
||||
<structs visible="yes" title=""/>
|
||||
<exceptions visible="yes" title=""/>
|
||||
<namespaces visible="yes" title=""/>
|
||||
<concepts visible="yes" title=""/>
|
||||
<constantgroups visible="yes" title=""/>
|
||||
<defines title=""/>
|
||||
<typedefs title=""/>
|
||||
@@ -145,6 +169,7 @@
|
||||
<enums title=""/>
|
||||
<functions title=""/>
|
||||
<variables title=""/>
|
||||
<properties title=""/>
|
||||
<membergroups visible="yes"/>
|
||||
</memberdecl>
|
||||
<detaileddescription title=""/>
|
||||
@@ -157,19 +182,24 @@
|
||||
<enums title=""/>
|
||||
<functions title=""/>
|
||||
<variables title=""/>
|
||||
<properties title=""/>
|
||||
</memberdef>
|
||||
<authorsection/>
|
||||
</file>
|
||||
|
||||
<!-- Layout definition for a group page -->
|
||||
<group>
|
||||
<briefdescription visible="yes"/>
|
||||
<groupgraph visible="$GROUP_GRAPHS"/>
|
||||
<briefdescription visible="no"/>
|
||||
<authorsection visible="no"/>
|
||||
<detaileddescription title=""/>
|
||||
<groupgraph visible="yes"/>
|
||||
<memberdecl>
|
||||
<nestedgroups visible="yes" title=""/>
|
||||
<modules visible="yes" title=""/>
|
||||
<dirs visible="yes" title=""/>
|
||||
<files visible="yes" title=""/>
|
||||
<namespaces visible="yes" title=""/>
|
||||
<concepts visible="yes" title=""/>
|
||||
<classes visible="yes" title=""/>
|
||||
<defines title=""/>
|
||||
<typedefs title=""/>
|
||||
@@ -188,7 +218,6 @@
|
||||
<friends title=""/>
|
||||
<membergroups visible="yes"/>
|
||||
</memberdecl>
|
||||
<detaileddescription title=""/>
|
||||
<memberdef>
|
||||
<pagedocs/>
|
||||
<inlineclasses title=""/>
|
||||
@@ -208,9 +237,27 @@
|
||||
<properties title=""/>
|
||||
<friends title=""/>
|
||||
</memberdef>
|
||||
<authorsection visible="yes"/>
|
||||
</group>
|
||||
|
||||
<!-- Layout definition for a C++20 module page -->
|
||||
<module>
|
||||
<briefdescription visible="yes"/>
|
||||
<exportedmodules visible="yes"/>
|
||||
<memberdecl>
|
||||
<concepts visible="yes" title=""/>
|
||||
<classes visible="yes" title=""/>
|
||||
<enums title=""/>
|
||||
<typedefs title=""/>
|
||||
<functions title=""/>
|
||||
<variables title=""/>
|
||||
<membergroups title=""/>
|
||||
</memberdecl>
|
||||
<detaileddescription title=""/>
|
||||
<memberdecl>
|
||||
<files visible="yes"/>
|
||||
</memberdecl>
|
||||
</module>
|
||||
|
||||
<!-- Layout definition for a directory page -->
|
||||
<directory>
|
||||
<briefdescription visible="yes"/>
|
107
doc/cpp20-modules.md
Normal file
107
doc/cpp20-modules.md
Normal file
@@ -0,0 +1,107 @@
|
||||
@page cpp20-modules C++20 Modules
|
||||
|
||||
|
||||
> [!WARNING]
|
||||
> This feature is still in development, and the API may change in future releases.
|
||||
> Your contribution is needed to help us improve the compatibility and usability
|
||||
> of C++20 modules in FTXUI. If you encounter any issues or have suggestions,
|
||||
> please open an issue.
|
||||
|
||||
FTXUI experimentally supports
|
||||
[C++20 modules](https://en.cppreference.com/w/cpp/language/modules) to reduce
|
||||
compilation times and improve code organization. Each header has a
|
||||
corresponding module.
|
||||
|
||||
Use the FTXUI_BUILD_MODULES option to build the FTXUI project itself to provide C++ 20 modules,
|
||||
for example with CMake and Ninja:
|
||||
|
||||
```sh
|
||||
cmake \
|
||||
-DCMAKE_GENERATOR=Ninja \
|
||||
-DFTXUI_BUILD_MODULES=ON \
|
||||
..
|
||||
|
||||
ninja
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> To use modules, you need a C++20 compatible compiler, CMake version 3.20 or
|
||||
> higher, and use a compatible generator like Ninja. Note that Makefile
|
||||
> generators **do not support modules**.
|
||||
|
||||
Then, in your own code you can consume the modules and code as normal:
|
||||
|
||||
```cpp
|
||||
import ftxui;
|
||||
|
||||
int main() {
|
||||
auto screen = ftxui::ScreenInteractive::TerminalOutput();
|
||||
auto button = ftxui::Button("Click me", screen.QuitClosure());
|
||||
screen.Loop(button);
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
Note, the `ftxui` convenience module which simply pulls together all the modules:
|
||||
|
||||
```cpp
|
||||
export import ftxui.component;
|
||||
export import ftxui.dom;
|
||||
export import ftxui.screen;
|
||||
export import ftxui.util;
|
||||
```
|
||||
You can instead import only the module(s) you need if desired.
|
||||
|
||||
To properly find and link the modules with CMake, use `target_link_libraries` to get the right
|
||||
compiler, linker, etc. flags.
|
||||
|
||||
```cmake
|
||||
target_link_libraries(my_executable
|
||||
#...whatever...
|
||||
PRIVATE ftxui::modules
|
||||
)
|
||||
```
|
||||
|
||||
### Module list
|
||||
|
||||
The modules directly reference the corresponding header, or a group of related
|
||||
headers to provide a more convenient interface. The following modules
|
||||
are available:
|
||||
|
||||
- `ftxui`
|
||||
- `ftxui.component`
|
||||
- `ftxui.component.Animation`
|
||||
- `ftxui.component.CapturedMouse`
|
||||
- `ftxui.component.Component`
|
||||
- `ftxui.component.ComponentBase`
|
||||
- `ftxui.component.ComponentOptions`
|
||||
- `ftxui.component.Event`
|
||||
- `ftxui.component.Loop`
|
||||
- `ftxui.component.Mouse`
|
||||
- `ftxui.component.Receiver`
|
||||
- `ftxui.component.ScreenInteractive`
|
||||
- `ftxui.component.Task`
|
||||
- `ftxui.dom`
|
||||
- `ftxui.dom.Canvas`
|
||||
- `ftxui.dom.Deprecated`
|
||||
- `ftxui.dom.Direction`
|
||||
- `ftxui.dom.Elements`
|
||||
- `ftxui.dom.FlexboxConfig`
|
||||
- `ftxui.dom.LinearGradient`
|
||||
- `ftxui.dom.Node`
|
||||
- `ftxui.dom.Requirement`
|
||||
- `ftxui.dom.Selection`
|
||||
- `ftxui.dom.Table`
|
||||
- `ftxui.screen`
|
||||
- `ftxui.screen.Box`
|
||||
- `ftxui.screen.Color`
|
||||
- `ftxui.screen.ColorInfo`
|
||||
- `ftxui.screen.Deprecated`
|
||||
- `ftxui.screen.Image`
|
||||
- `ftxui.screen.Pixel`
|
||||
- `ftxui.screen.Screen`
|
||||
- `ftxui.screen.String`
|
||||
- `ftxui.screen.Terminal`
|
||||
- `ftxui.util`
|
||||
- `ftxui.util.AutoReset`
|
||||
- `ftxui.util.Ref`
|
@@ -1,323 +0,0 @@
|
||||
/*
|
||||
* GitHub Markdown style CSS for doxygen 1.8.14
|
||||
* Source: https://github.com/sindresorhus/github-markdown-css
|
||||
* License: MIT <20> Sindre Sorhus
|
||||
*/
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body, table, div, p, dl {
|
||||
-ms-text-size-adjust: 100%;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
line-height: 1.5;
|
||||
color: #24292e;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
|
||||
font-size: 16px;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
b {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* @group Heading Levels */
|
||||
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
font-weight: 600;
|
||||
line-height: 1.25;
|
||||
margin-top: 24px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 2em;
|
||||
padding-bottom: 0.3em;
|
||||
border-bottom: 1px solid #eaecef;
|
||||
}
|
||||
|
||||
h2 {
|
||||
padding-bottom: 0.3em;
|
||||
font-size: 1.5em;
|
||||
border-bottom: 1px solid #eaecef;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 1.25em;
|
||||
}
|
||||
|
||||
h4 {
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
h5 {
|
||||
font-size: 0.875em;
|
||||
}
|
||||
|
||||
h6 {
|
||||
font-size: 0.85em;
|
||||
color: #6a737d;
|
||||
}
|
||||
|
||||
a {
|
||||
background-color: transparent;
|
||||
color: #0366d6;
|
||||
text-decoration: none;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.contents a:visited {
|
||||
color: #0366d6;
|
||||
}
|
||||
|
||||
a:active, a:hover {
|
||||
outline-width: 0;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
a:not([href]) {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a.el {
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.image {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.tip {
|
||||
background-image: url(tip.png);
|
||||
background-position: left center;
|
||||
background-repeat: no-repeat;
|
||||
padding-left: 30px;
|
||||
margin-top: 1em;
|
||||
margin-bottom: 1em;
|
||||
min-height: 31px;
|
||||
display: block;
|
||||
font-style:italic;
|
||||
}
|
||||
|
||||
.warn {
|
||||
background-image: url(warn.png);
|
||||
background-position: left center;
|
||||
background-repeat: no-repeat;
|
||||
padding-left: 48px;
|
||||
margin-top: 1em;
|
||||
margin-bottom: 1em;
|
||||
min-height: 31px;
|
||||
display: block;
|
||||
font-style:italic;
|
||||
}
|
||||
|
||||
#projectname {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
|
||||
font-size: 2em;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#projectbrief {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
|
||||
font-size: 0.8em;
|
||||
}
|
||||
|
||||
#projectnumber {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
div.contents {
|
||||
width: 980px;
|
||||
padding: 40px;
|
||||
margin-top: -1px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
margin-bottom: 10px;
|
||||
border: 1px solid #d1d5da;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
div.toc {
|
||||
border: 0 none;
|
||||
border-radius: 7px;
|
||||
}
|
||||
|
||||
div.header {
|
||||
width: 980px;
|
||||
padding: 10px;
|
||||
margin-top: 10px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
background-image: none;
|
||||
background-repeat: none;
|
||||
background-color: #f6f8fa;
|
||||
border: 1px solid #d1d5da;
|
||||
}
|
||||
|
||||
div.headertitle {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.title ol {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.title ol li {
|
||||
list-style-type: none;
|
||||
}
|
||||
|
||||
.ui-resizable-e {
|
||||
background: none;
|
||||
background-color: #E6E6E6;
|
||||
}
|
||||
|
||||
div.fragment {
|
||||
background-color: #f3f3f3;
|
||||
border-radius:5px;
|
||||
border: 0 solid;
|
||||
border: none;
|
||||
padding:16px;
|
||||
transition: all 0.5s ease-in-out;
|
||||
}
|
||||
|
||||
div.fragment:hover {
|
||||
background-color: #e9e9e9;
|
||||
box-shadow: 0 5px 10px -5px rgb(0,0,0,0.5) inset;
|
||||
}
|
||||
|
||||
div.line {
|
||||
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
|
||||
font-size: 90%;
|
||||
font-variant-numeric: tabular-nums lining-nums;
|
||||
font-kerning: none;
|
||||
-webkit-transition-duration: 0;
|
||||
-moz-transition-duration: 0;
|
||||
-ms-transition-duration: 0;
|
||||
-o-transition-duration: 0;
|
||||
transition-duration: 0;
|
||||
}
|
||||
|
||||
div.line.glow {
|
||||
background-color: auto;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
/* @group Code Colorization */
|
||||
span.keyword {
|
||||
color: #808000
|
||||
}
|
||||
|
||||
span.keywordtype {
|
||||
color: #808000
|
||||
}
|
||||
|
||||
span.keywordflow {
|
||||
color: #808000
|
||||
}
|
||||
|
||||
span.comment {
|
||||
color: #008000
|
||||
}
|
||||
|
||||
span.preprocessor {
|
||||
color: #800000
|
||||
}
|
||||
|
||||
span.stringliteral {
|
||||
color: #000080
|
||||
}
|
||||
|
||||
span.charliteral {
|
||||
color: #000080
|
||||
}
|
||||
|
||||
blockquote {
|
||||
background-color: #EEEEEE;
|
||||
border-left: 2px solid #606060;
|
||||
margin: 0 24px 0 4px;
|
||||
padding: 0 12px 0 16px;
|
||||
}
|
||||
|
||||
/* @end */
|
||||
|
||||
.arrow {
|
||||
box-sizing: content-box;
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
}
|
||||
|
||||
#nav-tree {
|
||||
background-image: none;
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
#nav-tree .label {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#side-nav {
|
||||
width: 25%;
|
||||
max-width: 50%;
|
||||
}
|
||||
|
||||
.memtitle {
|
||||
background-image: none;
|
||||
}
|
||||
|
||||
.memproto {
|
||||
text-shadow: none;
|
||||
/* opera specific markup */
|
||||
box-shadow: none;
|
||||
/* firefox specific markup */
|
||||
-moz-box-shadow: none;
|
||||
-moz-border-radius-topright: 4px;
|
||||
/* webkit specific markup */
|
||||
-webkit-box-shadow: none;
|
||||
-webkit-border-top-right-radius: 4px;
|
||||
}
|
||||
|
||||
.memdoc {
|
||||
background-image:none;
|
||||
background-repeat:repeat-x;
|
||||
background-color: #FFFFFF;
|
||||
/* opera specific markup */
|
||||
box-shadow: none;
|
||||
/* firefox specific markup */
|
||||
-moz-box-shadow: none;
|
||||
/* webkit specific markup */
|
||||
-webkit-box-shadow: none;
|
||||
}
|
||||
|
||||
#main-menu {
|
||||
background: none;
|
||||
border-bottom: 1px solid black;
|
||||
}
|
||||
|
||||
#main-menu li {
|
||||
border: none !important;
|
||||
transition: all 0.1s ease-in-out;
|
||||
}
|
||||
|
||||
#main-menu li:hover {
|
||||
color:black;
|
||||
background-color:black;
|
||||
}
|
||||
|
||||
.sm-dox a, .sm-dox a:focus, .sm-dox a:active, .sm-dox a:hover, .sm-dox a.highlighted {
|
||||
background-image:none;
|
||||
}
|
||||
|
||||
#titlearea {
|
||||
margin: 8px;
|
||||
border: none;
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
<!-- HTML footer for doxygen 1.8.14-->
|
||||
<!-- start footer part -->
|
||||
<!--BEGIN GENERATE_TREEVIEW-->
|
||||
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
||||
</div>
|
||||
<!--END GENERATE_TREEVIEW-->
|
||||
<!--BEGIN !GENERATE_TREEVIEW-->
|
||||
<!--END !GENERATE_TREEVIEW-->
|
||||
</body>
|
||||
</html>
|
@@ -1,59 +0,0 @@
|
||||
<!-- HTML header for doxygen 1.8.14-->
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="cache-control" content="max-age=86400"/>
|
||||
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
||||
<meta name="generator" content="Doxygen $doxygenversion"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<!--BEGIN PROJECT_NAME--><title>$projectname: $title</title><!--END PROJECT_NAME-->
|
||||
<!--BEGIN !PROJECT_NAME--><title>$title</title><!--END !PROJECT_NAME-->
|
||||
<link href="$relpath^tabs.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript" src="$relpath^jquery.js"></script>
|
||||
<script type="text/javascript" src="$relpath^dynsections.js"></script>
|
||||
$treeview
|
||||
$search
|
||||
$mathjax
|
||||
<link href="$relpath^$stylesheet" rel="stylesheet" type="text/css" />
|
||||
$extrastylesheet
|
||||
</head>
|
||||
<body>
|
||||
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
||||
|
||||
<!--BEGIN TITLEAREA-->
|
||||
<div id="titlearea">
|
||||
<table cellspacing="0" cellpadding="0">
|
||||
<tbody>
|
||||
<tr style="height: 56px;">
|
||||
<!--BEGIN PROJECT_LOGO-->
|
||||
<td id="projectlogo"><img alt="Logo" src="$relpath^$projectlogo"/></td>
|
||||
<!--END PROJECT_LOGO-->
|
||||
<!--BEGIN PROJECT_NAME-->
|
||||
<td id="projectalign" style="padding-left: 0.5em;">
|
||||
<div id="projectname">$projectname
|
||||
<!--BEGIN PROJECT_NUMBER--> <span id="projectnumber">$projectnumber</span><!--END PROJECT_NUMBER-->
|
||||
</div>
|
||||
<!--BEGIN PROJECT_BRIEF--><div id="projectbrief">$projectbrief</div><!--END PROJECT_BRIEF-->
|
||||
</td>
|
||||
<!--END PROJECT_NAME-->
|
||||
<!--BEGIN !PROJECT_NAME-->
|
||||
<!--BEGIN PROJECT_BRIEF-->
|
||||
<td style="padding-left: 0.5em;">
|
||||
<div id="projectbrief">$projectbrief</div>
|
||||
</td>
|
||||
<!--END PROJECT_BRIEF-->
|
||||
<!--END !PROJECT_NAME-->
|
||||
<!--BEGIN DISABLE_INDEX-->
|
||||
<!--BEGIN SEARCHENGINE-->
|
||||
<td>$searchbox</td>
|
||||
<!--END SEARCHENGINE-->
|
||||
<!--END DISABLE_INDEX-->
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!--END TITLEAREA-->
|
||||
<!-- end header part -->
|
||||
|
||||
|
17
doc/footer.html
Normal file
17
doc/footer.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<!-- HTML footer for doxygen 1.9.8-->
|
||||
<!-- start footer part -->
|
||||
<!--BEGIN GENERATE_TREEVIEW-->
|
||||
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
||||
<ul>
|
||||
$navpath
|
||||
<li class="footer">$generatedby <a href="https://www.doxygen.org/index.html"><img class="footer" src="$relpath^doxygen.svg" width="104" height="31" alt="doxygen"/></a> $doxygenversion </li>
|
||||
</ul>
|
||||
</div>
|
||||
<!--END GENERATE_TREEVIEW-->
|
||||
<!--BEGIN !GENERATE_TREEVIEW-->
|
||||
<hr class="footer"/><address class="footer"><small>
|
||||
$generatedby <a href="https://www.doxygen.org/index.html"><img class="footer" src="$relpath^doxygen.svg" width="104" height="31" alt="doxygen"/></a> $doxygenversion
|
||||
</small></address>
|
||||
<!--END !GENERATE_TREEVIEW-->
|
||||
</body>
|
||||
</html>
|
62
doc/getting-started.md
Normal file
62
doc/getting-started.md
Normal file
@@ -0,0 +1,62 @@
|
||||
@page getting-started Getting Started
|
||||
@tableofcontents
|
||||
|
||||

|
||||
|
||||
# Install FTXUI
|
||||
|
||||
To set up FTXUI in your project, follow the [installation guide](installation.html), which provides instructions for multiple build systems and package managers.
|
||||
|
||||
# Minimal Example
|
||||
|
||||
Save the following code as `main.cpp`:
|
||||
|
||||
```cpp
|
||||
#include <ftxui/dom/elements.hpp>
|
||||
#include <ftxui/screen/screen.hpp>
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
|
||||
Element document = hbox({
|
||||
text("left") | border,
|
||||
text("middle") | border | flex,
|
||||
text("right") | border,
|
||||
});
|
||||
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
}
|
||||
```
|
||||
|
||||
Build and run it using your preferred build system.
|
||||
If unsure, start with one of the methods described in the [installation page](installation.html).
|
||||
|
||||
Expected output:
|
||||
|
||||
```
|
||||
┌────┐┌────────────────────────────────────┐┌─────┐
|
||||
│left││middle ││right│
|
||||
└────┘└────────────────────────────────────┘└─────┘
|
||||
```
|
||||
|
||||
# Starter Template
|
||||
|
||||
For a complete working project, clone the official starter repository:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/ArthurSonzogni/ftxui-starter
|
||||
```
|
||||
|
||||
Follow the build instructions in the `README.md` of that repository.
|
||||
|
||||
<div class="section_buttons">
|
||||
|
||||
| Previous | Next |
|
||||
|:----------------------------------|------------------------:|
|
||||
| [Introduction](index.html) | [Modules](modules.html) |
|
||||
|
||||
|
||||
</div>
|
183
doc/header.html
Normal file
183
doc/header.html
Normal file
@@ -0,0 +1,183 @@
|
||||
<!-- HTML header for doxygen 1.9.8-->
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="$langISO">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
|
||||
<meta name="generator" content="Doxygen $doxygenversion"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<!--BEGIN PROJECT_NAME--><title>$projectname: $title</title><!--END PROJECT_NAME-->
|
||||
<!--BEGIN !PROJECT_NAME--><title>$title</title><!--END !PROJECT_NAME-->
|
||||
<link href="$relpath^tabs.css" rel="stylesheet" type="text/css"/>
|
||||
<!--BEGIN DISABLE_INDEX-->
|
||||
<!--BEGIN FULL_SIDEBAR-->
|
||||
<script type="text/javascript">var page_layout=1;</script>
|
||||
<!--END FULL_SIDEBAR-->
|
||||
<!--END DISABLE_INDEX-->
|
||||
<script type="text/javascript" src="$relpath^jquery.js"></script>
|
||||
<script type="text/javascript" src="$relpath^dynsections.js"></script>
|
||||
<script type="text/javascript" src="$relpath^doxygen-awesome-fragment-copy-button.js"></script>
|
||||
<script type="text/javascript" src="$relpath^doxygen-awesome-paragraph-link.js"></script>
|
||||
<script type="text/javascript" src="$relpath^doxygen-awesome-interactive-toc.js"></script>
|
||||
<script type="text/javascript" src="$relpath^doxygen-awesome-tabs.js"></script>
|
||||
<script type="module">
|
||||
DoxygenAwesomeFragmentCopyButton.init()
|
||||
DoxygenAwesomeParagraphLink.init()
|
||||
DoxygenAwesomeInteractiveToc.init()
|
||||
DoxygenAwesomeTabs.init()
|
||||
|
||||
await new Promise(r => window.addEventListener('DOMContentLoaded', r));
|
||||
|
||||
// Remove title when a img[alt='title-img'] is present.
|
||||
// Find an image with the alt "img-title".
|
||||
const img = document.querySelector("img[alt='title-img']");
|
||||
const header = document.querySelector(".headertitle");
|
||||
|
||||
if (img && header) {
|
||||
// Hide the header title progressively.
|
||||
header.style.display = "none";
|
||||
|
||||
// Show progressively the image.
|
||||
img.style.maxHeight = "40vh";
|
||||
img.style.maxWidth = "100%";
|
||||
img.style.objectFit = "contain";
|
||||
}
|
||||
|
||||
// In the "examples.html" page. Turn every link with text
|
||||
// "examples/<...>
|
||||
//
|
||||
// Add a "demo" link toward.
|
||||
// https://arthursonzogni.github.io/FTXUI/examples/?file=<...>
|
||||
const examples = document.querySelectorAll("a")
|
||||
examples.forEach((example) => {
|
||||
if (!example.textContent.startsWith("examples/")) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove the ".cpp" extension from the example name.
|
||||
const exampleName = example.textContent.replace("examples/", "").replace(".cpp", "");
|
||||
|
||||
const a = document.createElement("a");
|
||||
a.textContent = "[demo]";
|
||||
a.href = "https://arthursonzogni.github.io/FTXUI/examples/?file=" + exampleName;
|
||||
a.style.marginRight= "1em";
|
||||
a.style.fontWeight = "bold";
|
||||
|
||||
example.parentElement.insertBefore(a, example)
|
||||
});
|
||||
|
||||
// If the current URL ends with -example.html, we can add a link to the demo
|
||||
// as well using the div.title textContent.
|
||||
const url = new URL(window.location.href);
|
||||
if (url.pathname.endsWith("-example.html")) {
|
||||
// Get the title text.
|
||||
const title = document.querySelector("div.title").textContent;
|
||||
const example = title.replace("examples/", "").replace(".cpp", "");
|
||||
|
||||
// Create a link to the demo.
|
||||
const a = document.createElement("a");
|
||||
a.textContent = "[demo]";
|
||||
a.href = "https://arthursonzogni.github.io/FTXUI/examples/?file=" + example;
|
||||
a.style.marginLeft = "1em";
|
||||
a.style.fontWeight = "bold";
|
||||
a.style.display = "inline-block";
|
||||
|
||||
// Insert the link after the title.
|
||||
const titleDiv = document.querySelector("div.title");
|
||||
if (titleDiv) {
|
||||
titleDiv.insertBefore(a, titleDiv.nextSibling);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
<script type="module">
|
||||
// Click on the navtree, except for the main page where this is already done
|
||||
// automatically.
|
||||
let delay = 0;
|
||||
while(true) {
|
||||
const navtree = document.querySelector("div.item.selected");
|
||||
if (!navtree) {
|
||||
delay *= 2;
|
||||
delay += 1;
|
||||
await new Promise(resolve => setTimeout(resolve, delay));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Include only selected navtree items.
|
||||
console.log("navtree.textContent", navtree.textContent);
|
||||
if (!navtree.textContent.includes("Getting Started") &&
|
||||
!navtree.textContent.includes("Installation") &&
|
||||
!navtree.textContent.includes("ftxui / screen") &&
|
||||
!navtree.textContent.includes("ftxui / dom") &&
|
||||
!navtree.textContent.includes("ftxui / component") &&
|
||||
!navtree.textContent.includes("Reference")) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Find the first link inside the navtree.
|
||||
const link = navtree.querySelector("a");
|
||||
if (link) {
|
||||
// Simulate a click on the link.
|
||||
link.click();
|
||||
break;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
$treeview
|
||||
$search
|
||||
$mathjax
|
||||
$darkmode
|
||||
<link href="$relpath^$stylesheet" rel="stylesheet" type="text/css" />
|
||||
$extrastylesheet
|
||||
</head>
|
||||
<body>
|
||||
<!--BEGIN DISABLE_INDEX-->
|
||||
<!--BEGIN FULL_SIDEBAR-->
|
||||
<div id="side-nav" class="ui-resizable side-nav-resizable"><!-- do not remove this div, it is closed by doxygen! -->
|
||||
<!--END FULL_SIDEBAR-->
|
||||
<!--END DISABLE_INDEX-->
|
||||
|
||||
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
||||
|
||||
<!--BEGIN TITLEAREA-->
|
||||
<div id="titlearea">
|
||||
<table cellspacing="0" cellpadding="0">
|
||||
<tbody>
|
||||
<tr id="projectrow">
|
||||
<!--BEGIN PROJECT_LOGO-->
|
||||
<td id="projectlogo"><img alt="Logo" src="$relpath^$projectlogo"/></td>
|
||||
<!--END PROJECT_LOGO-->
|
||||
<!--BEGIN PROJECT_NAME-->
|
||||
<td id="projectalign">
|
||||
<div id="projectname">$projectname<!--BEGIN PROJECT_NUMBER--><span id="projectnumber"> $projectnumber</span><!--END PROJECT_NUMBER-->
|
||||
</div>
|
||||
<!--BEGIN PROJECT_BRIEF--><div id="projectbrief">$projectbrief</div><!--END PROJECT_BRIEF-->
|
||||
</td>
|
||||
<!--END PROJECT_NAME-->
|
||||
<!--BEGIN !PROJECT_NAME-->
|
||||
<!--BEGIN PROJECT_BRIEF-->
|
||||
<td>
|
||||
<div id="projectbrief">$projectbrief</div>
|
||||
</td>
|
||||
<!--END PROJECT_BRIEF-->
|
||||
<!--END !PROJECT_NAME-->
|
||||
<!--BEGIN DISABLE_INDEX-->
|
||||
<!--BEGIN SEARCHENGINE-->
|
||||
<!--BEGIN !FULL_SIDEBAR-->
|
||||
<td>$searchbox</td>
|
||||
<!--END !FULL_SIDEBAR-->
|
||||
<!--END SEARCHENGINE-->
|
||||
<!--END DISABLE_INDEX-->
|
||||
</tr>
|
||||
<!--BEGIN SEARCHENGINE-->
|
||||
<!--BEGIN FULL_SIDEBAR-->
|
||||
<tr><td colspan="2">$searchbox</td></tr>
|
||||
<!--END FULL_SIDEBAR-->
|
||||
<!--END SEARCHENGINE-->
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!--END TITLEAREA-->
|
||||
<!-- end header part -->
|
47
doc/installation.md
Normal file
47
doc/installation.md
Normal file
@@ -0,0 +1,47 @@
|
||||
|
||||
@page installation Installation
|
||||
@tableofcontents
|
||||
|
||||

|
||||
|
||||
## Overview
|
||||
|
||||
FTXUI can be integrated into your project using several build systems and package managers.
|
||||
This page serves as an entry point for the available integration methods.
|
||||
|
||||
## Supported Methods
|
||||
|
||||
- @subpage installation_cmake
|
||||
- @subpage installation_bazel
|
||||
- @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
|
||||
|
||||
Once FTXUI is installed:
|
||||
|
||||
- [Getting Started](getting-started.html): Write and run your first program
|
||||
- [Examples](examples.html): See what FTXUI can do
|
||||
- Modules:
|
||||
- [DOM](module-dom.html)
|
||||
- [Component](module-component.html)
|
||||
- [Screen](module-screen.html)
|
||||
|
||||
## Contributions
|
||||
|
||||
If you use another build system or package manager, feel free to contribute a guide.
|
||||
You can also open a feature request on the [GitHub issue tracker](https://github.com/ArthurSonzogni/FTXUI/issues).
|
||||
|
||||
<div class="section_buttons">
|
||||
|
||||
| Previous |
|
||||
|:------------------|
|
||||
| [Getting Started](getting-started.html) |
|
||||
|
||||
</div>
|
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>
|
38
doc/installation_bazel.md
Normal file
38
doc/installation_bazel.md
Normal file
@@ -0,0 +1,38 @@
|
||||
@page installation_bazel Bazel
|
||||
|
||||
FTXUI can be integrated into your project using [Bazel](https://bazel.build)
|
||||
with Bzlmod (Bazel modules).
|
||||
|
||||
The library is registered in the [Bazel Central Registry](https://registry.bazel.build/modules/ftxui)
|
||||
|
||||
**MODULE.bazel**
|
||||
```starlark
|
||||
bazel_dep(name = "ftxui", version = "6.1.9")
|
||||
```
|
||||
|
||||
**BUILD.bazel**
|
||||
```starlark
|
||||
cc_binary(
|
||||
name = "main",
|
||||
srcs = ["main.cpp"],
|
||||
deps = [
|
||||
"@ftxui//:component",
|
||||
"@ftxui//:dom",
|
||||
"@ftxui//:screen",
|
||||
],
|
||||
)
|
||||
```
|
||||
|
||||
## Starter Project
|
||||
|
||||
You can use the official Bazel starter project for a minimal working setup:
|
||||
|
||||
- [ftxui-bazel (starter)](https://github.com/ArthurSonzogni/ftxui-bazel)
|
||||
|
||||
<div class="section_buttons">
|
||||
|
||||
| Previous |
|
||||
|:------------------|
|
||||
| [Getting Started](getting-started.html) |
|
||||
|
||||
</div>
|
111
doc/installation_cmake.md
Normal file
111
doc/installation_cmake.md
Normal file
@@ -0,0 +1,111 @@
|
||||
@page installation_cmake CMake
|
||||
|
||||
@tableofcontents
|
||||
|
||||
This page explains how to depend on FTXUI using [CMake](https://cmake.org).
|
||||
|
||||
# Methods of Integration
|
||||
|
||||
## Using FetchContent
|
||||
|
||||
This approach downloads FTXUI at configure time and doesn't require a system-wide install.
|
||||
|
||||
```cmake
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(ftxui
|
||||
GIT_REPOSITORY https://github.com/ArthurSonzogni/FTXUI
|
||||
GIT_TAG v6.1.9 # Replace with a version, tag, or commit hash
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(ftxui)
|
||||
|
||||
add_executable(main main.cpp)
|
||||
target_link_libraries(main
|
||||
PRIVATE ftxui::screen
|
||||
PRIVATE ftxui::dom
|
||||
PRIVATE ftxui::component
|
||||
)
|
||||
```
|
||||
|
||||
This ensures reproducible builds and easy dependency management.
|
||||
|
||||
## Using find_package
|
||||
|
||||
If FTXUI is installed system-wide or via a package manager (e.g. vcpkg or Conan), you can use:
|
||||
|
||||
```cmake
|
||||
find_package(ftxui REQUIRED)
|
||||
|
||||
add_executable(main main.cpp)
|
||||
target_link_libraries(main
|
||||
PRIVATE ftxui::screen
|
||||
PRIVATE ftxui::dom
|
||||
PRIVATE ftxui::component
|
||||
)
|
||||
```
|
||||
|
||||
Make sure the package is visible in your `CMAKE_PREFIX_PATH`.
|
||||
|
||||
## Using git submodule
|
||||
|
||||
You can also add FTXUI as a [Git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules), keeping it as part of your repository:
|
||||
|
||||
```cmake
|
||||
git submodule add https://github.com/ArthurSonzogni/FTXUI external/ftxui
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
When cloning a repository that already includes FTXUI as a submodule, make sure to fetch submodules with:
|
||||
|
||||
```
|
||||
git clone --recurse-submodules <your-repo>
|
||||
# Or, if already cloned:
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
Then in your `CMakeLists.txt`:
|
||||
|
||||
```cmake
|
||||
add_subdirectory(external/ftxui)
|
||||
|
||||
add_executable(main main.cpp)
|
||||
target_link_libraries(main
|
||||
PRIVATE ftxui::screen
|
||||
PRIVATE ftxui::dom
|
||||
PRIVATE ftxui::component
|
||||
)
|
||||
```
|
||||
|
||||
This approach works well if you want to vendor FTXUI in your own repository.
|
||||
|
||||
# Optional CMake Flags
|
||||
|
||||
FTXUI supports the following CMake options:
|
||||
|
||||
| Option | Description | Default |
|
||||
| --------------------------------- | ----------------------------- | ------- |
|
||||
| FTXUI_BUILD_EXAMPLES | Build bundled examples | OFF |
|
||||
| FTXUI_BUILD_DOCS | Build the documentation | OFF |
|
||||
| FTXUI_BUILD_TESTS | Enable tests | OFF |
|
||||
| FTXUI_ENABLE_INSTALL | Generate install targets | ON |
|
||||
| FTXUI_MICROSOFT_TERMINAL_FALLBACK | Improve Windows compatibility | ON/OFF |
|
||||
|
||||
To enable an option:
|
||||
|
||||
```
|
||||
cmake -DFTXUI_BUILD_EXAMPLES=ON ..
|
||||
```
|
||||
|
||||
# Verifying Integration
|
||||
|
||||
To confirm the setup is working, build and run a minimal example.
|
||||
If you need a complete template, see: [ftxui-starter](https://github.com/ArthurSonzogni/ftxui-starter)
|
||||
|
||||
<div class="section_buttons">
|
||||
|
||||
| Previous |
|
||||
|:------------------|
|
||||
| [Getting Started](getting-started.html) |
|
||||
|
||||
</div>
|
24
doc/installation_conan.md
Normal file
24
doc/installation_conan.md
Normal file
@@ -0,0 +1,24 @@
|
||||
@page installation_conan Conan
|
||||
|
||||
Unofficial recipe for FTXUI exists on Conan Center:
|
||||
<https://conan.io/center/recipes/ftxui>
|
||||
|
||||
> [!note]
|
||||
> This is an unofficial recipe. That means it is not maintained by the FTXUI
|
||||
> team, but by the community. The package maintainers seems to actively update
|
||||
> the package to the latest version. Thanks to the maintainers for their work!
|
||||
|
||||
|
||||
@todo Add instructions on how to use the conan recipe.
|
||||
|
||||
@todo Please consider adding an "official" recipe to Conan Center if know how.
|
||||
It could be a github action that will automatically update the conan center
|
||||
when a new release is made.
|
||||
|
||||
<div class="section_buttons">
|
||||
|
||||
| Previous |
|
||||
|:------------------|
|
||||
| [Getting Started](getting-started.html) |
|
||||
|
||||
</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>
|
79
doc/installation_vcpkg.md
Normal file
79
doc/installation_vcpkg.md
Normal file
@@ -0,0 +1,79 @@
|
||||
@page installation_vcpkg Vcpkg
|
||||
@tableofcontents
|
||||
|
||||
# Vcpkg Package
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="section_buttons">
|
||||
|
||||
| Previous |
|
||||
|:------------------|
|
||||
| [Getting Started](getting-started.html) |
|
||||
|
||||
</div>
|
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>
|
88
doc/introduction.md
Normal file
88
doc/introduction.md
Normal file
@@ -0,0 +1,88 @@
|
||||
@mainpage Introduction
|
||||
@tableofcontents
|
||||
|
||||
<img src="https://github.com/ArthurSonzogni/FTXUI/assets/4759106/6925b6da-0a7e-49d9-883c-c890e1f36007" alt="Demo image"></img>
|
||||
|
||||
**FTXUI** is simple cross-platform C++ library for terminal based user interfaces!
|
||||
|
||||
# Feature
|
||||
* Functional style. Inspired by
|
||||
[1](https://hackernoon.com/building-reactive-terminal-interfaces-in-c-d392ce34e649?gi=d9fb9ce35901)
|
||||
and [React](https://reactjs.org/)
|
||||
* No dependencies
|
||||
* **Cross platform**.
|
||||
* Simple and elegant syntax (in my opinion)
|
||||
* Keyboard & mouse navigation.
|
||||
* Support for [UTF8](https://en.wikipedia.org/wiki/UTF-8) and [fullwidth chars](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) (→ 测试)
|
||||
* Support for animations. [Demo 1](https://arthursonzogni.github.io/FTXUI/examples/?file=component/menu_underline_animated_gallery), [Demo 2](https://arthursonzogni.github.io/FTXUI/examples/?file=component/button_style)
|
||||
* Support for drawing. [Demo](https://arthursonzogni.github.io/FTXUI/examples/?file=component/canvas_animated)
|
||||
* Learn by [examples](#documentation), and [tutorials](#documentation)
|
||||
* Multiple build system and packages:
|
||||
* Good practices: documentation, tests, fuzzers, performance tests, automated CI, automated packaging, etc...
|
||||
|
||||
# Example
|
||||
|
||||
```cpp
|
||||
#include <ftxui/dom/elements.hpp>
|
||||
#include <ftxui/screen/screen.hpp>
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
|
||||
// Create a simple document with three text elements.
|
||||
Element document = hbox({
|
||||
text("left") | border,
|
||||
text("middle") | border | flex,
|
||||
text("right") | border,
|
||||
});
|
||||
|
||||
// Create a screen with full width and height fitting the document.
|
||||
auto screen = Screen::Create(
|
||||
Dimension::Full(), // Width
|
||||
Dimension::Fit(document) // Height
|
||||
);
|
||||
|
||||
// Render the document onto the screen.
|
||||
Render(screen, document);
|
||||
|
||||
// Print the screen to the console.
|
||||
screen.Print();
|
||||
}
|
||||
```
|
||||
|
||||
Expected output:
|
||||
|
||||
```
|
||||
┌────┐┌────────────────────────────────────┐┌─────┐
|
||||
│left││middle ││right│
|
||||
└────┘└────────────────────────────────────┘└─────┘
|
||||
```
|
||||
|
||||
# Supported Platforms
|
||||
|
||||
- Linux
|
||||
- MacOS
|
||||
- Windows
|
||||
- WebAssembly
|
||||
|
||||
<div class="section_buttons">
|
||||
|
||||
| Next |
|
||||
|--------------------------------------:|
|
||||
| [Getting Started](getting-started.html) |
|
||||
|
||||
</div>
|
||||
|
||||
@defgroup screen ftxui/screen
|
||||
|
||||
Please check the [tutorial](module-screen.html) of the `ftxui/screen` module.
|
||||
|
||||
@defgroup dom ftxui/dom
|
||||
|
||||
Please check the [tutorial](module-dom.html) of the `ftxui/dom` module.
|
||||
|
||||
@defgroup component ftxui/component
|
||||
|
||||
Please check the [tutorial](module-component.html) of the `ftxui/component`
|
||||
module.
|
895
doc/mainpage.md
895
doc/mainpage.md
@@ -1,895 +0,0 @@
|
||||
\mainpage
|
||||
|
||||
# Introduction {#introduction}
|
||||
|
||||
Welcome to the FTXUI documentation!
|
||||
|
||||
This is a brief tutorial. You are also encouraged to self-learn by reading the
|
||||
[examples](./examples.html).
|
||||
|
||||
@tableofcontents
|
||||
|
||||
**Short example**
|
||||
|
||||
To build a single frame, you need create an `ftxui::Element`, and display it on
|
||||
a `ftxui::Screen`.
|
||||
|
||||
**main.cpp**
|
||||
```cpp
|
||||
#include <ftxui/dom/elements.hpp>
|
||||
#include <ftxui/screen/screen.hpp>
|
||||
#include <iostream>
|
||||
|
||||
int main(void) {
|
||||
using namespace ftxui;
|
||||
|
||||
// Define the document
|
||||
Element document =
|
||||
hbox({
|
||||
text("left") | border,
|
||||
text("middle") | border | flex,
|
||||
text("right") | border,
|
||||
});
|
||||
|
||||
auto screen = Screen::Create(
|
||||
Dimension::Full(), // Width
|
||||
Dimension::Fit(document) // Height
|
||||
);
|
||||
Render(screen, document);
|
||||
screen.Print();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
**output**
|
||||
```bash
|
||||
┌────┐┌────────────────────────────────────┐┌─────┐
|
||||
│left││middle ││right│
|
||||
└────┘└────────────────────────────────────┘└─────┘
|
||||
```
|
||||
|
||||
## Configure {#configure}
|
||||
### Using CMake and find_package {#build-cmake-find-package}
|
||||
|
||||
Assuming FTXUI is available or installed on the system.
|
||||
|
||||
**CMakeLists.txt**
|
||||
```cmake
|
||||
cmake_minimum_required (VERSION 3.11)
|
||||
find_package(ftxui 5 REQUIRED)
|
||||
project(ftxui-starter LANGUAGES CXX VERSION 1.0.0)
|
||||
add_executable(ftxui-starter src/main.cpp)
|
||||
target_link_libraries(ftxui-starter
|
||||
PRIVATE ftxui::screen
|
||||
PRIVATE ftxui::dom
|
||||
PRIVATE ftxui::component # Not needed for this example.
|
||||
)
|
||||
|
||||
```
|
||||
|
||||
### Using CMake and FetchContent {#build-cmake}
|
||||
|
||||
If you want to fetch FTXUI using cmake:
|
||||
|
||||
**CMakeLists.txt**
|
||||
```cmake
|
||||
cmake_minimum_required (VERSION 3.11)
|
||||
|
||||
include(FetchContent)
|
||||
set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
|
||||
FetchContent_Declare(ftxui
|
||||
GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
|
||||
GIT_TAG main # Important: Specify a version or a commit hash here.
|
||||
)
|
||||
FetchContent_MakeAvailable(ftxui)
|
||||
|
||||
project(ftxui-starter LANGUAGES CXX VERSION 1.0.0)
|
||||
add_executable(ftxui-starter src/main.cpp)
|
||||
target_link_libraries(ftxui-starter
|
||||
PRIVATE ftxui::screen
|
||||
PRIVATE ftxui::dom
|
||||
PRIVATE ftxui::component # Not needed for this example.
|
||||
)
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
```bash
|
||||
mkdir build && cd build
|
||||
cmake ..
|
||||
make
|
||||
./main
|
||||
```
|
||||
|
||||
# List of modules. {#modules}
|
||||
|
||||
The project is comprised of 3 modules:
|
||||
|
||||
1. **ftxui/screen** defines a `ftxui::Screen`, a grid of `ftxui::Pixel`.
|
||||
|
||||
2. **ftxui/dom** is the main module. It defines a hierarchical set of
|
||||
`ftxui::Element`. An element draws something on the `ftxui::Screen`. It is
|
||||
responsive to the size of its container.
|
||||
|
||||
3. **ftxui/component** The module is required if your program needs to respond
|
||||
to user input. It defines a set of `ftxui::Component`. These components can
|
||||
be utilized to navigate using the arrow keys *and/or* cursor. There are
|
||||
several builtin widgets like checkbox/inputbox/etc to interact with. You can
|
||||
combine them, or even define your own custom components.
|
||||
|
||||
# screen {#module-screen}
|
||||
|
||||
This is the visual element of the program. It defines a `ftxui::Screen`, which
|
||||
is a grid of `ftxui::Pixel`. A Pixel represents a Unicode character and its
|
||||
associated style (bold, italic, colors, etc.). The screen can be printed as a
|
||||
string using `ftxui::Screen::ToString()`. The following example highlights this
|
||||
process:
|
||||
|
||||
```cpp
|
||||
#include <ftxui/screen/screen.hpp>
|
||||
#include <iostream>
|
||||
|
||||
int main(void) {
|
||||
using namespace ftxui;
|
||||
auto screen = Screen::Create(Dimension::Fixed(32), Dimension::Fixed(10));
|
||||
|
||||
auto& pixel = screen.PixelAt(9,9);
|
||||
pixel.character = U'A';
|
||||
pixel.bold = true;
|
||||
pixel.foreground_color = Color::Blue;
|
||||
|
||||
std::cout << screen.ToString();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
```
|
||||
|
||||
# dom {#module-dom}
|
||||
|
||||
This module defines a hierarchical set of `ftxui::Element`. An element manages
|
||||
the layout and can be responsive to the terminal dimension changes. Note the
|
||||
following example where this module is used to create a simple layout with a
|
||||
number of operators:
|
||||
|
||||
**Example:**
|
||||
```cpp
|
||||
// Define the document
|
||||
Element document = vbox({
|
||||
text("The window") | bold | color(Color::Blue),
|
||||
gauge(0.5)
|
||||
text("The footer")
|
||||
});
|
||||
|
||||
// Add a border, by calling the `ftxui::border` decorator function.
|
||||
document = border(document);
|
||||
|
||||
// Add another border, using the pipe operator.
|
||||
document = document | border.
|
||||
|
||||
// Add another border, using the |= operator.
|
||||
document |= border
|
||||
|
||||
```
|
||||
|
||||
**List of elements**
|
||||
|
||||
The list of all elements are included and can be accessed by including the
|
||||
corresponding header file:
|
||||
```cpp
|
||||
#include <ftxui/dom/elements.hpp>
|
||||
```
|
||||
|
||||
\include ftxui/dom/elements.hpp
|
||||
|
||||
## text ## {#dom-text}
|
||||
|
||||
The most simple widget. It displays a text.
|
||||
```cpp
|
||||
text("I am a piece of text");
|
||||
```
|
||||
```bash
|
||||
I am a piece of text.
|
||||
```
|
||||
|
||||
## vtext {#dom-vtext}
|
||||
|
||||
Identical to `ftxui::text`, but displayed vertically.
|
||||
|
||||
Code:
|
||||
```cpp
|
||||
vtext("HELLO");
|
||||
```
|
||||
|
||||
Terminal output:
|
||||
```bash
|
||||
H
|
||||
E
|
||||
L
|
||||
L
|
||||
O
|
||||
```
|
||||
|
||||
## paragraph {#dom-paragraph}
|
||||
|
||||
Similar to `ftxui::text`, but the individual word are wrapped along multiple
|
||||
lines, depending on the width of its container.
|
||||
|
||||
Sample Code:
|
||||
```cpp
|
||||
paragraph("A very long text")
|
||||
```
|
||||
|
||||

|
||||
|
||||
For a more detailed example refer to [detailed example](https://arthursonzogni.github.io/FTXUI/examples_2dom_2paragraph_8cpp-example.html). Paragraph also includes a number of other variants as shown below:
|
||||
```cpp
|
||||
Element paragraph(std::string text);
|
||||
Element paragraphAlignLeft(std::string text);
|
||||
Element paragraphAlignRight(std::string text);
|
||||
Element paragraphAlignCenter(std::string text);
|
||||
Element paragraphAlignJustify(std::string text);
|
||||
```
|
||||
|
||||
|
||||
## border {#dom-border}
|
||||
|
||||
Adds a border around an element.
|
||||
|
||||
Code:
|
||||
```cpp
|
||||
border(text("The element"))
|
||||
```
|
||||
|
||||
Terminal output:
|
||||
```bash
|
||||
┌───────────┐
|
||||
│The element│
|
||||
└───────────┘
|
||||
```
|
||||
|
||||
You can achieve the same behavior by using the pipe operator.
|
||||
|
||||
Code:
|
||||
```cpp
|
||||
text("The element") | border
|
||||
```
|
||||
|
||||
Border also comes in a variety of styles as shown below:
|
||||
```cpp
|
||||
Element border(Element);
|
||||
Element borderLight(Element);
|
||||
Element borderHeavy(Element);
|
||||
Element borderDouble(Element);
|
||||
Element borderRounded(Element);
|
||||
Element borderEmpty(Element);
|
||||
Decorator borderStyled(BorderStyle);
|
||||
Decorator borderWith(Pixel);
|
||||
```
|
||||
|
||||
|
||||
## window ## {#dom-window}
|
||||
|
||||
A `ftxui::window` is a `ftxui::border`, but with an additional header. To add a
|
||||
window around an element, wrap it and specify a string as the header.
|
||||
Code:
|
||||
```cpp
|
||||
window("The window", text("The element"))
|
||||
```
|
||||
|
||||
Terminal output:
|
||||
```bash
|
||||
┌The window─┐
|
||||
│The element│
|
||||
└───────────┘
|
||||
```
|
||||
|
||||
## separator {#dom-separator}
|
||||
|
||||
Displays a vertical/horizontal line to visually split the content of a
|
||||
container in two.
|
||||
|
||||
Code:
|
||||
```cpp
|
||||
border(
|
||||
hbox({
|
||||
text("Left"),
|
||||
separator(),
|
||||
text("Right")
|
||||
})
|
||||
)
|
||||
```
|
||||
|
||||
Terminal output:
|
||||
```bash
|
||||
┌────┬─────┐
|
||||
│left│right│
|
||||
└────┴─────┘
|
||||
```
|
||||
|
||||
|
||||
Separators come in a variety of flavors as shown below:
|
||||
```cpp
|
||||
Element separator(void);
|
||||
Element separatorLight();
|
||||
Element separatorHeavy();
|
||||
Element separatorDouble();
|
||||
Element separatorEmpty();
|
||||
Element separatorStyled(BorderStyle);
|
||||
Element separator(Pixel);
|
||||
Element separatorCharacter(std::string);
|
||||
Element separatorHSelector(float left,
|
||||
float right,
|
||||
Color background,
|
||||
Color foreground);
|
||||
Element separatorVSelector(float up,
|
||||
float down,
|
||||
Color background,
|
||||
Color foreground);
|
||||
```
|
||||
|
||||
## gauge {#dom-gauge}
|
||||
|
||||
It constitutes a gauge. It can be used to represent a progress bar.
|
||||
|
||||
Code:
|
||||
```cpp
|
||||
border(gauge(0.5))
|
||||
```
|
||||
|
||||
Teminal output:
|
||||
```bash
|
||||
┌────────────────────────────────────────────────────────────────────────────┐
|
||||
│██████████████████████████████████████ │
|
||||
└────────────────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
Gauges can be displayed in many orientations as shown below:
|
||||
```cpp
|
||||
Element gauge(float ratio);
|
||||
Element gaugeLeft(float ratio);
|
||||
Element gaugeRight(float ratio);
|
||||
Element gaugeUp(float ratio);
|
||||
Element gaugeDown(float ratio);
|
||||
Element gaugeDirection(float ratio, GaugeDirection);
|
||||
```
|
||||
|
||||
## graph {#dom-graph}
|
||||
|
||||
@htmlonly
|
||||
<script id="asciicast-223726" src="https://asciinema.org/a/223726.js" async></script>
|
||||
@endhtmlonly
|
||||
|
||||
See:
|
||||
```cpp
|
||||
Element graph(GraphFunction);
|
||||
```
|
||||
|
||||
## Colors {#dom-colors}
|
||||
|
||||
Most terminal consoles can display colored text and colored backgrounds. FTXUI
|
||||
supports every color palette:
|
||||
```cpp
|
||||
Decorator color(Color);
|
||||
Decorator bgcolor(Color);
|
||||
```
|
||||
|
||||
|
||||
Color [gallery](https://arthursonzogni.github.io/FTXUI/examples_2dom_2color_gallery_8cpp-example.html):
|
||||

|
||||
|
||||
### Palette16 #{#dom-colors-palette-16}
|
||||
|
||||
On most terminals the following colors are supported:
|
||||
- Default
|
||||
|
||||
- Black
|
||||
- GrayDark
|
||||
- GrayLight
|
||||
|
||||
- White
|
||||
|
||||
- Blue
|
||||
- BlueLight
|
||||
|
||||
- Cyan
|
||||
- CyanLight
|
||||
|
||||
- Green
|
||||
- GreenLight
|
||||
|
||||
- Magenta
|
||||
- MagentaLight
|
||||
|
||||
- Red
|
||||
- RedLight
|
||||
|
||||
- Yellow
|
||||
- YellowLight
|
||||
|
||||
Example use of the above colors using the pipe operator:
|
||||
```cpp
|
||||
text("Blue foreground") | color(Color::Blue);
|
||||
text("Blue background") | bgcolor(Color::Blue);
|
||||
text("Black on white") | color(Color::Black) | bgcolor(Color::White);
|
||||
```
|
||||
|
||||
### Palette256 #{#dom-colors-palette-256}
|
||||
|
||||
On terminal supporting 256 colors.
|
||||
@htmlonly
|
||||
<script id="asciicast-OAUc3n6QrkmrLt7XEEb8AzbLt" src="https://asciinema.org/a/OAUc3n6QrkmrLt7XEEb8AzbLt.js" async></script>
|
||||
@endhtmlonly
|
||||
|
||||
```cpp
|
||||
text("HotPink") | color(Color::HotPink);
|
||||
```
|
||||
|
||||
### TrueColor #{#dom-colors-true-color}
|
||||
|
||||
On terminal supporting trueColor, you can directly use the 24bit RGB color
|
||||
space:
|
||||
|
||||
Use the constructors below to specify the **RGB** or **HSV** values for your
|
||||
color:
|
||||
|
||||
There are two constructors:
|
||||
```cpp
|
||||
ftxui::Color::RGB(uint8_t red, uint8_t green, uint8_t blue);
|
||||
ftxui::Color::HSV(uint8_t hue, uint8_t saturation, uint8_t value);
|
||||
```
|
||||
|
||||
@htmlonly
|
||||
<script id="asciicast-dk5r8IcCH0aFIIgWG0keSEHMG" src="https://asciinema.org/a/dk5r8IcCH0aFIIgWG0keSEHMG.js" async></script>
|
||||
<script id="asciicast-xwzzghmqcqzIuyLwCpQFEqbEu" src="https://asciinema.org/a/xwzzghmqcqzIuyLwCpQFEqbEu.js" async></script>
|
||||
@endhtmlonly
|
||||
|
||||
## LinearGradient #{#dom-linear-gradient}
|
||||
|
||||
FTXUI supports linear gradient. Either on the foreground or the background.
|
||||
|
||||
```cpp
|
||||
Decorator color(const LinearGradient&);
|
||||
Decorator bgcolor(const LinearGradient&);
|
||||
```
|
||||
|
||||
A `ftxui::LinearGradient` is defined by an angle in degree, and a list of color
|
||||
stops.
|
||||
```cpp
|
||||
auto gradient = LinearGradient()
|
||||
.Angle(45)
|
||||
.AddStop(0.0, Color::Red)
|
||||
.AddStop(0.5, Color::Green)
|
||||
.AddStop(1.0, Color::Blue);
|
||||
```
|
||||
|
||||
You can also use simplified constructors:
|
||||
```cpp
|
||||
LinearGradient(Color::Red, Color::Blue);
|
||||
```
|
||||
```cpp
|
||||
LinearGradient(45, Color::Red, Color::Blue);
|
||||
```
|
||||
|
||||
See [demo](https://arthursonzogni.github.io/FTXUI/examples/?file=component/linear_gradient_gallery).
|
||||
|
||||
|
||||
## Style {#dom-style}
|
||||
In addition to colored text and colored backgrounds. Many terminals support text
|
||||
effects such as: `bold`, `italic`, `dim`, `underlined`, `inverted`, `blink`.
|
||||
|
||||
```cpp
|
||||
Element bold(Element);
|
||||
Element italic(Element);
|
||||
Element dim(Element);
|
||||
Element inverted(Element);
|
||||
Element underlined(Element);
|
||||
Element underlinedDouble(Element);
|
||||
Element strikethrough(Element);
|
||||
Element blink(Element);
|
||||
Decorator color(Color);
|
||||
Decorator bgcolor(Color);
|
||||
Decorator colorgrad(LinearGradient);
|
||||
Decorator bgcolorgrad(LinearGradient);
|
||||
```
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2dom_2style_gallery_8cpp-example.html)
|
||||
|
||||

|
||||
|
||||
To use these effects, simply wrap your elements with your desired effect:
|
||||
```cpp
|
||||
underlined(bold(text("This text is bold and underlined")))
|
||||
```
|
||||
|
||||
Alternatively, use the pipe operator to chain it on your element:
|
||||
```cpp
|
||||
text("This text is bold") | bold | underlined
|
||||
```
|
||||
|
||||
## Layout {#dom-layout}
|
||||
|
||||
Enables elements to be arranged in the following ways:
|
||||
- **Horizontally** with `ftxui::hbox`
|
||||
- **Vertically** with `ftxui::vbox`
|
||||
- **Inside a grid** with `ftxui::gridbox`
|
||||
- **Wrapped along one direction** using the `ftxui::flexbox`.
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2dom_2vbox_hbox_8cpp-example.html) using `ftxui::hbox`, `ftxui::vbox` and `ftxui::filler`.
|
||||
|
||||

|
||||
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2dom_2gridbox_8cpp-example.htmlp)
|
||||
using `ftxui::gridbox`:
|
||||
|
||||

|
||||
|
||||
[Example](https://github.com/ArthurSonzogni/FTXUI/blob/master/examples/dom/hflow.cpp)
|
||||
using flexbox:
|
||||
|
||||

|
||||
|
||||
Checkout this
|
||||
[example](https://arthursonzogni.github.io/FTXUI/examples_2dom_2hflow_8cpp-example.html)
|
||||
and the associated
|
||||
[demo](https://arthursonzogni.github.io/FTXUI/examples/?file=component/flexbox).
|
||||
|
||||
Element can also become flexible using the the `ftxui::flex` decorator.
|
||||
|
||||
Code:
|
||||
```cpp
|
||||
hbox({
|
||||
text("left") | border ,
|
||||
text("middle") | border | flex,
|
||||
text("right") | border,
|
||||
});
|
||||
```
|
||||
Terminal output:
|
||||
```bash
|
||||
┌────┐┌─────────────────────────────────────────────────────┐┌─────┐
|
||||
│left││middle ││right│
|
||||
└────┘└─────────────────────────────────────────────────────┘└─────┘
|
||||
```
|
||||
|
||||
Code:
|
||||
```cpp
|
||||
hbox({
|
||||
text("left") | border ,
|
||||
text("middle") | border | flex,
|
||||
text("right") | border | flex,
|
||||
});
|
||||
```
|
||||
|
||||
Terminal output:
|
||||
```bash
|
||||
┌────┐┌───────────────────────────────┐┌───────────────────────────────┐
|
||||
│left││middle ││right │
|
||||
└────┘└───────────────────────────────┘└───────────────────────────────┘
|
||||
```
|
||||
|
||||
## Table {#dom-table}
|
||||
|
||||
Enables easy formatting of data into a neat table like visual form.
|
||||
|
||||
[Code example](https://arthursonzogni.github.io/FTXUI/examples_2dom_2table_8cpp-example.html):
|
||||
|
||||

|
||||
|
||||
## Canvas {#dom-canvas}
|
||||
|
||||
See the API [<ftxui/dom/canvas.hpp>](./canvas_8hpp_source.html)
|
||||
|
||||
```cpp
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawPointLine(10, 10, 80, 10, Color::Red);
|
||||
auto element = canvas(c);
|
||||
```
|
||||
|
||||
Drawing can be performed on a `ftxui::Canvas`, using braille, block, or simple
|
||||
characters:
|
||||
|
||||
Simple [example](https://github.com/ArthurSonzogni/FTXUI/blob/master/examples/dom/canvas.cpp):
|
||||
|
||||

|
||||
|
||||
Complex [example](https://github.com/ArthurSonzogni/FTXUI/blob/master/examples/component/canvas_animated.cpp):
|
||||
|
||||

|
||||
# component {#module-component}
|
||||
|
||||
The `ftxui::component` module defines the logic that produces interactive
|
||||
components that respond to user events (keyboard, mouse, etc.).
|
||||
|
||||
A `ftxui::ScreenInteractive` defines a main loop that renders a component.
|
||||
|
||||
A `ftxui::Component` is a shared pointer to a `ftxui::ComponentBase`. The latter defines:
|
||||
- `ftxui::ComponentBase::Render()`: How to render the interface.
|
||||
- `ftxui::ComponentBase::OnEvent()`: How to react to events.
|
||||
- `ftxui::ComponentBase::Add()`: Construct a parent/child relationship
|
||||
between two components. The tree of component is used to define how to
|
||||
navigate using the keyboard.
|
||||
|
||||
`ftxui::Element` are used to render a single frame.
|
||||
|
||||
`ftxui::Component` are used to render dynamic user interface, producing multiple
|
||||
frame, and updating its state on events.
|
||||
|
||||
[Gallery](https://arthursonzogni.github.io/FTXUI/examples_2component_2gallery_8cpp-example.html) of multiple components. ([demo](https://arthursonzogni.github.io/FTXUI/examples/?file=component/gallery))
|
||||
|
||||

|
||||
|
||||
All predefined components are available in
|
||||
["ftxui/dom/component.hpp"](./component_8hpp.html)
|
||||
|
||||
\include ftxui/component/component.hpp
|
||||
|
||||
## Input {#component-input}
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2component_2input_8cpp-example.html):
|
||||
|
||||

|
||||
|
||||
Produced by: `ftxui::Input()` from "ftxui/component/component.hpp"
|
||||
|
||||
@htmlonly
|
||||
<script id="asciicast-223719" src="https://asciinema.org/a/223719.js" async></script>
|
||||
@endhtmlonly
|
||||
|
||||
### Filtered input
|
||||
|
||||
On can filter out the characters received by the input component, using
|
||||
`ftxui::CatchEvent`.
|
||||
|
||||
```cpp
|
||||
std::string phone_number;
|
||||
Component input = Input(&phone_number, "phone number");
|
||||
|
||||
// Filter out non-digit characters.
|
||||
input |= CatchEvent([&](Event event) {
|
||||
return event.is_character() && !std::isdigit(event.character()[0]);
|
||||
});
|
||||
|
||||
// Filter out characters past the 10th one.
|
||||
input |= CatchEvent([&](Event event) {
|
||||
return event.is_character() && phone_number.size() >= 10;
|
||||
});
|
||||
```
|
||||
|
||||
## Menu {#component-menu}
|
||||
|
||||
Defines a menu object. It contains a list of entries, one of them is selected.
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2component_2menu_8cpp-example.html):
|
||||
|
||||

|
||||
|
||||
|
||||
Produced by: `ftxui::Menu()` from "ftxui/component/component.hpp"
|
||||
|
||||
@htmlonly
|
||||
<script id="asciicast-223720" src="https://asciinema.org/a/223720.js" async></script>
|
||||
@endhtmlonly
|
||||
|
||||
## Toggle {#component-toggle}
|
||||
|
||||
A special kind of menu. The entries are displayed horizontally.
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2component_2toggle_8cpp-example.html):
|
||||
|
||||

|
||||
|
||||
Produced by: `ftxui::Toggle()` from "ftxui/component/component.hpp"
|
||||
|
||||
@htmlonly
|
||||
<script id="asciicast-223722" src="https://asciinema.org/a/223722.js" async></script>
|
||||
@endhtmlonly
|
||||
|
||||
## CheckBox {#component-checkbox}
|
||||
|
||||
This component defines a checkbox. It is a single entry that can be turned
|
||||
on/off.
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2component_2checkbox_8cpp-example.html):
|
||||
|
||||

|
||||
|
||||
Produced by: `ftxui::Checkbox()` from "ftxui/component/component.hpp"
|
||||
|
||||
@htmlonly
|
||||
<script id="asciicast-223724" src="https://asciinema.org/a/223724.js" async></script>
|
||||
@endhtmlonly
|
||||
|
||||
## RadioBox {#component-radiobox}
|
||||
|
||||
A radiobutton component. This is a list of entries, where one can be turned on.
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2component_2radiobox_8cpp-example.html):
|
||||
|
||||

|
||||
|
||||
Produced by: `ftxui::Radiobox()` from "ftxui/component/component.hpp"
|
||||
|
||||
@htmlonly
|
||||
<script id="asciicast-223725" src="https://asciinema.org/a/223725.js" async></script>
|
||||
@endhtmlonly
|
||||
|
||||
## Dropdown {#component-dropdown}
|
||||
|
||||
A drop down menu is a component that when checked display a list of element for
|
||||
the user to select one.
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2component_2dropdown_8cpp-example.html):
|
||||
|
||||

|
||||
|
||||
Produced by: `ftxui::Dropdown()` from "ftxui/component/component.hpp"
|
||||
|
||||
## Slider {#component-slider}
|
||||
|
||||
Represents a slider object that consists of a range with binned intermediate
|
||||
intervals. It can be created by `ftxui::Slider()`.
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2component_2slider_8cpp-example.html):
|
||||
|
||||

|
||||
|
||||
Produced by: `ftxui::Slider()` from "ftxui/component/component.hpp"
|
||||
|
||||
## Renderer {#component-renderer}
|
||||
|
||||
Produced by: `ftxui::Renderer()` from \ref ftxui/component/component.hpp. This
|
||||
component decorate another one by using a different function to render an
|
||||
interface.
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
auto inner = [...]
|
||||
|
||||
auto renderer = Renderer(inner, [&] {
|
||||
return inner->Render() | border
|
||||
});
|
||||
```
|
||||
|
||||
`ftxui::Renderer` also supports the component decorator pattern:
|
||||
```cpp
|
||||
auto component = [...]
|
||||
component = component
|
||||
| Renderer([](Element e) { return e | border))
|
||||
| Renderer(bold)
|
||||
```
|
||||
|
||||
As a short hand, you can also compose a component with an element decorator:
|
||||
```cpp
|
||||
auto component = [...]
|
||||
component = component | border | bold;
|
||||
```
|
||||
|
||||
## CatchEvent {#component-catchevent}
|
||||
|
||||
Produced by: `ftxui::CatchEvent()` from \ref ftxui/component/component.hpp.
|
||||
This component decorate others, catching events before the underlying component.
|
||||
|
||||
Examples:
|
||||
```cpp
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
auto renderer = Renderer([] {
|
||||
return text("My interface");
|
||||
});
|
||||
auto component = CatchEvent(renderer, [&](Event event) {
|
||||
if (event == Event::Character('q')) {
|
||||
screen.ExitLoopClosure()();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
screen.Loop(component);
|
||||
```
|
||||
|
||||
The `ftxui::CatchEvent` can also be used as a decorator:
|
||||
```cpp
|
||||
component = component
|
||||
| CatchEvent(handler_1)
|
||||
| CatchEvent(handler_2)
|
||||
| CatchEvent(handler_3)
|
||||
;
|
||||
```
|
||||
|
||||
## Collapsible {#component-collapsible}
|
||||
|
||||
Useful for visual elements whose visibility can be toggle on/off by the user.
|
||||
Essentially, this the combination of the `ftxui::Checkbox()` and
|
||||
`ftxui::Maybe()` components.
|
||||
|
||||
```cpp
|
||||
auto collabsible = Collapsible("Show more", inner_element);
|
||||
```
|
||||
|
||||
## Maybe {#component-maybe}
|
||||
|
||||
Produced by: `ftxui::Maybe()` from \ref ftxui/component/component.hpp.
|
||||
This component can be utilized to show/hide any other component via a boolean or
|
||||
a predicate.
|
||||
|
||||
Example with a boolean:
|
||||
```cpp
|
||||
bool show = true;
|
||||
auto component = Renderer([]{ return "Hello World!"; });
|
||||
auto maybe_component = Maybe(component, &show)
|
||||
```
|
||||
|
||||
Example with a predicate:
|
||||
```cpp
|
||||
auto component = Renderer([]{ return "Hello World!"; });
|
||||
auto maybe_component = Maybe(component, [&] { return time > 10; })
|
||||
```
|
||||
|
||||
As usual, `ftxui::Maybe` can also be used as a decorator:
|
||||
```cpp
|
||||
component = component
|
||||
| Maybe(&a_boolean)
|
||||
| Maybe([&] { return time > 10; })
|
||||
;
|
||||
```
|
||||
|
||||
## Container {#component-container}
|
||||
|
||||
### Horizontal {#component-horizontal}
|
||||
|
||||
Produced by: `ftxui::Container::Horizontal()` from
|
||||
"ftxui/component/component.hpp". It displays a list of components horizontally
|
||||
and handle keyboard/mouse navigation.
|
||||
|
||||
### Vertical {#component-vertical}
|
||||
|
||||
Produced by: `ftxui::Container::Vertical()` from
|
||||
"ftxui/component/component.hpp". It displays a list of components vertically
|
||||
and handles keyboard/mouse navigation.
|
||||
|
||||
### Tab {#component-tab}
|
||||
|
||||
Produced by: `ftxui::Container::Tab()` from
|
||||
"ftxui/component/component.hpp". It take a list of component and display only
|
||||
one of them. This is useful for implementing a tab bar.
|
||||
|
||||
[Vertical](https://arthursonzogni.github.io/FTXUI/examples_2component_2tab_vertical_8cpp-example.html):
|
||||
|
||||

|
||||
|
||||
[Horizontal](https://arthursonzogni.github.io/FTXUI/examples_2component_2tab_horizontal_8cpp-example.html):
|
||||
|
||||

|
||||
|
||||
|
||||
## ResizableSplit {#component-resizable-split}
|
||||
|
||||
It defines a horizontal or vertical separation between two children components.
|
||||
The position of the split is variable and controllable using the mouse.
|
||||
There are four possible splits:
|
||||
- `ftxui::ResizableSplitLeft()`
|
||||
- `ftxui::ResizableSplitRight()`
|
||||
- `ftxui::ResizableSplitTop()`
|
||||
- `ftxui::ResizableSplitBottom()`
|
||||
from "ftxui/component/component.hpp"
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2component_2resizable_split_8cpp-example.html):
|
||||
|
||||

|
||||
|
||||
@htmlonly
|
||||
<script id="asciicast-tprMH2EdkUoMb7D2YxgMGgpzx" src="https://asciinema.org/a/tprMH2EdkUoMb7D2YxgMGgpzx.js" async></script>
|
||||
@endhtmlonly
|
||||
|
||||
## Force a frame redraw. {#component-force-redraw}
|
||||
|
||||
Typically, `ftxui::ScreenInteractive::Loop()` is responsible for drawing a new
|
||||
frame whenever a new group of events (e.g keyboard, mouse, window resize, etc.)
|
||||
has been processed. However, you might want to react to arbitrary events that
|
||||
are unknown to FTXUI. To accomplish this, you must post events using
|
||||
`ftxui::ScreenInteractive::PostEvent` (**this is thread safe**) via a thread.
|
||||
You will have to post the event `ftxui::Event::Custom`.
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
screen->PostEvent(Event::Custom);
|
||||
```
|
308
doc/module-component.md
Normal file
308
doc/module-component.md
Normal file
@@ -0,0 +1,308 @@
|
||||
@page module-component ftxui / component
|
||||
@tableofcontents
|
||||
|
||||

|
||||
|
||||
The `ftxui::component` module defines the logic that produces interactive
|
||||
components that respond to user events (keyboard, mouse, etc.).
|
||||
|
||||
The @subpage module-component-examples section provides a collection of examples.
|
||||
|
||||
A `ftxui::ScreenInteractive` defines a main loop that renders a component.
|
||||
|
||||
A `ftxui::Component` is a shared pointer to a `ftxui::ComponentBase`. The latter defines:
|
||||
- `ftxui::ComponentBase::Render()`: How to render the interface.
|
||||
- `ftxui::ComponentBase::OnEvent()`: How to react to events.
|
||||
- `ftxui::ComponentBase::Add()`: Construct a parent/child relationship
|
||||
between two components. The tree of components is used to define how to
|
||||
navigate using the keyboard.
|
||||
|
||||
`ftxui::Element` are used to render a single frame.
|
||||
|
||||
`ftxui::Component` are used to render dynamic user interface, producing multiple
|
||||
frame, and updating its state on events.
|
||||
|
||||
[Gallery](https://arthursonzogni.github.io/FTXUI/examples_2component_2gallery_8cpp-example.html) of multiple components. ([demo](https://arthursonzogni.github.io/FTXUI/examples/?file=component/gallery))
|
||||
|
||||

|
||||
|
||||
All predefined components are available in
|
||||
["ftxui/dom/component.hpp"](./component_8hpp.html)
|
||||
|
||||
\include ftxui/component/component.hpp
|
||||
|
||||
# Input {#component-input}
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2component_2input_8cpp-example.html):
|
||||
|
||||

|
||||
|
||||
Produced by: `ftxui::Input()` from "ftxui/component/component.hpp"
|
||||
|
||||
@htmlonly
|
||||
<script id="asciicast-223719" src="https://asciinema.org/a/223719.js" async></script>
|
||||
@endhtmlonly
|
||||
|
||||
## Filtered input
|
||||
|
||||
One can filter out the characters received by the input component, using
|
||||
`ftxui::CatchEvent`.
|
||||
|
||||
```cpp
|
||||
std::string phone_number;
|
||||
Component input = Input(&phone_number, "phone number");
|
||||
|
||||
// Filter out non-digit characters.
|
||||
input |= CatchEvent([&](Event event) {
|
||||
return event.is_character() && !std::isdigit(event.character()[0]);
|
||||
});
|
||||
|
||||
// Filter out characters past the 10th one.
|
||||
input |= CatchEvent([&](Event event) {
|
||||
return event.is_character() && phone_number.size() >= 10;
|
||||
});
|
||||
```
|
||||
|
||||
# Menu {#component-menu}
|
||||
|
||||
Defines a menu object. It contains a list of entries, one of them is selected.
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2component_2menu_8cpp-example.html):
|
||||
|
||||

|
||||
|
||||
|
||||
Produced by: `ftxui::Menu()` from "ftxui/component/component.hpp"
|
||||
|
||||
@htmlonly
|
||||
<script id="asciicast-223720" src="https://asciinema.org/a/223720.js" async></script>
|
||||
@endhtmlonly
|
||||
|
||||
# Toggle {#component-toggle}
|
||||
|
||||
A special kind of menu. The entries are displayed horizontally.
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2component_2toggle_8cpp-example.html):
|
||||
|
||||

|
||||
|
||||
Produced by: `ftxui::Toggle()` from "ftxui/component/component.hpp"
|
||||
|
||||
@htmlonly
|
||||
<script id="asciicast-223722" src="https://asciinema.org/a/223722.js" async></script>
|
||||
@endhtmlonly
|
||||
|
||||
# CheckBox {#component-checkbox}
|
||||
|
||||
This component defines a checkbox. It is a single entry that can be turned
|
||||
on/off.
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2component_2checkbox_8cpp-example.html):
|
||||
|
||||

|
||||
|
||||
Produced by: `ftxui::Checkbox()` from "ftxui/component/component.hpp"
|
||||
|
||||
@htmlonly
|
||||
<script id="asciicast-223724" src="https://asciinema.org/a/223724.js" async></script>
|
||||
@endhtmlonly
|
||||
|
||||
# RadioBox {#component-radiobox}
|
||||
|
||||
A radiobutton component. This is a list of entries, where one can be turned on.
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2component_2radiobox_8cpp-example.html):
|
||||
|
||||

|
||||
|
||||
Produced by: `ftxui::Radiobox()` from "ftxui/component/component.hpp"
|
||||
|
||||
@htmlonly
|
||||
<script id="asciicast-223725" src="https://asciinema.org/a/223725.js" async></script>
|
||||
@endhtmlonly
|
||||
|
||||
# Dropdown {#component-dropdown}
|
||||
|
||||
A drop-down menu is a component that, when opened, displays a list of elements
|
||||
for the user to select from.
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2component_2dropdown_8cpp-example.html):
|
||||
|
||||

|
||||
|
||||
Produced by: `ftxui::Dropdown()` from "ftxui/component/component.hpp"
|
||||
|
||||
# Slider {#component-slider}
|
||||
|
||||
Represents a slider object that consists of a range with binned intermediate
|
||||
intervals. It can be created by `ftxui::Slider()`.
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2component_2slider_8cpp-example.html):
|
||||
|
||||

|
||||
|
||||
Produced by: `ftxui::Slider()` from "ftxui/component/component.hpp"
|
||||
|
||||
# Renderer {#component-renderer}
|
||||
|
||||
Produced by: `ftxui::Renderer()` from \ref ftxui/component/component.hpp. This
|
||||
component decorate another one by using a different function to render an
|
||||
interface.
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
auto inner = [...]
|
||||
|
||||
auto renderer = Renderer(inner, [&] {
|
||||
return inner->Render() | border
|
||||
});
|
||||
```
|
||||
|
||||
`ftxui::Renderer` also supports the component decorator pattern:
|
||||
```cpp
|
||||
auto component = [...]
|
||||
component = component
|
||||
| Renderer([](Element e) { return e | border))
|
||||
| Renderer(bold)
|
||||
```
|
||||
|
||||
As a short hand, you can also compose a component with an element decorator:
|
||||
```cpp
|
||||
auto component = [...]
|
||||
component = component | border | bold;
|
||||
```
|
||||
|
||||
# CatchEvent {#component-catchevent}
|
||||
|
||||
Produced by: `ftxui::CatchEvent()` from \ref ftxui/component/component.hpp.
|
||||
This component decorate others, catching events before the underlying component.
|
||||
|
||||
Examples:
|
||||
```cpp
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
auto renderer = Renderer([] {
|
||||
return text("My interface");
|
||||
});
|
||||
auto component = CatchEvent(renderer, [&](Event event) {
|
||||
if (event == Event::Character('q')) {
|
||||
screen.ExitLoopClosure()();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
screen.Loop(component);
|
||||
```
|
||||
|
||||
The `ftxui::CatchEvent` can also be used as a decorator:
|
||||
```cpp
|
||||
component = component
|
||||
| CatchEvent(handler_1)
|
||||
| CatchEvent(handler_2)
|
||||
| CatchEvent(handler_3)
|
||||
;
|
||||
```
|
||||
|
||||
# Collapsible {#component-collapsible}
|
||||
|
||||
Useful for visual elements whose visibility can be toggled on or off by the
|
||||
user. Essentially, this is the combination of the `ftxui::Checkbox()` and
|
||||
`ftxui::Maybe()` components.
|
||||
|
||||
```cpp
|
||||
auto collapsible = Collapsible("Show more", inner_element);
|
||||
```
|
||||
|
||||
# Maybe {#component-maybe}
|
||||
|
||||
Produced by: `ftxui::Maybe()` from \ref ftxui/component/component.hpp.
|
||||
This component can be utilized to show/hide any other component via a boolean or
|
||||
a predicate.
|
||||
|
||||
Example with a boolean:
|
||||
```cpp
|
||||
bool show = true;
|
||||
auto component = Renderer([]{ return "Hello World!"; });
|
||||
auto maybe_component = Maybe(component, &show)
|
||||
```
|
||||
|
||||
Example with a predicate:
|
||||
```cpp
|
||||
auto component = Renderer([]{ return "Hello World!"; });
|
||||
auto maybe_component = Maybe(component, [&] { return time > 10; })
|
||||
```
|
||||
|
||||
As usual, `ftxui::Maybe` can also be used as a decorator:
|
||||
```cpp
|
||||
component = component
|
||||
| Maybe(&a_boolean)
|
||||
| Maybe([&] { return time > 10; })
|
||||
;
|
||||
```
|
||||
|
||||
# Container {#component-container}
|
||||
|
||||
## Horizontal {#component-horizontal}
|
||||
|
||||
Produced by: `ftxui::Container::Horizontal()` from
|
||||
"ftxui/component/component.hpp". It displays a list of components horizontally
|
||||
and handles keyboard/mouse navigation.
|
||||
|
||||
## Vertical {#component-vertical}
|
||||
|
||||
Produced by: `ftxui::Container::Vertical()` from
|
||||
"ftxui/component/component.hpp". It displays a list of components vertically
|
||||
and handles keyboard/mouse navigation.
|
||||
|
||||
## Tab {#component-tab}
|
||||
|
||||
Produced by: `ftxui::Container::Tab()` from
|
||||
"ftxui/component/component.hpp". It takes a list of components and displays
|
||||
only one of them. This is useful for implementing a tab bar.
|
||||
|
||||
[Vertical](https://arthursonzogni.github.io/FTXUI/examples_2component_2tab_vertical_8cpp-example.html):
|
||||
|
||||

|
||||
|
||||
[Horizontal](https://arthursonzogni.github.io/FTXUI/examples_2component_2tab_horizontal_8cpp-example.html):
|
||||
|
||||

|
||||
|
||||
|
||||
# ResizableSplit {#component-resizable-split}
|
||||
|
||||
It defines a horizontal or vertical separation between two children components.
|
||||
The position of the split is variable and controllable using the mouse.
|
||||
There are four possible splits:
|
||||
- `ftxui::ResizableSplitLeft()`
|
||||
- `ftxui::ResizableSplitRight()`
|
||||
- `ftxui::ResizableSplitTop()`
|
||||
- `ftxui::ResizableSplitBottom()`
|
||||
from "ftxui/component/component.hpp"
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2component_2resizable_split_8cpp-example.html):
|
||||
|
||||

|
||||
|
||||
@htmlonly
|
||||
<script id="asciicast-tprMH2EdkUoMb7D2YxgMGgpzx" src="https://asciinema.org/a/tprMH2EdkUoMb7D2YxgMGgpzx.js" async></script>
|
||||
@endhtmlonly
|
||||
|
||||
# Force a frame redraw. {#component-force-redraw}
|
||||
|
||||
Typically, `ftxui::ScreenInteractive::Loop()` is responsible for drawing a new
|
||||
frame whenever a new group of events (e.g keyboard, mouse, window resize, etc.)
|
||||
has been processed. However, you might want to react to arbitrary events that
|
||||
are unknown to FTXUI. To accomplish this, you must post events using
|
||||
`ftxui::ScreenInteractive::PostEvent` (**this is thread safe**) via a thread.
|
||||
You will have to post the event `ftxui::Event::Custom`.
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
screen->PostEvent(Event::Custom);
|
||||
```
|
||||
|
||||
If you don't need to process a new Event, you can use:
|
||||
```cpp
|
||||
screen->RequestAnimationFrame();
|
||||
```
|
||||
instead.
|
470
doc/module-dom.md
Normal file
470
doc/module-dom.md
Normal file
@@ -0,0 +1,470 @@
|
||||
@page module-dom ftxui / dom
|
||||
@tableofcontents
|
||||
|
||||

|
||||
|
||||
This module defines a hierarchical set of `ftxui::Element`. An element manages
|
||||
the layout and can be responsive to the terminal dimension changes. Note the
|
||||
following example where this module is used to create a simple layout with a
|
||||
number of operators:
|
||||
|
||||
The @subpage module-dom-examples section provides a collection of examples.
|
||||
|
||||
**Example:**
|
||||
```cpp
|
||||
namespace ftxui {
|
||||
...
|
||||
|
||||
// Define the document
|
||||
Element document = vbox({
|
||||
text("The window") | bold | color(Color::Blue),
|
||||
gauge(0.5)
|
||||
text("The footer")
|
||||
});
|
||||
|
||||
// Add a border, by calling the `ftxui::border` decorator function.
|
||||
document = border(document);
|
||||
|
||||
// Add another border, using the pipe operator.
|
||||
document = document | border.
|
||||
|
||||
// Add another border, using the |= operator.
|
||||
document |= border
|
||||
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
**List of elements**
|
||||
|
||||
The list of all elements are included and can be accessed by including the
|
||||
corresponding header file:
|
||||
```cpp
|
||||
#include <ftxui/dom/elements.hpp>
|
||||
```
|
||||
|
||||
\include{strip} "ftxui/dom/elements.hpp"
|
||||
|
||||
# text # {#dom-text}
|
||||
|
||||
The most simple widget. It displays a text.
|
||||
```cpp
|
||||
text("I am a piece of text");
|
||||
```
|
||||
```bash
|
||||
I am a piece of text.
|
||||
```
|
||||
|
||||
# vtext {#dom-vtext}
|
||||
|
||||
Identical to `ftxui::text`, but displayed vertically.
|
||||
|
||||
Code:
|
||||
```cpp
|
||||
vtext("HELLO");
|
||||
```
|
||||
|
||||
Terminal output:
|
||||
```bash
|
||||
H
|
||||
E
|
||||
L
|
||||
L
|
||||
O
|
||||
```
|
||||
|
||||
# paragraph {#dom-paragraph}
|
||||
|
||||
Similar to `ftxui::text`, but the individual word are wrapped along multiple
|
||||
lines, depending on the width of its container.
|
||||
|
||||
Sample Code:
|
||||
```cpp
|
||||
paragraph("A very long text")
|
||||
```
|
||||
|
||||

|
||||
|
||||
For a more detailed example refer to [detailed example](https://arthursonzogni.github.io/FTXUI/examples_2dom_2paragraph_8cpp-example.html). Paragraph also includes a number of other variants as shown below:
|
||||
```cpp
|
||||
namespace ftxui {
|
||||
Element paragraph(std::string text);
|
||||
Element paragraphAlignLeft(std::string text);
|
||||
Element paragraphAlignRight(std::string text);
|
||||
Element paragraphAlignCenter(std::string text);
|
||||
Element paragraphAlignJustify(std::string text);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
# border {#dom-border}
|
||||
|
||||
Adds a border around an element.
|
||||
|
||||
Code:
|
||||
```cpp
|
||||
border(text("The element"))
|
||||
```
|
||||
|
||||
Terminal output:
|
||||
```bash
|
||||
┌───────────┐
|
||||
│The element│
|
||||
└───────────┘
|
||||
```
|
||||
|
||||
> [!note]
|
||||
> You can achieve the same behavior by using the pipe operator.
|
||||
>
|
||||
> Code:
|
||||
> ```cpp
|
||||
> text("The element") | border
|
||||
> ```
|
||||
|
||||
Border also comes in a variety of styles as shown below:
|
||||
```cpp
|
||||
namespace ftxui {
|
||||
Element border(Element);
|
||||
Element borderLight(Element);
|
||||
Element borderHeavy(Element);
|
||||
Element borderDouble(Element);
|
||||
Element borderRounded(Element);
|
||||
Element borderEmpty(Element);
|
||||
Decorator borderStyled(BorderStyle);
|
||||
Decorator borderWith(Pixel);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
# window # {#dom-window}
|
||||
|
||||
A `ftxui::window` is a `ftxui::border`, but with an additional header. To add a
|
||||
window around an element, wrap it and specify a string as the header.
|
||||
Code:
|
||||
```cpp
|
||||
window("The window", text("The element"))
|
||||
```
|
||||
|
||||
Terminal output:
|
||||
```bash
|
||||
┌The window─┐
|
||||
│The element│
|
||||
└───────────┘
|
||||
```
|
||||
|
||||
# separator {#dom-separator}
|
||||
|
||||
Displays a vertical/horizontal line to visually split the content of a
|
||||
container in two.
|
||||
|
||||
Code:
|
||||
```cpp
|
||||
border(
|
||||
hbox({
|
||||
text("Left"),
|
||||
separator(),
|
||||
text("Right")
|
||||
})
|
||||
)
|
||||
```
|
||||
|
||||
Terminal output:
|
||||
```bash
|
||||
┌────┬─────┐
|
||||
│left│right│
|
||||
└────┴─────┘
|
||||
```
|
||||
|
||||
|
||||
Separators come in a variety of flavors as shown below:
|
||||
```cpp
|
||||
namespace ftxui {
|
||||
Element separator(void);
|
||||
Element separatorLight();
|
||||
Element separatorHeavy();
|
||||
Element separatorDouble();
|
||||
Element separatorEmpty();
|
||||
Element separatorStyled(BorderStyle);
|
||||
Element separator(Pixel);
|
||||
Element separatorCharacter(std::string);
|
||||
Element separatorHSelector(float left,
|
||||
float right,
|
||||
Color background,
|
||||
Color foreground);
|
||||
Element separatorVSelector(float up,
|
||||
float down,
|
||||
Color background,
|
||||
Color foreground);
|
||||
}
|
||||
```
|
||||
|
||||
# gauge {#dom-gauge}
|
||||
|
||||
This is a visual element that represents a ratio of progress.
|
||||
|
||||
Code:
|
||||
```cpp
|
||||
border(gauge(0.5))
|
||||
```
|
||||
|
||||
Terminal output:
|
||||
```bash
|
||||
┌────────────────────────────────────────────────────────────────────────────┐
|
||||
│██████████████████████████████████████ │
|
||||
└────────────────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
Gauges can be displayed in many orientations as shown below:
|
||||
```cpp
|
||||
namespace {
|
||||
Element gauge(float ratio);
|
||||
Element gaugeLeft(float ratio);
|
||||
Element gaugeRight(float ratio);
|
||||
Element gaugeUp(float ratio);
|
||||
Element gaugeDown(float ratio);
|
||||
Element gaugeDirection(float ratio, GaugeDirection);
|
||||
}
|
||||
```
|
||||
|
||||
# graph {#dom-graph}
|
||||
|
||||
@htmlonly
|
||||
<script id="asciicast-223726" src="https://asciinema.org/a/223726.js" async></script>
|
||||
@endhtmlonly
|
||||
|
||||
See:
|
||||
```cpp
|
||||
Element graph(GraphFunction);
|
||||
```
|
||||
|
||||
# Colors {#dom-colors}
|
||||
|
||||
Most terminal consoles can display colored text and colored backgrounds. FTXUI
|
||||
supports every color palette:
|
||||
```cpp
|
||||
Decorator color(Color);
|
||||
Decorator bgcolor(Color);
|
||||
```
|
||||
|
||||
|
||||
Color [gallery](https://arthursonzogni.github.io/FTXUI/examples_2dom_2color_gallery_8cpp-example.html):
|
||||

|
||||
|
||||
## Palette16 #{#dom-colors-palette-16}
|
||||
|
||||
On most terminals the following colors are supported:
|
||||
- Default
|
||||
|
||||
- Black
|
||||
- GrayDark
|
||||
- GrayLight
|
||||
|
||||
- White
|
||||
|
||||
- Blue
|
||||
- BlueLight
|
||||
|
||||
- Cyan
|
||||
- CyanLight
|
||||
|
||||
- Green
|
||||
- GreenLight
|
||||
|
||||
- Magenta
|
||||
- MagentaLight
|
||||
|
||||
- Red
|
||||
- RedLight
|
||||
|
||||
- Yellow
|
||||
- YellowLight
|
||||
|
||||
Example use of the above colors using the pipe operator:
|
||||
```cpp
|
||||
text("Blue foreground") | color(Color::Blue);
|
||||
text("Blue background") | bgcolor(Color::Blue);
|
||||
text("Black on white") | color(Color::Black) | bgcolor(Color::White);
|
||||
```
|
||||
|
||||
## Palette256 #{#dom-colors-palette-256}
|
||||
|
||||
On terminal supporting 256 colors.
|
||||
@htmlonly
|
||||
<script id="asciicast-OAUc3n6QrkmrLt7XEEb8AzbLt" src="https://asciinema.org/a/OAUc3n6QrkmrLt7XEEb8AzbLt.js" async></script>
|
||||
@endhtmlonly
|
||||
|
||||
```cpp
|
||||
text("HotPink") | color(Color::HotPink);
|
||||
```
|
||||
|
||||
## TrueColor #{#dom-colors-true-color}
|
||||
|
||||
On terminal supporting trueColor, you can directly use the 24bit RGB color
|
||||
space:
|
||||
|
||||
Use the constructors below to specify the **RGB** or **HSV** values for your
|
||||
color:
|
||||
|
||||
There are two constructors:
|
||||
```cpp
|
||||
ftxui::Color::RGB(uint8_t red, uint8_t green, uint8_t blue);
|
||||
ftxui::Color::HSV(uint8_t hue, uint8_t saturation, uint8_t value);
|
||||
```
|
||||
|
||||
@htmlonly
|
||||
<script id="asciicast-dk5r8IcCH0aFIIgWG0keSEHMG" src="https://asciinema.org/a/dk5r8IcCH0aFIIgWG0keSEHMG.js" async></script>
|
||||
<script id="asciicast-xwzzghmqcqzIuyLwCpQFEqbEu" src="https://asciinema.org/a/xwzzghmqcqzIuyLwCpQFEqbEu.js" async></script>
|
||||
@endhtmlonly
|
||||
|
||||
# LinearGradient #{#dom-linear-gradient}
|
||||
|
||||
FTXUI supports linear gradient. Either on the foreground or the background.
|
||||
|
||||
```cpp
|
||||
Decorator color(const LinearGradient&);
|
||||
Decorator bgcolor(const LinearGradient&);
|
||||
```
|
||||
|
||||
A `ftxui::LinearGradient` is defined by an angle in degree, and a list of color
|
||||
stops.
|
||||
```cpp
|
||||
auto gradient = LinearGradient()
|
||||
.Angle(45)
|
||||
.AddStop(0.0, Color::Red)
|
||||
.AddStop(0.5, Color::Green)
|
||||
.AddStop(1.0, Color::Blue);
|
||||
```
|
||||
|
||||
You can also use simplified constructors:
|
||||
```cpp
|
||||
LinearGradient(Color::Red, Color::Blue);
|
||||
```
|
||||
```cpp
|
||||
LinearGradient(45, Color::Red, Color::Blue);
|
||||
```
|
||||
|
||||
See [demo](https://arthursonzogni.github.io/FTXUI/examples/?file=component/linear_gradient_gallery).
|
||||
|
||||
|
||||
# Style {#dom-style}
|
||||
In addition to colored text and colored backgrounds. Many terminals support text
|
||||
effects such as: `bold`, `italic`, `dim`, `underlined`, `inverted`, `blink`.
|
||||
|
||||
```cpp
|
||||
Element bold(Element);
|
||||
Element italic(Element);
|
||||
Element dim(Element);
|
||||
Element inverted(Element);
|
||||
Element underlined(Element);
|
||||
Element underlinedDouble(Element);
|
||||
Element strikethrough(Element);
|
||||
Element blink(Element);
|
||||
Decorator color(Color);
|
||||
Decorator bgcolor(Color);
|
||||
Decorator colorgrad(LinearGradient);
|
||||
Decorator bgcolorgrad(LinearGradient);
|
||||
```
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2dom_2style_gallery_8cpp-example.html)
|
||||
|
||||

|
||||
|
||||
To use these effects, simply wrap your elements with your desired effect:
|
||||
```cpp
|
||||
underlined(bold(text("This text is bold and underlined")))
|
||||
```
|
||||
|
||||
Alternatively, use the pipe operator to chain it on your element:
|
||||
```cpp
|
||||
text("This text is bold") | bold | underlined
|
||||
```
|
||||
|
||||
# Layout {#dom-layout}
|
||||
|
||||
Enables elements to be arranged in the following ways:
|
||||
- **Horizontally** with `ftxui::hbox`
|
||||
- **Vertically** with `ftxui::vbox`
|
||||
- **Inside a grid** with `ftxui::gridbox`
|
||||
- **Wrapped along one direction** using the `ftxui::flexbox`.
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2dom_2vbox_hbox_8cpp-example.html) using `ftxui::hbox`, `ftxui::vbox` and `ftxui::filler`.
|
||||
|
||||

|
||||
|
||||
|
||||
[Example](https://arthursonzogni.github.io/FTXUI/examples_2dom_2gridbox_8cpp-example.htmlp)
|
||||
using `ftxui::gridbox`:
|
||||
|
||||

|
||||
|
||||
[Example](https://github.com/ArthurSonzogni/FTXUI/blob/master/examples/dom/hflow.cpp)
|
||||
using flexbox:
|
||||
|
||||

|
||||
|
||||
Checkout this
|
||||
[example](https://arthursonzogni.github.io/FTXUI/examples_2dom_2hflow_8cpp-example.html)
|
||||
and the associated
|
||||
[demo](https://arthursonzogni.github.io/FTXUI/examples/?file=component/flexbox).
|
||||
|
||||
Element can also become flexible using the `ftxui::flex` decorator.
|
||||
|
||||
Code:
|
||||
```cpp
|
||||
hbox({
|
||||
text("left") | border ,
|
||||
text("middle") | border | flex,
|
||||
text("right") | border,
|
||||
});
|
||||
```
|
||||
Terminal output:
|
||||
```bash
|
||||
┌────┐┌─────────────────────────────────────────────────────┐┌─────┐
|
||||
│left││middle ││right│
|
||||
└────┘└─────────────────────────────────────────────────────┘└─────┘
|
||||
```
|
||||
|
||||
Code:
|
||||
```cpp
|
||||
hbox({
|
||||
text("left") | border ,
|
||||
text("middle") | border | flex,
|
||||
text("right") | border | flex,
|
||||
});
|
||||
```
|
||||
|
||||
Terminal output:
|
||||
```bash
|
||||
┌────┐┌───────────────────────────────┐┌───────────────────────────────┐
|
||||
│left││middle ││right │
|
||||
└────┘└───────────────────────────────┘└───────────────────────────────┘
|
||||
```
|
||||
|
||||
# Table {#dom-table}
|
||||
|
||||
Enables easy formatting of data into a neat table like visual form.
|
||||
|
||||
[Code example](https://arthursonzogni.github.io/FTXUI/examples_2dom_2table_8cpp-example.html):
|
||||
|
||||

|
||||
|
||||
# Canvas {#dom-canvas}
|
||||
|
||||
See the API [<ftxui/dom/canvas.hpp>](./canvas_8hpp_source.html)
|
||||
|
||||
```cpp
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawPointLine(10, 10, 80, 10, Color::Red);
|
||||
auto element = canvas(c);
|
||||
```
|
||||
|
||||
Drawing can be performed on a `ftxui::Canvas`, using braille, block, or simple
|
||||
characters:
|
||||
|
||||
Simple [example](https://github.com/ArthurSonzogni/FTXUI/blob/master/examples/dom/canvas.cpp):
|
||||
|
||||

|
||||
|
||||
Complex [example](https://github.com/ArthurSonzogni/FTXUI/blob/master/examples/component/canvas_animated.cpp):
|
||||
|
||||

|
202
doc/module-screen.md
Normal file
202
doc/module-screen.md
Normal file
@@ -0,0 +1,202 @@
|
||||
@page module-screen ftxui / screen
|
||||
@tableofcontents
|
||||
|
||||

|
||||
|
||||
The `ftxui::screen` module is the low-level foundation. It can be used
|
||||
standalone, but it is primarily designed to be used together by
|
||||
[ftxui::dom](module-dom.html) and [ftxui::component](module-component.html)
|
||||
modules.
|
||||
|
||||
It provides a @ref ftxui::Screen.
|
||||
|
||||
---
|
||||
|
||||
# ftxui::Screen
|
||||
|
||||
The @ref ftxui::Screen class represents a 2D grid of styled characters that can
|
||||
be rendered to a terminal.
|
||||
It provides methods to create a screen, access pixels, and render elements.
|
||||
|
||||
You can access the individual cells (@ref ftxui::Pixel) of the screen using
|
||||
the @ref ftxui::Screen::PixelAt method, which returns a reference
|
||||
to the pixel at the specified coordinates.
|
||||
|
||||
**Example**
|
||||
```cpp
|
||||
#include <ftxui/screen/screen.hpp>
|
||||
#include <ftxui/screen/color.hpp>
|
||||
|
||||
void main() {
|
||||
auto screen = ftxui::Screen::Create(
|
||||
ftxui::Dimension::Full(), // Use full terminal width
|
||||
ftxui::Dimension::Fixed(10) // Fixed height of 10 rows
|
||||
);
|
||||
|
||||
// Access a specific pixel at (10, 5)
|
||||
auto& pixel = screen.PixelAt(10, 5);
|
||||
|
||||
// Set properties of the pixel.
|
||||
pixel.character = U'X';
|
||||
pixel.foreground_color = ftxui::Color::Red;
|
||||
pixel.background_color = ftxui::Color::RGB(0, 255, 0);
|
||||
pixel.bold = true; // Set bold style
|
||||
screen.Print(); // Print the screen to the terminal
|
||||
}
|
||||
```
|
||||
|
||||
> [!note]
|
||||
> If the coordinates are out of bounds, a dummy pixel is returned.
|
||||
|
||||
The screen can be printed to the terminal using @ref ftxui::Screen::Print() or
|
||||
converted to a std::string with @ref ftxui::Screen::ToString().
|
||||
|
||||
<div class="tabbed">
|
||||
|
||||
- <b class="tab-title">Print()</b>
|
||||
```cpp
|
||||
auto screen = ...;
|
||||
screen.Print();
|
||||
```
|
||||
- <b class="tab-title">ToString()</b>
|
||||
```cpp
|
||||
auto screen = ...;
|
||||
std::cout << screen.ToString();
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
Note that you can reset the cursor position to the top-left corner of the
|
||||
screen after printing by calling @ref ftxui::Screen::ResetCursorPosition().
|
||||
|
||||
**Example**
|
||||
```cpp
|
||||
auto screen = ...;
|
||||
while(true) {
|
||||
// Drawing operations:
|
||||
...
|
||||
|
||||
// Print the screen to the terminal. Then reset the cursor position and the
|
||||
// screen content.
|
||||
std::cout << screen.ToString();
|
||||
std::cout << screen.ResetCursorPosition(/*clear=*/true);
|
||||
std::cout << std::flush;
|
||||
|
||||
// Sleep for a short duration to control the refresh rate.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# ftxui::Dimension
|
||||
|
||||
The @ref ftxui::Dimension utility controls screen sizing:
|
||||
|
||||
* `Dimension::Full()` — use full terminal width or height
|
||||
* `Dimension::Fit(element)` — size to fit the rendered @ref ftxui::Element
|
||||
* `Dimension::Fixed(n)` — use exactly `n` columns or rows
|
||||
|
||||
These values are to be passed to `ftxui::Screen::Create()`.
|
||||
|
||||
@ref ftxui::Screen::Create() provides two overloads:
|
||||
|
||||
- `Screen::Create(Dimension)` sets both width and height to the same kind of dimension
|
||||
- `Screen::Create(Dimension width, Dimension height)` allows distinct control per axis
|
||||
|
||||
```cpp
|
||||
auto screen = ftxui::Screen::Create(
|
||||
ftxui::Dimension::Full(), // width
|
||||
ftxui::Dimension::Fixed(10) // height
|
||||
);
|
||||
```
|
||||
|
||||
Once created, render an element and display the result:
|
||||
|
||||
```cpp
|
||||
ftxui::Render(screen, element);
|
||||
screen.Print();
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# ftxui::Pixel
|
||||
|
||||
Each cell in the screen grid is a @ref ftxui::Pixel, which holds:
|
||||
|
||||
- Unicode codepoint.
|
||||
- `character`
|
||||
- @ref ftxui::Color:
|
||||
- `foreground_color`
|
||||
- `background_color`
|
||||
- Booleans:
|
||||
- `blink`
|
||||
- `bold`
|
||||
- `dim`
|
||||
- `italic`
|
||||
- `inverted` (swap foreground and background colors)
|
||||
- `underlined`
|
||||
- `underlined_double`
|
||||
- `strikethrough`
|
||||
|
||||
|
||||
```cpp
|
||||
auto screen = ftxui::Screen::Create(
|
||||
ftxui::Dimension::Fixed(5),
|
||||
ftxui::Dimension::Fixed(5),
|
||||
);
|
||||
|
||||
auto& pixel = screen.PixelAt(3, 3);
|
||||
pixel.character = U'X';
|
||||
pixel.bold = true;
|
||||
pixel.foreground_color = ftxui::Color::Red;
|
||||
pixel.background_color = ftxui::Color::RGB(0, 255, 0);
|
||||
|
||||
screen.Print();
|
||||
```
|
||||
|
||||
> [!note]
|
||||
> `PixelAt(x, y)` performs bounds checking and returns a reference to the pixel
|
||||
> at the specified coordinate. If out-of-bounds, a dummy pixel reference is
|
||||
> returned.
|
||||
|
||||
|
||||
Each cell in the screen is a @ref ftxui::Pixel. You can modify them using:
|
||||
|
||||
```cpp
|
||||
auto& pixel = screen.PixelAt(x, y);
|
||||
pixel.character = U'X';
|
||||
pixel.bold = true;
|
||||
pixel.foreground_color = Color::Red;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# ftxui::Color
|
||||
|
||||
The @ref ftxui::Color class is used to define foreground and background colors for each @ref ftxui::Pixel.
|
||||
|
||||
It supports various color spaces and predefined palettes. FTXUI will
|
||||
dynamically fallback to the closest available color in the terminal if the
|
||||
requested color is not supported by the terminal.
|
||||
|
||||
**Color Spaces**
|
||||
|
||||
- **Default**: `ftxui::Color::Default` (terminal's default color)
|
||||
- **16-color palette** [Demo](https://arthursonzogni.github.io/FTXUI/examples/?file=dom/color_gallery):
|
||||
- `ftxui::Color::Black`,
|
||||
- `ftxui::Color::Red`,
|
||||
- ...
|
||||
- **256-color palette** [Demo](https://arthursonzogni.github.io/FTXUI/examples/?file=dom/color_palette256):
|
||||
- `ftxui::Color::Chartreuse1`,
|
||||
- `ftxui::Color::DarkViolet`,
|
||||
- ...
|
||||
- **True color** (24bit) [Demo](https://arthursonzogni.github.io/FTXUI/examples/?file=dom/color_truecolor_HSV:
|
||||
- `ftxui::Color::RGB(uint8_t red, uint8_t green, uint8_t blue)`
|
||||
- `ftxui::Color::HSV(uint8_t h, uint8_t s, uint8_t v)`.
|
||||
|
||||
|
||||
> [!note]
|
||||
> You can query the terminal capability using @ref ftxui::Terminal::ColorSupport();
|
||||
>
|
||||
> This can manually be set using @ref ftxui::Terminal::SetColorSupport().
|
74
doc/module.md
Normal file
74
doc/module.md
Normal file
@@ -0,0 +1,74 @@
|
||||
# ftxui {#ftxui}
|
||||
|
||||

|
||||
|
||||
FTXUI is organized into three modules, each building upon the previous:
|
||||
|
||||
1. [ftxui/screen](#module-screen) - Low-level rendering
|
||||
2. [ftxui/dom](#module-dom) - Layout and composition
|
||||
3. [ftxui/component](#module-component) - User interaction
|
||||
|
||||
---
|
||||
|
||||
# ftxui/screen
|
||||
|
||||
Defines:
|
||||
|
||||
- **`ftxui::Screen`**: a 2D grid of styled characters.
|
||||
- **`ftxui::Pixel`**: the unit of rendering.
|
||||
- Helpers like `ftxui::Color` and `Dimension`.
|
||||
|
||||
Use for direct terminal drawing and styling.
|
||||
|
||||
<div class="section_buttons">
|
||||
|
||||
| Next |
|
||||
|--------------------------------------:|
|
||||
| [Documentation](module-screen.html) |
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
---
|
||||
|
||||
# ftxui/dom
|
||||
|
||||
Provides:
|
||||
|
||||
- **`ftxui::Element`**: a tree structure for layout and UI.
|
||||
- Composable and responsive elements.
|
||||
- `Render()` to draw onto a `Screen`.
|
||||
|
||||
Ideal for structured, styled UIs.
|
||||
|
||||
<div class="section_buttons">
|
||||
|
||||
| Next |
|
||||
|--------------------------------------:|
|
||||
| [Documentation](module-dom.html) |
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
---
|
||||
# ftxui/component
|
||||
|
||||
Adds:
|
||||
|
||||
- **`ftxui::Component`**: stateful, interactive widgets.
|
||||
- Built-ins: `Checkbox`, `Input`, `Menu`, `Button`.
|
||||
- Supports keyboard/cursor input and composition.
|
||||
|
||||
Use for interactive apps.
|
||||
|
||||
<div class="section_buttons">
|
||||
|
||||
| Next |
|
||||
|--------------------------------------:|
|
||||
| [Documentation](module-component.html) |
|
||||
|
||||
</div>
|
||||
|
||||
---
|
||||
|
||||
Modules can be used independently, or together: `screen → dom → component`.
|
58
doc/posix_pipe.md
Normal file
58
doc/posix_pipe.md
Normal file
@@ -0,0 +1,58 @@
|
||||
# POSIX Piped Input in FTXUI
|
||||
|
||||
> [!WARNING]
|
||||
> This feature works only on Linux and macOS. It is not supported on
|
||||
> Windows and WebAssembly.
|
||||
|
||||
## What is a POSIX Pipe?
|
||||
|
||||
A POSIX pipe is a way for two separate programs to communicate. One program sends its output directly as input to another program. Think of it like a one-way tube for data.
|
||||
|
||||
**Example:**
|
||||
|
||||
Imagine you want to list files and then filter them interactively.
|
||||
|
||||
- `ls`: Lists files.
|
||||
- `interactive_grep`: An FTXUI application that filters text and lets you type.
|
||||
|
||||
You can connect them with a pipe (`|`):
|
||||
|
||||
```bash
|
||||
ls -l | interactive_grep
|
||||
```
|
||||
|
||||
Here's what happens:
|
||||
1. `ls -l` lists files with details.
|
||||
2. The `|` sends this list directly to `interactive_grep`.
|
||||
3. `interactive_grep` receives the list and displays it. Because it's an FTXUI app, you can then type to filter the list, even though it received initial data from `ls`.
|
||||
|
||||
## How FTXUI Handles Piped Input
|
||||
|
||||
Now that you understand what a POSIX pipe is, let's look at how FTXUI uses them.
|
||||
|
||||
FTXUI lets your application read data from other programs (like from a pipe) while still allowing you to use your keyboard for interaction. This is useful for interactive command-line tools that process data.
|
||||
|
||||
Normally, FTXUI applications receive all input from `stdin`. However, when FTXUI detects that `stdin` is connected to the output of a pipe (meaning data is being piped into your application), it automatically switches to reading interactive keyboard input from `/dev/tty`. This ensures that your application can still receive user input even while processing piped data.
|
||||
|
||||
This feature is **turned on by default**.
|
||||
|
||||
If your FTXUI application needs to read piped data and also respond to keyboard input, you typically don't need to do anything special:
|
||||
|
||||
```cpp
|
||||
auto screen = ScreenInteractive::Fullscreen();
|
||||
// screen.HandlePipedInput(true); // This is enabled by default
|
||||
screen.Loop(component);
|
||||
```
|
||||
|
||||
|
||||
## Turning Off Piped Input
|
||||
|
||||
If you don't need this feature, or if it conflicts with your custom input handling, you can turn it off.
|
||||
|
||||
To disable it, call `HandlePipedInput(false)` before starting your application's main loop:
|
||||
|
||||
```cpp
|
||||
auto screen = ScreenInteractive::Fullscreen();
|
||||
screen.HandlePipedInput(false); // Turn off piped input handling
|
||||
screen.Loop(component);
|
||||
```
|
119
doc/stylesheet.css
Normal file
119
doc/stylesheet.css
Normal file
@@ -0,0 +1,119 @@
|
||||
html {
|
||||
--primary-color: #9ed072; /* green (identifier, strings) */
|
||||
--primary-dark-color: #f39660; /* orange (functions, tags) */
|
||||
--primary-light-color: #7fbbb3; /* teal (types, decorators) */
|
||||
|
||||
--page-background-color: #2c2e34; /* main background */
|
||||
--page-foreground-color: #e2e2e3; /* main text */
|
||||
--page-secondary-foreground-color: #9aa5ce; /* dim text */
|
||||
--separator-color: #3b3e48;
|
||||
--side-nav-background: #1a1b26;
|
||||
|
||||
--code-background: #2a2e38;
|
||||
--code-foreground: #e2e2e3;
|
||||
|
||||
--tablehead-background: #1f1f28;
|
||||
|
||||
--blockquote-background: #3a3e44;
|
||||
--blockquote-foreground: #d4bfff;
|
||||
|
||||
--warning-color: #e0af68;
|
||||
--warning-color-dark: #ff9e64;
|
||||
--warning-color-darker: #f7768e;
|
||||
--bug-color: #f7768e;
|
||||
|
||||
--fragment-background: #222222;
|
||||
--fragment-foreground: #e2e2e3;
|
||||
--fragment-keyword: #f7768e; /* pink */
|
||||
--fragment-keywordtype: #7fbbb3; /* teal */
|
||||
--fragment-keywordflow: #e0af68; /* orange-yellow */
|
||||
--fragment-token: #9ed072; /* green */
|
||||
--fragment-comment: #5c6370;
|
||||
--fragment-link: #7aa2f7; /* blue link */
|
||||
--fragment-preprocessor: #f39660; /* orange */
|
||||
--fragment-linenumber-color: #414868;
|
||||
--fragment-linenumber-background: #2c2e34;
|
||||
--fragment-linenumber-border: #1a1b26;
|
||||
--fragment-lineheight: 1.125em;
|
||||
}
|
||||
|
||||
/* Base style for all sections */
|
||||
.section.note,
|
||||
.section.warning,
|
||||
.section.remark,
|
||||
.section.attention,
|
||||
.section.important {
|
||||
border-left: 4px solid var(--primary-dark-color);
|
||||
border-radius: 6px;
|
||||
padding: 0.9em 1.2em;
|
||||
margin: 1.5em 0;
|
||||
background-color: #2e303e;
|
||||
color: var(--page-foreground-color);
|
||||
font-size: 0.95em;
|
||||
}
|
||||
|
||||
/* Section title */
|
||||
.section.note dt,
|
||||
.section.warning dt,
|
||||
.section.remark dt,
|
||||
.section.attention dt,
|
||||
.section.important dt {
|
||||
font-weight: bold;
|
||||
display: block;
|
||||
margin-bottom: 0.35em;
|
||||
}
|
||||
|
||||
/* Section body */
|
||||
.section.note dd,
|
||||
.section.warning dd,
|
||||
.section.remark dd,
|
||||
.section.attention dd,
|
||||
.section.important dd {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Note - soft cyan */
|
||||
.section.note {
|
||||
border-left-color: #7fbbb3;
|
||||
background-color: #263640;
|
||||
}
|
||||
.section.note dt {
|
||||
color: #7fbbb3;
|
||||
}
|
||||
|
||||
/* Warning - amber */
|
||||
.section.warning {
|
||||
border-left-color: #e0af68;
|
||||
background-color: #3d2f1f;
|
||||
}
|
||||
.section.warning dt {
|
||||
color: #e0af68;
|
||||
}
|
||||
|
||||
/* Tip (Remark) - green */
|
||||
.section.remark {
|
||||
border-left-color: #9ed072;
|
||||
background-color: #2d3a2d;
|
||||
}
|
||||
.section.remark dt {
|
||||
color: #9ed072;
|
||||
}
|
||||
|
||||
/* Caution (Attention) - bold red-orange */
|
||||
.section.attention {
|
||||
border-left-color: #f7768e;
|
||||
background-color: #3d2a2e;
|
||||
}
|
||||
.section.attention dt {
|
||||
color: #f7768e;
|
||||
}
|
||||
|
||||
/* Important - purple */
|
||||
.section.important {
|
||||
border-left-color: #ab9df2;
|
||||
background-color: #2f2a3a;
|
||||
}
|
||||
.section.important dt {
|
||||
color: #ab9df2;
|
||||
}
|
||||
|
@@ -15,15 +15,11 @@ 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.html"
|
||||
"index.mjs"
|
||||
"index.css"
|
||||
"sw.js"
|
||||
"run_webassembly.py")
|
||||
configure_file(${file} ${file})
|
||||
endforeach(file)
|
||||
|
@@ -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:
|
||||
|
@@ -3,6 +3,7 @@
|
||||
// the LICENSE file.
|
||||
#include <ftxui/component/component.hpp>
|
||||
#include <ftxui/component/screen_interactive.hpp>
|
||||
#include <string>
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
|
@@ -19,7 +19,7 @@ using namespace ftxui;
|
||||
int main() {
|
||||
auto screen = ScreenInteractive::TerminalOutput();
|
||||
std::array<int, 30> values;
|
||||
for (int i = 0; i < values.size(); ++i) {
|
||||
for (size_t i = 0; i < values.size(); ++i) {
|
||||
values[i] = 50 + 20 * std::sin(i * 0.3);
|
||||
}
|
||||
|
||||
|
@@ -3,6 +3,7 @@
|
||||
// the LICENSE file.
|
||||
#include <ftxui/component/component.hpp>
|
||||
#include <ftxui/component/screen_interactive.hpp>
|
||||
#include <string>
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -12,7 +12,6 @@
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
|
||||
int saturation = 255;
|
||||
Elements red_line;
|
||||
Elements green_line;
|
||||
Elements blue_line;
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include <memory> // for shared_ptr
|
||||
#include <string> // for operator<<, string
|
||||
#include <thread> // for sleep_for
|
||||
#include <utility> // for ignore
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
@@ -49,6 +50,7 @@ int main() {
|
||||
|
||||
std::string reset_position;
|
||||
for (int i = 0;; ++i) {
|
||||
std::ignore = i;
|
||||
auto document = hbox({
|
||||
vbox({
|
||||
graph(std::ref(my_graph)),
|
||||
|
@@ -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),
|
||||
|
@@ -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,9 +89,6 @@ window.Module = {
|
||||
const resize_observer = new ResizeObserver(resize_handler);
|
||||
resize_observer.observe(term_element);
|
||||
resize_handler();
|
||||
|
||||
// Disable scrollbar
|
||||
//term.write('\x1b[?47h')
|
||||
},
|
||||
};
|
||||
|
||||
|
@@ -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,17 +9,17 @@
|
||||
#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
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
/// @brief arguments for |ButtonOption::transform|, |CheckboxOption::transform|,
|
||||
/// |Radiobox::transform|, |MenuEntryOption::transform|,
|
||||
/// |MenuOption::transform|.
|
||||
/// @brief arguments for transform from |ButtonOption|, |CheckboxOption|,
|
||||
/// |RadioboxOption|, |MenuEntryOption|, |MenuOption|.
|
||||
struct EntryState {
|
||||
std::string label; ///< The label to display.
|
||||
bool state; ///< The state of the button/checkbox/radiobox
|
||||
@@ -28,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;
|
||||
|
||||
@@ -231,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.h>
|
||||
#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,8 +42,12 @@ class ScreenInteractive : public Screen {
|
||||
static ScreenInteractive FitComponent();
|
||||
static ScreenInteractive TerminalOutput();
|
||||
|
||||
// Destructor.
|
||||
~ScreenInteractive() override;
|
||||
|
||||
// Options. Must be called before Loop().
|
||||
void TrackMouse(bool enable = true);
|
||||
void HandlePipedInput(bool enable = true);
|
||||
|
||||
// Return the currently active screen, nullptr if none.
|
||||
static ScreenInteractive* Active();
|
||||
@@ -92,8 +101,14 @@ class ScreenInteractive : public Screen {
|
||||
void Draw(Component component);
|
||||
void ResetCursorPosition();
|
||||
|
||||
void InstallPipedInputHandling();
|
||||
|
||||
void Signal(int signal);
|
||||
|
||||
void FetchTerminalEvents();
|
||||
|
||||
void PostAnimationTask();
|
||||
|
||||
ScreenInteractive* suspended_screen_ = nullptr;
|
||||
enum class Dimension {
|
||||
FitComponent,
|
||||
@@ -101,30 +116,27 @@ 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);
|
||||
|
||||
bool track_mouse_ = true;
|
||||
const Dimension dimension_;
|
||||
const bool use_alternative_screen_;
|
||||
|
||||
Sender<Task> task_sender_;
|
||||
Receiver<Task> task_receiver_;
|
||||
bool track_mouse_ = true;
|
||||
|
||||
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;
|
||||
|
||||
@@ -133,6 +145,9 @@ class ScreenInteractive : public Screen {
|
||||
bool force_handle_ctrl_c_ = true;
|
||||
bool force_handle_ctrl_z_ = true;
|
||||
|
||||
// Piped input handling state (POSIX only)
|
||||
bool handle_piped_input_ = true;
|
||||
|
||||
// The style of the cursor to restore on exit.
|
||||
int cursor_reset_shape_ = 1;
|
||||
|
||||
@@ -152,8 +167,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.
|
||||
|
@@ -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_
|
16
src/ftxui/component.cppm
Normal file
16
src/ftxui/component.cppm
Normal file
@@ -0,0 +1,16 @@
|
||||
/// @module ftxui.component
|
||||
/// @brief Module file for FTXUI component operations.
|
||||
|
||||
export module ftxui.component;
|
||||
|
||||
export import ftxui.component.animation;
|
||||
export import ftxui.component.captured_mouse;
|
||||
export import ftxui.component.component;
|
||||
export import ftxui.component.component_base;
|
||||
export import ftxui.component.component_options;
|
||||
export import ftxui.component.event;
|
||||
export import ftxui.component.loop;
|
||||
export import ftxui.component.mouse;
|
||||
export import ftxui.component.receiver;
|
||||
export import ftxui.component.screen_interactive;
|
||||
export import ftxui.component.task;
|
65
src/ftxui/component/animation.cppm
Normal file
65
src/ftxui/component/animation.cppm
Normal file
@@ -0,0 +1,65 @@
|
||||
/// @module ftxui.component.animation
|
||||
/// @brief C++20 module interface for the Animation namespace of the Component module.
|
||||
///
|
||||
|
||||
module;
|
||||
|
||||
#include <ftxui/component/animation.hpp>
|
||||
|
||||
export module ftxui.component.animation;
|
||||
|
||||
/**
|
||||
* @namespace ftxui::animation
|
||||
* @brief The FTXUI ftxui::animation:: namespace
|
||||
*/
|
||||
export namespace ftxui::animation {
|
||||
using ftxui::animation::RequestAnimationFrame;
|
||||
|
||||
using ftxui::animation::Clock;
|
||||
using ftxui::animation::TimePoint;
|
||||
using ftxui::animation::Duration;
|
||||
|
||||
using ftxui::animation::Params;
|
||||
|
||||
/**
|
||||
* @namespace easing
|
||||
* @brief The FTXUI sf::animation::easing:: namespace
|
||||
*/
|
||||
namespace easing {
|
||||
using ftxui::animation::easing::Function;
|
||||
|
||||
using ftxui::animation::easing::Linear;
|
||||
using ftxui::animation::easing::QuadraticIn;
|
||||
using ftxui::animation::easing::QuadraticOut;
|
||||
using ftxui::animation::easing::QuadraticInOut;
|
||||
using ftxui::animation::easing::CubicIn;
|
||||
using ftxui::animation::easing::CubicOut;
|
||||
using ftxui::animation::easing::CubicInOut;
|
||||
using ftxui::animation::easing::QuarticIn;
|
||||
using ftxui::animation::easing::QuarticOut;
|
||||
using ftxui::animation::easing::QuarticInOut;
|
||||
using ftxui::animation::easing::QuinticIn;
|
||||
using ftxui::animation::easing::QuinticOut;
|
||||
using ftxui::animation::easing::QuinticInOut;
|
||||
using ftxui::animation::easing::SineIn;
|
||||
using ftxui::animation::easing::SineOut;
|
||||
using ftxui::animation::easing::SineInOut;
|
||||
using ftxui::animation::easing::CircularIn;
|
||||
using ftxui::animation::easing::CircularOut;
|
||||
using ftxui::animation::easing::CircularInOut;
|
||||
using ftxui::animation::easing::ExponentialIn;
|
||||
using ftxui::animation::easing::ExponentialOut;
|
||||
using ftxui::animation::easing::ExponentialInOut;
|
||||
using ftxui::animation::easing::ElasticIn;
|
||||
using ftxui::animation::easing::ElasticOut;
|
||||
using ftxui::animation::easing::ElasticInOut;
|
||||
using ftxui::animation::easing::BackIn;
|
||||
using ftxui::animation::easing::BackOut;
|
||||
using ftxui::animation::easing::BackInOut;
|
||||
using ftxui::animation::easing::BounceIn;
|
||||
using ftxui::animation::easing::BounceOut;
|
||||
using ftxui::animation::easing::BounceInOut;
|
||||
}
|
||||
|
||||
using ftxui::animation::Animator;
|
||||
}
|
@@ -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_ =
|
||||
|
16
src/ftxui/component/captured_mouse.cppm
Normal file
16
src/ftxui/component/captured_mouse.cppm
Normal file
@@ -0,0 +1,16 @@
|
||||
/// @module ftxui.component.captured_mouse
|
||||
/// @brief Module file for the CapturedMouseInterface class of the Component module
|
||||
|
||||
module;
|
||||
|
||||
#include <ftxui/component/captured_mouse.hpp>
|
||||
|
||||
export module ftxui.component.captured_mouse;
|
||||
|
||||
/**
|
||||
* @namespace ftxui
|
||||
* @brief The FTXUI ftxui:: namespace
|
||||
*/
|
||||
export namespace ftxui {
|
||||
using ftxui::CapturedMouseInterface;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user