bacon/tty/
mod.rs

1mod tline;
2mod tline_builder;
3mod trange;
4mod tstring;
5
6pub const CSI_RESET: &str = "\u{1b}[0m";
7pub const CSI_BOLD: &str = "\u{1b}[1m";
8pub const CSI_ITALIC: &str = "\u{1b}[3m";
9
10pub const CSI_GREEN: &str = "\u{1b}[32m";
11
12pub const CSI_RED: &str = "\u{1b}[31m";
13pub const CSI_BOLD_RED: &str = "\u{1b}[1m\u{1b}[38;5;9m";
14pub const CSI_BOLD_4BIT_RED: &str = "\u{1b}[1m\u{1b}[91m";
15pub const CSI_BOLD_ORANGE: &str = "\u{1b}[1m\u{1b}[38;5;208m";
16pub const CSI_BOLD_GREEN: &str = "\u{1b}[1m\u{1b}[38;5;34m";
17
18/// Used for "Blocking"
19pub const CSI_BLUE: &str = "\u{1b}[1m\u{1b}[36m";
20
21#[cfg(windows)]
22pub const CSI_BOLD_YELLOW: &str = "\u{1b}[1m\u{1b}[38;5;11m";
23#[cfg(not(windows))]
24pub const CSI_BOLD_YELLOW: &str = "\u{1b}[1m\u{1b}[33m";
25
26#[cfg(windows)]
27pub const CSI_BOLD_BLUE: &str = "\u{1b}[1m\u{1b}[38;5;14m";
28#[cfg(not(windows))]
29pub const CSI_BOLD_BLUE: &str = "\u{1b}[1m\u{1b}[38;5;12m";
30pub const CSI_BOLD_4BIT_BLUE: &str = "\u{1b}[1m\u{1b}[94m";
31
32#[cfg(windows)]
33pub const CSI_BOLD_4BIT_YELLOW: &str = "\u{1b}[1m\u{1b}[33m";
34
35#[cfg(windows)]
36pub const CSI_BOLD_WHITE: &str = "\u{1b}[1m\u{1b}[38;5;15m";
37
38static TAB_REPLACEMENT: &str = "    ";
39
40use {
41    crate::W,
42    anyhow::Result,
43    std::io::Write,
44};
45
46pub use {
47    tline::*,
48    tline_builder::*,
49    trange::*,
50    tstring::*,
51};
52
53pub fn draw(
54    w: &mut W,
55    csi: &str,
56    raw: &str,
57) -> Result<()> {
58    if csi.is_empty() {
59        write!(w, "{raw}")?;
60    } else {
61        write!(w, "{csi}{raw}{CSI_RESET}")?;
62    }
63    Ok(())
64}
65pub fn csi(
66    fg: u8,
67    bg: u8,
68) -> String {
69    format!("\u{1b}[1m\u{1b}[38;5;{fg}m\u{1b}[48;5;{bg}m")
70}