fixed error message using warning style

This commit is contained in:
2025-06-26 22:36:50 +02:00
parent 600feeacd5
commit 86744ce8fa
5 changed files with 14 additions and 55 deletions
@@ -110,7 +110,7 @@ pub fn apply_format(input: &String, style: &String) -> Result<String> {
Ok(value) => value,
Err(error) => return Err(error),
};
let style_reset: String = match parse_ansi_reset(style) {
let style_reset: String = match parse_ansi_unset(style) {
Ok(value) => value,
Err(error) => return Err(error),
};
@@ -258,7 +258,7 @@ pub fn parse_ansi_set(arg: &String) -> Result<String> {
/// input format is a quoted string (either double or single)
/// the style can be a combination of **one** color and
/// one or more style options (bold, italic, underlined, strikethrough)
pub fn parse_ansi_reset(arg: &String) -> Result<String> {
pub fn parse_ansi_unset(arg: &String) -> Result<String> {
let mut colors: Vec<String> = Vec::<String>::new();
let mut styles: Vec<String> = Vec::<String>::new();
@@ -48,43 +48,6 @@ pub fn gen_parse_from_map(config_name: &Ident, output_name: &Ident, assignments:
}
}
pub fn gen_to_ansi_sequences(fields: &Punctuated<Field, Comma>) -> TokenStream {
let mut conversions: TokenStream = TokenStream::new();
'fields: for field in fields.iter() {
let attr = &field.attrs;
let name = match &field.ident {
Some(value) => value,
// skip anonymous fields
None => continue 'fields,
};
for attribute in attr {
if let Attribute{ meta: Meta::Path( Path{segments: attr_name, ..} ), .. } = attribute {
match attr_name.first() {
Some(value) => if value.ident == "style_config" {
conversions.extend(quote! {
self.#name = match config_parser::parse_ansi_set(&self.#name) {
Ok(value) => value,
Err(_) => return Err(std::io::Error::other(format!("failed to convert '{}' to ansi escape sequence", self.#name))),
};
});
} else if value.ident == "nested_config" {
conversions.extend(quote! {
self.#name.to_ansi_sequences()?;
});
},
None => (),
}
}
}
};
quote!{
fn to_ansi_sequences(&mut self) -> std::io::Result<()> {
#conversions
Ok(())
}
}
}
pub fn gen_default(fields: &Punctuated<Field, Comma>) -> TokenStream {
let mut defaults: TokenStream = TokenStream::new();
'fields: for field in fields.iter() {
@@ -33,7 +33,6 @@ pub fn derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let assignments: TokenStream = gen_config_assignments(fields, &config_name, &output_name);
let func_parse_string: TokenStream = gen_parse_from_string(&config_name, &output_name, &assignments);
let func_parse_map: TokenStream = gen_parse_from_map(&config_name, &output_name, &assignments);
let func_to_ansi_sequences: TokenStream = gen_to_ansi_sequences(fields);
let func_default: TokenStream = gen_default(fields);
let func_to_string: TokenStream = gen_to_string(fields);
@@ -41,7 +40,6 @@ pub fn derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
impl #name {
#func_parse_string
#func_parse_map
#func_to_ansi_sequences
#func_default
#func_to_string
}