Skip to content

Commit

Permalink
Introduce shared 'tui' library
Browse files Browse the repository at this point in the history
This commit introduces a new shared library with components used by the
`explore` and `table` plugins. This new library contains all shared
logic, e.g., UI components and DOM elements.
  • Loading branch information
mavam committed Jul 24, 2023
1 parent 0e44fe7 commit 5b8fbb6
Show file tree
Hide file tree
Showing 18 changed files with 284 additions and 282 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
[submodule "libtenzir/aux/caf"]
path = libtenzir/aux/caf
url = https://github.com/tenzir/actor-framework
[submodule "plugins/tui/aux/ftxui"]
path = plugins/explore/aux/ftxui
[submodule "libtenzir_tui/aux/ftxui"]
path = libtenzir_tui/aux/ftxui
url = https://github.com/ArthurSonzogni/FTXUI.git
2 changes: 1 addition & 1 deletion libtenzir/builtins/operators/serve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace tenzir::plugins::serve {
namespace {

constexpr auto SERVE_ENDPOINT_ID = 0;
constexpr auto FINAL_CONTINUATION_TOKEN = std::string{"__DONE__"};
constexpr auto FINAL_CONTINUATION_TOKEN = std::string_view{"__DONE__"};

constexpr auto SPEC_V0 = R"_(
/serve:
Expand Down
40 changes: 40 additions & 0 deletions libtenzir_tui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
if (TARGET libtenzir_tui)
return()
endif()

find_package(Tenzir REQUIRED)

option(TENZIR_ENABLE_BUNDLED_FTXUI "Always use the bundled ftxui" OFF)
add_feature_info("TENZIR_ENABLE_BUNDLED_FTXUI" TENZIR_ENABLE_BUNDLED_FTXUI
"always use the bundled ftxui.")
if (NOT TENZIR_ENABLE_BUNDLED_FTXUI)
find_package(ftxui QUIET)
if (ftxui_FOUND)
string(APPEND TENZIR_FIND_DEPENDENCY_LIST "\nfind_package(ftxui REQUIRED)")
dependency_summary("ftxui" ftxui::screen "Dependencies")
endif ()
endif ()
if (NOT ftxui_FOUND)
if (NOT TENZIR_ENABLE_BUNDLED_FTXUI)
message(
STATUS "Cannot find installed ftxui; falling back to bundled version")
endif ()
set(CMAKE_CXX_STANDARD 20)
add_subdirectory(aux/ftxui)
unset(CMAKE_CXX_STANDARD)
dependency_summary("ftxui" "${CMAKE_CURRENT_SOURCE_DIR}/aux/ftxui"
"Dependencies")
endif ()

add_library(libtenzir_tui)

file(GLOB_RECURSE tui_sources CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
target_sources(libtenzir_tui PRIVATE ${tui_sources})

target_include_directories(libtenzir_tui
PUBLIC "${CMAKE_CURRENT_LIST_DIR}/include")

target_link_libraries(
libtenzir_tui PUBLIC tenzir::libtenzir tenzir::internal ftxui::screen
ftxui::dom ftxui::component)
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

#pragma once

#include "explore/ui_state.hpp"
#include "tenzir/tui/ui_state.hpp"

#include <tenzir/fwd.hpp>
#include <tenzir/view.hpp>

#include <ftxui/component/component.hpp>
#include <ftxui/dom/elements.hpp>

namespace tenzir::plugins::explore {
namespace tenzir::tui {

/// Lifts an FTXUI element into a component.
auto lift(ftxui::Element e) -> ftxui::Component;
Expand Down Expand Up @@ -91,4 +91,4 @@ auto Explorer(ui_state* state) -> ftxui::Component;
auto MainWindow(ftxui::ScreenInteractive* screen, ui_state* state)
-> ftxui::Component;

} // namespace tenzir::plugins::explore
} // namespace tenzir::tui
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

#include <ftxui/dom/elements.hpp>

namespace tenzir::plugins::explore {
namespace tenzir::tui {

/// Renders the Tenzir logo.
auto logo() -> ftxui::Element;

} // namespace tenzir::plugins::explore
} // namespace tenzir::tui
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <ftxui/dom/table.hpp>
#include <ftxui/screen/color.hpp>

namespace tenzir::plugins::explore {
namespace tenzir::tui {

/// The theme colors.
/// See https://rosepinetheme.com/palette/ for semantics.
Expand Down Expand Up @@ -63,4 +63,4 @@ struct theme {
/// Constructs the default scheme.
auto default_theme() -> theme;

} // namespace tenzir::plugins::explore
} // namespace tenzir::tui
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#pragma once

#include "explore/theme.hpp"
#include "tenzir/tui/theme.hpp"

#include <tenzir/table_slice.hpp>
#include <tenzir/type.hpp>
Expand All @@ -20,10 +20,7 @@
#include <unordered_map>
#include <vector>

namespace tenzir::plugins::explore {

struct operator_args;
struct printer_args;
namespace tenzir::tui {

struct table_state;
using table_state_ptr = std::shared_ptr<table_state>;
Expand Down Expand Up @@ -53,15 +50,6 @@ struct ui_state {

/// Flag that controls whether to show the column types.
bool hide_types = false;

/// Updates the UI state when a new slice of data arrives.
auto add(table_slice slice) -> void;
};

/// Construct the global UI state from the plugin configuration.
auto make_ui_state(const operator_args& args) -> ui_state;

/// Construct the global UI state from the plugin configuration.
auto make_ui_state(const printer_args& args) -> ui_state;

} // namespace tenzir::plugins::explore
} // namespace tenzir::tui
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
// SPDX-FileCopyrightText: (c) 2023 The TEnzir Contributors
// SPDX-License-Identifier: BSD-3-Clause

#include "explore/components.hpp"
#include "tenzir/tui/components.hpp"

#include "explore/elements.hpp"
#include "explore/ui_state.hpp"
#include "tenzir/tui/elements.hpp"
#include "tenzir/tui/ui_state.hpp"

#include <tenzir/collect.hpp>
#include <tenzir/concept/printable/tenzir/data.hpp>
Expand All @@ -26,7 +26,7 @@

using namespace ftxui;

namespace tenzir::plugins::explore {
namespace tenzir::tui {

auto lift(Element e) -> Component {
class Impl : public ComponentBase {
Expand Down Expand Up @@ -752,4 +752,4 @@ auto MainWindow(ScreenInteractive* screen, ui_state* state) -> Component {
return Make<Impl>(screen, state);
};

} // namespace tenzir::plugins::explore
} // namespace tenzir::tui
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// SPDX-FileCopyrightText: (c) 2023 The Tenzir Contributors
// SPDX-License-Identifier: BSD-3-Clause

#include "explore/elements.hpp"
#include "tenzir/tui/elements.hpp"

#include <tenzir/detail/string.hpp>

namespace tenzir::plugins::explore {
namespace tenzir::tui {

using namespace ftxui;

Expand All @@ -37,4 +37,4 @@ auto logo() -> Element {
return vbox(elements);
}

} // namespace tenzir::plugins::explore
} // namespace tenzir::tui
6 changes: 3 additions & 3 deletions plugins/explore/src/theme.cpp → libtenzir_tui/src/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
// SPDX-FileCopyrightText: (c) 2023 The Tenzir Contributors
// SPDX-License-Identifier: BSD-3-Clause

#include "explore/theme.hpp"
#include "tenzir/tui/theme.hpp"

#include <tenzir/detail/overload.hpp>

#include <ftxui/component/component.hpp>

namespace tenzir::plugins::explore {
namespace tenzir::tui {

using namespace ftxui;
using namespace ftxui::literals;
Expand Down Expand Up @@ -177,4 +177,4 @@ auto default_theme() -> theme {
return {};
}

} // namespace tenzir::plugins::explore
} // namespace tenzir::tui
31 changes: 4 additions & 27 deletions plugins/explore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,8 @@ TenzirRegisterPlugin(
SOURCES ${explore_sources}
INCLUDE_DIRECTORIES include)

option(TENZIR_ENABLE_BUNDLED_FTXUI "Always use the bundled ftxui" OFF)
add_feature_info("TENZIR_ENABLE_BUNDLED_FTXUI" TENZIR_ENABLE_BUNDLED_FTXUI
"always use the bundled ftxui.")
if (NOT TENZIR_ENABLE_BUNDLED_FTXUI)
find_package(ftxui QUIET)
if (ftxui_FOUND)
string(APPEND TENZIR_FIND_DEPENDENCY_LIST
"\nfind_package(ftxui REQUIRED)")
dependency_summary("ftxui" ftxui::screen "Dependencies")
endif ()
endif ()
if (NOT ftxui_FOUND)
if (NOT TENZIR_ENABLE_BUNDLED_FTXUI)
message(
STATUS
"Cannot find installed ftxui; falling back to bundled version")
endif ()
unset(COMPILE_WARNING_AS_ERROR)
set(CMAKE_CXX_STANDARD 20)
add_subdirectory(aux/ftxui)
set(COMPILE_WARNING_AS_ERROR)
unset(CMAKE_CXX_STANDARD)
dependency_summary("ftxui" "${CMAKE_CURRENT_SOURCE_DIR}/aux/ftxui"
"Dependencies")
endif ()
add_subdirectory(../../libtenzir_tui
"${CMAKE_CURRENT_BINARY_DIR}/libtenzir_tui")

target_link_libraries(explore PUBLIC tenzir::libtenzir tenzir::internal)
target_link_libraries(explore PUBLIC ftxui::screen ftxui::dom ftxui::component)
target_link_libraries(explore PUBLIC tenzir::libtenzir tenzir::internal
libtenzir_tui)
38 changes: 0 additions & 38 deletions plugins/explore/include/explore/operator_args.hpp

This file was deleted.

34 changes: 0 additions & 34 deletions plugins/explore/include/explore/printer_args.hpp

This file was deleted.

0 comments on commit 5b8fbb6

Please sign in to comment.