mirror of
https://github.com/CachyOS/New-Cli-Installer.git
synced 2025-01-23 22:42:31 +08:00
👷 update ui
fix build with clang
This commit is contained in:
parent
bbe2b4e641
commit
93c8cfa2a0
@ -39,14 +39,15 @@ FetchContent_Declare(ftxui
|
|||||||
GIT_REPOSITORY "https://github.com/arthursonzogni/ftxui.git"
|
GIT_REPOSITORY "https://github.com/arthursonzogni/ftxui.git"
|
||||||
GIT_TAG "7e5cd23b4c47972b70b99c39617d6e38f05d1b3a"
|
GIT_TAG "7e5cd23b4c47972b70b99c39617d6e38f05d1b3a"
|
||||||
)
|
)
|
||||||
FetchContent_Declare(spdlog
|
|
||||||
GIT_REPOSITORY "https://github.com/gabime/spdlog.git"
|
|
||||||
GIT_TAG "cc30229abb1e22ebe1f8657de4011a53db7bd6ac"
|
|
||||||
)
|
|
||||||
FetchContent_Declare(fmt
|
FetchContent_Declare(fmt
|
||||||
GIT_REPOSITORY "https://github.com/fmtlib/fmt.git"
|
GIT_REPOSITORY "https://github.com/fmtlib/fmt.git"
|
||||||
GIT_TAG "3a951a66cb0fb53ff5a9d5ce9c77e05ef9d382ce"
|
GIT_TAG "3a951a66cb0fb53ff5a9d5ce9c77e05ef9d382ce"
|
||||||
)
|
)
|
||||||
|
FetchContent_MakeAvailable(fmt)
|
||||||
|
FetchContent_Declare(spdlog
|
||||||
|
GIT_REPOSITORY "https://github.com/gabime/spdlog.git"
|
||||||
|
GIT_TAG "cc30229abb1e22ebe1f8657de4011a53db7bd6ac"
|
||||||
|
)
|
||||||
FetchContent_Declare(nlohmann_json
|
FetchContent_Declare(nlohmann_json
|
||||||
GIT_REPOSITORY "https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent.git"
|
GIT_REPOSITORY "https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent.git"
|
||||||
GIT_TAG "v3.10.4"
|
GIT_TAG "v3.10.4"
|
||||||
@ -55,17 +56,22 @@ FetchContent_Declare(cpr
|
|||||||
GIT_REPOSITORY "https://github.com/libcpr/cpr.git"
|
GIT_REPOSITORY "https://github.com/libcpr/cpr.git"
|
||||||
GIT_TAG "beb9e98806bb84bcc130a2cebfbcbbc6ce62b335"
|
GIT_TAG "beb9e98806bb84bcc130a2cebfbcbbc6ce62b335"
|
||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(ftxui spdlog fmt nlohmann_json cpr)
|
FetchContent_MakeAvailable(ftxui spdlog nlohmann_json cpr)
|
||||||
|
if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
|
||||||
|
FetchContent_Declare(range-v3
|
||||||
|
GIT_REPOSITORY "https://github.com/ericniebler/range-v3.git"
|
||||||
|
GIT_TAG "9aa032ccd0eb4bd77f58e5b181168f1038c222c6"
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(range-v3)
|
||||||
|
endif()
|
||||||
|
|
||||||
##
|
##
|
||||||
## CONFIGURATION
|
## CONFIGURATION
|
||||||
##
|
##
|
||||||
option(BUILD_SHARED_LIBS "Enable compilation of shared libraries" OFF)
|
|
||||||
set(SPDLOG_FMT_EXTERNAL ON CACHE INTERNAL "" FORCE)
|
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
|
||||||
|
|
||||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fwhole-program")
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fwhole-program")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Link this 'library' to set the c++ standard / compile-time options requested
|
# Link this 'library' to set the c++ standard / compile-time options requested
|
||||||
@ -109,6 +115,11 @@ include_directories(${CMAKE_SOURCE_DIR}/src)
|
|||||||
target_link_libraries(${PROJECT_NAME} PRIVATE project_warnings project_options spdlog::spdlog fmt::fmt ftxui::screen ftxui::dom ftxui::component nlohmann_json::nlohmann_json cpr::cpr PkgConfig::GLIBMM)
|
target_link_libraries(${PROJECT_NAME} PRIVATE project_warnings project_options spdlog::spdlog fmt::fmt ftxui::screen ftxui::dom ftxui::component nlohmann_json::nlohmann_json cpr::cpr PkgConfig::GLIBMM)
|
||||||
target_link_libraries(test-exec-interactive PRIVATE project_warnings project_options spdlog::spdlog fmt::fmt ftxui::component cpr::cpr PkgConfig::GLIBMM)
|
target_link_libraries(test-exec-interactive PRIVATE project_warnings project_options spdlog::spdlog fmt::fmt ftxui::component cpr::cpr PkgConfig::GLIBMM)
|
||||||
|
|
||||||
|
if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE range-v3::range-v3)
|
||||||
|
target_link_libraries(test-exec-interactive PRIVATE range-v3::range-v3)
|
||||||
|
endif()
|
||||||
|
|
||||||
option(ENABLE_UNITY "Enable Unity builds of projects" OFF)
|
option(ENABLE_UNITY "Enable Unity builds of projects" OFF)
|
||||||
if(ENABLE_UNITY)
|
if(ENABLE_UNITY)
|
||||||
# Add for any project you want to apply unity builds for
|
# Add for any project you want to apply unity builds for
|
||||||
|
@ -14,6 +14,15 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
|||||||
"RelWithDebInfo")
|
"RelWithDebInfo")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
|
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "" FORCE)
|
||||||
|
set(FTXUI_BUILD_DOCS OFF CACHE INTERNAL "" FORCE)
|
||||||
|
set(FTXUI_BUILD_EXAMPLES OFF CACHE INTERNAL "" FORCE)
|
||||||
|
set(FTXUI_ENABLE_INSTALL OFF CACHE INTERNAL "" FORCE)
|
||||||
|
set(SPDLOG_FMT_EXTERNAL ON CACHE INTERNAL "" FORCE)
|
||||||
|
set(SPDLOG_DISABLE_DEFAULT_LOGGER ON CACHE INTERNAL "" FORCE)
|
||||||
|
|
||||||
# Generate compile_commands.json to make it easier to work with clang based tools
|
# Generate compile_commands.json to make it easier to work with clang based tools
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
|
94
src/tui.cpp
94
src/tui.cpp
@ -22,6 +22,17 @@
|
|||||||
using namespace ftxui;
|
using namespace ftxui;
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wold-style-cast"
|
||||||
|
|
||||||
|
#include <range/v3/algorithm/copy.hpp>
|
||||||
|
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
#else
|
||||||
|
namespace ranges = std::ranges;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace tui {
|
namespace tui {
|
||||||
|
|
||||||
// Revised to deal with partion sizes now being displayed to the user
|
// Revised to deal with partion sizes now being displayed to the user
|
||||||
@ -201,6 +212,83 @@ void uefi_bootloader() noexcept {
|
|||||||
screen.Loop(renderer);
|
screen.Loop(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void install_base() noexcept {
|
||||||
|
static constexpr auto base_installed = "/mnt/.base_installed";
|
||||||
|
if (fs::exists(base_installed)) {
|
||||||
|
static constexpr auto content = "\nA CachyOS Base has already been installed on this partition.\nProceed anyway?\n";
|
||||||
|
const auto& do_reinstall = detail::yesno_widget(content, size(HEIGHT, LESS_THAN, 15) | size(WIDTH, LESS_THAN, 75));
|
||||||
|
/* clang-format off */
|
||||||
|
if (!do_reinstall) { return; }
|
||||||
|
/* clang-format on */
|
||||||
|
fs::remove(base_installed);
|
||||||
|
}
|
||||||
|
// Prep variables
|
||||||
|
auto* config_instance = Config::instance();
|
||||||
|
auto& config_data = config_instance->data();
|
||||||
|
const auto& mountpoint = std::get<std::string>(config_data["MOUNTPOINT"]);
|
||||||
|
const std::vector<std::string> available_kernels{"linux-cachyos", "linux", "linux-zen", "linux-lts", "linux-cachyos-cacule", "linux-cachyos-cacule-rdb", "linux-cachyos-bmq", "linux-cachyos-pds", "linux-cachyos-baby", "linux-cachyos-cacule-lts"};
|
||||||
|
|
||||||
|
// Create the base list of packages
|
||||||
|
std::vector<std::string> install_packages{};
|
||||||
|
|
||||||
|
std::unique_ptr<bool[]> kernels_state{new bool[available_kernels.size()]{false}};
|
||||||
|
|
||||||
|
auto kernels = Container::Vertical(detail::from_vector_checklist(available_kernels, kernels_state.get()));
|
||||||
|
|
||||||
|
auto screen = ScreenInteractive::Fullscreen();
|
||||||
|
auto content = Renderer(kernels, [&] {
|
||||||
|
return kernels->Render() | center | size(HEIGHT, GREATER_THAN, 10) | size(WIDTH, GREATER_THAN, 40) | vscroll_indicator;
|
||||||
|
});
|
||||||
|
|
||||||
|
auto ok_callback = [&] {
|
||||||
|
const auto& packages = detail::from_checklist_string(available_kernels, kernels_state.get());
|
||||||
|
auto ret_status = utils::exec(fmt::format("grep \"linux\" {}", packages), true);
|
||||||
|
if (ret_status == "0") {
|
||||||
|
// Check if a kernel is already installed
|
||||||
|
ret_status = utils::exec(fmt::format("ls {}/boot/*.img >/dev/null 2>&1", mountpoint), true);
|
||||||
|
if (ret_status != "0") {
|
||||||
|
static constexpr auto ErrNoKernel = "\nAt least one kernel must be selected.\n";
|
||||||
|
detail::msgbox_widget(ErrNoKernel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto& cmd = utils::exec(fmt::format("ls {}/boot/*.img | cut -d'-' -f2 | grep -v ucode.img | sort -u", mountpoint));
|
||||||
|
detail::msgbox_widget(fmt::format("\nlinux-{} detected\n", cmd));
|
||||||
|
std::raise(SIGINT);
|
||||||
|
}
|
||||||
|
std::raise(SIGINT);
|
||||||
|
};
|
||||||
|
|
||||||
|
ButtonOption button_option{.border = false};
|
||||||
|
auto controls_container = detail::controls_widget({"OK", "Cancel"}, {ok_callback, screen.ExitLoopClosure()}, &button_option);
|
||||||
|
|
||||||
|
auto controls = Renderer(controls_container, [&] {
|
||||||
|
return controls_container->Render() | hcenter | size(HEIGHT, LESS_THAN, 3) | size(WIDTH, GREATER_THAN, 25);
|
||||||
|
});
|
||||||
|
|
||||||
|
static constexpr auto InstStandBseBody = "\nThe base package group will be installed automatically.\nThe base-devel package group is required to use the Arch User Repository (AUR).\n";
|
||||||
|
static constexpr auto UseSpaceBar = "Use [Spacebar] to de/select options listed.";
|
||||||
|
const auto& kernels_options_body = fmt::format("\n{}{}\n", InstStandBseBody, UseSpaceBar);
|
||||||
|
auto global = Container::Vertical({
|
||||||
|
Renderer([&] { return detail::multiline_text(utils::make_multiline(kernels_options_body)); }),
|
||||||
|
Renderer([] { return separator(); }),
|
||||||
|
content,
|
||||||
|
Renderer([] { return separator(); }),
|
||||||
|
controls,
|
||||||
|
});
|
||||||
|
|
||||||
|
auto renderer = Renderer(global, [&] {
|
||||||
|
const auto& title = "New CLI Installer | Install Base";
|
||||||
|
return detail::centered_interative_multi(title, global);
|
||||||
|
});
|
||||||
|
|
||||||
|
screen.Loop(renderer);
|
||||||
|
|
||||||
|
//filter_packages
|
||||||
|
//utils::exec(fmt::format("pacstrap ${MOUNTPOINT} $(cat /mnt/.base) |& tee /tmp/pacstrap.log"));
|
||||||
|
|
||||||
|
//std::ofstream(base_installed);
|
||||||
|
}
|
||||||
|
|
||||||
void bios_bootloader() { }
|
void bios_bootloader() { }
|
||||||
|
|
||||||
void install_bootloader() {
|
void install_bootloader() {
|
||||||
@ -614,7 +702,7 @@ void make_swap() noexcept {
|
|||||||
}
|
}
|
||||||
const auto& partitions = std::get<std::vector<std::string>>(config_data["PARTITIONS"]);
|
const auto& partitions = std::get<std::vector<std::string>>(config_data["PARTITIONS"]);
|
||||||
temp.reserve(partitions.size());
|
temp.reserve(partitions.size());
|
||||||
std::ranges::copy(partitions, std::back_inserter(temp));
|
ranges::copy(partitions, std::back_inserter(temp));
|
||||||
|
|
||||||
std::int32_t selected{};
|
std::int32_t selected{};
|
||||||
bool success{};
|
bool success{};
|
||||||
@ -954,7 +1042,7 @@ void mount_partitions() noexcept {
|
|||||||
const auto& partitions = std::get<std::vector<std::string>>(config_data["PARTITIONS"]);
|
const auto& partitions = std::get<std::vector<std::string>>(config_data["PARTITIONS"]);
|
||||||
std::vector<std::string> temp{"Done -"};
|
std::vector<std::string> temp{"Done -"};
|
||||||
temp.reserve(partitions.size());
|
temp.reserve(partitions.size());
|
||||||
std::ranges::copy(partitions, std::back_inserter(temp));
|
ranges::copy(partitions, std::back_inserter(temp));
|
||||||
|
|
||||||
auto ok_callback = [&] {
|
auto ok_callback = [&] {
|
||||||
auto src = temp[static_cast<std::size_t>(selected)];
|
auto src = temp[static_cast<std::size_t>(selected)];
|
||||||
@ -1083,7 +1171,7 @@ void create_partitions() noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void install_desktop_system_menu() { }
|
void install_desktop_system_menu() { }
|
||||||
void install_core_menu() { }
|
void install_core_menu() { install_base(); }
|
||||||
void install_custom_menu() { }
|
void install_custom_menu() { }
|
||||||
void system_rescue_menu() {
|
void system_rescue_menu() {
|
||||||
std::vector<std::string> menu_entries = {
|
std::vector<std::string> menu_entries = {
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
#include <cstdlib> // for exit, WIFEXITED, WIFSIGNALED
|
#include <cstdlib> // for exit, WIFEXITED, WIFSIGNALED
|
||||||
#include <filesystem> // for exists, is_directory
|
#include <filesystem> // for exists, is_directory
|
||||||
#include <iostream> // for basic_istream, cin
|
#include <iostream> // for basic_istream, cin
|
||||||
#include <ranges> // for std::views::join
|
|
||||||
#include <regex> // for regex_search, match_results<>::_Base_type
|
#include <regex> // for regex_search, match_results<>::_Base_type
|
||||||
#include <string> // for operator==, string, basic_string, allocator
|
#include <string> // for operator==, string, basic_string, allocator
|
||||||
#include <sys/mount.h> // for mount
|
#include <sys/mount.h> // for mount
|
||||||
@ -21,6 +20,23 @@
|
|||||||
#include <unistd.h> // for execvp, fork
|
#include <unistd.h> // for execvp, fork
|
||||||
#include <unordered_map> // for unordered_map
|
#include <unordered_map> // for unordered_map
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wold-style-cast"
|
||||||
|
|
||||||
|
#include <range/v3/algorithm/for_each.hpp>
|
||||||
|
#include <range/v3/algorithm/reverse.hpp>
|
||||||
|
#include <range/v3/core.hpp>
|
||||||
|
#include <range/v3/view/filter.hpp>
|
||||||
|
#include <range/v3/view/split.hpp>
|
||||||
|
#include <range/v3/view/transform.hpp>
|
||||||
|
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
#else
|
||||||
|
#include <ranges>
|
||||||
|
namespace ranges = std::ranges;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef NDEVENV
|
#ifdef NDEVENV
|
||||||
#include <cpr/api.h>
|
#include <cpr/api.h>
|
||||||
#include <cpr/response.h>
|
#include <cpr/response.h>
|
||||||
@ -130,32 +146,38 @@ bool prompt_char(const char* prompt, const char* color, char* read) noexcept {
|
|||||||
|
|
||||||
auto make_multiline(const std::string_view& str, bool reverse, const std::string_view&& delim) noexcept -> std::vector<std::string> {
|
auto make_multiline(const std::string_view& str, bool reverse, const std::string_view&& delim) noexcept -> std::vector<std::string> {
|
||||||
static constexpr auto functor = [](auto&& rng) {
|
static constexpr auto functor = [](auto&& rng) {
|
||||||
return std::string_view(&*rng.begin(), static_cast<size_t>(std::ranges::distance(rng)));
|
return std::string_view(&*rng.begin(), static_cast<size_t>(ranges::distance(rng)));
|
||||||
};
|
};
|
||||||
static constexpr auto second = [](auto&& rng) { return rng != ""; };
|
static constexpr auto second = [](auto&& rng) { return rng != ""; };
|
||||||
|
|
||||||
const auto& view = str
|
#if defined(__clang__)
|
||||||
| std::views::split(delim)
|
const auto& splitted_view = str
|
||||||
| std::views::transform(functor);
|
| ranges::views::split(delim);
|
||||||
|
const auto& view_res = splitted_view
|
||||||
|
| ranges::views::transform(functor);
|
||||||
|
#else
|
||||||
|
const auto& view_res = str
|
||||||
|
| ranges::views::split(delim)
|
||||||
|
| ranges::views::transform(functor);
|
||||||
|
#endif
|
||||||
|
|
||||||
std::vector<std::string> lines{};
|
std::vector<std::string> lines{};
|
||||||
std::ranges::for_each(view | std::views::filter(second), [&](auto&& rng) { lines.emplace_back(rng); });
|
ranges::for_each(view_res | ranges::views::filter(second), [&](auto&& rng) { lines.emplace_back(rng); });
|
||||||
if (reverse) {
|
if (reverse) {
|
||||||
std::ranges::reverse(lines);
|
ranges::reverse(lines);
|
||||||
}
|
}
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto make_multiline(std::vector<std::string>& multiline, bool reverse, const std::string_view&& delim) noexcept -> std::string {
|
auto make_multiline(std::vector<std::string>& multiline, bool reverse, const std::string_view&& delim) noexcept -> std::string {
|
||||||
std::string res{};
|
std::string res{};
|
||||||
// for (const char c : multiline | std::views::join) res += c;
|
|
||||||
for (const auto& line : multiline) {
|
for (const auto& line : multiline) {
|
||||||
res += line;
|
res += line;
|
||||||
res += delim.data();
|
res += delim.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reverse) {
|
if (reverse) {
|
||||||
std::ranges::reverse(res);
|
ranges::reverse(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
Loading…
Reference in New Issue
Block a user