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    ReasoningEmphasis,
23    Warning,
24}
25
26impl MessageStyle {
27    /// Get the ANSI style for this message style
28    pub fn style(self) -> Style {
29        let styles = theme::active_styles();
30        match self {
31            Self::Info => styles.info,
32            Self::Error => styles.error,
33            Self::Output => styles.output,
34            Self::Response => styles.response,
35            Self::Tool => styles.tool,
36            Self::ToolDetail => styles.tool_detail,
37            Self::ToolOutput => styles.pty_output, // Use pty_output style for command output
38            Self::ToolError => styles.error,
39            Self::Status => styles.status,
40            Self::McpStatus => styles.mcp,
41            Self::User => styles.user,
42            Self::Reasoning => styles.reasoning,
43            Self::ReasoningEmphasis => styles.reasoning.bold(),
44            Self::Warning => styles.error,
45        }
46    }
47
48    /// Get the indentation string for this message style
49    pub fn indent(self) -> &'static str {
50        match self {
51            Self::Response | Self::Tool => "  ",
52            Self::Reasoning => "  ❋ ",
53            Self::ReasoningEmphasis => "  ▸ ",
54            Self::ToolDetail | Self::ToolOutput | Self::ToolError => "    ",
55            _ => "",
56        }
57    }
58
59    /// Map MessageStyle to InlineMessageKind for TUI integration
60    pub fn message_kind(self) -> InlineMessageKind {
61        match self {
62            Self::Info => InlineMessageKind::Info,
63            Self::Error => InlineMessageKind::Error,
64            Self::Output | Self::ToolOutput => InlineMessageKind::Pty,
65            Self::Response => InlineMessageKind::Agent,
66            Self::Tool | Self::ToolDetail | Self::ToolError => InlineMessageKind::Tool,
67            Self::Status | Self::McpStatus => InlineMessageKind::Info,
68            Self::User => InlineMessageKind::User,
69            Self::Reasoning => InlineMessageKind::Policy,
70            Self::ReasoningEmphasis => InlineMessageKind::Policy,
71            Self::Warning => InlineMessageKind::Warning,
72        }
73    }
74}