Compare commits

..
1 Commits
3 changed files with 20 additions and 10 deletions

No files matched your search

+10 -7
View File
@@ -1,7 +1,7 @@
use std::fmt::Display;
use crate::{ansi_colors, ansi_colors_2};
use crate::ansi_styles::Style as AnsiStyle;
use crate::{ansi_colors, ansi_colors_2};
#[derive(Clone)]
pub struct AnsiCodes {
pub prefix: String,
@@ -15,6 +15,9 @@ impl AnsiCodes {
}
impl Display for AnsiCodes {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.codes.is_empty() { // optim?
return write!(f, "");
}
write!(
f,
"{}{}{}",
@@ -53,8 +56,8 @@ pub trait StyleTrait {}
// honestly it could work
impl Style {
pub fn new() -> Self{
Self{inner: Vec::new()}
pub fn new() -> Self {
Self { inner: Vec::new() }
}
pub fn color<T: ColorTrait>(&mut self, color: T) -> &mut Self
where
@@ -69,10 +72,10 @@ impl Style {
}
}
impl Display for Style {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let a = AnsiCodes::from(vec![self.clone()]);
write!(f, "{a}")
}
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let a = AnsiCodes::from(vec![self.clone()]);
write!(f, "{a}")
}
}
impl From<Vec<Style>> for AnsiCodes {
fn from(value: Vec<Style>) -> Self {
+2
View File
@@ -5,6 +5,8 @@ pub struct ColorConstruct {
color: Color,
is_bright: bool,
}
/// do not assume context by default. because like its a color in a [`ColorConstruct`] broski
#[derive(Clone, Copy)]
pub enum Color {
Black,
+8 -3
View File
@@ -19,10 +19,10 @@ pub mod ansi_backbone;
use ansi_backbone::{AnsiCodes, ColorTrait, Style};
mod test;
/// text as text and styles will be turned to [`AnsiCodes`]
#[derive(Clone)]
struct AnsiStyles {
text: String,
pub struct AnsiStyles {
pub text: String,
styles: Vec<Style>, // no
}
@@ -59,3 +59,8 @@ impl Display for AnsiStyles {
}
}
impl From<AnsiStyles> for String {
fn from(value: AnsiStyles) -> Self {
format!("{value}") // wow
}
}