57 lines
1.3 KiB
Rust
57 lines
1.3 KiB
Rust
use tui::{text::{Span}, style::{Style, Color}};
|
|
|
|
use crate::entity::EntityId;
|
|
|
|
pub struct ChatLine {
|
|
pub speaker_id: EntityId,
|
|
pub speaker: String,
|
|
pub text: String,
|
|
pub action: bool,
|
|
}
|
|
|
|
pub struct Chat {
|
|
pub lines: Vec<ChatLine>,
|
|
}
|
|
|
|
impl ChatLine {
|
|
pub fn new(speaker_id: EntityId, speaker: String, text: String, action: bool) -> ChatLine {
|
|
ChatLine {
|
|
speaker_id: speaker_id,
|
|
speaker: speaker,
|
|
text: text,
|
|
action: action,
|
|
}
|
|
}
|
|
|
|
pub fn to_spans(&self) -> tui::text::Spans {
|
|
let mut spans = Vec::new();
|
|
spans.push(Span::styled(format!("{}: ", self.speaker), Style::default().fg(Color::Red)));
|
|
spans.push(Span::styled(format!("{}", self.text), Style::default().fg(Color::White)));
|
|
tui::text::Spans::from(spans)
|
|
}
|
|
|
|
}
|
|
|
|
impl Chat {
|
|
pub fn new() -> Chat {
|
|
Chat {
|
|
lines: Vec::new(),
|
|
}
|
|
}
|
|
|
|
pub fn add_line(&mut self, line: ChatLine) {
|
|
self.lines.push(line);
|
|
}
|
|
|
|
pub fn to_spans(&self) -> Vec<tui::text::Spans> {
|
|
let mut spans = Vec::new();
|
|
for line in &self.lines {
|
|
spans.push(line.to_spans());
|
|
spans.push(tui::text::Spans::from(vec![
|
|
Span::styled("\n", Style::default().fg(Color::White))
|
|
]));
|
|
}
|
|
spans
|
|
}
|
|
|
|
} |