no not released yet? cmon
This commit is contained in:
1 parent
4bb27986a0
commit
fb6e6dfefd
3 files changed
+21
-13
No files matched your search
+14
-3
@@ -15,7 +15,8 @@ impl AnsiCodes {
|
||||
}
|
||||
impl Display for AnsiCodes {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
if self.codes.is_empty() { // optim?
|
||||
if self.codes.is_empty() {
|
||||
// optim?
|
||||
return write!(f, "");
|
||||
}
|
||||
write!(
|
||||
@@ -42,6 +43,8 @@ impl ColorTrait for ansi_colors::Color {}
|
||||
|
||||
// }
|
||||
// }
|
||||
pub trait StyleTrait {}
|
||||
impl StyleTrait for AnsiStyle {}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Style {
|
||||
@@ -52,7 +55,12 @@ impl From<Style> for Vec<u8> {
|
||||
value.inner
|
||||
}
|
||||
}
|
||||
pub trait StyleTrait {}
|
||||
|
||||
impl Default for Style {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
// honestly it could work
|
||||
impl Style {
|
||||
@@ -66,7 +74,10 @@ impl Style {
|
||||
self.inner.append(&mut color.into());
|
||||
self // does this clear color.inner?
|
||||
}
|
||||
pub fn style(&mut self, style: AnsiStyle) -> &mut Self {
|
||||
pub fn style<T: StyleTrait>(&mut self, style: T) -> &mut Self
|
||||
where
|
||||
u8: From<T>,
|
||||
{
|
||||
self.inner.push(style.into());
|
||||
self
|
||||
}
|
||||
|
||||
@@ -154,10 +154,7 @@ impl Color {
|
||||
// debug_assert!(self.validate_mode().is_ok(), "Invalid color mode"); // IT IS IN self.codes() DO NOT
|
||||
let v = self.codes();
|
||||
let Some(a) = v.first() else { unreachable!() };
|
||||
match a {
|
||||
38 | 48 => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(a, 38 | 48)
|
||||
}
|
||||
/// if already custom then none
|
||||
/// also can not convert default
|
||||
@@ -182,7 +179,7 @@ impl Color {
|
||||
code + if bright { 8 } else { 0 },
|
||||
])
|
||||
})?;
|
||||
Some(Color::try_from(code).ok()?)
|
||||
Color::try_from(code).ok()
|
||||
}
|
||||
|
||||
pub fn codes(&self) -> Vec<u8> {
|
||||
|
||||
@@ -11,7 +11,7 @@ impl From<Color> for ColorConstruct {
|
||||
}
|
||||
impl From<ColorConstruct> for CustomColor {
|
||||
fn from(value: ColorConstruct) -> Self {
|
||||
value.to_custom()
|
||||
value.custom()
|
||||
}
|
||||
}
|
||||
impl From<ColorConstruct> for ColorType {
|
||||
@@ -35,10 +35,10 @@ impl ColorConstruct {
|
||||
self.is_bright = true;
|
||||
self
|
||||
}
|
||||
fn to_custom(&self) -> CustomColor {
|
||||
fn custom(&self) -> CustomColor {
|
||||
let mut val = self.color.value();
|
||||
if self.is_bright {
|
||||
val = val + 8
|
||||
val += 8
|
||||
}
|
||||
CustomColor::Color256(val)
|
||||
}
|
||||
@@ -119,11 +119,11 @@ impl AnsiColor {
|
||||
_ => self,
|
||||
}
|
||||
}
|
||||
pub fn to_custom(self) -> Self {
|
||||
pub fn custom(self) -> Self {
|
||||
match self.color {
|
||||
ColorType::CustomColor(_) => self,
|
||||
ColorType::BasicColor(c) => {
|
||||
let d = c.to_custom();
|
||||
let d = c.custom();
|
||||
Self {
|
||||
color: d.into(),
|
||||
..self
|
||||
|
||||
Reference in new issue
Block a user