Add welcome info box next to room list

This commit is contained in:
Joscha 2024-01-02 17:01:33 +01:00
parent a522b09f79
commit 2deecc2084
4 changed files with 34 additions and 24 deletions

View file

@ -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

View file

@ -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)?;

View file

@ -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<RoomIdentifier, EuphRoom>,
) {
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<RoomIdentifier, EuphRoom>,
) -> impl Widget<UiError> + '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),
)
}

2
cove/src/version.rs Normal file
View file

@ -0,0 +1,2 @@
pub const NAME: &str = env!("CARGO_PKG_NAME");
pub const VERSION: &str = env!("CARGO_PKG_VERSION");