Compare commits

...
1 Commits
6 changed files with 42 additions and 31 deletions

No files matched your search

+5 -3
View File
@@ -1,12 +1,14 @@
use std::{error::Error, fmt::{Debug, Display}}; use std::{error::Error, fmt::{Debug, Display}};
use crate::ansi_colors_2::Color; // use crate::ansi_colors_2::Color;
#[derive(Debug)] #[derive(Debug)]
pub enum ColorError { pub enum ColorError {
NoCode, NoCode,
InvalidCode, // 50 for example which is for other things /// 50 for example which is for other things
InvalidMode, // not 2 or 5, or 5 but 3 element InvalidCode,
/// not 2 or 5, or 5 but 3 element
InvalidMode,
// MissingMode, // 48; invalid mode // MissingMode, // 48; invalid mode
} }
impl Display for ColorError { impl Display for ColorError {
+3 -1
View File
@@ -149,6 +149,7 @@ impl Color {
self self
} }
/// also !is_basic cuz i lazy /// also !is_basic cuz i lazy
#[allow(dead_code)]
fn is_custom(&self) -> bool { fn is_custom(&self) -> bool {
// 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();
@@ -160,6 +161,7 @@ impl Color {
} }
/// if already custom then none /// if already custom then none
/// also can not convert default /// also can not convert default
#[allow(dead_code)]
fn to_custom(&self) -> Option<Self> { fn to_custom(&self) -> Option<Self> {
if self.is_custom() { if self.is_custom() {
return None; return None;
@@ -226,7 +228,7 @@ impl PartialEq for Color {
return true; return true;
}; };
todo!(); todo!();
true // true
} }
} }
+2 -1
View File
@@ -135,7 +135,8 @@ impl AnsiColor {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::{*, super::*}; use super::*;
// , super::*};
#[test] #[test]
fn test_basic() { fn test_basic() {
+3 -4
View File
@@ -90,9 +90,9 @@ impl ldaValue<Vec<u8>> for AnsiColor {
ColorType::CustomColor(v) => v.value(), ColorType::CustomColor(v) => v.value(),
}; };
let Some(code) = vect.first_mut() else { let code = vect
panic!("no code found"); .first_mut()
}; .expect("no code found, bad init");
*code += if self.is_bg { 40 } else { 30 }; *code += if self.is_bg { 40 } else { 30 };
vect vect
@@ -120,7 +120,6 @@ impl From<AnsiColor> for Vec<u8> {
} }
} }
// copilot // copilot
// First, define a wrapper type for our values // First, define a wrapper type for our values
+9 -12
View File
@@ -1,22 +1,15 @@
#![allow(unused)]
use std::fmt::Display; use std::fmt::Display;
use ansi_colors::Color; // use ansi_colors::Color;
pub mod ansi_colors; pub mod ansi_colors;
use ansi_styles::Style as AnsiStyle; // use ansi_styles::Style as AnsiStyle;
pub mod ansi_colors_2; pub mod ansi_colors_2;
pub mod ansi_styles; // here so ide dont dim code pub mod ansi_styles; // here so ide dont dim code
use ansi_colors_2::{
// ansi_color_interface::ColorContext as Color2Context,
AnsiColor as AnsiColor2,
Color as Color2,
CustomColor as CustomColor2,
};
pub mod ansi_backbone; pub mod ansi_backbone;
use ansi_backbone::{AnsiCodes, ColorTrait, Style}; use ansi_backbone::{AnsiCodes, Style}; // ColorTrait,
mod test; mod test;
/// text as text and styles will be turned to [`AnsiCodes`] /// text as text and styles will be turned to [`AnsiCodes`]
@@ -25,7 +18,11 @@ pub struct AnsiStyles {
pub text: String, pub text: String,
styles: Vec<Style>, // no styles: Vec<Style>, // no
} }
impl Default for AnsiStyles {
fn default() -> Self {
Self::new()
}
}
impl AnsiStyles { impl AnsiStyles {
pub fn new() -> AnsiStyles { pub fn new() -> AnsiStyles {
AnsiStyles { AnsiStyles {
+20 -10
View File
@@ -5,11 +5,19 @@
#![cfg(test)] #![cfg(test)]
use ansi_colors::Color;
use ansi_colors_2::{
ansi_color_interface::ColorContext as Color2Context,
// AnsiColor as AnsiColor2,
Color as Color2,
// CustomColor as CustomColor2,
};
use ansi_styles::Style as AnsiStyle;
use std::collections::HashSet; use std::collections::HashSet;
use ansi_colors_2::ansi_color_interface::ColorContext as _; // use ansi_colors_2::ansi_color_interface::ColorContext as _;
use ansi_colors::color_error::ColorError;
use super::*; use super::*;
#[derive(Debug)] #[derive(Debug)]
@@ -23,6 +31,7 @@ impl std::fmt::Display for CodeError {
impl std::error::Error for CodeError {} // ooh impl std::error::Error for CodeError {} // ooh
#[allow(dead_code)]
fn process_codes(codes: &[u8]) -> Result<(HashSet<u8>, HashSet<Vec<u8>>), CodeError> { fn process_codes(codes: &[u8]) -> Result<(HashSet<u8>, HashSet<Vec<u8>>), CodeError> {
let mut set = HashSet::new(); let mut set = HashSet::new();
let mut groups = HashSet::new(); let mut groups = HashSet::new();
@@ -72,7 +81,7 @@ fn process_codes(codes: &[u8]) -> Result<(HashSet<u8>, HashSet<Vec<u8>>), CodeEr
} }
fn process_codes2(codes: &[u8]) -> Result<(HashSet<u8>, HashSet<Vec<u8>>), CodeError> { fn process_codes2(codes: &[u8]) -> Result<(HashSet<u8>, HashSet<Vec<u8>>), ColorError> {
let mut set = HashSet::new(); let mut set = HashSet::new();
let mut groups = HashSet::new(); let mut groups = HashSet::new();
@@ -90,20 +99,20 @@ fn process_codes2(codes: &[u8]) -> Result<(HashSet<u8>, HashSet<Vec<u8>>), CodeE
if group.len() == 3 { if group.len() == 3 {
this.extend(group); this.extend(group);
} else { } else {
return Err(CodeError); return Err(ColorError::InvalidMode);
} }
} }
5 => { 5 => {
if let Some((_, &v)) = enumerate_codes.next() { if let Some((_, &v)) = enumerate_codes.next() {
this.push(v); this.push(v);
} else { } else {
return Err(CodeError); return Err(ColorError::InvalidMode);
} }
} }
_ => return Err(CodeError), _ => return Err(ColorError::InvalidMode),
} }
} else { } else {
return Err(CodeError); return Err(ColorError::InvalidMode);
} }
groups.insert(this); groups.insert(this);
} }
@@ -116,8 +125,8 @@ fn process_codes2(codes: &[u8]) -> Result<(HashSet<u8>, HashSet<Vec<u8>>), CodeE
Ok((set, groups)) Ok((set, groups))
} }
/// if checked code beforehand (use [`ansi_colors::Color::codes()`] or [`Vec<u8>::from<AnsiColor>()`]) probably never fails
fn compare_ansi_codes(actual: &[u8], expected: &[u8]) -> Result<bool, CodeError> { pub fn compare_ansi_codes(actual: &[u8], expected: &[u8]) -> Result<bool, ColorError> {
let (actual_set, actual_groups) = process_codes2(actual)?; let (actual_set, actual_groups) = process_codes2(actual)?;
let (expected_set, expected_groups) = process_codes2(expected)?; let (expected_set, expected_groups) = process_codes2(expected)?;
@@ -135,7 +144,8 @@ fn test_normal_use() {
.style(AnsiStyle::Bold) // 1 .style(AnsiStyle::Bold) // 1
.style(AnsiStyle::BlinkFast); // 6 .style(AnsiStyle::BlinkFast); // 6
builder.add_style(&error_style); builder.add_style(&error_style);
let mut reset_style = Style::new().style(AnsiStyle::Reset).to_owned(); //mut
let reset_style = Style::new().style(AnsiStyle::Reset).to_owned();
println!("{builder}{reset_style}"); // good so far 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 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]; let reset_estimate: Vec<u8> = vec![0];