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