Add modules support (#1015)

Add experimental C++20 module suppport.
Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
Miko 2025-06-04 09:02:20 -04:00 committed by GitHub
parent fe86d06595
commit b65bbce9bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
51 changed files with 1239 additions and 56 deletions

View File

@ -165,3 +165,47 @@ jobs:
flags: ${{ runner.os }} flags: ${{ runner.os }}
name: ${{ runner.os }}-coverage name: ${{ runner.os }}-coverage
files: ./build/coverage.xml files: ./build/coverage.xml
test_modules:
name: "Test modules"
strategy:
matrix:
include:
- os: ubuntu-latest
compiler: llvm
# TODO add gcc / msvc
runs-on: ${{ matrix.os }}
steps:
- name: "Checkout repository"
uses: actions/checkout@v3
- 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: "Generate ./examples_modules"
run: >
./tools/generate_examples_modules.sh
- name: "Build modules"
run: >
mkdir build;
cd build;
cmake ..
-DCMAKE_GENERATOR=Ninja
-DFTXUI_BUILD_MODULES=ON
-DFTXUI_BUILD_EXAMPLES=ON
-DCMAKE_BUILD_TYPE=Debug
-DFTXUI_BUILD_DOCS=OFF
-DFTXUI_BUILD_TESTS=OFF
-DFTXUI_BUILD_TESTS_FUZZER=OFF
-DFTXUI_ENABLE_INSTALL=ON
-DFTXUI_DEV_WARNINGS=ON ;
cmake --build .

2
.gitignore vendored
View File

@ -62,8 +62,10 @@ out/
!include/ftxui/**/*.cpp !include/ftxui/**/*.cpp
# src directory: # src directory:
!src/ftxui/*.cppm
!src/ftxui/**/*.hpp !src/ftxui/**/*.hpp
!src/ftxui/**/*.cpp !src/ftxui/**/*.cpp
!src/ftxui/**/*.cppm
# tools directory: # tools directory:
!tools/**/*.sh !tools/**/*.sh

View File

@ -9,6 +9,22 @@ Next
- Use Doxygen awesome. Add our own theme. - Use Doxygen awesome. Add our own theme.
- Break the documentation into several pages. - 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.
6.1.9 (2025-05-07) 6.1.9 (2025-05-07)
------------ ------------

View File

@ -1,4 +1,19 @@
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) cmake_minimum_required(VERSION 3.12)
endif()
project(ftxui project(ftxui
LANGUAGES CXX LANGUAGES CXX
@ -6,15 +21,6 @@ project(ftxui
DESCRIPTION "C++ Functional Terminal User Interface." 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 \ 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 \ terminal used will be one of Microsoft and use a set of reasonnable fallback \
@ -176,6 +182,13 @@ include(cmake/iwyu.cmake)
include(cmake/ftxui_export.cmake) include(cmake/ftxui_export.cmake)
include(cmake/ftxui_install.cmake) include(cmake/ftxui_install.cmake)
include(cmake/ftxui_package.cmake) include(cmake/ftxui_package.cmake)
include(cmake/ftxui_modules.cmake)
add_subdirectory(examples)
add_subdirectory(doc) 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()

View File

@ -39,7 +39,8 @@ 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 [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 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) * 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!). * **Cross platform**: Linux/MacOS (main target), WebAssembly, Windows (Thanks to contributors!).
* Learn by [examples](#documentation), and [tutorials](#documentation) * Learn by [examples](#documentation), and [tutorials](#documentation)
* Multiple packages: * Multiple packages:
@ -50,6 +51,7 @@ A simple cross-platform C++ library for terminal based user interfaces!
- [Ubuntu package](https://launchpad.net/ubuntu/+source/ftxui) - [Ubuntu package](https://launchpad.net/ubuntu/+source/ftxui)
- [Arch Linux](https://aur.archlinux.org/packages/ftxui/) - [Arch Linux](https://aur.archlinux.org/packages/ftxui/)
- [OpenSUSE](https://build.opensuse.org/package/show/devel:libraries:c_c++/ftxui) - [OpenSUSE](https://build.opensuse.org/package/show/devel:libraries:c_c++/ftxui)
- [XMake](https://xmake.io) repository [package](https://github.com/xmake-io/xmake-repo/blob/dev/packages/f/ftxui/xmake.lua)
* Good practices: documentation, tests, fuzzers, performance tests, automated CI, automated packaging, etc... * Good practices: documentation, tests, fuzzers, performance tests, automated CI, automated packaging, etc...
## Documentation ## Documentation
@ -357,6 +359,7 @@ Feel free to add your projects here:
- [terminal-rain](https://github.com/Oakamoore/terminal-rain) - [terminal-rain](https://github.com/Oakamoore/terminal-rain)
- [keywords](https://github.com/Oakamoore/keywords) ([Play web version :heart:](https://oakamoore.itch.io/keywords)) - [keywords](https://github.com/Oakamoore/keywords) ([Play web version :heart:](https://oakamoore.itch.io/keywords))
- [FTB - tertminal file browser](https://github.com/Cyxuan0311/FTB) - [FTB - tertminal file browser](https://github.com/Cyxuan0311/FTB)
- [openJuice](https://github.com/mikomikotaishi/openJuice)
- [SHOOT!](https://github.com/ShingZhanho/ENGG1340-Project-25Spring) - [SHOOT!](https://github.com/ShingZhanho/ENGG1340-Project-25Spring)
### [cpp-best-practices/game_jam](https://github.com/cpp-best-practices/game_jam) ### [cpp-best-practices/game_jam](https://github.com/cpp-best-practices/game_jam)
@ -435,6 +438,8 @@ If you choose to build and link FTXUI yourself, `ftxui-component` must be first
g++ . . . -lftxui-component -lftxui-dom -lftxui-screen . . . g++ . . . -lftxui-component -lftxui-dom -lftxui-screen . . .
``` ```
To build FTXUI with modules, check [documentation](https://arthursonzogni.github.io/FTXUI/cpp20-modules.html)
## Contributors ## Contributors
<a href="https://github.com/ArthurSonzogni/FTXUI/graphs/contributors"> <a href="https://github.com/ArthurSonzogni/FTXUI/graphs/contributors">

View File

@ -5,13 +5,14 @@ function(ftxui_message msg)
endfunction() endfunction()
ftxui_message("┌─ FTXUI options ─────────────────────") 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_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 : ${FTXUI_BUILD_TESTS}")
ftxui_message("│ FTXUI_BUILD_TESTS_FUZZER : ${FTXUI_BUILD_TESTS_FUZZER}") 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_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("└─────────────────────────────────────") ftxui_message("└─────────────────────────────────────")

82
cmake/ftxui_modules.cmake Normal file
View File

@ -0,0 +1,82 @@
if (NOT FTXUI_BUILD_MODULES)
return()
endif()
add_library(ftxui-modules)
target_sources(ftxui-modules
PUBLIC FILE_SET CXX_MODULES FILES
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()

View File

@ -1001,48 +1001,12 @@ INPUT_FILE_ENCODING =
FILE_PATTERNS = *.c \ FILE_PATTERNS = *.c \
*.cc \ *.cc \
*.cxx \
*.cpp \ *.cpp \
*.c++ \
*.java \
*.ii \
*.ixx \
*.ipp \ *.ipp \
*.i++ \
*.inl \
*.idl \
*.ddl \
*.odl \
*.h \ *.h \
*.hh \
*.hxx \
*.hpp \ *.hpp \
*.h++ \
*.cs \
*.d \
*.php \
*.php4 \
*.php5 \
*.phtml \
*.inc \
*.m \
*.markdown \
*.md \ *.md \
*.mm \ *.cppm \
*.dox \
*.py \
*.pyw \
*.f90 \
*.f95 \
*.f03 \
*.f08 \
*.f \
*.for \
*.tcl \
*.vhd \
*.vhdl \
*.ucf \
*.qsf
# The RECURSIVE tag can be used to specify whether or not subdirectories should # The RECURSIVE tag can be used to specify whether or not subdirectories should
# be searched for input files as well. # be searched for input files as well.

85
doc/cpp20-modules.md Normal file
View File

@ -0,0 +1,85 @@
@page cpp20-modules C++20 Modules
coucou
> [!WARNING]
> This feature is still in development, and the API may change in future releases.
> Your contribution is needed to help us improve the compatibility and usability
> of C++20 modules in FTXUI. If you encounter any issues or have suggestions,
> please open an issue.
FTXUI provides an experimental support for [C++20
modules](https://en.cppreference.com/w/cpp/language/modules) to improve
compilation times and code organization. The existing API has a module
corresponding to each header.
**Example with CMake and Ninja**
```cpp
import ftxui;
int main() {
auto screen = ftxui::ScreenInteractive::TerminalOutput();
auto button = ftxui::Button("Click me", screen.QuitClosure());
screen.Loop(button);
return 0;
}
```
```sh
cmake \
-DCMAKE_GENERATOR=Ninja \
-DFTXUI_BUILD_MODULES=ON \
..
ninja
```
> [!NOTE]
> To use modules, you need a C++20 compatible compiler, CMake version 3.20 or
> higher, and use a compatible generator like Ninja. Note that Makefile
> generators **do not support modules**.
### Module list
The modules directly reference the corresponding header, or a group of related
headers to provide a more convenient interface. The following modules
are available:
- `ftxui`
- `ftxui.component`
- `ftxui.component.Animation`
- `ftxui.component.CapturedMouse`
- `ftxui.component.Component`
- `ftxui.component.ComponentBase`
- `ftxui.component.ComponentOptions`
- `ftxui.component.Event`
- `ftxui.component.Loop`
- `ftxui.component.Mouse`
- `ftxui.component.Receiver`
- `ftxui.component.ScreenInteractive`
- `ftxui.component.Task`
- `ftxui.dom`
- `ftxui.dom.Canvas`
- `ftxui.dom.Deprecated`
- `ftxui.dom.Direction`
- `ftxui.dom.Elements`
- `ftxui.dom.FlexboxConfig`
- `ftxui.dom.LinearGradient`
- `ftxui.dom.Node`
- `ftxui.dom.Requirement`
- `ftxui.dom.Selection`
- `ftxui.dom.Table`
- `ftxui.screen`
- `ftxui.screen.Box`
- `ftxui.screen.Color`
- `ftxui.screen.ColorInfo`
- `ftxui.screen.Deprecated`
- `ftxui.screen.Image`
- `ftxui.screen.Pixel`
- `ftxui.screen.Screen`
- `ftxui.screen.String`
- `ftxui.screen.Terminal`
- `ftxui.util`
- `ftxui.util.AutoReset`
- `ftxui.util.Ref`

View File

@ -108,7 +108,6 @@
console.log("navtree.textContent", navtree.textContent); console.log("navtree.textContent", navtree.textContent);
if (!navtree.textContent.includes("Getting Started") && if (!navtree.textContent.includes("Getting Started") &&
!navtree.textContent.includes("Installation") && !navtree.textContent.includes("Installation") &&
!navtree.textContent.includes("Modules") &&
!navtree.textContent.includes("ftxui / screen") && !navtree.textContent.includes("ftxui / screen") &&
!navtree.textContent.includes("ftxui / dom") && !navtree.textContent.includes("ftxui / dom") &&
!navtree.textContent.includes("ftxui / component") && !navtree.textContent.includes("ftxui / component") &&

View File

@ -1,4 +1,4 @@
# Modules {#modules} # ftxui {#ftxui}
![title-img](https://nsm09.casimages.com/img/2025/05/30//2505300816063242518595251.jpg) ![title-img](https://nsm09.casimages.com/img/2025/05/30//2505300816063242518595251.jpg)

View File

@ -3,6 +3,7 @@
// the LICENSE file. // the LICENSE file.
#include <ftxui/component/component.hpp> #include <ftxui/component/component.hpp>
#include <ftxui/component/screen_interactive.hpp> #include <ftxui/component/screen_interactive.hpp>
#include <string>
using namespace ftxui; using namespace ftxui;

View File

@ -3,6 +3,7 @@
// the LICENSE file. // the LICENSE file.
#include <ftxui/component/component.hpp> #include <ftxui/component/component.hpp>
#include <ftxui/component/screen_interactive.hpp> #include <ftxui/component/screen_interactive.hpp>
#include <string>
using namespace ftxui; using namespace ftxui;

18
src/ftxui/component.cppm Normal file
View File

@ -0,0 +1,18 @@
/**
* @file component.cppm
* @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;

View File

@ -0,0 +1,66 @@
/// @module ftxui.component.animation
/// @brief Module file for the Animation namespace of the Component module.
///
/// @file animation.cppm
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;
}

View File

@ -0,0 +1,18 @@
/**
* @file captured_mouse.cppm
* @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;
}

View File

@ -0,0 +1,61 @@
/**
* @file component.cppm
* @brief Module file for the Component classes of the Component module
*/
module;
#include <ftxui/component/component.hpp>
export module ftxui.component.component;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::ButtonOption;
using ftxui::CheckboxOption;
using ftxui::Event;
using ftxui::InputOption;
using ftxui::MenuOption;
using ftxui::RadioboxOption;
using ftxui::MenuEntryOption;
using ftxui::Make;
using ftxui::ComponentDecorator;
using ftxui::ElementDecorator;
using ftxui::operator|;
using ftxui::operator|=;
namespace Container {
using ftxui::Container::Vertical;
using ftxui::Container::Horizontal;
using ftxui::Container::Tab;
using ftxui::Container::Stacked;
}
using ftxui::Button;
using ftxui::Checkbox;
using ftxui::Input;
using ftxui::Menu;
using ftxui::MenuEntry;
using ftxui::Radiobox;
using ftxui::Dropdown;
using ftxui::Toggle;
using ftxui::Slider;
using ftxui::ResizableSplit;
using ftxui::ResizableSplitLeft;
using ftxui::ResizableSplitRight;
using ftxui::ResizableSplitTop;
using ftxui::ResizableSplitBottom;
using ftxui::Renderer;
using ftxui::CatchEvent;
using ftxui::Maybe;
using ftxui::Modal;
using ftxui::Collapsible;
using ftxui::Hoverable;
using ftxui::Window;
}

View File

@ -0,0 +1,28 @@
/**
* @file component_base.cppm
* @brief Module file for the ComponentBase class of the Component module
*/
module;
#include <ftxui/component/component_base.hpp>
export module ftxui.component.component_base;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::Delegate;
using ftxui::Focus;
using ftxui::Event;
namespace animation {
using ftxui::animation::Params;
}
using ftxui::ComponentBase;
using ftxui::Component;
using ftxui::Components;
}

View File

@ -0,0 +1,33 @@
/**
* @file component_options.cppm
* @brief Module file for options for the Component class of the Component module
*/
module;
#include <ftxui/component/component_options.hpp>
export module ftxui.component.component_options;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::EntryState;
using ftxui::UnderlineOption;
using ftxui::AnimatedColorOption;
using ftxui::AnimatedColorsOption;
using ftxui::MenuEntryOption;
using ftxui::MenuOption;
using ftxui::ButtonOption;
using ftxui::CheckboxOption;
using ftxui::InputState;
using ftxui::InputOption;
using ftxui::RadioboxOption;
using ftxui::ResizableSplitOption;
using ftxui::SliderOption;
using ftxui::WindowRenderState;
using ftxui::WindowOptions;
using ftxui::DropdownOption;
}

View File

@ -0,0 +1,21 @@
/**
* @file event.cppm
* @brief Module file for the Event struct of the Component module
*/
module;
#include <ftxui/component/event.hpp>
export module ftxui.component.event;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::ScreenInteractive;
using ftxui::ComponentBase;
using ftxui::Event;
}

View File

@ -0,0 +1,22 @@
/**
* @file loop.cppm
* @brief Module file for the Loop class of the Component module
*/
module;
#include <ftxui/component/loop.hpp>
export module ftxui.component.loop;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::ComponentBase;
using ftxui::Component;
using ftxui::ScreenInteractive;
using ftxui::Loop;
}

View File

@ -0,0 +1,18 @@
/**
* @file mouse.cppm
* @brief Module file for the Mouse struct of the Component module
*/
module;
#include <ftxui/component/mouse.hpp>
export module ftxui.component.mouse;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::Mouse;
}

View File

@ -0,0 +1,22 @@
/**
* @file receiver.cppm
* @brief Module file for the Receiver class of the Component module
*/
module;
#include <ftxui/component/receiver.hpp>
export module ftxui.component.receiver;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::SenderImpl;
using ftxui::ReceiverImpl;
using ftxui::Sender;
using ftxui::Receiver;
using ftxui::MakeReceiver;
}

View File

@ -0,0 +1,25 @@
/**
* @file screen_interactive.cppm
* @brief Module file for the ScreenInteractive class of the Component module
*/
module;
#include <ftxui/component/screen_interactive.hpp>
export module ftxui.component.screen_interactive;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::ComponentBase;
using ftxui::Loop;
using ftxui::Event;
using ftxui::Component;
using ftxui::Screen;
using ftxui::ScreenInteractivePrivate;
using ftxui::ScreenInteractive;
}

View File

@ -0,0 +1,20 @@
/**
* @file task.cppm
* @brief Module file for the Task class of the Component module
*/
module;
#include <ftxui/component/task.hpp>
export module ftxui.component.task;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::AnimationTask;
using ftxui::Closure;
using ftxui::Task;
}

17
src/ftxui/dom.cppm Normal file
View File

@ -0,0 +1,17 @@
/**
* @file dom.cppm
* @brief Module file for FTXUI main operations.
*/
export module ftxui.dom;
export import ftxui.dom.canvas;
export import ftxui.dom.deprecated;
export import ftxui.dom.direction;
export import ftxui.dom.elements;
export import ftxui.dom.flexbox_config;
export import ftxui.dom.linear_gradient;
export import ftxui.dom.node;
export import ftxui.dom.requirement;
export import ftxui.dom.selection;
export import ftxui.dom.table;

18
src/ftxui/dom/canvas.cppm Normal file
View File

@ -0,0 +1,18 @@
/**
* @file canvas.cppm
* @brief Module file for the Canvas struct of the Dom module
*/
module;
#include <ftxui/dom/canvas.hpp>
export module ftxui.dom.canvas;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::Canvas;
}

View File

@ -0,0 +1,20 @@
/**
* @file deprecated.cppm
* @brief Module file for deprecated parts of the Dom module
*/
module;
#include <ftxui/dom/deprecated.hpp>
export module ftxui.dom.deprecated;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::text;
using ftxui::vtext;
using ftxui::paragraph;
}

View File

@ -0,0 +1,18 @@
/**
* @file direction.cppm
* @brief Module file for the Direction enum of the Dom module
*/
module;
#include <ftxui/dom/direction.hpp>
export module ftxui.dom.direction;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::Direction;
}

137
src/ftxui/dom/elements.cppm Normal file
View File

@ -0,0 +1,137 @@
/**
* @file canvas.cppm
* @brief Module file for the Element classes and functions of the Dom module
*/
module;
#include <ftxui/dom/elements.hpp>
export module ftxui.dom.elements;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::Node;
using ftxui::Element;
using ftxui::Elements;
using ftxui::Decorator;
using ftxui::GraphFunction;
using ftxui::BorderStyle;
using ftxui::operator|;
using ftxui::operator|=;
using ftxui::text;
using ftxui::vtext;
using ftxui::separator;
using ftxui::separatorLight;
using ftxui::separatorDashed;
using ftxui::separatorHeavy;
using ftxui::separatorDouble;
using ftxui::separatorEmpty;
using ftxui::separatorStyled;
using ftxui::separatorCharacter;
using ftxui::separatorHSelector;
using ftxui::separatorVSelector;
using ftxui::gauge;
using ftxui::gaugeLeft;
using ftxui::gaugeRight;
using ftxui::gaugeUp;
using ftxui::gaugeDown;
using ftxui::gaugeDirection;
using ftxui::border;
using ftxui::borderLight;
using ftxui::borderDashed;
using ftxui::borderHeavy;
using ftxui::borderDouble;
using ftxui::borderRounded;
using ftxui::borderEmpty;
using ftxui::borderStyled;
using ftxui::borderWith;
using ftxui::window;
using ftxui::spinner;
using ftxui::paragraph;
using ftxui::paragraphAlignLeft;
using ftxui::paragraphAlignRight;
using ftxui::paragraphAlignCenter;
using ftxui::paragraphAlignJustify;
using ftxui::graph;
using ftxui::emptyElement;
using ftxui::canvas;
using ftxui::bold;
using ftxui::dim;
using ftxui::italic;
using ftxui::inverted;
using ftxui::underlined;
using ftxui::underlinedDouble;
using ftxui::blink;
using ftxui::strikethrough;
using ftxui::color;
using ftxui::bgcolor;
using ftxui::focusPosition;
using ftxui::focusPositionRelative;
using ftxui::automerge;
using ftxui::hyperlink;
using ftxui::selectionStyleReset;
using ftxui::selectionColor;
using ftxui::selectionBackgroundColor;
using ftxui::selectionForegroundColor;
using ftxui::selectionStyle;
using ftxui::hbox;
using ftxui::vbox;
using ftxui::dbox;
using ftxui::flexbox;
using ftxui::gridbox;
using ftxui::hflow;
using ftxui::vflow;
using ftxui::flex;
using ftxui::flex_grow;
using ftxui::flex_shrink;
using ftxui::xflex;
using ftxui::xflex_grow;
using ftxui::xflex_shrink;
using ftxui::yflex;
using ftxui::yflex_grow;
using ftxui::yflex_shrink;
using ftxui::notflex;
using ftxui::filler;
using ftxui::WidthOrHeight;
using ftxui::Constraint;
using ftxui::size;
using ftxui::frame;
using ftxui::xframe;
using ftxui::yframe;
using ftxui::focus;
using ftxui::select;
using ftxui::focusCursorBlock;
using ftxui::focusCursorBlockBlinking;
using ftxui::focusCursorBar;
using ftxui::focusCursorBarBlinking;
using ftxui::focusCursorUnderline;
using ftxui::focusCursorUnderlineBlinking;
using ftxui::vscroll_indicator;
using ftxui::hscroll_indicator;
using ftxui::reflect;
using ftxui::clear_under;
using ftxui::hcenter;
using ftxui::vcenter;
using ftxui::center;
using ftxui::align_right;
using ftxui::nothing;
namespace Dimension {
using ftxui::Dimension::Fit;
}
}

View File

@ -0,0 +1,18 @@
/**
* @file flexbox_config.cppm
* @brief Module file for the FlexboxConfig struct of the Dom module
*/
module;
#include <ftxui/dom/flexbox_config.hpp>
export module ftxui.dom.flexbox_config;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::FlexboxConfig;
}

View File

@ -0,0 +1,18 @@
/**
* @file linear_gradient.cppm
* @brief Module file for the LinearGradient struct of the Dom module
*/
module;
#include <ftxui/dom/linear_gradient.hpp>
export module ftxui.dom.linear_gradient;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::LinearGradient;
}

25
src/ftxui/dom/node.cppm Normal file
View File

@ -0,0 +1,25 @@
/**
* @file node.cppm
* @brief Module file for the Node class of the Dom module
*/
module;
#include <ftxui/dom/node.hpp>
export module ftxui.dom.node;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::Node;
using ftxui::Screen;
using ftxui::Element;
using ftxui::Elements;
using ftxui::Render;
using ftxui::GetNodeSelectedContent;
}

View File

@ -0,0 +1,18 @@
/**
* @file requirement.cppm
* @brief Module file for the Requirement struct of the Dom module
*/
module;
#include <ftxui/dom/requirement.hpp>
export module ftxui.dom.requirement;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::Requirement;
}

View File

@ -0,0 +1,18 @@
/**
* @file selection.cppm
* @brief Module file for the Selection class of the Dom module
*/
module;
#include <ftxui/dom/selection.hpp>
export module ftxui.dom.selection;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::Selection;
}

19
src/ftxui/dom/table.cppm Normal file
View File

@ -0,0 +1,19 @@
/**
* @file table.cppm
* @brief Module file for the Table class of the Dom module
*/
module;
#include <ftxui/dom/table.hpp>
export module ftxui.dom.table;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::Table;
using ftxui::TableSelection;
}

11
src/ftxui/ftxui.cppm Normal file
View File

@ -0,0 +1,11 @@
/**
* @file ftxui.cppm
* @brief Module file re-exporting all FTXUI submodules.
*/
export module ftxui;
export import ftxui.component;
export import ftxui.dom;
export import ftxui.screen;
export import ftxui.util;

16
src/ftxui/screen.cppm Normal file
View File

@ -0,0 +1,16 @@
/**
* @file screen.cppm
* @brief Module file for FTXUI screen operations.
*/
export module ftxui.screen;
export import ftxui.screen.box;
export import ftxui.screen.color;
export import ftxui.screen.color_info;
export import ftxui.screen.deprecated;
export import ftxui.screen.image;
export import ftxui.screen.pixel;
export import ftxui.screen.screen;
export import ftxui.screen.string;
export import ftxui.screen.terminal;

18
src/ftxui/screen/box.cppm Normal file
View File

@ -0,0 +1,18 @@
/**
* @file box.cppm
* @brief Module file for the Box struct of the Screen module
*/
module;
#include <ftxui/screen/box.hpp>
export module ftxui.screen.box;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::Box;
}

View File

@ -0,0 +1,22 @@
/**
* @file color.cppm
* @brief Module file for the Color class of the Screen module
*/
module;
#include <ftxui/screen/color.hpp>
export module ftxui.screen.color;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::Color;
inline namespace literals {
using ftxui::literals::operator""_rgb;
}
}

View File

@ -0,0 +1,20 @@
/**
* @file color_info.cppm
* @brief Module file for the ColorInfo struct of the Screen module
*/
module;
#include <ftxui/screen/color_info.hpp>
export module ftxui.screen.color_info;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::ColorInfo;
using ftxui::GetColorInfo;
}

View File

@ -0,0 +1,19 @@
/**
* @file box.cppm
* @brief Module file for the deprecated parts of the Screen module
*/
module;
#include <ftxui/screen/deprecated.hpp>
export module ftxui.screen.deprecated;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::wchar_width;
using ftxui::wstring_width;
}

View File

@ -0,0 +1,18 @@
/**
* @file image.cppm
* @brief Module file for the Image class of the Screen module
*/
module;
#include <ftxui/screen/image.hpp>
export module ftxui.screen.image;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::Image;
}

View File

@ -0,0 +1,18 @@
/**
* @file pixel.cppm
* @brief Module file for the Pixel struct of the Screen module
*/
module;
#include <ftxui/screen/pixel.hpp>
export module ftxui.screen.pixel;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::Pixel;
}

View File

@ -0,0 +1,24 @@
/**
* @file screen.cppm
* @brief Module file for the Screen class of the Screen module
*/
module;
#include <ftxui/screen/screen.hpp>
export module ftxui.screen.screen;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
namespace Dimension {
using ftxui::Dimension::Fixed;
using ftxui::Dimension::Full;
}
using ftxui::Image;
using ftxui::Screen;
}

View File

@ -0,0 +1,22 @@
/**
* @file string.cppm
* @brief Module file for string functions of the Screen module
*/
module;
#include <ftxui/screen/string.hpp>
export module ftxui.screen.string;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::to_string;
using ftxui::to_wstring;
using ftxui::string_width;
using ftxui::Utf8ToGlyphs;
using ftxui::CellToGlyphIndex;
}

View File

@ -0,0 +1,26 @@
/**
* @file terminal.cppm
* @brief Module file for the Terminal namespace of the Screen module
*/
module;
#include <ftxui/screen/terminal.hpp>
export module ftxui.screen.terminal;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::Dimensions;
namespace Terminal {
using ftxui::Terminal::Size;
using ftxui::Terminal::SetFallbackSize;
using ftxui::Terminal::Color;
using ftxui::Terminal::ColorSupport;
using ftxui::Terminal::SetColorSupport;
}
}

9
src/ftxui/util.cppm Normal file
View File

@ -0,0 +1,9 @@
/**
* @file util.cppm
* @brief Module file for FTXUI utility operations.
*/
export module ftxui.util;
export import ftxui.util.autoreset;
export import ftxui.util.ref;

View File

@ -0,0 +1,18 @@
/**
* @file autoreset.cppm
* @brief Module file for the AutoReset class of the Util module
*/
module;
#include <ftxui/util/autoreset.hpp>
export module ftxui.util.autoreset;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::AutoReset;
}

22
src/ftxui/util/ref.cppm Normal file
View File

@ -0,0 +1,22 @@
/**
* @file ref.cppm
* @brief Module file for the Ref classes of the Util module
*/
module;
#include <ftxui/util/ref.hpp>
export module ftxui.util.ref;
/**
* @namespace ftxui
* @brief The FTXUI ftxui:: namespace
*/
export namespace ftxui {
using ftxui::ConstRef;
using ftxui::Ref;
using ftxui::StringRef;
using ftxui::ConstStringRef;
using ftxui::ConstStringListRef;
}

View File

@ -0,0 +1,29 @@
#!/bin/bash
# Generate ./examples_modules from ./examples to using C++20 modules instead of
# #includes for ftxui.
# This is useful for testing ftxui with modules. This ensures we don't forget
# to update the FTXUI modules when adding new features to FTXUI.
echo "Generating ./examples_modules"
rm -rf ./examples_modules
cp -r ./examples ./examples_modules
for file in ./examples_modules/**/*.cpp; do
echo "Generating $file"
sed -i '/#include "ftxui/d' "$file"
sed -i '/#include <ftxui/d' "$file"
sed -i '1i\import ftxui.component;' "$file"
sed -i '2i\import ftxui.dom;' "$file"
sed -i '3i\import ftxui.screen;' "$file"
sed -i '4i\import ftxui.util;' "$file"
sed -i '5i\\' "$file"
done
# Modify the CMakeLists.txt file to link against ftxui-modules
sed -i 's/${DIRECTORY_LIB}/ftxui-modules/g' ./examples_modules/CMakeLists.txt
sed -i 's/ftxui_example_/ftxui_modules_example_/g' ./examples_modules/CMakeLists.txt