Add room and nick list UI mockup

This commit is contained in:
Joscha 2022-02-20 00:32:17 +01:00
parent 992e84e67e
commit fbc24a1154
4 changed files with 217 additions and 6 deletions

View file

@ -9,6 +9,7 @@ clap = { version = "3.1.0", features = ["derive"] }
cove-core = { path = "../cove-core" }
crossterm = "0.22.1"
# futures = "0.3.21"
palette = "0.6.0"
# serde_json = "1.0.78"
thiserror = "1.0.30"
tokio = { version = "1.16.1", features = ["full"] }

View file

@ -1,7 +1,7 @@
mod replies;
mod room;
mod config;
mod never;
mod replies;
mod room;
use std::io::{self, Stdout};
use std::time::Duration;
@ -10,17 +10,109 @@ use config::Config;
use crossterm::event::{DisableMouseCapture, EnableMouseCapture};
use crossterm::execute;
use crossterm::terminal::{EnterAlternateScreen, LeaveAlternateScreen};
use palette::rgb::Rgb;
use palette::{FromColor, Hsl, Hsv, Saturate, Srgb};
use tokio::time;
use tui::backend::CrosstermBackend;
use tui::widgets::{Block, Borders};
use tui::layout::{Constraint, Corner, Direction, Layout};
use tui::style::{Color, Modifier, Style};
use tui::symbols::line::VERTICAL;
use tui::text::{Span, Spans};
use tui::widgets::{Block, Borders, Cell, List, ListItem, ListState, Paragraph, Row, Table, Tabs};
use tui::Terminal;
async fn run(terminal: &mut Terminal<CrosstermBackend<Stdout>>) -> anyhow::Result<()> {
terminal.draw(|f| {
let block = Block::default().title("Block").borders(Borders::ALL);
f.render_widget(block, f.size());
let hchunks = Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Length(20),
Constraint::Length(2),
Constraint::Min(0),
Constraint::Length(2),
Constraint::Length(20),
])
.split(f.size());
// Borders
f.render_widget(Block::default().borders(Borders::LEFT), hchunks[1]);
f.render_widget(Block::default().borders(Borders::LEFT), hchunks[3]);
// Room list
let room_style = Style::default().fg(Color::LightBlue);
let mut state = ListState::default();
// state.select(Some(1));
f.render_stateful_widget(
List::new(vec![
ListItem::new(Span::styled(
"Cove",
Style::default().add_modifier(Modifier::BOLD),
)),
ListItem::new(Span::styled("&dunno", room_style)),
ListItem::new(Span::styled("&test", room_style)),
ListItem::new(" "),
ListItem::new(Span::styled(
"Euphoria",
Style::default().add_modifier(Modifier::BOLD),
)),
ListItem::new(Span::styled("&xkcd", room_style)),
ListItem::new(Span::styled("&music", room_style)),
ListItem::new(Span::styled("&bots", room_style)),
ListItem::new(" "),
ListItem::new(Span::styled(
"Instant",
Style::default().add_modifier(Modifier::BOLD),
)),
ListItem::new(Span::styled("&welcome", room_style)),
]),
// .highlight_style(Style::default().add_modifier(Modifier::BOLD))
// .highlight_symbol(">"),
hchunks[0],
&mut state,
);
// f.render_widget(Paragraph::new("foo"), hchunks[0]);
// Nick list
let nchunks = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Length(1), Constraint::Min(0)])
.split(hchunks[4]);
f.render_widget(
Paragraph::new(Spans::from(vec![
Span::styled("Users", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" "),
Span::styled("(13)", Style::default().fg(Color::Gray)),
])),
nchunks[0],
);
fn userstyle(r: u8, g: u8, b: u8) -> Style {
let rgb = Srgb::new(r, g, b).into_format::<f32>();
let mut hsl = Hsl::from_color(rgb);
hsl.saturation = 1.0;
hsl.lightness = 0.7;
let rgb = Rgb::from_color(hsl).into_format::<u8>();
Style::default().fg(Color::Rgb(rgb.red, rgb.green, rgb.blue))
}
f.render_widget(
List::new([
ListItem::new(Span::styled("TerryTvType", userstyle(192, 242, 238))),
ListItem::new(Span::styled("r*4", userstyle(192, 211, 242))),
ListItem::new(Span::styled("Swedish", userstyle(192, 242, 207))),
ListItem::new(Span::styled("Garmy", userstyle(242, 225, 192))),
ListItem::new(Span::styled("SRP", userstyle(242, 219, 192))),
ListItem::new(Span::styled("C", userstyle(192, 218, 242))),
ListItem::new(Span::styled("fill", userstyle(192, 197, 242))),
ListItem::new(Span::styled("ohnezo", userstyle(242, 203, 192))),
ListItem::new(Span::styled("Sumärzru", userstyle(242, 223, 192))),
ListItem::new(Span::styled("SuperGeek", userstyle(192, 242, 203))),
ListItem::new(Span::styled("certainlyhominid", userstyle(192, 242, 209))),
ListItem::new(Span::styled("Plugh", userstyle(192, 242, 215))),
ListItem::new(Span::styled("🎼\u{fe0e}🎷🎷🎷🎼\u{fe0e}", userstyle(242, 192, 192))),
]),
nchunks[1],
);
})?;
time::sleep(Duration::from_secs(1)).await;
let _ = crossterm::event::read();
Ok(())
}

View file

@ -162,6 +162,7 @@ impl Room {
Rpl::Room(RoomRpl::Success) => {
*room_verified = true;
if let Some(nick) = &self.initial_nick {
// TODO Use previous nick if there is one
tokio::spawn(Self::identify(
room.clone(),
nick.clone(),