Skip to main content

xcodeai/
ui.rs

1// src/ui.rs
2// Styling helpers for xcodeai CLI output.
3// Extracted from main.rs for clarity and reuse.
4//
5// These functions handle colored output, banners, separators, and status messages.
6// They are used in both the CLI entrypoint and the REPL loop.
7//
8// For Rust learners: This module demonstrates how to use the `console` crate for styled terminal output.
9
10use console::{style, Term};
11
12/// Print the xcodeai banner at startup, showing version, model, project, and auth status.
13pub fn print_banner(version: &str, model: &str, project: &str, auth_status: &str) {
14    let term = Term::stdout();
15    let width = term.size().1 as usize;
16    let width = width.clamp(60, 100);
17    let line = style("─".repeat(width)).dim().to_string();
18
19    println!();
20    println!(
21        " {} {}  {}  {}",
22        style("✦").cyan().bold(),
23        style("xcodeai").cyan().bold(),
24        style(format!("v{}", version)).dim(),
25        style("autonomous AI coding agent").dim(),
26    );
27    println!(
28        "   {} {}    {} {}",
29        style("model:").dim(),
30        style(model).green(),
31        style("project:").dim(),
32        style(project).yellow(),
33    );
34    println!("   {} {}", style("auth:").dim(), auth_status,);
35    println!("{}", line);
36    println!(
37        "   {}",
38        style("Type a task and press Enter.  /plan to discuss first.  /help for commands.  Ctrl-D to quit.").dim()
39    );
40    println!("{}", line);
41    println!();
42}
43
44/// Print a separator line, optionally with a label.
45pub fn print_separator(label: &str) {
46    let label_str = if label.is_empty() {
47        style("─".repeat(44)).dim().to_string()
48    } else {
49        format!(
50            "{} {} {}",
51            style("─".repeat(2)).dim(),
52            style(label).dim(),
53            style("─".repeat(40 - label.len().min(38))).dim()
54        )
55    };
56    println!("{}", label_str);
57}
58
59/// Print a success message with a green checkmark.
60pub fn ok(msg: &str) {
61    println!(" {} {}", style("✓").green().bold(), msg);
62}
63
64/// Print a warning message with a yellow exclamation mark.
65pub fn warn(msg: &str) {
66    println!(" {} {}", style("!").yellow().bold(), style(msg).yellow());
67}
68
69/// Print an error message with a red cross.
70pub fn err(msg: &str) {
71    eprintln!(" {} {}", style("✗").red().bold(), style(msg).red());
72}
73
74/// Print an informational message in dim text.
75pub fn info(msg: &str) {
76    println!("   {}", style(msg).dim());
77}