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