git_commit_helper_cli/
terminal_format.rs1use std::io::{self, Write};
5
6pub struct Style;
7
8impl Style {
9 pub const RESET: &'static str = "\x1b[0m";
10 pub const BOLD: &'static str = "\x1b[1m";
11 pub const BLUE: &'static str = "\x1b[34m";
12 pub const BRIGHT_BLUE: &'static str = "\x1b[94m";
13 pub const BRIGHT_GREEN: &'static str = "\x1b[92m";
14 pub const BRIGHT_YELLOW: &'static str = "\x1b[93m";
15 pub const BRIGHT_RED: &'static str = "\x1b[91m";
16 pub const GRAY: &'static str = "\x1b[90m";
17
18 pub fn separator() -> String {
20 format!("{}{}───────────────────────────────────────────────{}\n", Self::GRAY, Self::BOLD, Self::RESET)
21 }
22
23 pub fn title(text: &str) -> String {
25 format!("{}{}{}{}{}", Self::BRIGHT_BLUE, Self::BOLD, text, Self::RESET, "\n")
26 }
27
28 pub fn green(text: &str) -> String {
30 format!("{}{}{}{}", Self::BRIGHT_GREEN, text, Self::RESET, "\n")
31 }
32
33 pub fn blue(text: &str) -> String {
35 format!("{}{}{}{}", Self::BLUE, text, Self::RESET, "\n")
36 }
37
38 pub fn yellow(text: &str) -> String {
40 format!("{}{}{}{}", Self::BRIGHT_YELLOW, text, Self::RESET, "\n")
41 }
42
43 pub fn red(text: &str) -> String {
45 format!("{}{}{}{}", Self::BRIGHT_RED, text, Self::RESET, "\n")
46 }
47
48 pub fn plain(text: &str) -> String {
50 format!("{}{}", text, "\n")
51 }
52}
53
54pub fn print_progress(msg: &str, percent: Option<u8>) {
59 let progress = match percent {
61 Some(p) => format!(" {}%...", p),
62 None => " ...".to_string(),
63 };
64 let text = format!("\r{}{}{}", msg, progress, " ");
66 print!("{}", text);
67 io::stdout().flush().ok();
68}