Make new ChatMsg trait for Chat message rendering

This commit is contained in:
Joscha 2022-08-01 19:57:05 +02:00
parent 5c9c6e9d98
commit 4ac0b5f074
13 changed files with 122 additions and 69 deletions

View file

@ -6,7 +6,9 @@ use std::sync::Arc;
use async_trait::async_trait;
use crossterm::event::KeyEvent;
use parking_lot::FairMutex;
use time::OffsetDateTime;
use toss::frame::{Frame, Size};
use toss::styled::Styled;
use toss::terminal::Terminal;
use crate::store::{Msg, MsgStore};
@ -15,6 +17,17 @@ use self::tree::{TreeView, TreeViewState};
use super::widgets::Widget;
///////////
// Trait //
///////////
pub trait ChatMsg {
fn time(&self) -> OffsetDateTime;
fn styled(&self) -> (Styled, Styled);
fn edit(nick: &str, content: &str) -> (Styled, Styled);
fn pseudo(nick: &str, content: &str) -> (Styled, Styled);
}
///////////
// State //
///////////
@ -87,7 +100,7 @@ pub enum Chat<M: Msg, S: MsgStore<M>> {
#[async_trait]
impl<M, S> Widget for Chat<M, S>
where
M: Msg,
M: Msg + ChatMsg,
M::Id: Send + Sync,
S: MsgStore<M> + Send + Sync,
{