Use module partitions instead of full modules (#1146)

Follow-up to #1015. This pull request replaces the full modules that represent headers, with partitions, to emphasise the belonging of the header to the module. This should hopefully provide a speedup to compilation, and confuse users less by aggregating the usable modules into a smaller set.
This commit is contained in:
Miko
2025-11-12 12:42:37 +00:00
committed by GitHub
parent e87d5ff95a
commit 229cae78b5
37 changed files with 140 additions and 149 deletions

View File

@@ -4,15 +4,15 @@
> [!WARNING] > [!WARNING]
> This feature is still in development, and the API may change in future releases. > 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 > 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, > of C++ modules in FTXUI. If you encounter any issues or have suggestions,
> please open an issue. > please open an issue.
FTXUI experimentally supports FTXUI experimentally supports
[C++20 modules](https://en.cppreference.com/w/cpp/language/modules) to reduce [C++20 modules](https://en.cppreference.com/w/cpp/language/modules) to reduce
compilation times and improve code organization. Each header has a compilation times and improve code organization. Each part of the library has a
corresponding module. corresponding module, split into partitions per each header.
Use the FTXUI_BUILD_MODULES option to build the FTXUI project itself to provide C++ 20 modules, Use the FTXUI_BUILD_MODULES option to build the FTXUI project itself to provide C++20 modules,
for example with CMake and Ninja: for example with CMake and Ninja:
```sh ```sh
@@ -25,7 +25,7 @@ ninja
``` ```
> [!NOTE] > [!NOTE]
> To use modules, you need a C++20 compatible compiler, CMake version 3.20 or > 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 > higher, and use a compatible generator like Ninja. Note that Makefile
> generators **do not support modules**. > generators **do not support modules**.
@@ -34,9 +34,12 @@ Then, in your own code you can consume the modules and code as normal:
```cpp ```cpp
import ftxui; import ftxui;
using ftxui::Button;
using ftxui::ScreenInteractive;
int main() { int main() {
auto screen = ftxui::ScreenInteractive::TerminalOutput(); auto screen = ScreenInteractive::TerminalOutput();
auto button = ftxui::Button("Click me", screen.QuitClosure()); auto button = Button("Click me", screen.QuitClosure());
screen.Loop(button); screen.Loop(button);
return 0; return 0;
} }
@@ -70,38 +73,6 @@ are available:
- `ftxui` - `ftxui`
- `ftxui.component` - `ftxui.component`
- `ftxui.component.Animation` - `ftxui.dom`
- `ftxui.component.CapturedMouse` - `ftxui.screen`
- `ftxui.component.Component` - `ftxui.util`
- `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

@@ -3,14 +3,14 @@
export module ftxui.component; export module ftxui.component;
export import ftxui.component.animation; export import :Animation;
export import ftxui.component.captured_mouse; export import :CapturedMouse;
export import ftxui.component.component; export import :Component;
export import ftxui.component.component_base; export import :ComponentBase;
export import ftxui.component.component_options; export import :ComponentOptions;
export import ftxui.component.event; export import :Event;
export import ftxui.component.loop; export import :Loop;
export import ftxui.component.mouse; export import :Mouse;
export import ftxui.component.receiver; export import :Receiver;
export import ftxui.component.screen_interactive; export import :ScreenInteractive;
export import ftxui.component.task; export import :Task;

View File

@@ -1,4 +1,4 @@
/// @module ftxui.component.animation /// @module ftxui.component:Animation
/// @brief C++20 module interface for the Animation namespace of the Component module. /// @brief C++20 module interface for the Animation namespace of the Component module.
/// ///
@@ -6,7 +6,7 @@ module;
#include <ftxui/component/animation.hpp> #include <ftxui/component/animation.hpp>
export module ftxui.component.animation; export module ftxui.component:Animation;
/** /**
* @namespace ftxui::animation * @namespace ftxui::animation
@@ -23,7 +23,7 @@ export namespace ftxui::animation {
/** /**
* @namespace easing * @namespace easing
* @brief The FTXUI sf::animation::easing:: namespace * @brief The FTXUI ftxui::animation::easing:: namespace
*/ */
namespace easing { namespace easing {
using ftxui::animation::easing::Function; using ftxui::animation::easing::Function;

View File

@@ -1,11 +1,11 @@
/// @module ftxui.component.captured_mouse /// @module ftxui.component.CapturedMouse
/// @brief Module file for the CapturedMouseInterface class of the Component module /// @brief Module file for the CapturedMouseInterface class of the Component module
module; module;
#include <ftxui/component/captured_mouse.hpp> #include <ftxui/component/captured_mouse.hpp>
export module ftxui.component.captured_mouse; export module ftxui.component:CapturedMouse;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -1,11 +1,11 @@
/// @module ftxui.component.component /// @module ftxui.component:Component
/// @brief Module file for the Component classes of the Component module /// @brief Module file for the Component classes of the Component module
module; module;
#include <ftxui/component/component.hpp> #include <ftxui/component/component.hpp>
export module ftxui.component.component; export module ftxui.component:Component;
/** /**
* @namespace ftxui * @namespace ftxui
@@ -28,6 +28,10 @@ export namespace ftxui {
using ftxui::operator|; using ftxui::operator|;
using ftxui::operator|=; using ftxui::operator|=;
/**
* @namespace Container
* @brief The FTXUI ftxui::Container:: namespace
*/
namespace Container { namespace Container {
using ftxui::Container::Vertical; using ftxui::Container::Vertical;
using ftxui::Container::Horizontal; using ftxui::Container::Horizontal;

View File

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

View File

@@ -1,11 +1,11 @@
/// @module ftxui.component.component_options /// @module ftxui.component:ComponentOptions
/// @brief Module file for options for the Component class of the Component module /// @brief Module file for options for the Component class of the Component module
module; module;
#include <ftxui/component/component_options.hpp> #include <ftxui/component/component_options.hpp>
export module ftxui.component.component_options; export module ftxui.component:ComponentOptions;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -1,11 +1,11 @@
/// @module ftxui.component.event /// @module ftxui.component:Event
/// @brief Module file for the Event struct of the Component module /// @brief Module file for the Event struct of the Component module
module; module;
#include <ftxui/component/event.hpp> #include <ftxui/component/event.hpp>
export module ftxui.component.event; export module ftxui.component:Event;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -1,11 +1,11 @@
/// @module ftxui.component.loop /// @module ftxui.component:Loop
/// @brief Module file for the Loop class of the Component module /// @brief Module file for the Loop class of the Component module
module; module;
#include <ftxui/component/loop.hpp> #include <ftxui/component/loop.hpp>
export module ftxui.component.loop; export module ftxui.component:Loop;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -1,11 +1,11 @@
/// @module ftxui.component.mouse /// @module ftxui.component:Mouse
/// @brief Module file for the Mouse struct of the Component module /// @brief Module file for the Mouse struct of the Component module
module; module;
#include <ftxui/component/mouse.hpp> #include <ftxui/component/mouse.hpp>
export module ftxui.component.mouse; export module ftxui.component:Mouse;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -1,11 +1,11 @@
/// @module ftxui.component.receiver /// @module ftxui.component:Receiver
/// @brief Module file for the Receiver class of the Component module /// @brief Module file for the Receiver class of the Component module
module; module;
#include <ftxui/component/receiver.hpp> #include <ftxui/component/receiver.hpp>
export module ftxui.component.receiver; export module ftxui.component:Receiver;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -1,11 +1,11 @@
/// @module ftxui.component.screen_interactive /// @module ftxui.component:ScreenInteractive
/// @brief Module file for the ScreenInteractive class of the Component module /// @brief Module file for the ScreenInteractive class of the Component module
module; module;
#include <ftxui/component/screen_interactive.hpp> #include <ftxui/component/screen_interactive.hpp>
export module ftxui.component.screen_interactive; export module ftxui.component:ScreenInteractive;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -1,11 +1,11 @@
/// @module ftxui.component.task /// @module ftxui.component:Task
/// @brief Module file for the Task class of the Component module /// @brief Module file for the Task class of the Component module
module; module;
#include <ftxui/component/task.hpp> #include <ftxui/component/task.hpp>
export module ftxui.component.task; export module ftxui.component:Task;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -1,15 +1,15 @@
/// @module ftxui.dom /// @module ftxui.dom
/// @brief Module file for FTXUI main operations. /// @brief Module file for FTXUI DOM operations.
export module ftxui.dom; export module ftxui.dom;
export import ftxui.dom.canvas; export import :Canvas;
export import ftxui.dom.deprecated; export import :Deprecated;
export import ftxui.dom.direction; export import :Direction;
export import ftxui.dom.elements; export import :Elements;
export import ftxui.dom.flexbox_config; export import :FlexboxConfig;
export import ftxui.dom.linear_gradient; export import :LinearGradient;
export import ftxui.dom.node; export import :Node;
export import ftxui.dom.requirement; export import :Requirement;
export import ftxui.dom.selection; export import :Selection;
export import ftxui.dom.table; export import :Table;

View File

@@ -1,11 +1,11 @@
/// @module ftxui.dom.canvas /// @module ftxui.dom:Canvas
/// @brief Module file for the Canvas struct of the Dom module /// @brief Module file for the Canvas struct of the DOM module
module; module;
#include <ftxui/dom/canvas.hpp> #include <ftxui/dom/canvas.hpp>
export module ftxui.dom.canvas; export module ftxui.dom:Canvas;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -1,11 +1,11 @@
/// @module ftxui.dom.deprecated /// @module ftxui.dom:Deprecated
/// @brief Module file for deprecated parts of the Dom module /// @brief Module file for deprecated parts of the DOM module
module; module;
#include <ftxui/dom/deprecated.hpp> #include <ftxui/dom/deprecated.hpp>
export module ftxui.dom.deprecated; export module ftxui.dom:Deprecated;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -1,11 +1,11 @@
/// @module ftxui.dom.direction /// @module ftxui.dom:Direction
/// @brief Module file for the Direction enum of the Dom module /// @brief Module file for the Direction enum of the Dom module
module; module;
#include <ftxui/dom/direction.hpp> #include <ftxui/dom/direction.hpp>
export module ftxui.dom.direction; export module ftxui.dom:Direction;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -1,11 +1,11 @@
/// @module ftxui.dom.elements /// @module ftxui.dom:Elements
/// @brief Module file for the Element classes and functions of the Dom module /// @brief Module file for the Element classes and functions of the DOM module
module; module;
#include <ftxui/dom/elements.hpp> #include <ftxui/dom/elements.hpp>
export module ftxui.dom.elements; export module ftxui.dom:Elements;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -1,11 +1,11 @@
/// @module ftxui.dom.flexbox_config /// @module ftxui.dom:FlexboxConfig
/// @brief Module file for the FlexboxConfig struct of the Dom module /// @brief Module file for the FlexboxConfig struct of the DOM module
module; module;
#include <ftxui/dom/flexbox_config.hpp> #include <ftxui/dom/flexbox_config.hpp>
export module ftxui.dom.flexbox_config; export module ftxui.dom:FlexboxConfig;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -1,11 +1,11 @@
/// @module ftxui.dom.linear_gradient /// @module ftxui.dom:LinearGradient
/// @brief Module file for the LinearGradient struct of the Dom module /// @brief Module file for the LinearGradient struct of the DOM module
module; module;
#include <ftxui/dom/linear_gradient.hpp> #include <ftxui/dom/linear_gradient.hpp>
export module ftxui.dom.linear_gradient; export module ftxui.dom:LinearGradient;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -1,11 +1,11 @@
/// @module ftxui.dom.node /// @module ftxui.dom:Node
/// @brief Module file for the Node class of the Dom module /// @brief Module file for the Node class of the DOM module
module; module;
#include <ftxui/dom/node.hpp> #include <ftxui/dom/node.hpp>
export module ftxui.dom.node; export module ftxui.dom:Node;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -1,11 +1,11 @@
/// @module ftxui.dom.requirement /// @module ftxui.dom:Requirement
/// @brief Module file for the Requirement struct of the Dom module /// @brief Module file for the Requirement struct of the DOM module
module; module;
#include <ftxui/dom/requirement.hpp> #include <ftxui/dom/requirement.hpp>
export module ftxui.dom.requirement; export module ftxui.dom:Requirement;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -1,11 +1,11 @@
/// @module ftxui.dom.selection /// @module ftxui.dom:Selection
/// @brief Module file for the Selection class of the Dom module /// @brief Module file for the Selection class of the DOM module
module; module;
#include <ftxui/dom/selection.hpp> #include <ftxui/dom/selection.hpp>
export module ftxui.dom.selection; export module ftxui.dom:Selection;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -1,11 +1,11 @@
/// @module ftxui.dom.table /// @module ftxui.dom:Table
/// @brief Module file for the Table class of the Dom module /// @brief Module file for the Table class of the DOM module
module; module;
#include <ftxui/dom/table.hpp> #include <ftxui/dom/table.hpp>
export module ftxui.dom.table; export module ftxui.dom:Table;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -3,12 +3,12 @@
export module ftxui.screen; export module ftxui.screen;
export import ftxui.screen.box; export import :Box;
export import ftxui.screen.color; export import :Color;
export import ftxui.screen.color_info; export import :ColorInfo;
export import ftxui.screen.deprecated; export import :Deprecated;
export import ftxui.screen.image; export import :Image;
export import ftxui.screen.pixel; export import :Pixel;
export import ftxui.screen.screen; export import :Screen;
export import ftxui.screen.string; export import :String;
export import ftxui.screen.terminal; export import :Terminal;

View File

@@ -1,11 +1,11 @@
/// @module ftxui.screen.box /// @module ftxui.screen:Box
/// @brief Module file for the Box struct of the Screen module /// @brief Module file for the Box struct of the Screen module
module; module;
#include <ftxui/screen/box.hpp> #include <ftxui/screen/box.hpp>
export module ftxui.screen.box; export module ftxui.screen:Box;
/** /**
* @namespace ftxui * @namespace ftxui

View File

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

View File

@@ -1,11 +1,11 @@
/// @module ftxui.screen.color_info /// @module ftxui.screen:ColorInfo
/// @brief Module file for the ColorInfo struct of the Screen module /// @brief Module file for the ColorInfo struct of the Screen module
module; module;
#include <ftxui/screen/color_info.hpp> #include <ftxui/screen/color_info.hpp>
export module ftxui.screen.color_info; export module ftxui.screen:ColorInfo;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -1,11 +1,11 @@
/// @module ftxui.screen.deprecated /// @module ftxui.screen:Deprecated
/// @brief Module file for the deprecated parts of the Screen module /// @brief Module file for the deprecated parts of the Screen module
module; module;
#include <ftxui/screen/deprecated.hpp> #include <ftxui/screen/deprecated.hpp>
export module ftxui.screen.deprecated; export module ftxui.screen:Deprecated;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -1,11 +1,11 @@
/// @module ftxui.screen.image /// @module ftxui.screen:Image
/// @brief Module file for the Image class of the Screen module /// @brief Module file for the Image class of the Screen module
module; module;
#include <ftxui/screen/image.hpp> #include <ftxui/screen/image.hpp>
export module ftxui.screen.image; export module ftxui.screen:Image;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -1,11 +1,11 @@
/// @module ftxui.screen.pixel /// @module ftxui.screen:Pixel
/// @brief Module file for the Pixel struct of the Screen module /// @brief Module file for the Pixel struct of the Screen module
module; module;
#include <ftxui/screen/pixel.hpp> #include <ftxui/screen/pixel.hpp>
export module ftxui.screen.pixel; export module ftxui.screen:Pixel;
/** /**
* @namespace ftxui * @namespace ftxui

View File

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

View File

@@ -1,11 +1,11 @@
/// @module ftxui.screen.string /// @module ftxui.screen:String
/// @brief Module file for string functions of the Screen module /// @brief Module file for string functions of the Screen module
module; module;
#include <ftxui/screen/string.hpp> #include <ftxui/screen/string.hpp>
export module ftxui.screen.string; export module ftxui.screen:String;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -1,11 +1,11 @@
/// @module ftxui.screen.terminal /// @module ftxui.screen:Terminal
/// @brief Module file for the Terminal namespace of the Screen module /// @brief Module file for the Terminal namespace of the Screen module
module; module;
#include <ftxui/screen/terminal.hpp> #include <ftxui/screen/terminal.hpp>
export module ftxui.screen.terminal; export module ftxui.screen:Terminal;
/** /**
* @namespace ftxui * @namespace ftxui
@@ -14,6 +14,10 @@ export module ftxui.screen.terminal;
export namespace ftxui { export namespace ftxui {
using ftxui::Dimensions; using ftxui::Dimensions;
/**
* @namespace Terminal
* @brief The FTXUI ftxui::Terminal:: namespace
*/
namespace Terminal { namespace Terminal {
using ftxui::Terminal::Size; using ftxui::Terminal::Size;
using ftxui::Terminal::SetFallbackSize; using ftxui::Terminal::SetFallbackSize;

View File

@@ -3,5 +3,5 @@
export module ftxui.util; export module ftxui.util;
export import ftxui.util.autoreset; export import :AutoReset;
export import ftxui.util.ref; export import :Ref;

View File

@@ -1,11 +1,11 @@
/// @module ftxui.util.autoreset /// @module ftxui.util:AutoReset
/// @brief Module file for the AutoReset class of the Util module /// @brief Module file for the AutoReset class of the Util module
module; module;
#include <ftxui/util/autoreset.hpp> #include <ftxui/util/autoreset.hpp>
export module ftxui.util.autoreset; export module ftxui.util:AutoReset;
/** /**
* @namespace ftxui * @namespace ftxui

View File

@@ -1,11 +1,11 @@
/// @module ftxui.util.ref /// @module ftxui.util:Ref
/// @brief Module file for the Ref classes of the Util module /// @brief Module file for the Ref classes of the Util module
module; module;
#include <ftxui/util/ref.hpp> #include <ftxui/util/ref.hpp>
export module ftxui.util.ref; export module ftxui.util:Ref;
/** /**
* @namespace ftxui * @namespace ftxui