feat(tui): add time and version in border

This commit is contained in:
Paul Campbell 2024-09-14 15:02:14 +01:00
parent 8359d0d7ca
commit 978205b823
4 changed files with 22 additions and 4 deletions

1
Cargo.lock generated
View file

@ -1100,6 +1100,7 @@ dependencies = [
"assert2", "assert2",
"bon", "bon",
"bytes", "bytes",
"chrono",
"clap", "clap",
"color-eyre", "color-eyre",
"derive-with", "derive-with",

View file

@ -33,6 +33,7 @@ lazy_static = "1.5"
color-eyre = "0.6" color-eyre = "0.6"
tui-scrollview = "0.4" tui-scrollview = "0.4"
regex = "1.10" regex = "1.10"
chrono = "0.4"
# CLI parsing # CLI parsing
clap = { version = "4.5", features = ["cargo", "derive"] } clap = { version = "4.5", features = ["cargo", "derive"] }

View file

@ -16,7 +16,7 @@ categories = { workspace = true }
default = ["forgejo", "github", "tui"] default = ["forgejo", "github", "tui"]
forgejo = ["git-next-forge-forgejo"] forgejo = ["git-next-forge-forgejo"]
github = ["git-next-forge-github"] github = ["git-next-forge-github"]
tui = ["ratatui", "directories", "lazy_static", "tui-scrollview", "regex"] tui = ["ratatui", "directories", "lazy_static", "tui-scrollview", "regex", "chrono"]
[dependencies] [dependencies]
git-next-core = { workspace = true } git-next-core = { workspace = true }
@ -30,6 +30,7 @@ lazy_static = { workspace = true, optional = true }
color-eyre = { workspace = true } color-eyre = { workspace = true }
tui-scrollview = { workspace = true, optional = true } tui-scrollview = { workspace = true, optional = true }
regex = { workspace = true, optional = true } regex = { workspace = true, optional = true }
chrono = { workspace = true, optional = true }
# CLI parsing # CLI parsing
clap = { workspace = true } clap = { workspace = true }

View file

@ -5,7 +5,10 @@ use ratatui::{
style::{Color, Style, Stylize as _}, style::{Color, Style, Stylize as _},
symbols::border, symbols::border,
text::{Line, Span}, text::{Line, Span},
widgets::{block::Title, Block, Paragraph, StatefulWidget, Widget}, widgets::{
block::{Position, Title},
Block, Paragraph, StatefulWidget, Widget,
},
}; };
use git_next_core::{ 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)] #[derive(Clone, Debug, PartialEq, Eq)]
pub enum ServerState { pub enum ServerState {
/// UI has started but has no information on the state of the server /// UI has started but has no information on the state of the server
@ -356,7 +363,10 @@ impl StatefulWidget for &State {
Self: Sized, Self: Sized,
{ {
let block = Block::bordered() 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(
Title::from(Line::from(vec![ Title::from(Line::from(vec![
" [q]uit ".into(), " [q]uit ".into(),
@ -364,7 +374,12 @@ impl StatefulWidget for &State {
" ".into(), " ".into(),
])) ]))
.alignment(Alignment::Center) .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); .border_set(border::THICK);
let interior = block.inner(area); let interior = block.inner(area);