From f128c442cc054f40e2db6dbd4709d7fb02e1b1c1 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Wed, 23 Apr 2025 19:57:35 +0200 Subject: [PATCH 01/31] Support Bazel BUG:https://github.com/ArthurSonzogni/FTXUI/issues/1032 --- .bazelrc | 3 + .gitignore | 4 + BUILD.bazel | 258 ++++++++++++++++++ MODULE.bazel | 18 ++ WORKSPACE | 1 + cmake/ftxui_test.cmake | 4 +- include/ftxui/component/component_base.hpp | 4 +- .../{dom => component}/selection_test.cpp | 2 - 8 files changed, 288 insertions(+), 6 deletions(-) create mode 100644 .bazelrc create mode 100644 BUILD.bazel create mode 100644 MODULE.bazel create mode 100644 WORKSPACE rename src/ftxui/{dom => component}/selection_test.cpp (99%) diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 00000000..b1fd142d --- /dev/null +++ b/.bazelrc @@ -0,0 +1,3 @@ +build --cxxopt=-std=c++20 +build --cxxopt=-Wall +build --cxxopt=-Werror diff --git a/.gitignore b/.gitignore index 4d12e758..f3477250 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,10 @@ out/ !flake.nix !ftxui.pc.in !iwyu.imp +!WORKSPACE +!BUILD.bazel +!MODULE.bazel +!.bazelrc # .github directory: !.github/**/*.yaml diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 00000000..a4978a3d --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,258 @@ +load( + "@rules_cc//cc:defs.bzl", + "cc_library", + "cc_test", + "cc_binary", +) + +package(default_visibility = ["//visibility:public"]) + +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", + ], + includes = ["include", "src"], + strip_include_prefix = "", + copts = ["-std=c++17"], +) + +cc_test( + name = "screen_test", + srcs = [ + "src/ftxui/screen/string_test.cpp", + "src/ftxui/screen/color_test.cpp", + ], + deps = [ + "//:screen", + "@googletest//:gtest_main", + ], + includes = ["include", "src"], + copts = ["-std=c++20"], + testonly = True, +) + +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", + ], + includes = ["include", "src"], + deps = [":screen"], +) + +cc_test( + name = "dom_test", + srcs = [ + "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", + ], + deps = [ + "//:dom", + "@googletest//:gtest_main", + ], + includes = ["include", "src"], + copts = ["-std=c++20"], + testonly = True, +) + +#"src/ftxui/dom/benchmark_test.cpp", +cc_library( + name = "component", + srcs = [ + "src/ftxui/component/maybe.cpp", + "src/ftxui/component/hoverable.cpp", + "src/ftxui/component/collapsible.cpp", + "src/ftxui/component/screen_interactive.cpp", + "src/ftxui/component/modal.cpp", + "src/ftxui/component/util.cpp", + "src/ftxui/component/animation.cpp", + "src/ftxui/component/button.cpp", + "src/ftxui/component/dropdown.cpp", + "src/ftxui/component/loop.cpp", + "src/ftxui/component/slider.cpp", + "src/ftxui/component/container.cpp", + "src/ftxui/component/renderer.cpp", + "src/ftxui/component/terminal_input_parser.cpp", + "src/ftxui/component/component_options.cpp", + "src/ftxui/component/resizable_split.cpp", + "src/ftxui/component/component.cpp", + "src/ftxui/component/event.cpp", + "src/ftxui/component/catch_event.cpp", + "src/ftxui/component/input.cpp", + "src/ftxui/component/menu.cpp", + "src/ftxui/component/window.cpp", + "src/ftxui/component/checkbox.cpp", + "src/ftxui/component/radiobox.cpp", + "src/ftxui/component/terminal_input_parser.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", + ], + includes = [ + "include", + "src", + ], + strip_include_prefix = "", + include_prefix = "", + deps = [":dom"], + linkopts = ["-lpthread"], +) + + #"src/ftxui/component/component_fuzzer.cpp", + #"src/ftxui/component/terminal_input_parser_test_fuzzer.cpp", + #"src/ftxui/component/hoverable_test.cpp", + #"src/ftxui/component/collapsible_test.cpp", + #"src/ftxui/component/toggle_test.cpp", + #"src/ftxui/component/screen_interactive_test.cpp", + #"src/ftxui/component/modal_test.cpp", + #"src/ftxui/component/animation_test.cpp", + #"src/ftxui/component/★ selection_test.cpp", + #"src/ftxui/component/button_test.cpp", + #"src/ftxui/component/dropdown_test.cpp", + #"src/ftxui/component/slider_test.cpp", + #"src/ftxui/component/container_test.cpp", + #"src/ftxui/component/terminal_input_parser_test.cpp", + #"src/ftxui/component/receiver_test.cpp", + #"src/ftxui/component/resizable_split_test.cpp", + #"src/ftxui/component/component_test.cpp", + #"src/ftxui/component/input_test.cpp", + #"src/ftxui/component/menu_test.cpp", + #"src/ftxui/component/radiobox_test.cpp", + +cc_test( + name = "component_test", + 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/screen_interactive_test.cpp", + "src/ftxui/component/selection_test.cpp", + "src/ftxui/component/slider_test.cpp", + "src/ftxui/component/toggle_test.cpp", + ], + deps = [ + "//:component", + "@googletest//:gtest_main", + ], + includes = ["include", "src"], + copts = ["-std=c++20"], + testonly = True, + ) diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 00000000..8284154f --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,18 @@ +# Module. +module( + name = "ftxui", + version = "6.0.2", +) + +# Build deps. +bazel_dep(name = "rules_cc", version = "0.0.17") + +# Test deps. +bazel_dep(name = "googletest", version = "1.15.2") + +# Toolchain deps. +cc_configure = use_extension( + "@rules_cc//bzlmod:extensions.bzl", + "cc_configure", +) +use_repo(cc_configure, "local_config_cc_toolchains") diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 00000000..945e96dd --- /dev/null +++ b/WORKSPACE @@ -0,0 +1 @@ +workspace(name = "ftxui") diff --git a/cmake/ftxui_test.cmake b/cmake/ftxui_test.cmake index 665b7444..652e7055 100644 --- a/cmake/ftxui_test.cmake +++ b/cmake/ftxui_test.cmake @@ -19,10 +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/selection_test.cpp src/ftxui/component/slider_test.cpp src/ftxui/component/terminal_input_parser_test.cpp src/ftxui/component/toggle_test.cpp @@ -42,7 +42,7 @@ add_executable(ftxui-tests src/ftxui/dom/italic_test.cpp src/ftxui/dom/linear_gradient_test.cpp src/ftxui/dom/scroll_indicator_test.cpp - src/ftxui/dom/selection_test.cpp + src/ftxui/util/ref_test.cpp src/ftxui/dom/separator_test.cpp src/ftxui/dom/spinner_test.cpp src/ftxui/dom/table_test.cpp diff --git a/include/ftxui/component/component_base.hpp b/include/ftxui/component/component_base.hpp index fcc67e16..e0fd527e 100644 --- a/include/ftxui/component/component_base.hpp +++ b/include/ftxui/component/component_base.hpp @@ -42,8 +42,8 @@ class ComponentBase { // Component hierarchy: ComponentBase* Parent() const; - Component& ChildAt(size_t i); - size_t ChildCount() const; + Component& ChildAt(int i); + int ChildCount() const; int Index() const; void Add(Component children); void Detach(); diff --git a/src/ftxui/dom/selection_test.cpp b/src/ftxui/component/selection_test.cpp similarity index 99% rename from src/ftxui/dom/selection_test.cpp rename to src/ftxui/component/selection_test.cpp index 7c48e28e..8f29c177 100644 --- a/src/ftxui/dom/selection_test.cpp +++ b/src/ftxui/component/selection_test.cpp @@ -127,8 +127,6 @@ TEST(SelectionTest, SelectionOnChangeSquashedEvents) { } TEST(SelectionTest, StyleSelection) { - int selectionChangeCounter = 0; - auto element = hbox({ text("Lorem "), text("ipsum") | selectionColor(Color::Red), From 45bf24f8ea0e227e9277e39ccc70e36f906546c4 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Thu, 24 Apr 2025 03:02:10 +0200 Subject: [PATCH 02/31] Add workflow + examples + tests --- .github/workflows/build.yaml | 6 + BUILD.bazel | 450 ++++++++++----------- CMakeLists.txt | 4 +- MODULE.bazel | 18 +- WORKSPACE | 1 - examples/component/slider_direction.cpp | 2 +- examples/dom/color_truecolor_RGB.cpp | 1 - include/ftxui/component/component_base.hpp | 4 +- src/ftxui/component/menu_test.cpp | 2 +- src/ftxui/component/selection_test.cpp | 222 ---------- 10 files changed, 243 insertions(+), 467 deletions(-) delete mode 100644 WORKSPACE delete mode 100644 src/ftxui/component/selection_test.cpp diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index f9149b74..8bebbd87 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -55,6 +55,12 @@ jobs: gcovr: "5.0" opencppcoverage: true + - name: "Install Bazel" + uses: bazelbuild/setup-bazel@v5 + + - name: "Tests with Bazel" + run: bazel run test + # make sure coverage is only enabled for Debug builds, since it sets -O0 # to make sure coverage has meaningful results - name: "Configure CMake" diff --git a/BUILD.bazel b/BUILD.bazel index a4978a3d..d180a7c8 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,235 +1,193 @@ -load( - "@rules_cc//cc:defs.bzl", - "cc_library", - "cc_test", - "cc_binary", -) +# 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: +# - Windows/MSVC support. +# - Pass /utf-8 to MSVC users depending on FTXUI. +# - Pass "FTXUI_MICROSOFT_TERMINAL_FALLBACK" to windows users. +# - Support building benchmark. +# - Support building examples. +# - Support building fuzzer. +# - Support building 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", "generate_examples") package(default_visibility = ["//visibility:public"]) -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", - ], - includes = ["include", "src"], - strip_include_prefix = "", - copts = ["-std=c++17"], +# A meta target that depends on all the ftxui sub modules. +alias( + name = "ftxui", + actual = ":component", # Note that :component depends on :dom, which depends + # on :screen. Bazel doesn't really support "public" + # and "private" dependencies. They are all public. + visibility = ["//visibility:public"], ) -cc_test( - name = "screen_test", - srcs = [ - "src/ftxui/screen/string_test.cpp", - "src/ftxui/screen/color_test.cpp", - ], - deps = [ - "//:screen", - "@googletest//:gtest_main", - ], - includes = ["include", "src"], - copts = ["-std=c++20"], - testonly = True, -) - -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", +# 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/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", + 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", ], - includes = ["include", "src"], - deps = [":screen"], ) +# 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/terminal_input_parser.cpp", + "src/ftxui/component/terminal_input_parser.hpp", + "src/ftxui/component/util.cpp", + "src/ftxui/component/window.cpp", + ], + 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", + ], + linkopts = ["-lpthread"], + deps = [":dom"], +) + +# FTXUI's tests cc_test( - name = "dom_test", - srcs = [ - "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", - ], - deps = [ - "//:dom", - "@googletest//:gtest_main", - ], - includes = ["include", "src"], - copts = ["-std=c++20"], - testonly = True, -) - -#"src/ftxui/dom/benchmark_test.cpp", -cc_library( - name = "component", - srcs = [ - "src/ftxui/component/maybe.cpp", - "src/ftxui/component/hoverable.cpp", - "src/ftxui/component/collapsible.cpp", - "src/ftxui/component/screen_interactive.cpp", - "src/ftxui/component/modal.cpp", - "src/ftxui/component/util.cpp", - "src/ftxui/component/animation.cpp", - "src/ftxui/component/button.cpp", - "src/ftxui/component/dropdown.cpp", - "src/ftxui/component/loop.cpp", - "src/ftxui/component/slider.cpp", - "src/ftxui/component/container.cpp", - "src/ftxui/component/renderer.cpp", - "src/ftxui/component/terminal_input_parser.cpp", - "src/ftxui/component/component_options.cpp", - "src/ftxui/component/resizable_split.cpp", - "src/ftxui/component/component.cpp", - "src/ftxui/component/event.cpp", - "src/ftxui/component/catch_event.cpp", - "src/ftxui/component/input.cpp", - "src/ftxui/component/menu.cpp", - "src/ftxui/component/window.cpp", - "src/ftxui/component/checkbox.cpp", - "src/ftxui/component/radiobox.cpp", - "src/ftxui/component/terminal_input_parser.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", - ], - includes = [ - "include", - "src", - ], - strip_include_prefix = "", - include_prefix = "", - deps = [":dom"], - linkopts = ["-lpthread"], -) - - #"src/ftxui/component/component_fuzzer.cpp", - #"src/ftxui/component/terminal_input_parser_test_fuzzer.cpp", - #"src/ftxui/component/hoverable_test.cpp", - #"src/ftxui/component/collapsible_test.cpp", - #"src/ftxui/component/toggle_test.cpp", - #"src/ftxui/component/screen_interactive_test.cpp", - #"src/ftxui/component/modal_test.cpp", - #"src/ftxui/component/animation_test.cpp", - #"src/ftxui/component/★ selection_test.cpp", - #"src/ftxui/component/button_test.cpp", - #"src/ftxui/component/dropdown_test.cpp", - #"src/ftxui/component/slider_test.cpp", - #"src/ftxui/component/container_test.cpp", - #"src/ftxui/component/terminal_input_parser_test.cpp", - #"src/ftxui/component/receiver_test.cpp", - #"src/ftxui/component/resizable_split_test.cpp", - #"src/ftxui/component/component_test.cpp", - #"src/ftxui/component/input_test.cpp", - #"src/ftxui/component/menu_test.cpp", - #"src/ftxui/component/radiobox_test.cpp", - -cc_test( - name = "component_test", + name = "tests", + testonly = True, srcs = [ "src/ftxui/component/animation_test.cpp", "src/ftxui/component/button_test.cpp", @@ -242,17 +200,51 @@ cc_test( "src/ftxui/component/menu_test.cpp", "src/ftxui/component/modal_test.cpp", "src/ftxui/component/radiobox_test.cpp", + "src/ftxui/component/receiver_test.cpp", "src/ftxui/component/resizable_split_test.cpp", - "src/ftxui/component/screen_interactive_test.cpp", - "src/ftxui/component/selection_test.cpp", "src/ftxui/component/slider_test.cpp", + "src/ftxui/component/terminal_input_parser_test.cpp", + "src/ftxui/component/terminal_input_parser_test_fuzzer.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", + + # TODO: Enable the two tests timing out with Bazel: + # - "src/ftxui/component/screen_interactive_test.cpp", + # - "src/ftxui/dom/selection_test.cpp", + ], + copts = ["-std=c++20"], + includes = [ + "include", + "src", ], deps = [ - "//:component", + "//:ftxui", "@googletest//:gtest_main", ], - includes = ["include", "src"], - copts = ["-std=c++20"], - testonly = True, - ) +) + +generate_examples() diff --git a/CMakeLists.txt b/CMakeLists.txt index 0af94e52..1401920e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12) project(ftxui LANGUAGES CXX - VERSION 6.0.2 + VERSION 6.0.3 DESCRIPTION "C++ Functional Terminal User Interface." ) @@ -17,7 +17,7 @@ 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 \ +terminal used will be one of Microsoft and use a set of reasonable fallback \ to counteract its implementations problems.") if (WIN32) option(FTXUI_MICROSOFT_TERMINAL_FALLBACK diff --git a/MODULE.bazel b/MODULE.bazel index 8284154f..af988d1e 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,18 +1,20 @@ -# Module. +# FTXUI Module. module( - name = "ftxui", - version = "6.0.2", + name = "ftxui", + version = "6.0.3", ) # Build deps. bazel_dep(name = "rules_cc", version = "0.0.17") +bazel_dep(name = "platforms", version = "0.0.10") +bazel_dep(name = "bazel_skylib", version = "1.7.1") # Test deps. bazel_dep(name = "googletest", version = "1.15.2") # Toolchain deps. -cc_configure = use_extension( - "@rules_cc//bzlmod:extensions.bzl", - "cc_configure", -) -use_repo(cc_configure, "local_config_cc_toolchains") +#cc_configure = use_extension( +#"@rules_cc//bzlmod:extensions.bzl", +#"cc_configure", +#) +#use_repo(cc_configure, "local_config_cc_toolchains") diff --git a/WORKSPACE b/WORKSPACE deleted file mode 100644 index 945e96dd..00000000 --- a/WORKSPACE +++ /dev/null @@ -1 +0,0 @@ -workspace(name = "ftxui") diff --git a/examples/component/slider_direction.cpp b/examples/component/slider_direction.cpp index 4a6c3bad..77f466c8 100644 --- a/examples/component/slider_direction.cpp +++ b/examples/component/slider_direction.cpp @@ -19,7 +19,7 @@ using namespace ftxui; int main() { auto screen = ScreenInteractive::TerminalOutput(); std::array 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); } diff --git a/examples/dom/color_truecolor_RGB.cpp b/examples/dom/color_truecolor_RGB.cpp index 6a8d1f3c..5f0985ba 100644 --- a/examples/dom/color_truecolor_RGB.cpp +++ b/examples/dom/color_truecolor_RGB.cpp @@ -12,7 +12,6 @@ int main() { using namespace ftxui; - int saturation = 255; Elements red_line; Elements green_line; Elements blue_line; diff --git a/include/ftxui/component/component_base.hpp b/include/ftxui/component/component_base.hpp index e0fd527e..fcc67e16 100644 --- a/include/ftxui/component/component_base.hpp +++ b/include/ftxui/component/component_base.hpp @@ -42,8 +42,8 @@ class ComponentBase { // Component hierarchy: ComponentBase* Parent() const; - Component& ChildAt(int i); - int ChildCount() const; + Component& ChildAt(size_t i); + size_t ChildCount() const; int Index() const; void Add(Component children); void Detach(); diff --git a/src/ftxui/component/menu_test.cpp b/src/ftxui/component/menu_test.cpp index ca099468..de3182ab 100644 --- a/src/ftxui/component/menu_test.cpp +++ b/src/ftxui/component/menu_test.cpp @@ -266,7 +266,7 @@ TEST(MenuTest, MenuEntryIndex) { menu->OnEvent(Event::ArrowDown); menu->OnEvent(Event::ArrowDown); menu->OnEvent(Event::Return); - for (int index = 0; index < menu->ChildCount(); index++) { + for (size_t index = 0; index < menu->ChildCount(); index++) { EXPECT_EQ(menu->ChildAt(index)->Index(), index); } } diff --git a/src/ftxui/component/selection_test.cpp b/src/ftxui/component/selection_test.cpp deleted file mode 100644 index 8f29c177..00000000 --- a/src/ftxui/component/selection_test.cpp +++ /dev/null @@ -1,222 +0,0 @@ -// Copyright 2022 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 -#include // for raise, SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM - -#include "ftxui/component/component.hpp" // for Input, Renderer, Vertical -#include "ftxui/component/event.hpp" // for Event -#include "ftxui/component/loop.hpp" // for Loop -#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Pressed, Mouse::Released -#include "ftxui/component/screen_interactive.hpp" -#include "ftxui/dom/elements.hpp" // for text -#include "ftxui/dom/node.hpp" // for Render -#include "ftxui/screen/screen.hpp" // for Screen - -// NOLINTBEGIN -namespace ftxui { - -namespace { -Event MousePressed(int x, int y) { - Mouse mouse; - mouse.button = Mouse::Left; - mouse.motion = Mouse::Pressed; - mouse.shift = false; - mouse.meta = false; - mouse.control = false; - mouse.x = x; - mouse.y = y; - return Event::Mouse("", mouse); -} - -Event MouseReleased(int x, int y) { - Mouse mouse; - mouse.button = Mouse::Left; - mouse.motion = Mouse::Released; - mouse.shift = false; - mouse.meta = false; - mouse.control = false; - mouse.x = x; - mouse.y = y; - return Event::Mouse("", mouse); -} - -Event MouseMove(int x, int y) { - Mouse mouse; - mouse.button = Mouse::Left; - mouse.motion = Mouse::Moved; - mouse.shift = false; - mouse.meta = false; - mouse.control = false; - mouse.x = x; - mouse.y = y; - return Event::Mouse("", mouse); -} - -} // namespace - -TEST(SelectionTest, DefaultSelection) { - auto component = Renderer([&] { return text("Lorem ipsum dolor"); }); - auto screen = ScreenInteractive::FixedSize(20, 1); - EXPECT_EQ(screen.GetSelection(), ""); - Loop loop(&screen, component); - screen.PostEvent(MousePressed(3, 1)); - screen.PostEvent(MouseReleased(10, 1)); - loop.RunOnce(); - - EXPECT_EQ(screen.GetSelection(), "rem ipsu"); -} - -TEST(SelectionTest, SelectionChange) { - int selectionChangeCounter = 0; - auto component = Renderer([&] { return text("Lorem ipsum dolor"); }); - auto screen = ScreenInteractive::FixedSize(20, 1); - screen.SelectionChange([&] { selectionChangeCounter++; }); - - Loop loop(&screen, component); - loop.RunOnce(); - EXPECT_EQ(selectionChangeCounter, 0); - - screen.PostEvent(MousePressed(3, 1)); - loop.RunOnce(); - EXPECT_EQ(selectionChangeCounter, 0); - - screen.PostEvent(MouseMove(5, 1)); - loop.RunOnce(); - EXPECT_EQ(selectionChangeCounter, 1); - - screen.PostEvent(MouseMove(7, 1)); - loop.RunOnce(); - EXPECT_EQ(selectionChangeCounter, 2); - - screen.PostEvent(MouseReleased(10, 1)); - loop.RunOnce(); - EXPECT_EQ(selectionChangeCounter, 3); - - screen.PostEvent(MouseMove(10, 1)); - loop.RunOnce(); - EXPECT_EQ(selectionChangeCounter, 3); - - EXPECT_EQ(screen.GetSelection(), "rem ipsu"); -} - -// Check that submitting multiple mouse events quickly doesn't trigger multiple -// selection change events. -TEST(SelectionTest, SelectionOnChangeSquashedEvents) { - int selectionChangeCounter = 0; - auto component = Renderer([&] { return text("Lorem ipsum dolor"); }); - auto screen = ScreenInteractive::FixedSize(20, 1); - screen.SelectionChange([&] { selectionChangeCounter++; }); - - Loop loop(&screen, component); - loop.RunOnce(); - EXPECT_EQ(selectionChangeCounter, 0); - - screen.PostEvent(MousePressed(3, 1)); - screen.PostEvent(MouseMove(5, 1)); - screen.PostEvent(MouseMove(7, 1)); - loop.RunOnce(); - EXPECT_EQ(selectionChangeCounter, 1); - - screen.PostEvent(MouseReleased(10, 1)); - screen.PostEvent(MouseMove(10, 1)); - loop.RunOnce(); - EXPECT_EQ(selectionChangeCounter, 2); - - EXPECT_EQ(screen.GetSelection(), "rem ipsu"); -} - -TEST(SelectionTest, StyleSelection) { - auto element = hbox({ - text("Lorem "), - text("ipsum") | selectionColor(Color::Red), - text(" dolor"), - }); - - auto screen = ScreenInteractive::FixedSize(20, 1); - Selection selection(2, 0, 9, 0); - - Render(screen, element.get(), selection); - for (int i = 0; i < 20; i++) { - if (i >= 2 && i <= 9) { - EXPECT_EQ(screen.PixelAt(i, 0).inverted, true); - } else { - EXPECT_EQ(screen.PixelAt(i, 0).inverted, false); - } - - if (i >= 6 && i <= 9) { - EXPECT_EQ(screen.PixelAt(i, 0).foreground_color, Color::Red); - } else { - EXPECT_EQ(screen.PixelAt(i, 0).foreground_color, Color::Default); - } - } -} - -TEST(SelectionTest, VBoxSelection) { - auto element = vbox({ - text("Lorem ipsum dolor"), - text("Ut enim ad minim"), - }); - - auto screen = ScreenInteractive::FixedSize(20, 2); - - Selection selection(2, 0, 2, 1); - Render(screen, element.get(), selection); - - EXPECT_EQ(selection.GetParts(), "rem ipsum dolor\nUt "); - EXPECT_EQ(screen.ToString(), - "Lo\x1B[7mrem ipsum dolor\x1B[27m \r\n" - "\x1B[7mUt \x1B[27menim ad minim "); -} - -TEST(SelectionTest, VBoxSaturatedSelection) { - auto element = vbox({ - text("Lorem ipsum dolor"), - text("Ut enim ad minim"), - text("Duis aute irure"), - }); - - auto screen = ScreenInteractive::FixedSize(20, 3); - Selection selection(2, 0, 2, 2); - Render(screen, element.get(), selection); - EXPECT_EQ(selection.GetParts(), "rem ipsum dolor\nUt enim ad minim\nDui"); - - EXPECT_EQ(screen.ToString(), - "Lo\x1B[7mrem ipsum dolor\x1B[27m \r\n" - "\x1B[7mUt enim ad minim\x1B[27m \r\n" - "\x1B[7mDui\x1B[27ms aute irure "); -} - -TEST(SelectionTest, HBoxSelection) { - auto element = hbox({ - text("Lorem ipsum dolor"), - text("Ut enim ad minim"), - }); - - auto screen = ScreenInteractive::FixedSize(40, 1); - Selection selection(2, 0, 20, 0); - Render(screen, element.get(), selection); - EXPECT_EQ(selection.GetParts(), "rem ipsum dolorUt e"); - EXPECT_EQ(screen.ToString(), - "Lo\x1B[7mrem ipsum dolorUt e\x1B[27mnim ad minim "); -} - -TEST(SelectionTest, HBoxSaturatedSelection) { - auto element = hbox({ - text("Lorem ipsum dolor"), - text("Ut enim ad minim"), - text("Duis aute irure"), - }); - - auto screen = ScreenInteractive::FixedSize(60, 1); - - Selection selection(2, 0, 35, 0); - Render(screen, element.get(), selection); - EXPECT_EQ(selection.GetParts(), "rem ipsum dolorUt enim ad minimDui"); - EXPECT_EQ(screen.ToString(), - "Lo\x1B[7mrem ipsum dolorUt enim ad minimDui\x1B[27ms aute irure " - " "); -} - -} // namespace ftxui -// NOLINTEND From 053a1d8290ca432eedc88802cbc6ea36a62e7910 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Thu, 24 Apr 2025 03:05:01 +0200 Subject: [PATCH 03/31] Setup bazel in workflow --- .github/workflows/build.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 8bebbd87..a156ccd9 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -56,7 +56,11 @@ jobs: opencppcoverage: true - name: "Install Bazel" - uses: bazelbuild/setup-bazel@v5 + uses: bazel-contrib/setup-bazel@0.14.0 + with: + bazelisk-cache: true + disk-cache: ${{ github.workflow }} + repository-cache: true - name: "Tests with Bazel" run: bazel run test From c3d03dc716ee48a72cc9d5aa70e482c838c8e364 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Thu, 24 Apr 2025 03:11:13 +0200 Subject: [PATCH 04/31] Fix workflow issue. --- .gitignore | 5 +- BUILD.bazel | 7 +- WORKSPACE.bazel | 1 + bazel/ftxui.bzl | 44 ++++++ src/ftxui/dom/selection_test.cpp | 222 +++++++++++++++++++++++++++++++ 5 files changed, 275 insertions(+), 4 deletions(-) create mode 100644 WORKSPACE.bazel create mode 100644 bazel/ftxui.bzl create mode 100644 src/ftxui/dom/selection_test.cpp diff --git a/.gitignore b/.gitignore index f3477250..3b71c497 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,7 @@ out/ !flake.nix !ftxui.pc.in !iwyu.imp -!WORKSPACE +!WORKSPACE.bazel !BUILD.bazel !MODULE.bazel !.bazelrc @@ -33,6 +33,9 @@ out/ !cmake/**/*.in !cmake/**/*.cmake +# bazel directory: +!bazel/**/*.bzl + # doc directory: !doc/**/Doxyfile.in !doc/**/*.txt diff --git a/BUILD.bazel b/BUILD.bazel index d180a7c8..1c3ffa87 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -21,9 +21,10 @@ package(default_visibility = ["//visibility:public"]) # A meta target that depends on all the ftxui sub modules. alias( name = "ftxui", - actual = ":component", # Note that :component depends on :dom, which depends - # on :screen. Bazel doesn't really support "public" - # and "private" dependencies. They are all public. + # Note that :component depends on :dom, which depends on :screen. Bazel + # doesn't really support "public" and "private" dependencies. They are all + # public. This is equivalent to depending on all the submodules. + actual = ":component", visibility = ["//visibility:public"], ) diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel new file mode 100644 index 00000000..945e96dd --- /dev/null +++ b/WORKSPACE.bazel @@ -0,0 +1 @@ +workspace(name = "ftxui") diff --git a/bazel/ftxui.bzl b/bazel/ftxui.bzl new file mode 100644 index 00000000..684841fc --- /dev/null +++ b/bazel/ftxui.bzl @@ -0,0 +1,44 @@ +# ftxui_common.bzl + +load("@rules_cc//cc:defs.bzl", "cc_library") + +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 = ["-std=c++17"], + visibility = ["//visibility:public"], + ) + +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", "") + + native.cc_binary( + name = name, + srcs = [src], + deps = ["//:component"], + ) diff --git a/src/ftxui/dom/selection_test.cpp b/src/ftxui/dom/selection_test.cpp new file mode 100644 index 00000000..8f29c177 --- /dev/null +++ b/src/ftxui/dom/selection_test.cpp @@ -0,0 +1,222 @@ +// Copyright 2022 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 +#include // for raise, SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM + +#include "ftxui/component/component.hpp" // for Input, Renderer, Vertical +#include "ftxui/component/event.hpp" // for Event +#include "ftxui/component/loop.hpp" // for Loop +#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Pressed, Mouse::Released +#include "ftxui/component/screen_interactive.hpp" +#include "ftxui/dom/elements.hpp" // for text +#include "ftxui/dom/node.hpp" // for Render +#include "ftxui/screen/screen.hpp" // for Screen + +// NOLINTBEGIN +namespace ftxui { + +namespace { +Event MousePressed(int x, int y) { + Mouse mouse; + mouse.button = Mouse::Left; + mouse.motion = Mouse::Pressed; + mouse.shift = false; + mouse.meta = false; + mouse.control = false; + mouse.x = x; + mouse.y = y; + return Event::Mouse("", mouse); +} + +Event MouseReleased(int x, int y) { + Mouse mouse; + mouse.button = Mouse::Left; + mouse.motion = Mouse::Released; + mouse.shift = false; + mouse.meta = false; + mouse.control = false; + mouse.x = x; + mouse.y = y; + return Event::Mouse("", mouse); +} + +Event MouseMove(int x, int y) { + Mouse mouse; + mouse.button = Mouse::Left; + mouse.motion = Mouse::Moved; + mouse.shift = false; + mouse.meta = false; + mouse.control = false; + mouse.x = x; + mouse.y = y; + return Event::Mouse("", mouse); +} + +} // namespace + +TEST(SelectionTest, DefaultSelection) { + auto component = Renderer([&] { return text("Lorem ipsum dolor"); }); + auto screen = ScreenInteractive::FixedSize(20, 1); + EXPECT_EQ(screen.GetSelection(), ""); + Loop loop(&screen, component); + screen.PostEvent(MousePressed(3, 1)); + screen.PostEvent(MouseReleased(10, 1)); + loop.RunOnce(); + + EXPECT_EQ(screen.GetSelection(), "rem ipsu"); +} + +TEST(SelectionTest, SelectionChange) { + int selectionChangeCounter = 0; + auto component = Renderer([&] { return text("Lorem ipsum dolor"); }); + auto screen = ScreenInteractive::FixedSize(20, 1); + screen.SelectionChange([&] { selectionChangeCounter++; }); + + Loop loop(&screen, component); + loop.RunOnce(); + EXPECT_EQ(selectionChangeCounter, 0); + + screen.PostEvent(MousePressed(3, 1)); + loop.RunOnce(); + EXPECT_EQ(selectionChangeCounter, 0); + + screen.PostEvent(MouseMove(5, 1)); + loop.RunOnce(); + EXPECT_EQ(selectionChangeCounter, 1); + + screen.PostEvent(MouseMove(7, 1)); + loop.RunOnce(); + EXPECT_EQ(selectionChangeCounter, 2); + + screen.PostEvent(MouseReleased(10, 1)); + loop.RunOnce(); + EXPECT_EQ(selectionChangeCounter, 3); + + screen.PostEvent(MouseMove(10, 1)); + loop.RunOnce(); + EXPECT_EQ(selectionChangeCounter, 3); + + EXPECT_EQ(screen.GetSelection(), "rem ipsu"); +} + +// Check that submitting multiple mouse events quickly doesn't trigger multiple +// selection change events. +TEST(SelectionTest, SelectionOnChangeSquashedEvents) { + int selectionChangeCounter = 0; + auto component = Renderer([&] { return text("Lorem ipsum dolor"); }); + auto screen = ScreenInteractive::FixedSize(20, 1); + screen.SelectionChange([&] { selectionChangeCounter++; }); + + Loop loop(&screen, component); + loop.RunOnce(); + EXPECT_EQ(selectionChangeCounter, 0); + + screen.PostEvent(MousePressed(3, 1)); + screen.PostEvent(MouseMove(5, 1)); + screen.PostEvent(MouseMove(7, 1)); + loop.RunOnce(); + EXPECT_EQ(selectionChangeCounter, 1); + + screen.PostEvent(MouseReleased(10, 1)); + screen.PostEvent(MouseMove(10, 1)); + loop.RunOnce(); + EXPECT_EQ(selectionChangeCounter, 2); + + EXPECT_EQ(screen.GetSelection(), "rem ipsu"); +} + +TEST(SelectionTest, StyleSelection) { + auto element = hbox({ + text("Lorem "), + text("ipsum") | selectionColor(Color::Red), + text(" dolor"), + }); + + auto screen = ScreenInteractive::FixedSize(20, 1); + Selection selection(2, 0, 9, 0); + + Render(screen, element.get(), selection); + for (int i = 0; i < 20; i++) { + if (i >= 2 && i <= 9) { + EXPECT_EQ(screen.PixelAt(i, 0).inverted, true); + } else { + EXPECT_EQ(screen.PixelAt(i, 0).inverted, false); + } + + if (i >= 6 && i <= 9) { + EXPECT_EQ(screen.PixelAt(i, 0).foreground_color, Color::Red); + } else { + EXPECT_EQ(screen.PixelAt(i, 0).foreground_color, Color::Default); + } + } +} + +TEST(SelectionTest, VBoxSelection) { + auto element = vbox({ + text("Lorem ipsum dolor"), + text("Ut enim ad minim"), + }); + + auto screen = ScreenInteractive::FixedSize(20, 2); + + Selection selection(2, 0, 2, 1); + Render(screen, element.get(), selection); + + EXPECT_EQ(selection.GetParts(), "rem ipsum dolor\nUt "); + EXPECT_EQ(screen.ToString(), + "Lo\x1B[7mrem ipsum dolor\x1B[27m \r\n" + "\x1B[7mUt \x1B[27menim ad minim "); +} + +TEST(SelectionTest, VBoxSaturatedSelection) { + auto element = vbox({ + text("Lorem ipsum dolor"), + text("Ut enim ad minim"), + text("Duis aute irure"), + }); + + auto screen = ScreenInteractive::FixedSize(20, 3); + Selection selection(2, 0, 2, 2); + Render(screen, element.get(), selection); + EXPECT_EQ(selection.GetParts(), "rem ipsum dolor\nUt enim ad minim\nDui"); + + EXPECT_EQ(screen.ToString(), + "Lo\x1B[7mrem ipsum dolor\x1B[27m \r\n" + "\x1B[7mUt enim ad minim\x1B[27m \r\n" + "\x1B[7mDui\x1B[27ms aute irure "); +} + +TEST(SelectionTest, HBoxSelection) { + auto element = hbox({ + text("Lorem ipsum dolor"), + text("Ut enim ad minim"), + }); + + auto screen = ScreenInteractive::FixedSize(40, 1); + Selection selection(2, 0, 20, 0); + Render(screen, element.get(), selection); + EXPECT_EQ(selection.GetParts(), "rem ipsum dolorUt e"); + EXPECT_EQ(screen.ToString(), + "Lo\x1B[7mrem ipsum dolorUt e\x1B[27mnim ad minim "); +} + +TEST(SelectionTest, HBoxSaturatedSelection) { + auto element = hbox({ + text("Lorem ipsum dolor"), + text("Ut enim ad minim"), + text("Duis aute irure"), + }); + + auto screen = ScreenInteractive::FixedSize(60, 1); + + Selection selection(2, 0, 35, 0); + Render(screen, element.get(), selection); + EXPECT_EQ(selection.GetParts(), "rem ipsum dolorUt enim ad minimDui"); + EXPECT_EQ(screen.ToString(), + "Lo\x1B[7mrem ipsum dolorUt enim ad minimDui\x1B[27ms aute irure " + " "); +} + +} // namespace ftxui +// NOLINTEND From 4a75d4947861a286bdc3b0bf90d35d30de024262 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Thu, 24 Apr 2025 03:12:57 +0200 Subject: [PATCH 05/31] Fix workflow file. --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index a156ccd9..6be7b345 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -63,7 +63,7 @@ jobs: repository-cache: true - name: "Tests with Bazel" - run: bazel run test + run: bazel run tests # make sure coverage is only enabled for Debug builds, since it sets -O0 # to make sure coverage has meaningful results From 38869c4aaac5878e4a8a9f9d35ddfb00a89775c4 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Thu, 24 Apr 2025 03:16:12 +0200 Subject: [PATCH 06/31] fix workflow. --- .github/workflows/build.yaml | 3 +++ CMakeLists.txt | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 6be7b345..1226562e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -62,6 +62,9 @@ jobs: disk-cache: ${{ github.workflow }} repository-cache: true + - name: "Build with Bazel" + run: bazel build ... + - name: "Tests with Bazel" run: bazel run tests diff --git a/CMakeLists.txt b/CMakeLists.txt index 1401920e..0af94e52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12) project(ftxui LANGUAGES CXX - VERSION 6.0.3 + VERSION 6.0.2 DESCRIPTION "C++ Functional Terminal User Interface." ) @@ -17,7 +17,7 @@ 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 reasonable fallback \ +terminal used will be one of Microsoft and use a set of reasonnable fallback \ to counteract its implementations problems.") if (WIN32) option(FTXUI_MICROSOFT_TERMINAL_FALLBACK From f8d488051737ffe06553e349c023e8242346540f Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Thu, 24 Apr 2025 03:20:03 +0200 Subject: [PATCH 07/31] fix workflow. --- cmake/ftxui_test.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/ftxui_test.cmake b/cmake/ftxui_test.cmake index 652e7055..665b7444 100644 --- a/cmake/ftxui_test.cmake +++ b/cmake/ftxui_test.cmake @@ -19,10 +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/selection_test.cpp src/ftxui/component/slider_test.cpp src/ftxui/component/terminal_input_parser_test.cpp src/ftxui/component/toggle_test.cpp @@ -42,7 +42,7 @@ add_executable(ftxui-tests src/ftxui/dom/italic_test.cpp src/ftxui/dom/linear_gradient_test.cpp src/ftxui/dom/scroll_indicator_test.cpp - src/ftxui/util/ref_test.cpp + src/ftxui/dom/selection_test.cpp src/ftxui/dom/separator_test.cpp src/ftxui/dom/spinner_test.cpp src/ftxui/dom/table_test.cpp From e185d6d47563988473c9fb4af9736862150e6286 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Thu, 24 Apr 2025 03:36:04 +0200 Subject: [PATCH 08/31] Fix workflow. --- .bazelrc | 3 --- examples/dom/graph.cpp | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) delete mode 100644 .bazelrc diff --git a/.bazelrc b/.bazelrc deleted file mode 100644 index b1fd142d..00000000 --- a/.bazelrc +++ /dev/null @@ -1,3 +0,0 @@ -build --cxxopt=-std=c++20 -build --cxxopt=-Wall -build --cxxopt=-Werror diff --git a/examples/dom/graph.cpp b/examples/dom/graph.cpp index 461933fe..c63f9296 100644 --- a/examples/dom/graph.cpp +++ b/examples/dom/graph.cpp @@ -10,6 +10,7 @@ #include // for shared_ptr #include // for operator<<, string #include // for sleep_for +#include // for ignore #include // 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)), From f69adb605a257e377b68faa6b5b691fece63c088 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Thu, 24 Apr 2025 14:23:23 +0200 Subject: [PATCH 09/31] Update workflow --- .github/workflows/build.yaml | 57 ++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 1226562e..036c2ca2 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -10,8 +10,57 @@ on: - main jobs: - test: - name: "Tests" + + test_bazel: + name: "Bazel tests" + strategy: + fail-fast: false + matrix: + include: + - name: Linux GCC + os: ubuntu-latest + compiler: gcc + + - name: Linux Clang + os: ubuntu-latest + compiler: llvm + gcov_executable: "llvm-cov gcov" + + - name: MacOS clang + os: macos-latest + compiler: llvm + gcov_executable: "llvm-cov gcov" + + - name: Windows MSVC + os: windows-latest + compiler: cl + + 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' )}} + + - name: "Install Bazel" + uses: bazel-contrib/setup-bazel@0.14.0 + with: + bazelisk-cache: true + disk-cache: ${{ github.workflow }} + repository-cache: true + + - name: "Build with Bazel" + run: bazel build ... + + - name: "Tests with Bazel" + run: bazel run tests + + test_cmake: + name: "CMake tests" strategy: fail-fast: false matrix: @@ -135,7 +184,9 @@ jobs: # Create a release on new v* tags release: - needs: test + needs: + - test_cmake + - test_bazel if: ${{ github.event_name == 'create' && startsWith(github.ref, 'refs/tags/v') }} name: "Create release" runs-on: ubuntu-latest From d6006d3475d8a4a5780672b204897288e24be616 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Thu, 24 Apr 2025 14:29:21 +0200 Subject: [PATCH 10/31] Update workflow. --- .github/workflows/build.yaml | 17 ++--------------- MODULE.bazel | 10 +++++----- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 036c2ca2..ceaf235a 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -12,7 +12,7 @@ on: jobs: test_bazel: - name: "Bazel tests" + name: "Test Bazel" strategy: fail-fast: false matrix: @@ -60,7 +60,7 @@ jobs: run: bazel run tests test_cmake: - name: "CMake tests" + name: "Tests CMake" strategy: fail-fast: false matrix: @@ -104,19 +104,6 @@ jobs: gcovr: "5.0" opencppcoverage: true - - name: "Install Bazel" - uses: bazel-contrib/setup-bazel@0.14.0 - with: - bazelisk-cache: true - disk-cache: ${{ github.workflow }} - repository-cache: true - - - name: "Build with Bazel" - run: bazel build ... - - - name: "Tests with Bazel" - run: bazel run tests - # make sure coverage is only enabled for Debug builds, since it sets -O0 # to make sure coverage has meaningful results - name: "Configure CMake" diff --git a/MODULE.bazel b/MODULE.bazel index af988d1e..0d393c61 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -13,8 +13,8 @@ bazel_dep(name = "bazel_skylib", version = "1.7.1") bazel_dep(name = "googletest", version = "1.15.2") # Toolchain deps. -#cc_configure = use_extension( -#"@rules_cc//bzlmod:extensions.bzl", -#"cc_configure", -#) -#use_repo(cc_configure, "local_config_cc_toolchains") +cc_configure = use_extension( + "@rules_cc//bzlmod:extensions.bzl", + "cc_configure", +) +use_repo(cc_configure, "local_config_cc_toolchains") From dad4a67fcbd11fafdef0fc501701c6cccd59b39c Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Thu, 24 Apr 2025 14:34:13 +0200 Subject: [PATCH 11/31] Update workflow --- .github/workflows/build.yaml | 4 ++-- CHANGELOG.md | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index ceaf235a..177da905 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -49,9 +49,9 @@ jobs: - name: "Install Bazel" uses: bazel-contrib/setup-bazel@0.14.0 with: - bazelisk-cache: true + bazelisk-cache: false disk-cache: ${{ github.workflow }} - repository-cache: true + repository-cache: false - name: "Build with Bazel" run: bazel build ... diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c8f7af0..1a55b8e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,12 @@ Changelog ========= -Development ------------ +Next release (2025-04-01) +------------------------- + +### Build +- Feature: Support `bazel`. See #1032. Proposed by @kcc. + ### Component - Bugfix: Fix a crash with ResizeableSplit. See #1023. - Clamp screen size to terminal size. From 8feac77d8c579da98b705ca36ed912bd2ce44b91 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Thu, 24 Apr 2025 14:39:15 +0200 Subject: [PATCH 12/31] Update workflow file. --- .github/workflows/build.yaml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 177da905..5b6de7b4 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -24,12 +24,10 @@ jobs: - name: Linux Clang os: ubuntu-latest compiler: llvm - gcov_executable: "llvm-cov gcov" - name: MacOS clang os: macos-latest compiler: llvm - gcov_executable: "llvm-cov gcov" - name: Windows MSVC os: windows-latest @@ -52,6 +50,14 @@ jobs: bazelisk-cache: false disk-cache: ${{ github.workflow }} repository-cache: false + + # Need on macos. See https://github.com/bazelbuild/bazel/issues/21718 + - Clean Bazel cache 1 + run: bazel clean --expunge + + # Need on macos. See https://github.com/bazelbuild/bazel/issues/21718 + - Clean Bazel cache 2 + run: bazel fetch --configure --force - name: "Build with Bazel" run: bazel build ... From 321c308a981a82f51d080a32ce5834ba4f9fcb15 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Thu, 24 Apr 2025 14:41:44 +0200 Subject: [PATCH 13/31] Update workflow file. --- .github/workflows/build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 5b6de7b4..6bde8cb1 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -52,11 +52,11 @@ jobs: repository-cache: false # Need on macos. See https://github.com/bazelbuild/bazel/issues/21718 - - Clean Bazel cache 1 + - name: Clean Bazel cache 1 run: bazel clean --expunge # Need on macos. See https://github.com/bazelbuild/bazel/issues/21718 - - Clean Bazel cache 2 + - name: Clean Bazel cache 2 run: bazel fetch --configure --force - name: "Build with Bazel" From c8a14f5d70d066259c1c7e6ad9749a7c54a819ec Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Thu, 24 Apr 2025 14:43:35 +0200 Subject: [PATCH 14/31] Update workflow. --- MODULE.bazel | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 0d393c61..80562811 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,8 +1,5 @@ # FTXUI Module. -module( - name = "ftxui", - version = "6.0.3", -) +module(name = "ftxui", version = "6.0.3") # Build deps. bazel_dep(name = "rules_cc", version = "0.0.17") @@ -11,10 +8,3 @@ bazel_dep(name = "bazel_skylib", version = "1.7.1") # Test deps. bazel_dep(name = "googletest", version = "1.15.2") - -# Toolchain deps. -cc_configure = use_extension( - "@rules_cc//bzlmod:extensions.bzl", - "cc_configure", -) -use_repo(cc_configure, "local_config_cc_toolchains") From fd5e5c77e5aea9c268cbd89aef986c4794ecae92 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Thu, 24 Apr 2025 14:48:55 +0200 Subject: [PATCH 15/31] Update bazel workflow. --- .github/workflows/build.yaml | 4 ---- MODULE.bazel | 7 +++---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 6bde8cb1..073e1205 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -55,10 +55,6 @@ jobs: - name: Clean Bazel cache 1 run: bazel clean --expunge - # Need on macos. See https://github.com/bazelbuild/bazel/issues/21718 - - name: Clean Bazel cache 2 - run: bazel fetch --configure --force - - name: "Build with Bazel" run: bazel build ... diff --git a/MODULE.bazel b/MODULE.bazel index 80562811..503fe36e 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -2,9 +2,8 @@ module(name = "ftxui", version = "6.0.3") # Build deps. -bazel_dep(name = "rules_cc", version = "0.0.17") -bazel_dep(name = "platforms", version = "0.0.10") -bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "rules_cc", version = "0.1.1") +bazel_dep(name = "platforms", version = "0.0.11") # Test deps. -bazel_dep(name = "googletest", version = "1.15.2") +bazel_dep(name = "googletest", version = "1.16.0.bcr.1") From 1d7d84c15582f410ac1fbe995ee88db930b7ffdb Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Thu, 24 Apr 2025 15:07:17 +0200 Subject: [PATCH 16/31] Update workflow --- .github/workflows/build.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 073e1205..80c05095 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -46,13 +46,9 @@ jobs: - name: "Install Bazel" uses: bazel-contrib/setup-bazel@0.14.0 - with: - bazelisk-cache: false - disk-cache: ${{ github.workflow }} - repository-cache: false # Need on macos. See https://github.com/bazelbuild/bazel/issues/21718 - - name: Clean Bazel cache 1 + - name: Clean Bazel cache run: bazel clean --expunge - name: "Build with Bazel" From 632f8032bccbf75f53a70aa1ace5d5d1f1ebad33 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Sat, 26 Apr 2025 00:05:25 +0200 Subject: [PATCH 17/31] Update workflow. --- .github/workflows/build.yaml | 19 +++++++------------ BUILD.bazel | 1 - bazel/ftxui.bzl | 2 +- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 80c05095..23c78a3a 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -17,20 +17,19 @@ jobs: fail-fast: false matrix: include: - - name: Linux GCC - os: ubuntu-latest + - os: ubuntu-latest compiler: gcc - - name: Linux Clang - os: ubuntu-latest + - os: ubuntu-latest compiler: llvm - - name: MacOS clang - os: macos-latest + - os: macos-latest compiler: llvm - - name: Windows MSVC - os: windows-latest + - os: macos-latest + compiler: gcc + + - os: windows-latest compiler: cl runs-on: ${{ matrix.os }} @@ -46,10 +45,6 @@ jobs: - name: "Install Bazel" uses: bazel-contrib/setup-bazel@0.14.0 - - # Need on macos. See https://github.com/bazelbuild/bazel/issues/21718 - - name: Clean Bazel cache - run: bazel clean --expunge - name: "Build with Bazel" run: bazel build ... diff --git a/BUILD.bazel b/BUILD.bazel index 1c3ffa87..df97147a 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -237,7 +237,6 @@ cc_test( # - "src/ftxui/component/screen_interactive_test.cpp", # - "src/ftxui/dom/selection_test.cpp", ], - copts = ["-std=c++20"], includes = [ "include", "src", diff --git a/bazel/ftxui.bzl b/bazel/ftxui.bzl index 684841fc..0c2e5fc8 100644 --- a/bazel/ftxui.bzl +++ b/bazel/ftxui.bzl @@ -20,7 +20,7 @@ def ftxui_cc_library( "include", "src", ], - copts = ["-std=c++17"], + copts = ["-std=c++20"], visibility = ["//visibility:public"], ) From 3184033f4d1f898b6e332d662e8a23de3848d550 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Sat, 26 Apr 2025 00:16:41 +0200 Subject: [PATCH 18/31] update workdflow. --- README.md | 5 ++--- bazel/ftxui.bzl | 8 +++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e7d8f319..8bcaee97 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ A simple cross-platform C++ library for terminal based user interfaces! * No dependencies * **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, vcpkg, pkgbuild, conan. * Good practices: documentation, tests, fuzzers, performance tests, automated CI, automated packaging, etc... ## Documentation @@ -383,6 +383,7 @@ endif() ``` If you don't, FTXUI may be used from the following packages: +- [bazel](...) - [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) @@ -395,8 +396,6 @@ If you choose to build and link FTXUI yourself, `ftxui-component` must be first g++ . . . -lftxui-component -lftxui-dom -lftxui-screen . . . ``` - - ## Contributors diff --git a/bazel/ftxui.bzl b/bazel/ftxui.bzl index 0c2e5fc8..0a42a7f5 100644 --- a/bazel/ftxui.bzl +++ b/bazel/ftxui.bzl @@ -8,6 +8,12 @@ def ftxui_cc_library( hdrs, linkopts = [], deps = []): + + cpp20 = select({ + "@bazel_tools//tools/cpp:msvc": ["/std:c++20"], + "//conditions:default": ["-std=c++20"], + }) + cc_library( name = name, srcs = srcs, @@ -20,7 +26,7 @@ def ftxui_cc_library( "include", "src", ], - copts = ["-std=c++20"], + copts = cpp20, visibility = ["//visibility:public"], ) From 31ec197811701767b65720ce0655b50b2dbbfb10 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Sat, 26 Apr 2025 00:44:44 +0200 Subject: [PATCH 19/31] Set c++ standard. --- BUILD.bazel | 5 ++++- bazel/ftxui.bzl | 35 +++++++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index df97147a..74d4ae41 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -14,7 +14,9 @@ # - Support WebAssembly load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") -load(":bazel/ftxui.bzl", "ftxui_cc_library", "generate_examples") +load(":bazel/ftxui.bzl", "ftxui_cc_library") +load(":bazel/ftxui.bzl", "generate_examples") +load(":bazel/ftxui.bzl", "cpp20") package(default_visibility = ["//visibility:public"]) @@ -241,6 +243,7 @@ cc_test( "include", "src", ], + copts = cpp20(), deps = [ "//:ftxui", "@googletest//:gtest_main", diff --git a/bazel/ftxui.bzl b/bazel/ftxui.bzl index 0a42a7f5..aa0eb775 100644 --- a/bazel/ftxui.bzl +++ b/bazel/ftxui.bzl @@ -2,6 +2,33 @@ load("@rules_cc//cc:defs.bzl", "cc_library") +def cpp17(): + return select({ + "@rules_cc//cc/compiler:msvc-cl": ["/std:c++17"], + "@rules_cc//cc/compiler:clang-cl": ["/std:c++17"], + "@rules_cc//cc/compiler:clang": ["-std=c++17"], + "@rules_cc//cc/compiler:gcc": ["-std=c++17"], + "//conditions:default": ["-std=c++17"], + }) + +def cpp20(): + return select({ + "@rules_cc//cc/compiler:msvc-cl": ["/std:c++20"], + "@rules_cc//cc/compiler:clang-cl": ["/std:c++20"], + "@rules_cc//cc/compiler:clang": ["-std=c++20"], + "@rules_cc//cc/compiler:gcc": ["-std=c++20"], + "//conditions:default": ["-std=c++20"], + }) + +def utf8(): + return select({ + "@rules_cc//cc/compiler:msvc-cl": ["/utf-8"], + "@rules_cc//cc/compiler:clang-cl": ["/utf-8"], + "@rules_cc//cc/compiler:clang": ["-finput-charset=UTF-8"], + "@rules_cc//cc/compiler:gcc": ["-finput-charset=UTF-8"], + "//conditions:default": ["-finput-charset=UTF-8"], + }) + def ftxui_cc_library( name, srcs, @@ -9,11 +36,6 @@ def ftxui_cc_library( linkopts = [], deps = []): - cpp20 = select({ - "@bazel_tools//tools/cpp:msvc": ["/std:c++20"], - "//conditions:default": ["-std=c++20"], - }) - cc_library( name = name, srcs = srcs, @@ -26,7 +48,7 @@ def ftxui_cc_library( "include", "src", ], - copts = cpp20, + copts = cpp17() + utf8(), visibility = ["//visibility:public"], ) @@ -47,4 +69,5 @@ def generate_examples(): name = name, srcs = [src], deps = ["//:component"], + copts = cpp20() + utf8(), ) From a9b54106d4c44b2a72331c646cc189f3668f5472 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Sat, 26 Apr 2025 00:55:47 +0200 Subject: [PATCH 20/31] Fix /utf-8 --- bazel/ftxui.bzl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bazel/ftxui.bzl b/bazel/ftxui.bzl index aa0eb775..15bc0cc6 100644 --- a/bazel/ftxui.bzl +++ b/bazel/ftxui.bzl @@ -20,13 +20,12 @@ def cpp20(): "//conditions:default": ["-std=c++20"], }) +# Force Microsoft Visual Studio to decode sources files in UTF-8, as it should. def utf8(): return select({ "@rules_cc//cc/compiler:msvc-cl": ["/utf-8"], "@rules_cc//cc/compiler:clang-cl": ["/utf-8"], - "@rules_cc//cc/compiler:clang": ["-finput-charset=UTF-8"], - "@rules_cc//cc/compiler:gcc": ["-finput-charset=UTF-8"], - "//conditions:default": ["-finput-charset=UTF-8"], + "//conditions:default": [], }) def ftxui_cc_library( From 44d25564ee6ce0f10d837d29c5f822ebe959eb10 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Sat, 26 Apr 2025 01:10:42 +0200 Subject: [PATCH 21/31] Fix MSVC --- BUILD.bazel | 3 ++- bazel/ftxui.bzl | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 74d4ae41..40beed62 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -17,6 +17,7 @@ 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", "cpp20") +load(":bazel/ftxui.bzl", "msvc_copts") package(default_visibility = ["//visibility:public"]) @@ -243,7 +244,7 @@ cc_test( "include", "src", ], - copts = cpp20(), + copts = cpp20() + msvc_copts(), deps = [ "//:ftxui", "@googletest//:gtest_main", diff --git a/bazel/ftxui.bzl b/bazel/ftxui.bzl index 15bc0cc6..b55ceac1 100644 --- a/bazel/ftxui.bzl +++ b/bazel/ftxui.bzl @@ -20,11 +20,20 @@ def cpp20(): "//conditions:default": ["-std=c++20"], }) -# Force Microsoft Visual Studio to decode sources files in UTF-8, as it should. -def utf8(): +def msvc_copts(): return select({ - "@rules_cc//cc/compiler:msvc-cl": ["/utf-8"], - "@rules_cc//cc/compiler:clang-cl": ["/utf-8"], + "@rules_cc//cc/compiler:msvc-cl": [ + # Force Microsoft Visual Studio to decode sources files in UTF-8. + "/utf-8", + + # Force Microsoft Visual Studio to interpret the source files as + # Unicode. + "/DUNICODE", + "/D_UNICODE", + + # Fallback for Microsoft Terminal. + "/DFTXUI_MICROSOFT_TERMINAL_FALLBACK", + ], "//conditions:default": [], }) @@ -47,7 +56,7 @@ def ftxui_cc_library( "include", "src", ], - copts = cpp17() + utf8(), + copts = cpp17() + msvc_copts(), visibility = ["//visibility:public"], ) @@ -68,5 +77,5 @@ def generate_examples(): name = name, srcs = [src], deps = ["//:component"], - copts = cpp20() + utf8(), + copts = cpp20() + msvc_copts(), ) From 2270fe628f58c359548bfab05a16ed955ed4766a Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Sat, 26 Apr 2025 01:14:09 +0200 Subject: [PATCH 22/31] tmp --- .github/workflows/build.yaml | 10 ++++++---- bazel/ftxui.bzl | 27 +++++++++++++++------------ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 23c78a3a..9fc5fa78 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -23,11 +23,13 @@ jobs: - os: ubuntu-latest compiler: llvm - - os: macos-latest - compiler: llvm + # Failing + #- os: macos-latest + #compiler: llvm - - os: macos-latest - compiler: gcc + # Failing + #- os: macos-latest + #compiler: gcc - os: windows-latest compiler: cl diff --git a/bazel/ftxui.bzl b/bazel/ftxui.bzl index b55ceac1..d0ddf68f 100644 --- a/bazel/ftxui.bzl +++ b/bazel/ftxui.bzl @@ -21,19 +21,22 @@ def cpp20(): }) def msvc_copts(): + MSVC_COPTS = [ + # Force Microsoft Visual Studio to decode sources files in UTF-8. + "/utf-8", + + # Force Microsoft Visual Studio to interpret the source files as + # Unicode. + "/DUNICODE", + "/D_UNICODE", + + # Fallback for Microsoft Terminal. + "/DFTXUI_MICROSOFT_TERMINAL_FALLBACK", + ] + return select({ - "@rules_cc//cc/compiler:msvc-cl": [ - # Force Microsoft Visual Studio to decode sources files in UTF-8. - "/utf-8", - - # Force Microsoft Visual Studio to interpret the source files as - # Unicode. - "/DUNICODE", - "/D_UNICODE", - - # Fallback for Microsoft Terminal. - "/DFTXUI_MICROSOFT_TERMINAL_FALLBACK", - ], + "@rules_cc//cc/compiler:msvc-cl": MSVC_COPTS, + "@rules_cc//cc/compiler:clang-cl": MSVC_COPTS, "//conditions:default": [], }) From 378e30bef0a06c99cda86c805af0e91cb99df621 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Sat, 26 Apr 2025 01:25:29 +0200 Subject: [PATCH 23/31] update workflow --- BUILD.bazel | 3 ++- bazel/ftxui.bzl | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/BUILD.bazel b/BUILD.bazel index 40beed62..1eda9326 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -18,6 +18,7 @@ load(":bazel/ftxui.bzl", "ftxui_cc_library") load(":bazel/ftxui.bzl", "generate_examples") load(":bazel/ftxui.bzl", "cpp20") load(":bazel/ftxui.bzl", "msvc_copts") +load(":bazel/ftxui.bzl", "pthread_linkopts") package(default_visibility = ["//visibility:public"]) @@ -184,7 +185,7 @@ ftxui_cc_library( "include/ftxui/component/screen_interactive.hpp", "include/ftxui/component/task.hpp", ], - linkopts = ["-lpthread"], + linkopts = pthread_linkopts(), deps = [":dom"], ) diff --git a/bazel/ftxui.bzl b/bazel/ftxui.bzl index d0ddf68f..0f5e0c89 100644 --- a/bazel/ftxui.bzl +++ b/bazel/ftxui.bzl @@ -40,6 +40,16 @@ def msvc_copts(): "//conditions:default": [], }) +def pthread_linkopts(): + return select({ + # With MSVC, threading is already built-in (you don't need -pthread. + "@rules_cc//cc/compiler:msvc-cl": [], + "@rules_cc//cc/compiler:clang-cl": [], + "@rules_cc//cc/compiler:clang": ["-pthread"], + "@rules_cc//cc/compiler:gcc": ["-pthread"], + "//conditions:default": ["-pthread"], + }) + def ftxui_cc_library( name, srcs, From 8e055a5a61e3822faa9cc688f62323463d1037e9 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Sat, 26 Apr 2025 01:29:39 +0200 Subject: [PATCH 24/31] update workflow --- .github/workflows/build.yaml | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 9fc5fa78..b484d399 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -23,13 +23,11 @@ jobs: - os: ubuntu-latest compiler: llvm - # Failing - #- os: macos-latest - #compiler: llvm + - os: macos-latest + compiler: llvm - # Failing - #- os: macos-latest - #compiler: gcc + - os: macos-latest + compiler: gcc - os: windows-latest compiler: cl @@ -39,15 +37,6 @@ jobs: - name: "Checkout repository" uses: actions/checkout@v3 - - name: "Setup Cpp" - uses: aminya/setup-cpp@v1 - with: - compiler: ${{ matrix.compiler }} - vcvarsall: ${{ contains(matrix.os, 'windows' )}} - - - name: "Install Bazel" - uses: bazel-contrib/setup-bazel@0.14.0 - - name: "Build with Bazel" run: bazel build ... From 2a5d7646da0b3dcd1ed9055d9d02e135ba857512 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Sat, 26 Apr 2025 02:38:32 +0200 Subject: [PATCH 25/31] Add publish to BCR --- .bcr/README.md | 9 +++++++++ .bcr/config.yaml | 18 +++++++++++++++++ .bcr/metadata.template.json | 16 +++++++++++++++ .bcr/presubmit.yml | 25 ++++++++++++++++++++++++ .bcr/source.template.json | 5 +++++ .github/workflows/publish_to_bcr.yaml | 28 +++++++++++++++++++++++++++ .gitignore | 1 + MODULE.bazel | 4 ++++ WORKSPACE.bazel | 3 +++ 9 files changed, 109 insertions(+) create mode 100644 .bcr/README.md create mode 100644 .bcr/config.yaml create mode 100644 .bcr/metadata.template.json create mode 100644 .bcr/presubmit.yml create mode 100644 .bcr/source.template.json create mode 100644 .github/workflows/publish_to_bcr.yaml diff --git a/.bcr/README.md b/.bcr/README.md new file mode 100644 index 00000000..44ae7fe5 --- /dev/null +++ b/.bcr/README.md @@ -0,0 +1,9 @@ +# Bazel Central Registry + +When the ruleset is released, we want it to be published to the +Bazel Central Registry automatically: + + +This folder contains configuration files to automate the publish step. +See +for authoritative documentation about these files. diff --git a/.bcr/config.yaml b/.bcr/config.yaml new file mode 100644 index 00000000..37d1ca99 --- /dev/null +++ b/.bcr/config.yaml @@ -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. +{ + "homepage": "https://github.com/ArthurSonzogni/FTXUI", + "maintainers": [ + { + "name": "Arthur Sonzogni", + "email": "sonzogniarthur@gmail.com", + "github": "ArthurSonzogni" + } + ], + "repository": [ + "github:ArthurSonzogni/FTXUI" + ], + "versions": [], + "yanked_versions": {} +} diff --git a/.bcr/metadata.template.json b/.bcr/metadata.template.json new file mode 100644 index 00000000..9b2b52de --- /dev/null +++ b/.bcr/metadata.template.json @@ -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": {} +} diff --git a/.bcr/presubmit.yml b/.bcr/presubmit.yml new file mode 100644 index 00000000..8ca84f16 --- /dev/null +++ b/.bcr/presubmit.yml @@ -0,0 +1,25 @@ +# 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. +bcr_test_module: + module_path: "." + matrix: + platform: [ + "debian11", + "macos", + "macos-arm64", + "ubuntu2204", + "windows", + ] + bazel: [ + 6.x, + 7.x, + 8.x, + ] + tasks: + run_tests: + name: "Run test module" + platform: ${{ platform }} + bazel: ${{ bazel }} + test_targets: + - "//..." diff --git a/.bcr/source.template.json b/.bcr/source.template.json new file mode 100644 index 00000000..20374716 --- /dev/null +++ b/.bcr/source.template.json @@ -0,0 +1,5 @@ +{ + "integrity": "", + "strip_prefix": "{REPO}-{VERSION}", + "url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{REPO}-{TAG}.tar.gz" +} diff --git a/.github/workflows/publish_to_bcr.yaml b/.github/workflows/publish_to_bcr.yaml new file mode 100644 index 00000000..43e11599 --- /dev/null +++ b/.github/workflows/publish_to_bcr.yaml @@ -0,0 +1,28 @@ +on: + # Run the publish workflow after a successful release. + workflow_call: + inputs: + tag_name: + required: true + type: string + + # Allow manual triggering of the workflow. + workflow_dispatch: + inputs: + tag_name: + required: true + type: string + +jobs: + publish: + uses: bazel-contrib/publish-to-bcr/.github/workflows/publish.yaml@[version] + with: + tag_name: ${{ inputs.tag_name }} + # GitHub repository which is a fork of the upstream where the Pull Request will be opened. + registry_fork: ArthurSonzogni/bazel-central-registry + permissions: + attestations: write + contents: write + id-token: write + secrets: + publish_token: ${{ secrets.PUBLISH_TOKEN }} diff --git a/.gitignore b/.gitignore index 3b71c497..a3820005 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ out/ # bazel directory: !bazel/**/*.bzl +!.bcr/* # doc directory: !doc/**/Doxyfile.in diff --git a/MODULE.bazel b/MODULE.bazel index 503fe36e..b26b6c95 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,3 +1,7 @@ +# 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. + # FTXUI Module. module(name = "ftxui", version = "6.0.3") diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 945e96dd..1c3bb376 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -1 +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") From c2df863e5d7cb1d18459cf70aa81355a5bf2f11a Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Sat, 26 Apr 2025 19:24:34 +0200 Subject: [PATCH 26/31] tmp --- .bcr/config.yaml | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 .bcr/config.yaml diff --git a/.bcr/config.yaml b/.bcr/config.yaml deleted file mode 100644 index 37d1ca99..00000000 --- a/.bcr/config.yaml +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright 2025 Arthur Sonzogni. All rights reserved. -# Use of this source code is governed by the MIT license that can be found in -# the LICENSE file. -{ - "homepage": "https://github.com/ArthurSonzogni/FTXUI", - "maintainers": [ - { - "name": "Arthur Sonzogni", - "email": "sonzogniarthur@gmail.com", - "github": "ArthurSonzogni" - } - ], - "repository": [ - "github:ArthurSonzogni/FTXUI" - ], - "versions": [], - "yanked_versions": {} -} From 30304f1668451e6c4a8511b51b565c35534018da Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Sun, 27 Apr 2025 11:29:28 +0200 Subject: [PATCH 27/31] Update workflow --- .bcr/presubmit.yml | 43 ++++++++++++++++++------------------ .bcr/source.template.json | 4 ++-- .github/workflows/build.yaml | 29 +++++++++++++++++++++--- 3 files changed, 49 insertions(+), 27 deletions(-) diff --git a/.bcr/presubmit.yml b/.bcr/presubmit.yml index 8ca84f16..658def63 100644 --- a/.bcr/presubmit.yml +++ b/.bcr/presubmit.yml @@ -1,25 +1,24 @@ # 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. -bcr_test_module: - module_path: "." - matrix: - platform: [ - "debian11", - "macos", - "macos-arm64", - "ubuntu2204", - "windows", - ] - bazel: [ - 6.x, - 7.x, - 8.x, - ] - tasks: - run_tests: - name: "Run test module" - platform: ${{ platform }} - bazel: ${{ bazel }} - test_targets: - - "//..." +matrix: + platform: + - centos7 + - debian10 + - ubuntu2004 + - macos + - windows + bazel: [6.x, 7.x, 8.x] +tasks: + verify_targets: + name: Build and test. + platform: ${{ platform }} + bazel: ${{ bazel }} + build_targets: + - '@ftxui//:ftxui' + - '@ftxui//:screen' + - '@ftxui//:dom' + - '@ftxui//:component' + test_targets: + - '@ftxui//:tests' + diff --git a/.bcr/source.template.json b/.bcr/source.template.json index 20374716..c7078647 100644 --- a/.bcr/source.template.json +++ b/.bcr/source.template.json @@ -1,5 +1,5 @@ { "integrity": "", - "strip_prefix": "{REPO}-{VERSION}", - "url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{REPO}-{TAG}.tar.gz" + "strip_prefix": "", + "url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/source.tar.gz", } diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index b484d399..5ca73610 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -12,7 +12,7 @@ on: jobs: test_bazel: - name: "Test Bazel" + name: "${{ matrix.os }}/Bazel/${{ matrix.compiler }}" strategy: fail-fast: false matrix: @@ -44,7 +44,7 @@ jobs: run: bazel run tests test_cmake: - name: "Tests CMake" + name: "${{ matrix.os }}/CMake/${{ matrix.compiler }}" strategy: fail-fast: false matrix: @@ -173,7 +173,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Build artifact for the release - package: + package_compiled: name: "Build packages" needs: release strategy: @@ -217,6 +217,29 @@ jobs: 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 --prefix=ftxui/ -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 + documentation: if: github.ref == 'refs/heads/main' From a0d59acf62b0057ae5f3dbea47cb519e1789c3b7 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Sun, 27 Apr 2025 11:32:19 +0200 Subject: [PATCH 28/31] Update workflow. --- .github/workflows/build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 5ca73610..f22c9182 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -12,7 +12,7 @@ on: jobs: test_bazel: - name: "${{ matrix.os }}/Bazel/${{ matrix.compiler }}" + name: "Bazel, ${{ matrix.compiler }}, ${{ matrix.os }}" strategy: fail-fast: false matrix: @@ -44,7 +44,7 @@ jobs: run: bazel run tests test_cmake: - name: "${{ matrix.os }}/CMake/${{ matrix.compiler }}" + name: "CMake, ${{ matrix.compiler }}, ${{ matrix.os }}" strategy: fail-fast: false matrix: From cabb7cad91133897a80858fdbad608b0ff83e00d Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Sun, 27 Apr 2025 11:38:44 +0200 Subject: [PATCH 29/31] Update workflow --- .bcr/source.template.json | 2 +- .github/workflows/{publish_to_bcr.yaml => publish.yaml} | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) rename .github/workflows/{publish_to_bcr.yaml => publish.yaml} (71%) diff --git a/.bcr/source.template.json b/.bcr/source.template.json index c7078647..6a897698 100644 --- a/.bcr/source.template.json +++ b/.bcr/source.template.json @@ -1,5 +1,5 @@ { "integrity": "", "strip_prefix": "", - "url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/source.tar.gz", + "url": "https://github.com/ArthurSonzogni/FTXUI/releases/download/{TAG}/source.tar.gz" } diff --git a/.github/workflows/publish_to_bcr.yaml b/.github/workflows/publish.yaml similarity index 71% rename from .github/workflows/publish_to_bcr.yaml rename to .github/workflows/publish.yaml index 43e11599..83f17ba9 100644 --- a/.github/workflows/publish_to_bcr.yaml +++ b/.github/workflows/publish.yaml @@ -1,12 +1,12 @@ on: - # Run the publish workflow after a successful release. + # On new releases: workflow_call: inputs: tag_name: required: true type: string - # Allow manual triggering of the workflow. + # On manual trigger: workflow_dispatch: inputs: tag_name: @@ -15,10 +15,9 @@ on: jobs: publish: - uses: bazel-contrib/publish-to-bcr/.github/workflows/publish.yaml@[version] + uses: bazel-contrib/publish-to-bcr/.github/workflows/publish.yaml@v0.0.4 with: tag_name: ${{ inputs.tag_name }} - # GitHub repository which is a fork of the upstream where the Pull Request will be opened. registry_fork: ArthurSonzogni/bazel-central-registry permissions: attestations: write From aa6d1df1dd90ffb2ea13bb5b9ec4ffd05486b9e4 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Sun, 27 Apr 2025 11:41:21 +0200 Subject: [PATCH 30/31] Update workflow --- BUILD.bazel | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 1eda9326..e0e3cf8a 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -3,13 +3,9 @@ # the LICENSE file. # TODO: -# - Windows/MSVC support. -# - Pass /utf-8 to MSVC users depending on FTXUI. -# - Pass "FTXUI_MICROSOFT_TERMINAL_FALLBACK" to windows users. -# - Support building benchmark. -# - Support building examples. -# - Support building fuzzer. -# - Support building documentation. +# - Build benchmark. +# - Build fuzzers. +# - Build documentation. # - Enable the two tests timing out. # - Support WebAssembly From ee80e956dd10af76785b70a27283a9a42967c858 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Sun, 27 Apr 2025 12:39:48 +0200 Subject: [PATCH 31/31] Update workflow --- BUILD.bazel | 4 ++-- bazel/ftxui.bzl | 33 +++++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index e0e3cf8a..94bd4389 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -13,7 +13,7 @@ load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") load(":bazel/ftxui.bzl", "ftxui_cc_library") load(":bazel/ftxui.bzl", "generate_examples") load(":bazel/ftxui.bzl", "cpp20") -load(":bazel/ftxui.bzl", "msvc_copts") +load(":bazel/ftxui.bzl", "windows_copts") load(":bazel/ftxui.bzl", "pthread_linkopts") package(default_visibility = ["//visibility:public"]) @@ -241,7 +241,7 @@ cc_test( "include", "src", ], - copts = cpp20() + msvc_copts(), + copts = cpp20() + windows_copts(), deps = [ "//:ftxui", "@googletest//:gtest_main", diff --git a/bazel/ftxui.bzl b/bazel/ftxui.bzl index 0f5e0c89..c96cf5b6 100644 --- a/bazel/ftxui.bzl +++ b/bazel/ftxui.bzl @@ -20,23 +20,42 @@ def cpp20(): "//conditions:default": ["-std=c++20"], }) -def msvc_copts(): +# Microsoft terminal is a bit buggy ¯\_(ツ)_/¯ and MSVC uses bad defaults. +def windows_copts(): MSVC_COPTS = [ - # Force Microsoft Visual Studio to decode sources files in UTF-8. + # Microsoft Visual Studio must decode sources files as UTF-8. "/utf-8", - # Force Microsoft Visual Studio to interpret the source files as - # Unicode. + # 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 never not updated. + # - 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": [], }) @@ -69,10 +88,12 @@ def ftxui_cc_library( "include", "src", ], - copts = cpp17() + msvc_copts(), + copts = cpp17() + windows_copts(), visibility = ["//visibility:public"], ) +# Compile all the examples in the examples/ directory. +# This is useful to check the Bazel is synchronized with CMake definitions. def generate_examples(): cpp_files = native.glob(["examples/**/*.cpp"]) @@ -90,5 +111,5 @@ def generate_examples(): name = name, srcs = [src], deps = ["//:component"], - copts = cpp20() + msvc_copts(), + copts = cpp20() + windows_copts(), )