Display nicks with hashed color
This commit is contained in:
parent
37d10821a4
commit
11422801b0
8 changed files with 92 additions and 6 deletions
|
|
@ -3,6 +3,7 @@
|
|||
use std::collections::VecDeque;
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use crossterm::style::ContentStyle;
|
||||
|
||||
use crate::chat::Cursor;
|
||||
|
||||
|
|
@ -24,6 +25,7 @@ impl<I> Block<I> {
|
|||
indent: usize,
|
||||
time: DateTime<Utc>,
|
||||
nick: String,
|
||||
nick_style: ContentStyle,
|
||||
lines: Vec<String>,
|
||||
) -> Self {
|
||||
Self {
|
||||
|
|
@ -33,7 +35,11 @@ impl<I> Block<I> {
|
|||
indent,
|
||||
time: Some(time),
|
||||
cursor: false,
|
||||
body: BlockBody::Msg(MsgBlock { nick, lines }),
|
||||
body: BlockBody::Msg(MsgBlock {
|
||||
nick,
|
||||
nick_style,
|
||||
lines,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -61,6 +67,7 @@ pub enum BlockBody {
|
|||
|
||||
pub struct MsgBlock {
|
||||
pub nick: String,
|
||||
pub nick_style: ContentStyle,
|
||||
pub lines: Vec<String>,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ fn msg_to_block<M: Msg>(frame: &mut Frame, size: Size, msg: &M, indent: usize) -
|
|||
let content_width = content_width as usize;
|
||||
let lines = toss::split_at_indices(&content, &frame.wrap(&content, content_width));
|
||||
let lines = lines.into_iter().map(|s| s.to_string()).collect::<Vec<_>>();
|
||||
Block::msg(msg.id(), indent, msg.time(), nick, lines)
|
||||
Block::msg(msg.id(), indent, msg.time(), nick, msg.nick_style(), lines)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,10 +44,18 @@ fn render_indent(frame: &mut Frame, x: i32, y: i32, cursor: bool, indent: usize)
|
|||
}
|
||||
}
|
||||
|
||||
fn render_nick(frame: &mut Frame, x: i32, y: i32, indent: usize, nick: &str) {
|
||||
fn render_nick(
|
||||
frame: &mut Frame,
|
||||
x: i32,
|
||||
y: i32,
|
||||
indent: usize,
|
||||
nick: &str,
|
||||
nick_style: ContentStyle,
|
||||
) {
|
||||
let nick_pos = Pos::new(x + util::after_indent(indent), y);
|
||||
let nick = format!("[{}]", nick);
|
||||
frame.write(nick_pos, &nick, ContentStyle::default());
|
||||
let inner_nick_pos = Pos::new(nick_pos.x + 1, nick_pos.y);
|
||||
frame.write(nick_pos, &format!("[{nick}]"), ContentStyle::default());
|
||||
frame.write(inner_nick_pos, nick, nick_style);
|
||||
}
|
||||
|
||||
fn render_block<M: Msg>(frame: &mut Frame, pos: Pos, size: Size, block: &Block<M::Id>) {
|
||||
|
|
@ -64,7 +72,7 @@ fn render_block<M: Msg>(frame: &mut Frame, pos: Pos, size: Size, block: &Block<M
|
|||
if i == 0 {
|
||||
render_indent(frame, pos.x, y, block.cursor, block.indent);
|
||||
render_time(frame, pos.x, y, block.cursor, block.time);
|
||||
render_nick(frame, pos.x, y, block.indent, &msg.nick);
|
||||
render_nick(frame, pos.x, y, block.indent, &msg.nick, msg.nick_style);
|
||||
} else {
|
||||
render_indent(frame, pos.x, y, false, block.indent + 1);
|
||||
render_indent(frame, pos.x, y, block.cursor, block.indent);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ use std::vec;
|
|||
|
||||
use async_trait::async_trait;
|
||||
use chrono::{DateTime, Utc};
|
||||
use crossterm::style::{ContentStyle, Stylize};
|
||||
use log::{Level, Log};
|
||||
use parking_lot::Mutex;
|
||||
use tokio::sync::mpsc;
|
||||
|
|
@ -36,6 +37,16 @@ impl Msg for LogMsg {
|
|||
format!("{}", self.level)
|
||||
}
|
||||
|
||||
fn nick_style(&self) -> ContentStyle {
|
||||
match self.level {
|
||||
Level::Error => ContentStyle::default().bold().red(),
|
||||
Level::Warn => ContentStyle::default().bold().yellow(),
|
||||
Level::Info => ContentStyle::default().bold().green(),
|
||||
Level::Debug => ContentStyle::default().bold().blue(),
|
||||
Level::Trace => ContentStyle::default().bold().magenta(),
|
||||
}
|
||||
}
|
||||
|
||||
fn content(&self) -> String {
|
||||
self.content.clone()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use std::hash::Hash;
|
|||
|
||||
use async_trait::async_trait;
|
||||
use chrono::{DateTime, Utc};
|
||||
use crossterm::style::ContentStyle;
|
||||
|
||||
pub trait Msg {
|
||||
type Id: Clone + Debug + Hash + Eq + Ord;
|
||||
|
|
@ -12,6 +13,7 @@ pub trait Msg {
|
|||
|
||||
fn time(&self) -> DateTime<Utc>;
|
||||
fn nick(&self) -> String;
|
||||
fn nick_style(&self) -> ContentStyle;
|
||||
fn content(&self) -> String;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,12 @@ use std::mem;
|
|||
|
||||
use async_trait::async_trait;
|
||||
use chrono::{DateTime, TimeZone, Utc};
|
||||
use crossterm::style::ContentStyle;
|
||||
use rusqlite::types::{FromSql, FromSqlError, ToSqlOutput, Value, ValueRef};
|
||||
use rusqlite::{named_params, params, Connection, OptionalExtension, ToSql, Transaction};
|
||||
use tokio::sync::{mpsc, oneshot};
|
||||
|
||||
use crate::euph;
|
||||
use crate::euph::api::{Message, Snowflake, Time};
|
||||
use crate::store::{Msg, MsgStore, Path, Tree};
|
||||
|
||||
|
|
@ -65,6 +67,10 @@ impl Msg for EuphMsg {
|
|||
self.nick.clone()
|
||||
}
|
||||
|
||||
fn nick_style(&self) -> ContentStyle {
|
||||
euph::nick_style(&self.nick)
|
||||
}
|
||||
|
||||
fn content(&self) -> String {
|
||||
self.content.trim().to_string()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue