syncable_cli/agent/ui/
colors.rs

1//! Color theme and styling utilities for terminal UI
2//!
3//! Provides semantic colors and ANSI escape codes for consistent styling.
4
5use colored::Colorize;
6
7/// Status icons for different states
8pub mod icons {
9    pub const PENDING: &str = "○";
10    pub const EXECUTING: &str = "◐";
11    pub const SUCCESS: &str = "✓";
12    pub const ERROR: &str = "✗";
13    pub const WARNING: &str = "⚠";
14    pub const CANCELED: &str = "⊘";
15    pub const CONFIRMING: &str = "⏳";
16    pub const ARROW: &str = "→";
17    pub const THINKING: &str = "💭";
18    pub const ROBOT: &str = "🤖";
19    pub const TOOL: &str = "🔧";
20    pub const SHELL: &str = "🐚";
21    pub const EDIT: &str = "✏️";
22    pub const FILE: &str = "📄";
23    pub const FOLDER: &str = "📁";
24    pub const SECURITY: &str = "🔒";
25    pub const SEARCH: &str = "🔍";
26    pub const DOCKER: &str = "🐳";
27    pub const LINT: &str = "📋";
28    pub const FIX: &str = "🔧";
29    pub const CRITICAL: &str = "🔴";
30    pub const HIGH: &str = "🟠";
31    pub const MEDIUM: &str = "🟡";
32    pub const LOW: &str = "🟢";
33    pub const KUBERNETES: &str = "☸";
34    pub const HELM: &str = "⎈";
35}
36
37/// ANSI escape codes for direct terminal control
38pub mod ansi {
39    /// Clear current line
40    pub const CLEAR_LINE: &str = "\x1b[2K\r";
41    /// Move cursor up one line
42    pub const CURSOR_UP: &str = "\x1b[1A";
43    /// Hide cursor
44    pub const HIDE_CURSOR: &str = "\x1b[?25l";
45    /// Show cursor
46    pub const SHOW_CURSOR: &str = "\x1b[?25h";
47    /// Reset all styles
48    pub const RESET: &str = "\x1b[0m";
49    /// Bold
50    pub const BOLD: &str = "\x1b[1m";
51    /// Dim
52    pub const DIM: &str = "\x1b[2m";
53
54    // 256-color codes for Syncable brand
55    pub const PURPLE: &str = "\x1b[38;5;141m";
56    pub const ORANGE: &str = "\x1b[38;5;216m";
57    pub const PINK: &str = "\x1b[38;5;212m";
58    pub const MAGENTA: &str = "\x1b[38;5;207m";
59    pub const CYAN: &str = "\x1b[38;5;51m";
60    pub const GRAY: &str = "\x1b[38;5;245m";
61    pub const WHITE: &str = "\x1b[38;5;255m";
62    pub const SUCCESS: &str = "\x1b[38;5;114m"; // Green for success
63
64    // Hadolint/Docker specific colors (teal/docker-blue theme)
65    pub const DOCKER_BLUE: &str = "\x1b[38;5;39m"; // Docker brand blue
66    pub const TEAL: &str = "\x1b[38;5;30m"; // Teal for hadolint
67    pub const CRITICAL: &str = "\x1b[38;5;196m"; // Bright red
68    pub const HIGH: &str = "\x1b[38;5;208m"; // Orange
69    pub const MEDIUM: &str = "\x1b[38;5;220m"; // Yellow
70    pub const LOW: &str = "\x1b[38;5;114m"; // Green
71    pub const INFO_BLUE: &str = "\x1b[38;5;75m"; // Light blue for info
72}
73
74/// Format a tool name for display
75pub fn format_tool_name(name: &str) -> String {
76    name.cyan().bold().to_string()
77}
78
79/// Format a status message based on success/failure
80pub fn format_status(success: bool, message: &str) -> String {
81    if success {
82        format!("{} {}", icons::SUCCESS.green(), message.green())
83    } else {
84        format!("{} {}", icons::ERROR.red(), message.red())
85    }
86}
87
88/// Format elapsed time for display
89pub fn format_elapsed(seconds: u64) -> String {
90    if seconds < 60 {
91        format!("{}s", seconds)
92    } else {
93        let mins = seconds / 60;
94        let secs = seconds % 60;
95        format!("{}m {}s", mins, secs)
96    }
97}
98
99/// Format a thinking/reasoning message
100pub fn format_thinking(subject: &str) -> String {
101    format!("{} {}", icons::THINKING, subject.cyan().italic())
102}
103
104/// Format an info message
105pub fn format_info(message: &str) -> String {
106    format!("{} {}", icons::ARROW.cyan(), message)
107}
108
109/// Format a warning message
110pub fn format_warning(message: &str) -> String {
111    format!("⚠ {}", message.yellow())
112}
113
114/// Format an error message
115pub fn format_error(message: &str) -> String {
116    format!("{} {}", icons::ERROR.red(), message.red())
117}
118
119#[cfg(test)]
120mod tests {
121    use super::*;
122
123    #[test]
124    fn test_format_elapsed() {
125        assert_eq!(format_elapsed(5), "5s");
126        assert_eq!(format_elapsed(30), "30s");
127        assert_eq!(format_elapsed(65), "1m 5s");
128        assert_eq!(format_elapsed(125), "2m 5s");
129    }
130}