Skip to main content

rustyclaw_tui/
types.rs

1// ── Display types for TUI messages ──────────────────────────────────────────
2
3use rustyclaw_core::types::MessageRole;
4
5/// A single message displayed in the chat pane.
6#[derive(Debug, Clone)]
7pub struct DisplayMessage {
8    pub role: MessageRole,
9    pub content: String,
10}
11
12impl DisplayMessage {
13    pub fn new(role: MessageRole, content: impl Into<String>) -> Self {
14        Self {
15            role,
16            content: content.into(),
17        }
18    }
19
20    pub fn user(content: impl Into<String>) -> Self {
21        Self::new(MessageRole::User, content)
22    }
23    pub fn assistant(content: impl Into<String>) -> Self {
24        Self::new(MessageRole::Assistant, content)
25    }
26    pub fn info(content: impl Into<String>) -> Self {
27        Self::new(MessageRole::Info, content)
28    }
29    pub fn success(content: impl Into<String>) -> Self {
30        Self::new(MessageRole::Success, content)
31    }
32    pub fn warning(content: impl Into<String>) -> Self {
33        Self::new(MessageRole::Warning, content)
34    }
35    pub fn error(content: impl Into<String>) -> Self {
36        Self::new(MessageRole::Error, content)
37    }
38    pub fn system(content: impl Into<String>) -> Self {
39        Self::new(MessageRole::System, content)
40    }
41    pub fn tool_call(content: impl Into<String>) -> Self {
42        Self::new(MessageRole::ToolCall, content)
43    }
44    pub fn tool_result(content: impl Into<String>) -> Self {
45        Self::new(MessageRole::ToolResult, content)
46    }
47    pub fn thinking(content: impl Into<String>) -> Self {
48        Self::new(MessageRole::Thinking, content)
49    }
50
51    /// Append text to the message content.
52    pub fn append(&mut self, text: &str) {
53        self.content.push_str(text);
54    }
55}