that looks pretty good i think

This commit is contained in:
Mars 2025-05-07 02:13:52 -04:00
parent e8d0789277
commit b6b01636f5
6 changed files with 458 additions and 503 deletions

View file

@ -1701,8 +1701,7 @@ namespace argparse {
} }
if (m_is_optional) { if (m_is_optional) {
// TODO: check if an implicit value was programmed for this argument if (!m_is_used && !m_default_value.has_value() && !m_implicit_value.has_value() && m_is_required)
if (!m_is_used && !m_default_value.has_value() && m_is_required)
return Err(DracError(DracErrorCode::InvalidArgument, std::format("Required argument '{}' was not provided", m_names[0]))); return Err(DracError(DracErrorCode::InvalidArgument, std::format("Required argument '{}' was not provided", m_names[0])));
if (m_is_used && m_is_required && m_values.empty()) if (m_is_used && m_is_required && m_values.empty())

File diff suppressed because it is too large Load diff

View file

@ -13,21 +13,26 @@
#include "src/util/error.hpp" #include "src/util/error.hpp"
#include "src/util/types.hpp" #include "src/util/types.hpp"
#include "include/matchit.hpp"
using util::error::DracError, util::error::DracErrorCode; using util::error::DracError, util::error::DracErrorCode;
namespace { namespace {
using util::types::i32, util::types::CStr; using util::types::i32, util::types::CStr;
fn getOrdinalSuffix(const i32 day) -> CStr { fn getOrdinalSuffix(const i32 day) -> CStr {
using matchit::match, matchit::is, matchit::_, matchit::within;
if (day >= 11 && day <= 13) if (day >= 11 && day <= 13)
return "th"; return "th";
switch (day % 10) { return match(day % 10)(
case 1: return "st"; is | within(11, 13) = "th",
case 2: return "nd"; is | 1 = "st",
case 3: return "rd"; is | 2 = "nd",
default: return "th"; is | 3 = "rd",
} is | _ = "th"
);
} }
fn getDate() -> Result<String> { fn getDate() -> Result<String> {

View file

@ -76,8 +76,7 @@ namespace {
} }
template <usize sz> template <usize sz>
fn FindShellInProcessTree(const DWORD startPid, const Array<Pair<StringView, StringView>, sz>& shellMap) fn FindShellInProcessTree(const DWORD startPid, const Array<Pair<StringView, StringView>, sz>& shellMap) -> Option<String> {
-> Option<String> {
if (startPid == 0) if (startPid == 0)
return None; return None;

View file

@ -77,8 +77,10 @@ namespace ui {
auto colorView = auto colorView =
std::views::iota(0, 16) | std::views::transform([](i32 colorIndex) { std::views::iota(0, 16) | std::views::transform([](i32 colorIndex) {
return ftxui::hbox( return ftxui::hbox(
{ ftxui::text("") | ftxui::bold | ftxui::color(static_cast<ftxui::Color::Palette256>(colorIndex)), {
ftxui::text(" ") } ftxui::text("") | ftxui::bold | ftxui::color(static_cast<ftxui::Color::Palette256>(colorIndex)),
ftxui::text(" "),
}
); );
}); });
@ -104,8 +106,24 @@ namespace ui {
const String& name = config.general.name; const String& name = config.general.name;
const Weather& weather = config.weather; const Weather& weather = config.weather;
const auto& [userIcon, paletteIcon, calendarIcon, hostIcon, kernelIcon, osIcon, memoryIcon, weatherIcon, musicIcon, diskIcon, shellIcon, packageIcon, deIcon, wmIcon] = // clang-format off
ui::ICON_TYPE; const auto& [
userIcon,
paletteIcon,
calendarIcon,
hostIcon,
kernelIcon,
osIcon,
memoryIcon,
weatherIcon,
diskIcon,
shellIcon,
packageIcon,
deIcon,
wmIcon,
musicIcon
] = ui::ICON_TYPE;
// clang-format on
std::vector<RowInfo> initialRows; // Date, Weather std::vector<RowInfo> initialRows; // Date, Weather
std::vector<RowInfo> systemInfoRows; // Host, Kernel, OS, RAM, Disk, Shell, Packages std::vector<RowInfo> systemInfoRows; // Host, Kernel, OS, RAM, Disk, Shell, Packages
@ -116,9 +134,11 @@ namespace ui {
if (weather.enabled && data.weather) { if (weather.enabled && data.weather) {
const weather::Output& weatherInfo = *data.weather; const weather::Output& weatherInfo = *data.weather;
String weatherValue = weather.showTownName String weatherValue = weather.showTownName
? std::format("{}°F in {}", std::lround(weatherInfo.main.temp), weatherInfo.name) ? std::format("{}°F in {}", std::lround(weatherInfo.main.temp), weatherInfo.name)
: std::format("{}°F, {}", std::lround(weatherInfo.main.temp), weatherInfo.weather[0].description); : std::format("{}°F, {}", std::lround(weatherInfo.main.temp), weatherInfo.weather[0].description);
initialRows.push_back({ .icon = weatherIcon, .label = "Weather", .value = std::move(weatherValue) }); initialRows.push_back({ .icon = weatherIcon, .label = "Weather", .value = std::move(weatherValue) });
} else if (weather.enabled && !data.weather.has_value()) } else if (weather.enabled && !data.weather.has_value())
debug_at(data.weather.error()); debug_at(data.weather.error());
@ -133,9 +153,7 @@ namespace ui {
systemInfoRows.push_back({ .icon = kernelIcon, .label = "Kernel", .value = *data.kernelVersion }); systemInfoRows.push_back({ .icon = kernelIcon, .label = "Kernel", .value = *data.kernelVersion });
if (data.memInfo) if (data.memInfo)
systemInfoRows.push_back( systemInfoRows.push_back({ .icon = memoryIcon, .label = "RAM", .value = std::format("{}", BytesToGiB { *data.memInfo }) });
{ .icon = memoryIcon, .label = "RAM", .value = std::format("{}", BytesToGiB { *data.memInfo }) }
);
else if (!data.memInfo.has_value()) else if (!data.memInfo.has_value())
debug_at(data.memInfo.error()); debug_at(data.memInfo.error());
@ -144,8 +162,7 @@ namespace ui {
{ {
.icon = diskIcon, .icon = diskIcon,
.label = "Disk", .label = "Disk",
.value = .value = std::format("{}/{}", BytesToGiB { data.diskUsage->usedBytes }, BytesToGiB { data.diskUsage->totalBytes }),
std::format("{}/{}", BytesToGiB { data.diskUsage->usedBytes }, BytesToGiB { data.diskUsage->totalBytes }),
} }
); );
@ -154,9 +171,7 @@ namespace ui {
if (data.packageCount) { if (data.packageCount) {
if (*data.packageCount > 0) if (*data.packageCount > 0)
systemInfoRows.push_back( systemInfoRows.push_back({ .icon = packageIcon, .label = "Packages", .value = std::format("{}", *data.packageCount) });
{ .icon = packageIcon, .label = "Packages", .value = std::format("{}", *data.packageCount) }
);
else else
debug_log("Package count is 0, skipping"); debug_log("Package count is 0, skipping");
} }
@ -184,12 +199,10 @@ namespace ui {
usize maxContentWidth = 0; usize maxContentWidth = 0;
const usize greetingWidth = get_visual_width_sv(userIcon) + get_visual_width_sv("Hello ") + get_visual_width(name) + const usize greetingWidth = get_visual_width_sv(userIcon) + get_visual_width_sv("Hello ") + get_visual_width(name) + get_visual_width_sv("! ");
get_visual_width_sv("! ");
maxContentWidth = std::max(maxContentWidth, greetingWidth); maxContentWidth = std::max(maxContentWidth, greetingWidth);
const usize paletteWidth = const usize paletteWidth = get_visual_width_sv(userIcon) + (16 * (get_visual_width_sv("") + get_visual_width_sv(" ")));
get_visual_width_sv(userIcon) + (16 * (get_visual_width_sv("") + get_visual_width_sv(" ")));
maxContentWidth = std::max(maxContentWidth, paletteWidth); maxContentWidth = std::max(maxContentWidth, paletteWidth);
const usize iconActualWidth = get_visual_width_sv(userIcon); const usize iconActualWidth = get_visual_width_sv(userIcon);
@ -228,8 +241,7 @@ namespace ui {
i32 paragraphLimit = 1; i32 paragraphLimit = 1;
if (nowPlayingActive) { if (nowPlayingActive) {
i32 availableForParagraph = i32 availableForParagraph = static_cast<i32>(targetBoxWidth) - static_cast<i32>(npFixedWidthLeft) - static_cast<i32>(npFixedWidthRight);
static_cast<i32>(targetBoxWidth) - static_cast<i32>(npFixedWidthLeft) - static_cast<i32>(npFixedWidthRight);
availableForParagraph -= 2; availableForParagraph -= 2;

View file

@ -5,7 +5,6 @@
#include <filesystem> // std::filesystem::path #include <filesystem> // std::filesystem::path
#include <format> // std::format #include <format> // std::format
#include <ftxui/screen/color.hpp> // ftxui::Color #include <ftxui/screen/color.hpp> // ftxui::Color
#include <mutex> // std::{mutex, lock_guard}
#include <utility> // std::forward #include <utility> // std::forward
#ifdef __cpp_lib_print #ifdef __cpp_lib_print
@ -22,8 +21,6 @@
#include "src/util/error.hpp" #include "src/util/error.hpp"
#include "src/util/types.hpp" #include "src/util/types.hpp"
#include "ftxui/dom/elements.hpp"
namespace util::logging { namespace util::logging {
using types::usize, types::u8, types::i32, types::i64, types::CStr, types::String, types::StringView, types::Array, using types::usize, types::u8, types::i32, types::i64, types::CStr, types::String, types::StringView, types::Array,
types::Option, types::None, types::Mutex, types::LockGuard; types::Option, types::None, types::Mutex, types::LockGuard;