👷 enable devenv by default

Add `centered_widget` element which allows to place any widget in the
center
This commit is contained in:
Vladislav Nepogodin 2021-12-02 00:03:46 +04:00
parent afff098c23
commit 279b6539b7
No known key found for this signature in database
GPG Key ID: B62C3D10C54D5DA9
7 changed files with 53 additions and 25 deletions

View File

@ -44,3 +44,9 @@ endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-D_GLIBCXX_ASSERTIONS)
endif()
# Enables dev environment.
option(ENABLE_DEVENV "Enable dev environment" ON)
if(NOT ENABLE_DEVENV)
add_definitions(-DNDEVENV)
endif()

View File

@ -9,6 +9,7 @@ project('cachyos-installer', 'cpp',
'b_ndebug=if-release'])
is_debug_build = get_option('buildtype').startswith('debug')
is_dev_environment = get_option('devenv')
cc = meson.get_compiler('cpp')
if cc.get_id() == 'clang'
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')
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
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'])
@ -66,11 +75,7 @@ if cc.get_id() == 'gcc'
]
endif
if is_debug_build
possible_cc_flags += [
'-D_GLIBCXX_ASSERTIONS',
]
else
if not is_debug_build
if cc.get_id() == 'gcc'
possible_cc_flags += [
'-flto',
@ -81,6 +86,10 @@ else
'-flto=thin',
]
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
add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language : 'cpp')

1
meson_options.txt Normal file
View File

@ -0,0 +1 @@
option('devenv', type: 'boolean', value: true, description: 'enable dev environment')

View File

@ -14,13 +14,11 @@ int main() {
utils::exec("setterm -blank 0 -powersave off");
}
#ifdef NDEBUG
if (!utils::check_root()) {
std::this_thread::sleep_for(std::chrono::seconds(3));
utils::clear_screen();
return 1;
}
#endif
if (!Config::initialize()) {
return 1;

View File

@ -11,6 +11,26 @@
using namespace ftxui;
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 {
auto screen = ScreenInteractive::Fullscreen();
@ -28,22 +48,7 @@ void init() noexcept {
});
auto renderer = Renderer(container, [&] {
return vbox({
// -------- 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(),
});
return tui::centered_widget(container, "New CLI Installer", text("TODO!!") | size(HEIGHT, GREATER_THAN, 5));
});
screen.Loop(renderer);

View File

@ -1,7 +1,10 @@
#ifndef TUI_HPP
#define TUI_HPP
#include <ftxui/component/component.hpp>
namespace tui {
ftxui::Element centered_widget(ftxui::Component& container, const std::string_view& title, const ftxui::Element& widget);
void init() noexcept;
} // namespace tui

View File

@ -20,17 +20,23 @@ namespace utils {
static constexpr std::int32_t CONNECTION_TIMEOUT = 15;
bool is_connected() noexcept {
#ifdef NDEVENV
/* clang-format off */
auto r = cpr::Get(cpr::Url{"https://www.google.com"},
cpr::Timeout{1000});
info("{}\n", r.status_code);
/* 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));
#else
return true;
#endif
}
bool check_root() noexcept {
#ifdef NDEVENV
return (utils::exec("whoami") == "root\n");
#else
return true;
#endif
}
void clear_screen() noexcept {