mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-03 05:54:33 +00:00
chore: add StyledStr::destyle
This commit is contained in:
parent
e1adb8d118
commit
f6144b29a2
2 changed files with 36 additions and 1 deletions
|
@ -162,6 +162,20 @@ impl Color {
|
||||||
Color::White => WHITE,
|
Color::White => WHITE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn decolor(colored: &str) -> &str {
|
||||||
|
colored
|
||||||
|
.trim_end_matches(RESET)
|
||||||
|
.trim_start_matches(BLACK)
|
||||||
|
.trim_start_matches(BLUE)
|
||||||
|
.trim_start_matches(CYAN)
|
||||||
|
.trim_start_matches(GRAY)
|
||||||
|
.trim_start_matches(GREEN)
|
||||||
|
.trim_start_matches(MAGENTA)
|
||||||
|
.trim_start_matches(RED)
|
||||||
|
.trim_start_matches(YELLOW)
|
||||||
|
.trim_start_matches(WHITE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Hash)]
|
||||||
|
@ -181,6 +195,14 @@ impl Attribute {
|
||||||
Attribute::Reversed => REVERSED,
|
Attribute::Reversed => REVERSED,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn deattr(attributed: &str) -> &str {
|
||||||
|
attributed
|
||||||
|
.trim_end_matches(ATTR_RESET)
|
||||||
|
.trim_start_matches(UNDERLINE)
|
||||||
|
.trim_start_matches(BOLD)
|
||||||
|
.trim_start_matches(REVERSED)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
@ -347,6 +369,10 @@ impl<'a> StyledStr<'a> {
|
||||||
attribute,
|
attribute,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn destyle(styled: &str) -> &str {
|
||||||
|
Attribute::deattr(Color::decolor(styled))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for StyledStr<'_> {
|
impl std::fmt::Display for StyledStr<'_> {
|
||||||
|
|
|
@ -1,9 +1,18 @@
|
||||||
.available_zones: Set Str, _
|
.available_timezones: () -> Set(Str, _)
|
||||||
|
.reset_tzpath!: (to := Sequence(Str) or PathLike) => NoneType
|
||||||
.TZPATH: [Str; _]
|
.TZPATH: [Str; _]
|
||||||
|
|
||||||
|
.ZoneInfoNotFoundError: ClassType
|
||||||
|
.ZoneInfoNotFoundError <: Exception
|
||||||
|
|
||||||
|
.InvalidTZPathWarning: ClassType
|
||||||
|
.InvalidTZPathWarning <: Warning
|
||||||
|
|
||||||
.ZoneInfo: ClassType
|
.ZoneInfo: ClassType
|
||||||
.ZoneInfo.
|
.ZoneInfo.
|
||||||
key: Str
|
key: Str
|
||||||
__call__: (key: Str) -> .ZoneInfo
|
__call__: (key: Str) -> .ZoneInfo
|
||||||
from_file: (fobj: FileLike, key := Str) -> .ZoneInfo
|
from_file: (fobj: FileLike, key := Str) -> .ZoneInfo
|
||||||
|
no_cache: (key: Str) -> .ZoneInfo
|
||||||
|
clear_cache!: () => NoneType
|
||||||
__str__: (self: .ZoneInfo) -> Str
|
__str__: (self: .ZoneInfo) -> Str
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue