fixed error message using warning style
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
+2
-2
@@ -124,7 +124,7 @@ impl Bookmarks {
|
||||
Ok(value) => value,
|
||||
Err(error) => return Err(Error::other(format!("-- failed to conver home directory to string: {}", error.to_str().unwrap()))),
|
||||
},
|
||||
None => return Err(Error::other("-- `stack_home_as_tilde` = true, but home directory can't be determined")),
|
||||
None => return Err(Error::other("-- `bookmarks_home_as_tilde` = true, but home directory can't be determined")),
|
||||
};
|
||||
path = path.replace(&home, "~");
|
||||
}
|
||||
@@ -138,7 +138,7 @@ impl Bookmarks {
|
||||
path = segments.join(&slash);
|
||||
|
||||
name = apply_format(&name, &config.styles.bookmarks_name_style)?;
|
||||
separator = apply_format(&separator, &config.styles.stack_separator_style)?;
|
||||
separator = apply_format(&separator, &config.styles.bookmarks_seperator_style)?;
|
||||
}
|
||||
|
||||
let mut line: String;
|
||||
|
||||
+10
-12
@@ -1,7 +1,7 @@
|
||||
#![allow(unused)]
|
||||
|
||||
use clap::builder::EnumValueParser;
|
||||
use config_parser::apply_format;
|
||||
use config_parser::{apply_format, parse_ansi_set, parse_ansi_unset};
|
||||
|
||||
use super::config::*;
|
||||
|
||||
@@ -71,27 +71,25 @@ impl Output {
|
||||
self.push_command(&"false".to_owned());
|
||||
}
|
||||
|
||||
let mut info: String = self.info.iter().map(|entry| format!("echo '{}'", entry)).collect::<Vec<String>>().join(" && ");
|
||||
let mut warning: String = self.warning.iter().map(|entry| format!("echo '{}'", entry)).collect::<Vec<String>>().join(" && ");
|
||||
let mut error: String = self.error.iter().map(|entry| format!("echo '{}'", entry)).collect::<Vec<String>>().join(" && ");
|
||||
let mut command: String = self.command.join(" && ");
|
||||
let mut output: Vec<String> = Vec::<String>::new();
|
||||
|
||||
if !info.is_empty() {
|
||||
if !self.info.is_empty() {
|
||||
let mut info: String = self.info.iter().map(|entry| format!("echo '{}'", entry)).collect::<Vec<String>>().join(" && ");
|
||||
output.push(info);
|
||||
}
|
||||
if !warning.is_empty() {
|
||||
warning = format!("echo '{}'", apply_format(&warning, &config.styles.error_style).unwrap());
|
||||
if !self.warning.is_empty() {
|
||||
let mut warning: String = self.warning.iter().map(|entry| apply_format(entry, &config.styles.warning_style).unwrap()).map(|entry| format!("echo '{}'", entry)).collect::<Vec<String>>().join(" && ");
|
||||
output.push(warning);
|
||||
}
|
||||
if !error.is_empty() {
|
||||
error = format!("echo '{}'", apply_format(&error, &config.styles.error_style).unwrap());
|
||||
if !self.error.is_empty() {
|
||||
let mut error: String = self.error.iter().map(|entry| apply_format(entry, &config.styles.error_style).unwrap()).map(|entry| format!("echo '{}'", entry)).collect::<Vec<String>>().join(" && ");
|
||||
output.push(error);
|
||||
}
|
||||
if !command.is_empty() {
|
||||
if !self.command.is_empty() {
|
||||
let mut command: String = self.command.join(" && ");
|
||||
output.push(command);
|
||||
}
|
||||
|
||||
println!("{}", output.join(" && echo && "));
|
||||
println!("{}", output.join(" && "));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user