Compare commits
1
Commits
7895660ba9
...
b26cdf9f3f
No files matched your search
+14
-9
@@ -47,23 +47,25 @@ pub trait StyleTrait {}
|
||||
impl StyleTrait for AnsiStyle {}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Style {
|
||||
pub struct StyleConstruct {
|
||||
pub(super) inner: Vec<u8>,
|
||||
}
|
||||
impl From<Style> for Vec<u8> {
|
||||
fn from(value: Style) -> Self {
|
||||
value.inner
|
||||
|
||||
// why do i need this impl
|
||||
impl From<StyleConstruct> for Vec<u8> {
|
||||
fn from(value: StyleConstruct) -> Self {
|
||||
value.into_inner()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Style {
|
||||
impl Default for StyleConstruct {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
// honestly it could work
|
||||
impl Style {
|
||||
impl StyleConstruct {
|
||||
pub fn new() -> Self {
|
||||
Self { inner: Vec::new() }
|
||||
}
|
||||
@@ -81,15 +83,18 @@ impl Style {
|
||||
self.inner.push(style.into());
|
||||
self
|
||||
}
|
||||
pub fn into_inner(self) -> Vec<u8> {
|
||||
self.inner
|
||||
}
|
||||
impl Display for Style {
|
||||
}
|
||||
impl Display for StyleConstruct {
|
||||
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 {
|
||||
impl From<Vec<StyleConstruct>> for AnsiCodes {
|
||||
fn from(value: Vec<StyleConstruct>) -> Self {
|
||||
Self {
|
||||
prefix: AnsiCodes::ESCAPE.into(),
|
||||
suffix: Self::STYLE_SUFFIX.into(),
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use std::{error::Error, fmt::{Debug, Display}};
|
||||
use std::{
|
||||
error::Error,
|
||||
fmt::{Debug, Display},
|
||||
};
|
||||
|
||||
// use crate::ansi_colors_2::Color;
|
||||
|
||||
|
||||
@@ -90,9 +90,7 @@ impl ldaValue<Vec<u8>> for AnsiColor {
|
||||
ColorType::CustomColor(v) => v.value(),
|
||||
};
|
||||
|
||||
let code = vect
|
||||
.first_mut()
|
||||
.expect("no code found, bad init");
|
||||
let code = vect.first_mut().expect("no code found, bad init");
|
||||
*code += if self.is_bg { 40 } else { 30 };
|
||||
|
||||
vect
|
||||
|
||||
@@ -49,7 +49,6 @@ impl From<Style> for u8 {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl std::ops::Not for Style {
|
||||
type Output = Self;
|
||||
fn not(self) -> Self::Output {
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
pub use crate::{
|
||||
ansi_backbone::StyleConstruct,
|
||||
ansi_colors_2::{ansi_color_interface::ColorContext, Color, CustomColor},
|
||||
ansi_styles::Style,
|
||||
AnsiStyles,
|
||||
};
|
||||
+7
-7
@@ -7,16 +7,14 @@ pub mod ansi_colors;
|
||||
pub mod ansi_colors_2;
|
||||
pub mod ansi_styles; // here so ide dont dim code
|
||||
|
||||
|
||||
pub mod ansi_backbone;
|
||||
use ansi_backbone::{AnsiCodes, Style}; // ColorTrait,
|
||||
use ansi_backbone::{AnsiCodes, StyleConstruct}; // ColorTrait,
|
||||
|
||||
mod test;
|
||||
/// text as text and styles will be turned to [`AnsiCodes`]
|
||||
#[derive(Clone)]
|
||||
pub struct AnsiStyles {
|
||||
pub text: String,
|
||||
styles: Vec<Style>, // no
|
||||
styles: Vec<StyleConstruct>, // no
|
||||
}
|
||||
impl Default for AnsiStyles {
|
||||
fn default() -> Self {
|
||||
@@ -36,16 +34,16 @@ impl AnsiStyles {
|
||||
styles: Vec::new(),
|
||||
}
|
||||
}
|
||||
pub fn add_style(&mut self, style: &Style) -> &mut Self {
|
||||
pub fn add_style(&mut self, style: &StyleConstruct) -> &mut Self {
|
||||
self.styles.push(style.clone());
|
||||
self
|
||||
}
|
||||
// chaining support
|
||||
pub fn style(mut self, style: Style) -> Self {
|
||||
pub fn style(mut self, style: StyleConstruct) -> Self {
|
||||
self.add_style(&style);
|
||||
self
|
||||
}
|
||||
pub fn clone_with_style(&mut self,style: Style) -> Self {
|
||||
pub fn clone_with_style(&mut self, style: StyleConstruct) -> Self {
|
||||
let c = self.clone();
|
||||
c.style(style)
|
||||
}
|
||||
@@ -65,3 +63,5 @@ impl From<AnsiStyles> for String {
|
||||
format!("{value}") // wow
|
||||
}
|
||||
}
|
||||
|
||||
pub mod import;
|
||||
+3
-1
@@ -1,5 +1,7 @@
|
||||
use lda_ansi::ansi_colors::Color;
|
||||
use lda_ansi::ansi_colors_2::{Color as Color2, CustomColor as CustomColor2, ansi_color_interface::ColorContext};
|
||||
use lda_ansi::ansi_colors_2::{
|
||||
ansi_color_interface::ColorContext, Color as Color2, CustomColor as CustomColor2,
|
||||
};
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn main() {
|
||||
|
||||
+11
-10
@@ -3,8 +3,6 @@
|
||||
//!
|
||||
//! copilot chat teach me how to do stuff (all code made by copilot chat)
|
||||
|
||||
|
||||
#![cfg(test)]
|
||||
use ansi_colors::Color;
|
||||
use ansi_colors_2::{
|
||||
ansi_color_interface::ColorContext as Color2Context,
|
||||
@@ -13,12 +11,13 @@ use ansi_colors_2::{
|
||||
// CustomColor as CustomColor2,
|
||||
};
|
||||
use ansi_styles::Style as AnsiStyle;
|
||||
use lda_ansi::{ansi_colors, ansi_colors_2, ansi_styles};
|
||||
use std::collections::HashSet;
|
||||
|
||||
// use ansi_colors_2::ansi_color_interface::ColorContext as _;
|
||||
|
||||
use ansi_colors::color_error::ColorError;
|
||||
use super::*;
|
||||
// use super::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct CodeError;
|
||||
@@ -80,7 +79,6 @@ fn process_codes(codes: &[u8]) -> Result<(HashSet<u8>, HashSet<Vec<u8>>), CodeEr
|
||||
Ok((set, groups))
|
||||
}
|
||||
|
||||
|
||||
fn process_codes2(codes: &[u8]) -> Result<(HashSet<u8>, HashSet<Vec<u8>>), ColorError> {
|
||||
let mut set = HashSet::new();
|
||||
let mut groups = HashSet::new();
|
||||
@@ -95,7 +93,8 @@ fn process_codes2(codes: &[u8]) -> Result<(HashSet<u8>, HashSet<Vec<u8>>), Color
|
||||
this.push(*colop);
|
||||
match colop {
|
||||
2 => {
|
||||
let group: Vec<_> = enumerate_codes.by_ref().take(3).map(|(_, &v)| v).collect(); // by ref is big
|
||||
let group: Vec<_> =
|
||||
enumerate_codes.by_ref().take(3).map(|(_, &v)| v).collect(); // by ref is big
|
||||
if group.len() == 3 {
|
||||
this.extend(group);
|
||||
} else {
|
||||
@@ -136,8 +135,8 @@ pub fn compare_ansi_codes(actual: &[u8], expected: &[u8]) -> Result<bool, ColorE
|
||||
fn test_normal_use() {
|
||||
// what kinda shit
|
||||
|
||||
let mut builder = AnsiStyles::init("what is going on here");
|
||||
let mut error_style = Style::new();
|
||||
let mut builder = lda_ansi::AnsiStyles::init("what is going on here");
|
||||
let mut error_style = lda_ansi::ansi_backbone::StyleConstruct::new();
|
||||
error_style
|
||||
.color(Color2::Red.fg().bright()) // 91
|
||||
.color(Color::custom_256(232).bg()) // 48;5;232
|
||||
@@ -145,11 +144,13 @@ fn test_normal_use() {
|
||||
.style(AnsiStyle::BlinkFast); // 6
|
||||
builder.add_style(&error_style);
|
||||
//mut
|
||||
let reset_style = Style::new().style(AnsiStyle::Reset).to_owned();
|
||||
let reset_style = lda_ansi::ansi_backbone::StyleConstruct::new()
|
||||
.style(AnsiStyle::Reset)
|
||||
.to_owned();
|
||||
println!("{builder}{reset_style}"); // good so far
|
||||
let error_estimate: Vec<u8> = vec![6, 1, 91, 48, 5, 232]; // 48, 5, 232 sticks together in a clump
|
||||
let reset_estimate: Vec<u8> = vec![0];
|
||||
|
||||
assert!(compare_ansi_codes(&error_style.clone().inner, &error_estimate).unwrap());
|
||||
assert!(compare_ansi_codes(&reset_style.clone().inner, &reset_estimate).unwrap());
|
||||
assert!(compare_ansi_codes(&error_style.clone().into_inner(), &error_estimate).unwrap());
|
||||
assert!(compare_ansi_codes(&reset_style.clone().into_inner(), &reset_estimate).unwrap());
|
||||
}
|
||||
Reference in new issue
Block a user