slight changes MY ass
cargo fmt, cargo clippy --fix or something idfk
This commit is contained in:
1 parent
7895660ba9
commit
b26cdf9f3f
8 files changed
+56
-42
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;
|
||||
|
||||
@@ -6,9 +9,9 @@ use std::{error::Error, fmt::{Debug, Display}};
|
||||
pub enum ColorError {
|
||||
NoCode,
|
||||
/// 50 for example which is for other things
|
||||
InvalidCode,
|
||||
InvalidCode,
|
||||
/// not 2 or 5, or 5 but 3 element
|
||||
InvalidMode,
|
||||
InvalidMode,
|
||||
// MissingMode, // 48; invalid mode
|
||||
}
|
||||
impl Display for ColorError {
|
||||
|
||||
@@ -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
|
||||
|
||||
+3
-4
@@ -44,12 +44,11 @@ impl Style {
|
||||
}
|
||||
|
||||
impl From<Style> for u8 {
|
||||
fn from(value: Style) -> Self {
|
||||
value.code()
|
||||
}
|
||||
fn from(value: Style) -> Self {
|
||||
value.code()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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,
|
||||
};
|
||||
+9
-9
@@ -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,17 +34,17 @@ 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 {
|
||||
let c= self.clone();
|
||||
pub fn clone_with_style(&mut self, style: StyleConstruct) -> Self {
|
||||
let c = self.clone();
|
||||
c.style(style)
|
||||
}
|
||||
pub fn apply(&mut self, str: &str) {
|
||||
@@ -64,4 +62,6 @@ impl From<AnsiStyles> for String {
|
||||
fn from(value: AnsiStyles) -> Self {
|
||||
format!("{value}") // wow
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod import;
|
||||
+5
-3
@@ -1,10 +1,12 @@
|
||||
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(){
|
||||
fn main() {
|
||||
let white_bg = Color::white().bg();
|
||||
let bright_green_text = Color::green().bright();
|
||||
let white_bg2 = Color2::Magenta.bg();
|
||||
let bright_green_text2 = CustomColor2::Color256(215).fg();
|
||||
}
|
||||
}
|
||||
+12
-11
@@ -1,10 +1,8 @@
|
||||
//! test for lib.rs
|
||||
//! very good
|
||||
//!
|
||||
//!
|
||||
//! 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