From 978205b8231ffcf1af8e72a2b29579eec4df5795 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 14 Sep 2024 15:02:14 +0100 Subject: [PATCH] feat(tui): add time and version in border --- Cargo.lock | 1 + Cargo.toml | 1 + crates/cli/Cargo.toml | 3 ++- crates/cli/src/tui/actor/model.rs | 21 ++++++++++++++++++--- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bd2414d..95cc714 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1100,6 +1100,7 @@ dependencies = [ "assert2", "bon", "bytes", + "chrono", "clap", "color-eyre", "derive-with", diff --git a/Cargo.toml b/Cargo.toml index 78ea927..77940ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ lazy_static = "1.5" color-eyre = "0.6" tui-scrollview = "0.4" regex = "1.10" +chrono = "0.4" # CLI parsing clap = { version = "4.5", features = ["cargo", "derive"] } diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 885ecdf..e478c2b 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -16,7 +16,7 @@ categories = { workspace = true } default = ["forgejo", "github", "tui"] forgejo = ["git-next-forge-forgejo"] github = ["git-next-forge-github"] -tui = ["ratatui", "directories", "lazy_static", "tui-scrollview", "regex"] +tui = ["ratatui", "directories", "lazy_static", "tui-scrollview", "regex", "chrono"] [dependencies] git-next-core = { workspace = true } @@ -30,6 +30,7 @@ lazy_static = { workspace = true, optional = true } color-eyre = { workspace = true } tui-scrollview = { workspace = true, optional = true } regex = { workspace = true, optional = true } +chrono = { workspace = true, optional = true } # CLI parsing clap = { workspace = true } diff --git a/crates/cli/src/tui/actor/model.rs b/crates/cli/src/tui/actor/model.rs index a62214c..f779dd4 100644 --- a/crates/cli/src/tui/actor/model.rs +++ b/crates/cli/src/tui/actor/model.rs @@ -5,7 +5,10 @@ use ratatui::{ style::{Color, Style, Stylize as _}, symbols::border, text::{Line, Span}, - widgets::{block::Title, Block, Paragraph, StatefulWidget, Widget}, + widgets::{ + block::{Position, Title}, + Block, Paragraph, StatefulWidget, Widget, + }, }; use git_next_core::{ @@ -51,6 +54,10 @@ impl State { } } +fn time() -> String { + chrono::Local::now().format("%H:%M").to_string() +} + #[derive(Clone, Debug, PartialEq, Eq)] pub enum ServerState { /// UI has started but has no information on the state of the server @@ -356,7 +363,10 @@ impl StatefulWidget for &State { Self: Sized, { let block = Block::bordered() - .title(Title::from(" Git-Next ".bold()).alignment(Alignment::Center)) + .title( + Title::from(format!(" Git-Next v{} ", clap::crate_version!()).bold()) + .alignment(Alignment::Center), + ) .title( Title::from(Line::from(vec![ " [q]uit ".into(), @@ -364,7 +374,12 @@ impl StatefulWidget for &State { " ".into(), ])) .alignment(Alignment::Center) - .position(ratatui::widgets::block::Position::Bottom), + .position(Position::Bottom), + ) + .title( + Title::from(format!(" {} ", time())) + .alignment(Alignment::Right) + .position(Position::Bottom), ) .border_set(border::THICK); let interior = block.inner(area);