From 2deecc2084d15e17c5bf6f52011c243a43642099 Mon Sep 17 00:00:00 2001 From: Joscha Date: Tue, 2 Jan 2024 17:01:33 +0100 Subject: [PATCH] Add welcome info box next to room list --- CHANGELOG.md | 2 +- cove/src/main.rs | 8 +++----- cove/src/ui/rooms.rs | 46 +++++++++++++++++++++++++++----------------- cove/src/version.rs | 2 ++ 4 files changed, 34 insertions(+), 24 deletions(-) create mode 100644 cove/src/version.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index e881bbf..b1532cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,9 +17,9 @@ Procedure when bumping the version number: ### Added - Support for multiple euph server domains -- Room domains are visible in the UI - Domain field to "connect to new room" popup - `--domain` option to `cove export` command +- Welcome info box next to room list ### Changed - The default euph domain is now https://euphoria.leet.nu/ everywhere diff --git a/cove/src/main.rs b/cove/src/main.rs index cc5ae63..e5eeb5c 100644 --- a/cove/src/main.rs +++ b/cove/src/main.rs @@ -22,6 +22,7 @@ mod store; mod ui; mod util; mod vault; +mod version; use std::path::PathBuf; @@ -36,6 +37,7 @@ use toss::Terminal; use crate::logger::Logger; use crate::ui::Ui; use crate::vault::Vault; +use crate::version::{NAME, VERSION}; #[derive(Debug, clap::Parser)] enum Command { @@ -176,11 +178,7 @@ async fn run( config: &'static Config, dirs: &ProjectDirs, ) -> anyhow::Result<()> { - info!( - "Welcome to {} {}", - env!("CARGO_PKG_NAME"), - env!("CARGO_PKG_VERSION") - ); + info!("Welcome to {NAME} {VERSION}",); let vault = open_vault(config, dirs)?; diff --git a/cove/src/ui/rooms.rs b/cove/src/ui/rooms.rs index 914bf7e..a2319f9 100644 --- a/cove/src/ui/rooms.rs +++ b/cove/src/ui/rooms.rs @@ -13,12 +13,13 @@ use euphoxide::api::SessionType; use euphoxide::bot::instance::{Event, ServerConfig}; use euphoxide::conn::{self, Joined}; use tokio::sync::mpsc; -use toss::widgets::{BoxedAsync, Join2, Text}; +use toss::widgets::{BoxedAsync, Empty, Join2, Text}; use toss::{Style, Styled, Widget, WidgetExt}; use crate::euph; use crate::macros::logging_unwrap; use crate::vault::{EuphVault, RoomIdentifier, Vault}; +use crate::version::{NAME, VERSION}; use self::connect::{ConnectResult, ConnectState}; use self::delete::{DeleteResult, DeleteState}; @@ -360,20 +361,10 @@ impl Rooms { } async fn render_rows( - config: &Config, list_builder: &mut ListBuilder<'_, RoomIdentifier, Text>, order: Order, euph_rooms: &HashMap, ) { - if euph_rooms.is_empty() { - let style = Style::new().grey().italic(); - list_builder.add_unsel(Text::new( - Styled::new("Press ", style) - .and_then(key_bindings::format_binding(&config.keys.general.help)) - .then(" for key bindings", style), - )); - } - let mut rooms = vec![]; for (id, room) in euph_rooms { let state = room.room_state(); @@ -406,16 +397,35 @@ impl Rooms { order: Order, euph_rooms: &HashMap, ) -> impl Widget + 'a { - let heading_style = Style::new().bold(); - let heading_text = - Styled::new("Rooms", heading_style).then_plain(format!(" ({})", euph_rooms.len())); + let version_info = Styled::new_plain("Welcome to ") + .then(format!("{NAME} {VERSION}"), Style::new().yellow().bold()) + .then_plain("!"); + let help_info = Styled::new("Press ", Style::new().grey()) + .and_then(key_bindings::format_binding(&config.keys.general.help)) + .then(" for key bindings.", Style::new().grey()); + let info = Join2::vertical( + Text::new(version_info).float().with_center_h().segment(), + Text::new(help_info).segment(), + ) + .padding() + .with_horizontal(1) + .border(); + + let heading = Styled::new("Rooms", Style::new().bold()) + .then_plain(format!(" ({})", euph_rooms.len())); let mut list_builder = ListBuilder::new(); - Self::render_rows(config, &mut list_builder, order, euph_rooms).await; + Self::render_rows(&mut list_builder, order, euph_rooms).await; - Join2::vertical( - Text::new(heading_text).segment().with_fixed(true), - list_builder.build(list).segment(), + Join2::horizontal( + Join2::vertical( + Text::new(heading).segment().with_fixed(true), + list_builder.build(list).segment(), + ) + .segment(), + Join2::vertical(info.segment().with_growing(false), Empty::new().segment()) + .segment() + .with_growing(false), ) } diff --git a/cove/src/version.rs b/cove/src/version.rs new file mode 100644 index 0000000..2a4c731 --- /dev/null +++ b/cove/src/version.rs @@ -0,0 +1,2 @@ +pub const NAME: &str = env!("CARGO_PKG_NAME"); +pub const VERSION: &str = env!("CARGO_PKG_VERSION");