mirror of
https://github.com/CachyOS/New-Cli-Installer.git
synced 2025-01-23 14:32:22 +08:00
👷 update ui
This commit is contained in:
parent
d0bc5f469a
commit
c36ab03920
@ -71,7 +71,9 @@ target_compile_features(project_options INTERFACE cxx_std_20)
|
||||
## Target
|
||||
##
|
||||
add_executable(${PROJECT_NAME}
|
||||
src/view.hpp
|
||||
src/definitions.hpp
|
||||
src/screen_service.hpp src/screen_service.cpp
|
||||
src/config.cpp src/config.hpp
|
||||
src/utils.cpp src/utils.hpp
|
||||
src/tui.cpp src/tui.hpp
|
||||
@ -90,7 +92,7 @@ enable_sanitizers(project_options)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/src)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE project_warnings project_options fmt::fmt ftxui::screen ftxui::dom ftxui::component nlohmann_json::nlohmann_json cpr::cpr PkgConfig::LIBNM)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE project_warnings project_options fmt::fmt ftxui::screen ftxui::dom ftxui::component nlohmann_json::nlohmann_json cpr::cpr)
|
||||
|
||||
option(ENABLE_UNITY "Enable Unity builds of projects" OFF)
|
||||
if(ENABLE_UNITY)
|
||||
|
@ -39,7 +39,9 @@ cpr = dependency('cpr', version : ['>=1.7.0'], fallback : ['cpr', 'cpr_dep'])
|
||||
libnm = dependency('libnm', version : ['>=1.10.6'])
|
||||
|
||||
src_files = files(
|
||||
'src/view.hpp',
|
||||
'src/definitions.hpp',
|
||||
'src/screen_service.hpp', 'src/screen_service.cpp',
|
||||
'src/config.cpp', 'src/config.hpp',
|
||||
'src/utils.cpp', 'src/utils.hpp',
|
||||
'src/tui.cpp', 'src/tui.hpp',
|
||||
@ -97,7 +99,7 @@ add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language :
|
||||
executable(
|
||||
'cachyos-installer',
|
||||
src_files,
|
||||
dependencies: [fmt, ftxui, nlohmann_json, cpr, libnm],
|
||||
dependencies: [fmt, ftxui, nlohmann_json, cpr],
|
||||
include_directories: [include_directories('src')],
|
||||
install: true)
|
||||
|
||||
|
@ -11,8 +11,8 @@ class Config final {
|
||||
using reference = value_type&;
|
||||
using const_reference = const value_type&;
|
||||
|
||||
Config() = default;
|
||||
virtual ~Config() = default;
|
||||
Config() noexcept = default;
|
||||
virtual ~Config() noexcept = default;
|
||||
|
||||
static bool initialize() noexcept;
|
||||
static Config* instance();
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "config.hpp"
|
||||
#include "definitions.hpp"
|
||||
#include "screen_service.hpp"
|
||||
#include "tui.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
@ -31,5 +32,11 @@ int main() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!tui::screen_service::initialize()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// auto app_router = std::make_shared<router>(tui::screen_service::instance());
|
||||
// app_router->navigate("", std::any());
|
||||
tui::init();
|
||||
}
|
||||
|
22
src/screen_service.cpp
Normal file
22
src/screen_service.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include "screen_service.hpp"
|
||||
#include "definitions.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace tui {
|
||||
static std::unique_ptr<screen_service> s_screen = nullptr;
|
||||
|
||||
bool screen_service::initialize() noexcept {
|
||||
if (s_screen != nullptr) {
|
||||
error("You should only initialize it once!\n");
|
||||
return false;
|
||||
}
|
||||
s_screen = std::make_unique<screen_service>();
|
||||
return s_screen.get();
|
||||
}
|
||||
|
||||
auto screen_service::instance() -> screen_service* {
|
||||
return s_screen.get();
|
||||
}
|
||||
|
||||
} // namespace tui
|
44
src/screen_service.hpp
Normal file
44
src/screen_service.hpp
Normal file
@ -0,0 +1,44 @@
|
||||
// taken from https://github.com/adrianoviana87/ltuiny
|
||||
#ifndef SCREEN_SERVICE_HPP
|
||||
#define SCREEN_SERVICE_HPP
|
||||
|
||||
#include "view.hpp"
|
||||
|
||||
/* clang-format off */
|
||||
#include <memory>
|
||||
#include <ftxui/component/screen_interactive.hpp>
|
||||
/* clang-format on */
|
||||
|
||||
namespace tui {
|
||||
class screen_service final {
|
||||
public:
|
||||
using value_type = ftxui::ScreenInteractive;
|
||||
using reference = value_type&;
|
||||
using const_reference = const value_type&;
|
||||
|
||||
screen_service() noexcept = default;
|
||||
virtual ~screen_service() noexcept = default;
|
||||
|
||||
static bool initialize() noexcept;
|
||||
static screen_service* instance();
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
// Element access.
|
||||
auto data() noexcept -> reference
|
||||
{ return m_screen; }
|
||||
auto data() const noexcept -> const_reference
|
||||
{ return m_screen; }
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
screen_service(const screen_service&) noexcept = delete;
|
||||
screen_service& operator=(const screen_service&) noexcept = delete;
|
||||
|
||||
private:
|
||||
value_type m_screen = ftxui::ScreenInteractive::Fullscreen();
|
||||
// std::shared_ptr<tui::view> m_current_view{};
|
||||
};
|
||||
} // namespace tui
|
||||
|
||||
#endif // SCREEN_SERVICE_HPP
|
@ -1,6 +1,7 @@
|
||||
#include "tui.hpp"
|
||||
#include "config.hpp"
|
||||
#include "definitions.hpp"
|
||||
#include "screen_service.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
/* clang-format off */
|
||||
@ -81,7 +82,7 @@ ftxui::Element multiline_text(const std::vector<std::string>& lines) {
|
||||
|
||||
// Simple code to show devices / partitions.
|
||||
void show_devices() noexcept {
|
||||
auto screen = ScreenInteractive::Fullscreen();
|
||||
auto& screen = tui::screen_service::instance()->data();
|
||||
auto lsblk = utils::exec("lsblk -o NAME,MODEL,TYPE,FSTYPE,SIZE,MOUNTPOINT | grep \"disk\\|part\\|lvm\\|crypt\\|NAME\\|MODEL\\|TYPE\\|FSTYPE\\|SIZE\\|MOUNTPOINT\"");
|
||||
|
||||
/* clang-format off */
|
||||
@ -109,7 +110,7 @@ void select_device() noexcept {
|
||||
auto devices = utils::exec("lsblk -lno NAME,SIZE,TYPE | grep 'disk' | awk '{print \"/dev/\" $1 \" \" $2}' | sort -u");
|
||||
const auto& devices_list = utils::make_multiline(devices);
|
||||
|
||||
auto screen = ScreenInteractive::Fullscreen();
|
||||
auto& screen = tui::screen_service::instance()->data();
|
||||
std::int32_t selected{};
|
||||
auto menu = Menu(&devices_list, &selected);
|
||||
auto content = Renderer(menu, [&] {
|
||||
@ -117,7 +118,7 @@ void select_device() noexcept {
|
||||
});
|
||||
|
||||
auto ok_callback = [&] {
|
||||
auto src = devices_list[selected];
|
||||
auto src = devices_list[static_cast<std::size_t>(selected)];
|
||||
const auto& lines = utils::make_multiline(src, " ");
|
||||
config_data["DEVICE"] = lines[0];
|
||||
};
|
||||
@ -141,7 +142,7 @@ void select_device() noexcept {
|
||||
}
|
||||
|
||||
void init() noexcept {
|
||||
auto screen = ScreenInteractive::Fullscreen();
|
||||
auto& screen = tui::screen_service::instance()->data();
|
||||
auto ok_callback = [=] { info("ok\n"); };
|
||||
auto container = controls_widget({"OK", "Quit"}, {ok_callback, screen.ExitLoopClosure()});
|
||||
|
||||
|
28
src/view.hpp
Normal file
28
src/view.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
// taken from https://github.com/adrianoviana87/ltuiny
|
||||
#ifndef VIEW_HPP
|
||||
#define VIEW_HPP
|
||||
|
||||
/* clang-format off */
|
||||
#include <functional>
|
||||
#include <ftxui/component/component.hpp>
|
||||
/* clang-format on */
|
||||
|
||||
namespace tui {
|
||||
class view : public ftxui::Component {
|
||||
public:
|
||||
view() = default;
|
||||
virtual ~view() = default;
|
||||
|
||||
void initialize() { initialize_ui(); };
|
||||
void set_on_close(std::function<void()>&& val) { on_close = std::move(val); }
|
||||
|
||||
protected:
|
||||
void close() { on_close(); }
|
||||
virtual void initialize_ui() = 0;
|
||||
|
||||
private:
|
||||
std::function<void()> on_close;
|
||||
};
|
||||
} // namespace tui
|
||||
|
||||
#endif // VIEW_HPP
|
Loading…
Reference in New Issue
Block a user