mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 02:39:20 +00:00
update: colors mod and feature
This commit is contained in:
parent
eaded7ac5d
commit
db12bb1e2d
1 changed files with 32 additions and 45 deletions
|
@ -1,29 +1,44 @@
|
|||
use self::colors::*;
|
||||
use std::borrow::Cow;
|
||||
|
||||
pub const ATTR_RESET: &str = "\x1b[0m";
|
||||
pub const BOLD: &str = "\x1b[1m";
|
||||
pub const UNDERLINE: &str = "\x1b[4m";
|
||||
pub const REVERSED: &str = "\x1b[7m";
|
||||
pub const RESET: &str = "\x1b[m";
|
||||
|
||||
// Escape sequences change the color of the terminal
|
||||
pub const RESET: &str = "\x1b[m";
|
||||
pub const BLACK: &str = "\x1b[30m";
|
||||
pub const BLUE: &str = "\x1b[94m";
|
||||
pub const CYAN: &str = "\x1b[96m";
|
||||
pub const GRAY: &str = "\x1b[37m";
|
||||
pub const GREEN: &str = "\x1b[92m";
|
||||
pub const MAGENTA: &str = "\x1b[95m";
|
||||
pub const RED: &str = "\x1b[91m";
|
||||
pub const WHITE: &str = "\x1b[97m";
|
||||
pub const YELLOW: &str = "\x1b[93m";
|
||||
#[cfg(not(feature = "pretty"))]
|
||||
pub mod colors {
|
||||
pub const BLACK: &str = "\x1b[30m";
|
||||
pub const BLUE: &str = "\x1b[94m";
|
||||
pub const CYAN: &str = "\x1b[96m";
|
||||
pub const GRAY: &str = "\x1b[37m";
|
||||
pub const GREEN: &str = "\x1b[92m";
|
||||
pub const MAGENTA: &str = "\x1b[95m";
|
||||
pub const RED: &str = "\x1b[91m";
|
||||
pub const WHITE: &str = "\x1b[97m";
|
||||
pub const YELLOW: &str = "\x1b[93m";
|
||||
pub const DEBUG_MAIN: &str = GREEN;
|
||||
pub const DEBUG: &str = CYAN;
|
||||
pub const DEBUG_ERROR: &str = RED;
|
||||
}
|
||||
// custom colors when use `pretty`
|
||||
pub const CUSTOM_RED: &str = "\x1b[38;2;255;76;76m";
|
||||
pub const CUSTOM_BLUE: &str = "\x1b[38;2;76;76;255m";
|
||||
pub const CUSTOM_GRAY: &str = "\x1b[38;2;231;231;235m";
|
||||
pub const CUSTOM_CYAN: &str = "\x1b[38;2;76;255;255m";
|
||||
pub const CUSTOM_MAGENTA: &str = "\x1b[38;2;165;76;255m";
|
||||
pub const CUSTOM_GREEN: &str = "\x1b[38;2;76;255;76m";
|
||||
pub const CUSTOM_YELLOW: &str = "\x1b[38;2;255;255;76m";
|
||||
#[cfg(feature = "pretty")]
|
||||
pub mod colors {
|
||||
pub const BLACK: &str = "\x1b[30m";
|
||||
pub const BLUE: &str = "\x1b[38;2;76;76;255m";
|
||||
pub const CYAN: &str = "\x1b[38;2;76;255;255m";
|
||||
pub const GRAY: &str = "\x1b[38;2;231;231;235m";
|
||||
pub const GREEN: &str = "\x1b[38;2;76;255;76m";
|
||||
pub const MAGENTA: &str = "\x1b[38;2;165;76;255m";
|
||||
pub const RED: &str = "\x1b[38;2;255;76;76m";
|
||||
pub const WHITE: &str = "\x1b[97m";
|
||||
pub const YELLOW: &str = "\x1b[38;2;255;255;76m";
|
||||
pub const DEBUG_MAIN: &str = BLUE;
|
||||
pub const DEBUG: &str = MAGENTA;
|
||||
pub const DEBUG_ERROR: &str = CYAN;
|
||||
}
|
||||
|
||||
pub fn remove_style(s: &str) -> String {
|
||||
s.replace(RED, "")
|
||||
|
@ -53,13 +68,6 @@ pub enum Color {
|
|||
Red,
|
||||
White,
|
||||
Yellow,
|
||||
CustomRed,
|
||||
CustomBlue,
|
||||
CustomGray,
|
||||
CustomCyan,
|
||||
CustomMagenta,
|
||||
CustomGreen,
|
||||
CustomYellow,
|
||||
}
|
||||
|
||||
impl Color {
|
||||
|
@ -75,13 +83,6 @@ impl Color {
|
|||
Color::Red => RED,
|
||||
Color::Yellow => YELLOW,
|
||||
Color::White => WHITE,
|
||||
Color::CustomRed => CUSTOM_RED,
|
||||
Color::CustomBlue => CUSTOM_BLUE,
|
||||
Color::CustomGray => CUSTOM_GRAY,
|
||||
Color::CustomCyan => CUSTOM_CYAN,
|
||||
Color::CustomMagenta => CUSTOM_MAGENTA,
|
||||
Color::CustomGreen => CUSTOM_GREEN,
|
||||
Color::CustomYellow => CUSTOM_YELLOW,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,7 +116,6 @@ pub struct ThemeColors {
|
|||
pub accent: Color,
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "pretty"))]
|
||||
pub const COLORS: ThemeColors = ThemeColors {
|
||||
error: Color::Red,
|
||||
warning: Color::Yellow,
|
||||
|
@ -125,16 +125,6 @@ pub const COLORS: ThemeColors = ThemeColors {
|
|||
accent: Color::White,
|
||||
};
|
||||
|
||||
#[cfg(feature = "pretty")]
|
||||
pub const COLORS: ThemeColors = ThemeColors {
|
||||
error: Color::CustomRed,
|
||||
warning: Color::CustomYellow,
|
||||
exception: Color::CustomMagenta,
|
||||
gutter: Color::CustomCyan,
|
||||
hint: Color::CustomGreen,
|
||||
accent: Color::CustomGray,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Characters {
|
||||
hat: char, // error
|
||||
|
@ -524,9 +514,6 @@ mod tests {
|
|||
println!("{BLUE}Hello{RESET}, {GREEN}World{RESET}");
|
||||
println!("{MAGENTA}Hello{RESET}, {BLACK}World{RESET}");
|
||||
println!("{GRAY}Hello{RESET}, {WHITE}World{RESET}");
|
||||
println!("{CUSTOM_BLUE}Hello{RESET}, {CUSTOM_CYAN}World{RESET}");
|
||||
println!("{CUSTOM_GRAY}Hello{RESET}, {CUSTOM_GREEN}World{RESET}");
|
||||
println!("{CUSTOM_MAGENTA}Hello{RESET}, {CUSTOM_RED}World{RESET}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue