Skip to main content

vtcode_core/utils/
message_style.rs

1//! Unified message styles and their logical mappings
2
3use crate::ui::theme;
4use crate::ui::tui::InlineMessageKind;
5use anstyle::Style;
6
7/// Styles available for rendering messages
8#[derive(Clone, Copy, Debug, PartialEq, Eq)]
9pub enum MessageStyle {
10    Info,
11    Error,
12    Output,
13    Response,
14    Tool,
15    ToolDetail,
16    ToolOutput,
17    ToolError,
18    Status,
19    McpStatus,
20    User,
21    Reasoning,
22    Warning,
23}
24
25impl MessageStyle {
26    /// Get the ANSI style for this message style
27    pub fn style(self) -> Style {
28        let styles = theme::active_styles();
29        match self {
30            Self::Info => styles.info,
31            Self::Error => styles.error,
32            Self::Output => styles.output,
33            Self::Response => styles.response,
34            Self::Tool => styles.tool,
35            Self::ToolDetail => styles.tool_detail,
36            Self::ToolOutput => styles.tool_output,
37            Self::ToolError => styles.error,
38            Self::Status => styles.status,
39            Self::McpStatus => styles.mcp,
40            Self::User => styles.user,
41            Self::Reasoning => styles.reasoning,
42            Self::Warning => styles.error,
43        }
44    }
45
46    /// Get the indentation string for this message style
47    pub fn indent(self) -> &'static str {
48        match self {
49            Self::Response | Self::Tool => "  ",
50            Self::Reasoning => "  ❋ ",
51            Self::ToolDetail | Self::ToolOutput | Self::ToolError => "    ",
52            _ => "",
53        }
54    }
55
56    /// Map MessageStyle to InlineMessageKind for TUI integration
57    pub fn message_kind(self) -> InlineMessageKind {
58        match self {
59            Self::Info => InlineMessageKind::Info,
60            Self::Error => InlineMessageKind::Error,
61            Self::Output | Self::ToolOutput => InlineMessageKind::Pty,
62            Self::Response => InlineMessageKind::Agent,
63            Self::Tool | Self::ToolDetail | Self::ToolError => InlineMessageKind::Tool,
64            Self::Status | Self::McpStatus => InlineMessageKind::Info,
65            Self::User => InlineMessageKind::User,
66            Self::Reasoning => InlineMessageKind::Policy,
67            Self::Warning => InlineMessageKind::Warning,
68        }
69    }
70}