fundaia 0.52.3

Command line for the Fundaia deployment platform: projects, services, variables, deployments, logs and metrics
use std::io::{IsTerminal, Write};

pub struct ProgressLine {
    interactive: bool,
    drawn: bool,
}

impl ProgressLine {
    pub fn new(json: bool) -> Self {
        Self {
            interactive: !json && std::io::stdout().is_terminal(),
            drawn: false,
        }
    }

    pub fn draw(&mut self, text: &str) {
        if !self.interactive {
            return;
        }
        print!("\r\u{1b}[2K{text}");
        let _ = std::io::stdout().flush();
        self.drawn = true;
    }

    pub fn clear(&mut self) {
        if self.drawn {
            print!("\r\u{1b}[2K");
            let _ = std::io::stdout().flush();
            self.drawn = false;
        }
    }
}