summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--cli/CMakeLists.txt18
-rw-r--r--cli/component.cpp99
-rw-r--r--cli/component.hpp33
-rw-r--r--cli/page.cpp6
-rw-r--r--tests/CMakeLists.txt2
6 files changed, 76 insertions, 84 deletions
diff --git a/README.md b/README.md
index 688a064..4582401 100644
--- a/README.md
+++ b/README.md
@@ -12,7 +12,7 @@ implementation, that exposes the library to a user.
```sh
cmake -B build -G Ninja
-make -C build
+ninja -C build
```
Pass `-DCMAKE_BUILD_TYPE=Debug` or `-DCMAKE_BUILD_TYPE=Release` to
diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt
index 533e2bc..1e7921d 100644
--- a/cli/CMakeLists.txt
+++ b/cli/CMakeLists.txt
@@ -18,14 +18,18 @@ FetchContent_Declare(toml11
)
FetchContent_MakeAvailable(toml11)
-add_executable(katja-cli main.cpp component.hpp component.cpp)
-target_sources(katja-cli PUBLIC FILE_SET all_my_modules TYPE CXX_MODULES FILES page.cpp)
+set(FTXUI_BUILD_MODULES ON)
+
+add_executable(katja-cli main.cpp)
+target_sources(katja-cli PUBLIC FILE_SET all_my_modules TYPE CXX_MODULES FILES
+ component.cpp page.cpp
+)
target_include_directories(katja-cli PRIVATE ${Boost_INCLUDE_DIR})
target_link_libraries(katja-cli
- LINK_PUBLIC katja
- LINK_PRIVATE ftxui::screen
- LINK_PRIVATE ftxui::dom
- LINK_PRIVATE ftxui::component
- LINK_PRIVATE toml11::toml11
+ PUBLIC katja
+ PRIVATE ftxui::screen
+ PRIVATE ftxui::dom
+ PRIVATE ftxui::component
+ PRIVATE toml11::toml11
)
set_target_properties(katja-cli PROPERTIES RUNTIME_OUTPUT_NAME katja)
diff --git a/cli/component.cpp b/cli/component.cpp
index 0419ad4..b33be7a 100644
--- a/cli/component.cpp
+++ b/cli/component.cpp
@@ -3,69 +3,86 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
-#include "component.hpp"
+module;
+#include <optional>
#include <sstream>
-namespace katja
-{
- PackageListBase::PackageListBase(const std::string& title, const std::vector<package_identifier>& packages)
- : title(title), packages(packages)
- {
- }
+#include <ftxui/component/event.hpp>
+#include <ftxui/component/component.hpp>
+#include <ftxui/dom/elements.hpp>
+
+#include "katja/repository.hpp"
+
+export module component;
- ftxui::Element PackageListBase::OnRender()
+export namespace katja
+{
+ class PackageListBase : public ftxui::ComponentBase
{
- std::vector<ftxui::Element> lines;
+ std::string title;
+ const std::vector<package_identifier> packages;
+ std::optional<std::size_t> selected;
- for (const auto& package_identifier : this->packages)
- {
- auto line = ftxui::text(package_identifier.to_string()) | color(ftxui::Color::SkyBlue2);
- lines.push_back(line);
- }
- if (this->selected.has_value() && this->selected.value() < lines.size())
+ public:
+ PackageListBase(const std::string& title, const std::vector<package_identifier>& packages = {})
+ : title(title), packages(packages)
{
- lines[this->selected.value()] |= ftxui::focus;
}
- std::stringstream summary;
-
- summary << title << '(' << packages.size() << ')';
- return ftxui::window(ftxui::text(summary.str()), ftxui::vbox(lines) | ftxui::yframe);
- }
-
- bool PackageListBase::OnEvent(ftxui::Event event)
- {
- if (event == ftxui::Event::ArrowDown)
+ ftxui::Element OnRender() override
{
- if (!this->selected.has_value() && !this->packages.empty())
+ std::vector<ftxui::Element> lines;
+
+ for (const auto& package_identifier : this->packages)
{
- this->selected = std::make_optional<std::size_t>(0);
+ auto line = ftxui::text(package_identifier.to_string()) | color(ftxui::Color::SkyBlue2);
+ lines.push_back(line);
}
- else if (this->selected.has_value() && this->selected.value() + 1 < this->packages.size())
+ if (this->selected.has_value() && this->selected.value() < lines.size())
{
- this->selected = std::make_optional<std::size_t>(this->selected.value() + 1);
+ lines[this->selected.value()] |= ftxui::focus;
}
- return true;
+ std::stringstream summary;
+
+ summary << title << '(' << packages.size() << ')';
+
+ return ftxui::window(ftxui::text(summary.str()), ftxui::vbox(lines) | ftxui::yframe);
}
- else if (event == ftxui::Event::ArrowUp)
+
+ bool OnEvent(ftxui::Event event) override
{
- if (!this->selected.has_value() && !this->packages.empty())
+ if (event == ftxui::Event::ArrowDown)
{
- this->selected = std::make_optional<std::size_t>(0);
+ if (!this->selected.has_value() && !this->packages.empty())
+ {
+ this->selected = std::make_optional<std::size_t>(0);
+ }
+ else if (this->selected.has_value() && this->selected.value() + 1 < this->packages.size())
+ {
+ this->selected = std::make_optional<std::size_t>(this->selected.value() + 1);
+ }
+ return true;
}
- else if (this->selected.has_value()
- && this->selected.value() < this->packages.size()
- && this->selected.value() > 0)
+ else if (event == ftxui::Event::ArrowUp)
{
- this->selected = std::make_optional<std::size_t>(this->selected.value() - 1);
+ if (!this->selected.has_value() && !this->packages.empty())
+ {
+ this->selected = std::make_optional<std::size_t>(0);
+ }
+ else if (this->selected.has_value()
+ && this->selected.value() < this->packages.size()
+ && this->selected.value() > 0)
+ {
+ this->selected = std::make_optional<std::size_t>(this->selected.value() - 1);
+ }
+ return true;
}
- return true;
+ return false;
}
- return false;
- }
+ };
- ftxui::Component PackageList(const std::string& title, const std::vector<package_identifier>& packages)
+ ftxui::Component PackageList(const std::string& title, const std::vector<package_identifier>& packages = {})
{
return ftxui::Make<PackageListBase>(title, packages);
}
diff --git a/cli/component.hpp b/cli/component.hpp
deleted file mode 100644
index a396036..0000000
--- a/cli/component.hpp
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at https://mozilla.org/MPL/2.0/.
- */
-#pragma once
-
-#include <optional>
-
-#include <ftxui/component/event.hpp>
-#include <ftxui/component/component.hpp>
-#include <ftxui/dom/elements.hpp>
-
-#include "katja/repository.hpp"
-
-namespace katja
-{
- class PackageListBase : public ftxui::ComponentBase
- {
- std::string title;
- const std::vector<package_identifier> packages;
- std::optional<std::size_t> selected;
-
- public:
- PackageListBase(const std::string& title, const std::vector<package_identifier>& packages = {});
-
- ftxui::Element OnRender() override;
- bool OnEvent(ftxui::Event event) override;
- };
-
- ftxui::Component PackageList(const std::string& title, const std::vector<package_identifier>& packages = {});
-
-}
diff --git a/cli/page.cpp b/cli/page.cpp
index fe0bd5a..617ee07 100644
--- a/cli/page.cpp
+++ b/cli/page.cpp
@@ -7,10 +7,14 @@ module;
#include <algorithm>
-#include "component.hpp"
+#include <ftxui/component/component.hpp>
+
+#include "katja/repository.hpp"
export module page;
+import component;
+
export namespace katja
{
class PageBase : public ftxui::ComponentBase
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 8276475..3555ece 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -13,7 +13,7 @@ foreach(test_source ${KATJA_TEST_SOURCES})
add_executable(${tester} ${test_source})
target_compile_definitions(${tester} PRIVATE "BOOST_TEST_DYN_LINK=1")
- target_link_libraries(${tester} LINK_PRIVATE katja Boost::unit_test_framework)
+ target_link_libraries(${tester} PRIVATE katja Boost::unit_test_framework)
add_test(NAME ${test_name} COMMAND ${tester})
endforeach()