mirror of
https://github.com/CachyOS/New-Cli-Installer.git
synced 2025-02-02 22:07:13 +08:00
👷 enable devenv by default
Add `centered_widget` element which allows to place any widget in the center
This commit is contained in:
parent
afff098c23
commit
279b6539b7
@ -44,3 +44,9 @@ endif()
|
|||||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
add_definitions(-D_GLIBCXX_ASSERTIONS)
|
add_definitions(-D_GLIBCXX_ASSERTIONS)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Enables dev environment.
|
||||||
|
option(ENABLE_DEVENV "Enable dev environment" ON)
|
||||||
|
if(NOT ENABLE_DEVENV)
|
||||||
|
add_definitions(-DNDEVENV)
|
||||||
|
endif()
|
||||||
|
19
meson.build
19
meson.build
@ -9,6 +9,7 @@ project('cachyos-installer', 'cpp',
|
|||||||
'b_ndebug=if-release'])
|
'b_ndebug=if-release'])
|
||||||
|
|
||||||
is_debug_build = get_option('buildtype').startswith('debug')
|
is_debug_build = get_option('buildtype').startswith('debug')
|
||||||
|
is_dev_environment = get_option('devenv')
|
||||||
cc = meson.get_compiler('cpp')
|
cc = meson.get_compiler('cpp')
|
||||||
if cc.get_id() == 'clang'
|
if cc.get_id() == 'clang'
|
||||||
specific_cc_flags = [
|
specific_cc_flags = [
|
||||||
@ -22,6 +23,14 @@ if cc.get_id() == 'clang'
|
|||||||
add_global_link_arguments(cc.get_supported_link_arguments(specific_link_flags), language : 'cpp')
|
add_global_link_arguments(cc.get_supported_link_arguments(specific_link_flags), language : 'cpp')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if is_debug_build
|
||||||
|
add_global_arguments('-D_GLIBCXX_ASSERTIONS', language : 'cpp')
|
||||||
|
endif
|
||||||
|
|
||||||
|
if not is_dev_environment
|
||||||
|
add_global_arguments('-DNDEVENV', language : 'cpp')
|
||||||
|
endif
|
||||||
|
|
||||||
# Common dependencies
|
# Common dependencies
|
||||||
fmt = dependency('fmt', version : ['>=8.0.0'], fallback : ['fmt', 'fmt_dep'])
|
fmt = dependency('fmt', version : ['>=8.0.0'], fallback : ['fmt', 'fmt_dep'])
|
||||||
ftxui = dependency('ftxui', modules : ['ftxui::screen', 'ftxui::dom', 'ftxui::component'], fallback : ['ftxui', 'ftxui_dep'])
|
ftxui = dependency('ftxui', modules : ['ftxui::screen', 'ftxui::dom', 'ftxui::component'], fallback : ['ftxui', 'ftxui_dep'])
|
||||||
@ -66,11 +75,7 @@ if cc.get_id() == 'gcc'
|
|||||||
]
|
]
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if is_debug_build
|
if not is_debug_build
|
||||||
possible_cc_flags += [
|
|
||||||
'-D_GLIBCXX_ASSERTIONS',
|
|
||||||
]
|
|
||||||
else
|
|
||||||
if cc.get_id() == 'gcc'
|
if cc.get_id() == 'gcc'
|
||||||
possible_cc_flags += [
|
possible_cc_flags += [
|
||||||
'-flto',
|
'-flto',
|
||||||
@ -81,6 +86,10 @@ else
|
|||||||
'-flto=thin',
|
'-flto=thin',
|
||||||
]
|
]
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
possible_cc_flags += ['-fdata-sections', '-ffunction-sections']
|
||||||
|
possible_link_flags = ['-Wl,--gc-sections']
|
||||||
|
add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language : 'cpp')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language : 'cpp')
|
add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language : 'cpp')
|
||||||
|
1
meson_options.txt
Normal file
1
meson_options.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
option('devenv', type: 'boolean', value: true, description: 'enable dev environment')
|
@ -14,13 +14,11 @@ int main() {
|
|||||||
utils::exec("setterm -blank 0 -powersave off");
|
utils::exec("setterm -blank 0 -powersave off");
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NDEBUG
|
|
||||||
if (!utils::check_root()) {
|
if (!utils::check_root()) {
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||||
utils::clear_screen();
|
utils::clear_screen();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!Config::initialize()) {
|
if (!Config::initialize()) {
|
||||||
return 1;
|
return 1;
|
||||||
|
37
src/tui.cpp
37
src/tui.cpp
@ -11,6 +11,26 @@
|
|||||||
using namespace ftxui;
|
using namespace ftxui;
|
||||||
|
|
||||||
namespace tui {
|
namespace tui {
|
||||||
|
|
||||||
|
ftxui::Element centered_widget(ftxui::Component& container, const std::string_view& title, const ftxui::Element& widget) {
|
||||||
|
return vbox({
|
||||||
|
// -------- Title --------------
|
||||||
|
text(title.data()) | bold,
|
||||||
|
filler(),
|
||||||
|
// -------- Center Menu --------------
|
||||||
|
hbox({
|
||||||
|
filler(),
|
||||||
|
border(vbox({
|
||||||
|
widget,
|
||||||
|
separator(),
|
||||||
|
container->Render() | hcenter | size(HEIGHT, LESS_THAN, 3) | size(WIDTH, GREATER_THAN, 25),
|
||||||
|
})),
|
||||||
|
filler(),
|
||||||
|
}) | center,
|
||||||
|
filler(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void init() noexcept {
|
void init() noexcept {
|
||||||
auto screen = ScreenInteractive::Fullscreen();
|
auto screen = ScreenInteractive::Fullscreen();
|
||||||
|
|
||||||
@ -28,22 +48,7 @@ void init() noexcept {
|
|||||||
});
|
});
|
||||||
|
|
||||||
auto renderer = Renderer(container, [&] {
|
auto renderer = Renderer(container, [&] {
|
||||||
return vbox({
|
return tui::centered_widget(container, "New CLI Installer", text("TODO!!") | size(HEIGHT, GREATER_THAN, 5));
|
||||||
// -------- Title --------------
|
|
||||||
text("New CLI Installer") | bold,
|
|
||||||
filler(),
|
|
||||||
// -------- Center Menu --------------
|
|
||||||
hbox({
|
|
||||||
filler(),
|
|
||||||
border(vbox({
|
|
||||||
text("TODO!!") | size(HEIGHT, GREATER_THAN, 5),
|
|
||||||
separator(),
|
|
||||||
container->Render() | hcenter | size(HEIGHT, LESS_THAN, 3) | size(WIDTH, GREATER_THAN, 25),
|
|
||||||
})),
|
|
||||||
filler(),
|
|
||||||
}) | center,
|
|
||||||
filler(),
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
screen.Loop(renderer);
|
screen.Loop(renderer);
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
#ifndef TUI_HPP
|
#ifndef TUI_HPP
|
||||||
#define TUI_HPP
|
#define TUI_HPP
|
||||||
|
|
||||||
|
#include <ftxui/component/component.hpp>
|
||||||
|
|
||||||
namespace tui {
|
namespace tui {
|
||||||
|
ftxui::Element centered_widget(ftxui::Component& container, const std::string_view& title, const ftxui::Element& widget);
|
||||||
void init() noexcept;
|
void init() noexcept;
|
||||||
} // namespace tui
|
} // namespace tui
|
||||||
|
|
||||||
|
@ -20,17 +20,23 @@ namespace utils {
|
|||||||
static constexpr std::int32_t CONNECTION_TIMEOUT = 15;
|
static constexpr std::int32_t CONNECTION_TIMEOUT = 15;
|
||||||
|
|
||||||
bool is_connected() noexcept {
|
bool is_connected() noexcept {
|
||||||
|
#ifdef NDEVENV
|
||||||
/* clang-format off */
|
/* clang-format off */
|
||||||
auto r = cpr::Get(cpr::Url{"https://www.google.com"},
|
auto r = cpr::Get(cpr::Url{"https://www.google.com"},
|
||||||
cpr::Timeout{1000});
|
cpr::Timeout{1000});
|
||||||
|
|
||||||
info("{}\n", r.status_code);
|
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
return cpr::status::is_success(static_cast<std::int32_t>(r.status_code)) || cpr::status::is_redirect(static_cast<std::int32_t>(r.status_code));
|
return cpr::status::is_success(static_cast<std::int32_t>(r.status_code)) || cpr::status::is_redirect(static_cast<std::int32_t>(r.status_code));
|
||||||
|
#else
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool check_root() noexcept {
|
bool check_root() noexcept {
|
||||||
|
#ifdef NDEVENV
|
||||||
return (utils::exec("whoami") == "root\n");
|
return (utils::exec("whoami") == "root\n");
|
||||||
|
#else
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear_screen() noexcept {
|
void clear_screen() noexcept {
|
||||||
|
Loading…
Reference in New Issue
Block a user