Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/setup/prompts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,20 @@ pub fn confirm(prompt: &str, default: bool) -> io::Result<bool> {
})
}

/// Print the IronClaw ASCII art banner in blue.
pub fn print_banner() {
let mut stdout = io::stdout();
let _ = execute!(stdout, SetForegroundColor(Color::Cyan));
println!();
println!(r" ██╗██████╗ ██████╗ ███╗ ██╗ ██████╗██╗ █████╗ ██╗ ██╗");
println!(r" ██║██╔══██╗██╔═══██╗████╗ ██║██╔════╝██║ ██╔══██╗██║ ██║");
println!(r" ██║██████╔╝██║ ██║██╔██╗ ██║██║ ██║ ███████║██║ █╗ ██║");
println!(r" ██║██╔══██╗██║ ██║██║╚██╗██║██║ ██║ ██╔══██║██║███╗██║");
println!(r" ██║██║ ██║╚██████╔╝██║ ╚████║╚██████╗███████╗██║ ██║╚███╔███╔╝");
println!(r" ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝╚══════╝╚═╝ ╚═╝ ╚══╝╚══╝ ");
let _ = execute!(stdout, ResetColor);
}
Comment on lines +263 to +275

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This implementation isn't fully panic-safe. If any of the println! macros were to panic (e.g., due to a broken pipe when writing to stdout), the ResetColor command at the end would not be executed, leaving the user's terminal in a colored state.

Additionally, the doc comment says the banner is 'blue', but the code uses Color::Cyan.

To improve robustness and fix the documentation, I suggest using a simple RAII guard to ensure the color is always reset. This is a common pattern in Rust for cleanup logic.

/// Print the IronClaw ASCII art banner in cyan.
pub fn print_banner() {
    struct ResetGuard;
    impl Drop for ResetGuard {
        fn drop(&mut self) {
            // Best-effort attempt to reset terminal color.
            let _ = execute!(io::stdout(), ResetColor);
        }
    }

    let mut stdout = io::stdout();
    // Setting color can fail, but we'll try to reset anyway.
    let _ = execute!(stdout, SetForegroundColor(Color::Cyan));
    let _guard = ResetGuard;

    println!();
    println!(r" ██╗██████╗  ██████╗ ███╗   ██╗ ██████╗██╗      █████╗ ██╗    ██╗");
    println!(r" ██║██╔══██╗██╔═══██╗████╗  ██║██╔════╝██║     ██╔══██╗██║    ██║");
    println!(r" ██║██████╔╝██║   ██║██╔██╗ ██║██║     ██║     ███████║██║ █╗ ██║");
    println!(r" ██║██╔══██╗██║   ██║██║╚██╗██║██║     ██║     ██╔══██║██║███╗██║");
    println!(r" ██║██║  ██║╚██████╔╝██║ ╚██████║╚██████╗███████╗██║  ██║╚███╔███╔╝");
    println!(r" ╚═╝╚═╝  ╚═╝ ╚═════╝ ╚═╝  ╚═══╝ ╚═════╝╚══════╝╚═╝  ╚═╝ ╚══╝╚══╝ ");
}


/// Print a styled header box.
///
/// # Example
Expand Down
5 changes: 3 additions & 2 deletions src/setup/wizard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ use crate::setup::channels::{
SecretsContext, setup_http, setup_signal, setup_tunnel, setup_wasm_channel,
};
use crate::setup::prompts::{
confirm, input, optional_input, print_error, print_header, print_info, print_step,
print_success, secret_input, select_many, select_one,
confirm, input, optional_input, print_banner, print_error, print_header, print_info,
print_step, print_success, secret_input, select_many, select_one,
};

// unused const, keep commented for clarity / future use
Expand Down Expand Up @@ -139,6 +139,7 @@ impl SetupWizard {
/// settings are loaded from the database after Step 1 establishes a
/// connection, so users don't have to re-enter everything.
pub async fn run(&mut self) -> Result<(), SetupError> {
print_banner();
print_header("IronClaw Setup Wizard");

if self.config.channels_only {
Expand Down