mirror of
https://github.com/CachyOS/New-Cli-Installer.git
synced 2025-01-23 22:42:31 +08:00
👷 update ui
refactor code
This commit is contained in:
parent
1fda6ae4a9
commit
bb77f2bbc1
@ -12,10 +12,15 @@ bool Config::initialize() noexcept {
|
||||
}
|
||||
s_config = std::make_unique<Config>();
|
||||
if (s_config) {
|
||||
s_config->m_data["H_INIT"] = "openrc";
|
||||
s_config->m_data["SYSTEM"] = "BIOS";
|
||||
s_config->m_data["KEYMAP"] = "us";
|
||||
s_config->m_data["XKBMAP"] = "us";
|
||||
s_config->m_data["H_INIT"] = "openrc";
|
||||
s_config->m_data["SYSTEM"] = "BIOS";
|
||||
s_config->m_data["KEYMAP"] = "us";
|
||||
s_config->m_data["XKBMAP"] = "us";
|
||||
|
||||
// file systems
|
||||
s_config->m_data["LVM_SEP_BOOT"] = 0;
|
||||
|
||||
// Mounting
|
||||
s_config->m_data["MOUNTPOINT"] = "/mnt";
|
||||
}
|
||||
|
||||
|
100
src/tui.cpp
100
src/tui.cpp
@ -32,18 +32,21 @@ bool confirm_mount([[maybe_unused]] const std::string_view& part_user) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
// auto* config_instance = Config::instance();
|
||||
// auto& config_data = config_instance->data();
|
||||
// const auto& partition = std::get<std::string>(config_data["PARTITION"]);
|
||||
// auto& partitions = std::get<std::vector<std::string>>(config_data["PARTITIONS"]);
|
||||
auto* config_instance = Config::instance();
|
||||
auto& config_data = config_instance->data();
|
||||
const auto& partition = std::get<std::string>(config_data["PARTITION"]);
|
||||
auto& partitions = std::get<std::vector<std::string>>(config_data["PARTITIONS"]);
|
||||
auto& number_partitions = std::get<std::int32_t>(config_data["NUMBER_PARTITIONS"]);
|
||||
|
||||
detail::infobox_widget("\nMount Successful!\n");
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
|
||||
// const auto& temp = utils::exec(fmt::format("echo {0} | sed \"s~{1} [0-9]*[G-M]~~\" | sed \"s~{1} [0-9]*\\.[0-9]*[G-M]~~\" | sed s~{1}$\' -\'~~", partitions, partition));
|
||||
// spdlog::info("human-info-about-partitions: {}", temp);
|
||||
// PARTITIONS=$()
|
||||
// NUMBER_PARTITIONS=$(( NUMBER_PARTITIONS - 1 ))
|
||||
// TODO: reimplement natively
|
||||
const auto& str = utils::make_multiline(partitions);
|
||||
const auto& cmd = fmt::format("echo \"{0}\" | sed \"s~{1} [0-9]*[G-M]~~\" | sed \"s~{1} [0-9]*\\.[0-9]*[G-M]~~\" | sed \"s~{1}$\' -\'~~\"", str, partition);
|
||||
const auto& res_text = utils::exec(cmd);
|
||||
partitions = utils::make_multiline(res_text);
|
||||
number_partitions -= 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -475,7 +478,7 @@ void mount_partitions() noexcept {
|
||||
// check to see if we already have a zfs root mounted
|
||||
const auto& mountpoint_info = std::get<std::string>(config_data["MOUNTPOINT"]);
|
||||
if (utils::exec(fmt::format("findmnt -ln -o FSTYPE \"{}\"", mountpoint_info)) == "zfs") {
|
||||
// DIALOG " $_PrepMntPart " --infobox "\n$_zfsFoundRoot\n " 0 0
|
||||
detail::infobox_widget("\nUsing ZFS root on \'/\'\n");
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
} else {
|
||||
// Identify and mount root
|
||||
@ -549,45 +552,58 @@ void mount_partitions() noexcept {
|
||||
done*/
|
||||
|
||||
// All other partitions
|
||||
/*while [[ $NUMBER_PARTITIONS > 0 ]]; do
|
||||
DIALOG " $_PrepMntPart " --menu "\n$_ExtPartBody\n " 0 0 12 "$_Done" $"-" ${PARTITIONS} 2>${ANSWER} || return 0
|
||||
PARTITION=$(cat ${ANSWER})
|
||||
const auto& number_partitions = std::get<std::int32_t>(config_data["NUMBER_PARTITIONS"]);
|
||||
const auto& system_info = std::get<std::string>(config_data["SYSTEM"]);
|
||||
while (number_partitions > 0) {
|
||||
// DIALOG " $_PrepMntPart " --menu "\n$_ExtPartBody\n " 0 0 12 "$_Done" $"-" ${PARTITIONS} 2>${ANSWER} || return 0
|
||||
// PARTITION=$(cat ${ANSWER})
|
||||
|
||||
if [[ $PARTITION == $_Done ]]; then
|
||||
make_esp
|
||||
get_cryptroot
|
||||
get_cryptboot
|
||||
echo "$LUKS_DEV" > /tmp/.luks_dev
|
||||
return 0;
|
||||
else
|
||||
MOUNT=""
|
||||
select_filesystem
|
||||
// if [[ $PARTITION == $_Done ]]; then
|
||||
// make_esp
|
||||
// get_cryptroot
|
||||
// get_cryptboot
|
||||
// echo "$LUKS_DEV" > /tmp/.luks_dev
|
||||
// return 0;
|
||||
// else
|
||||
config_data["MOUNT"] = "";
|
||||
tui::select_filesystem();
|
||||
|
||||
# Ask user for mountpoint. Don't give /boot as an example for UEFI systems!
|
||||
[[ $SYSTEM == "UEFI" ]] && MNT_EXAMPLES="/home\n/var" || MNT_EXAMPLES="/boot\n/home\n/var"
|
||||
/* clang-format off */
|
||||
// Ask user for mountpoint. Don't give /boot as an example for UEFI systems!
|
||||
std::string_view mnt_examples = "/boot\n/home\n/var";
|
||||
if (system_info == "UEFI") { mnt_examples = "/home\n/var"; }
|
||||
/* clang-format on */
|
||||
// DIALOG " $_PrepMntPart $PARTITION " --inputbox "\n$_ExtPartBody1$MNT_EXAMPLES\n " 0 0 "/" 2>${ANSWER} || return 0
|
||||
// MOUNT=$(cat ${ANSWER})
|
||||
auto& mount_dev = std::get<std::string>(config_data["MOUNT"]);
|
||||
|
||||
// loop while the mountpoint specified is incorrect (is only '/', is blank, or has spaces).
|
||||
/*while [[ ${MOUNT:0:1} != "/" ]] || [[ ${#MOUNT} -le 1 ]] || [[ $MOUNT =~ \ |\' ]]; do
|
||||
// Warn user about naming convention
|
||||
DIALOG " $_ErrTitle " --msgbox "\n$_ExtErrBody\n " 0 0
|
||||
// Ask user for mountpoint again
|
||||
DIALOG " $_PrepMntPart $PARTITON " --inputbox "\n$_ExtPartBody1$MNT_EXAMPLES\n " 0 0 "/" 2>${ANSWER} || return 0
|
||||
MOUNT=$(cat ${ANSWER})
|
||||
done*/
|
||||
|
||||
# loop while the mountpoint specified is incorrect (is only '/', is blank, or has spaces).
|
||||
while [[ ${MOUNT:0:1} != "/" ]] || [[ ${#MOUNT} -le 1 ]] || [[ $MOUNT =~ \ |\' ]]; do
|
||||
# Warn user about naming convention
|
||||
DIALOG " $_ErrTitle " --msgbox "\n$_ExtErrBody\n " 0 0
|
||||
# Ask user for mountpoint again
|
||||
DIALOG " $_PrepMntPart $PARTITON " --inputbox "\n$_ExtPartBody1$MNT_EXAMPLES\n " 0 0 "/" 2>${ANSWER} || return 0
|
||||
MOUNT=$(cat ${ANSWER})
|
||||
done
|
||||
// Create directory and mount.
|
||||
tui::mount_current_partition();
|
||||
// delete_partition_in_list "$PARTITION"
|
||||
|
||||
# Create directory and mount.
|
||||
mount_current_partition
|
||||
delete_partition_in_list "$PARTITION"
|
||||
|
||||
# Determine if a seperate /boot is used. 0 = no seperate boot, 1 = seperate non-lvm boot,
|
||||
# 2 = seperate lvm boot. For Grub configuration
|
||||
if [[ $MOUNT == "/boot" ]]; then
|
||||
[[ $(lsblk -lno TYPE ${PARTITION} | grep "lvm") != "" ]] && LVM_SEP_BOOT=2 || LVM_SEP_BOOT=1
|
||||
fi
|
||||
fi
|
||||
done*/
|
||||
// Determine if a seperate /boot is used.
|
||||
// 0 = no seperate boot,
|
||||
// 1 = seperate non-lvm boot,
|
||||
// 2 = seperate lvm boot. For Grub configuration
|
||||
if (mount_dev == "/boot") {
|
||||
const auto& cmd = fmt::format("lsblk -lno TYPE {} | grep \"lvm\"", std::get<std::string>(config_data["PARTITION"]));
|
||||
const auto& cmd_out = utils::exec(cmd);
|
||||
config_data["LVM_SEP_BOOT"] = 1;
|
||||
if (!cmd_out.empty()) {
|
||||
config_data["LVM_SEP_BOOT"] = 2;
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
void create_partitions() noexcept {
|
||||
|
@ -127,16 +127,18 @@ bool prompt_char(const char* prompt, const char* color, char* read) noexcept {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto make_multiline(std::string& 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) {
|
||||
return std::string_view(&*rng.begin(), static_cast<size_t>(std::ranges::distance(rng)));
|
||||
};
|
||||
static constexpr auto second = [](auto&& rng) { return rng != ""; };
|
||||
|
||||
const auto& view = str
|
||||
| std::views::split(delim)
|
||||
| std::views::transform([](auto&& rng) {
|
||||
const auto& tmp = std::string(&*rng.begin(), static_cast<size_t>(std::ranges::distance(rng)));
|
||||
return tmp;
|
||||
});
|
||||
| std::views::transform(functor);
|
||||
|
||||
std::vector<std::string> lines{};
|
||||
std::ranges::copy(view, std::back_inserter(lines));
|
||||
std::ranges::for_each(view | std::views::filter(second), [&](auto&& rng) { lines.emplace_back(rng); });
|
||||
if (reverse) {
|
||||
std::ranges::reverse(lines);
|
||||
}
|
||||
@ -152,7 +154,7 @@ auto make_multiline(std::vector<std::string>& multiline, bool reverse, const std
|
||||
}
|
||||
|
||||
if (reverse) {
|
||||
std::ranges::reverse(res.begin(), res.end());
|
||||
std::ranges::reverse(res);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
@ -13,7 +13,7 @@ void print_banner() noexcept;
|
||||
[[nodiscard]] bool is_connected() noexcept;
|
||||
bool prompt_char(const char* prompt, const char* color = RESET, char* read = nullptr) noexcept;
|
||||
void clear_screen() noexcept;
|
||||
[[nodiscard]] auto make_multiline(std::string& str, bool reverse = false, const std::string_view&& delim = "\n") noexcept -> std::vector<std::string>;
|
||||
[[nodiscard]] auto make_multiline(const std::string_view& str, bool reverse = false, const std::string_view&& delim = "\n") noexcept -> std::vector<std::string>;
|
||||
[[nodiscard]] auto make_multiline(std::vector<std::string>& multiline, bool reverse = false, const std::string_view&& delim = "\n") noexcept -> std::string;
|
||||
void secure_wipe() noexcept;
|
||||
[[nodiscard]] bool check_mount() noexcept;
|
||||
|
Loading…
Reference in New Issue
Block a user