feat: added escape_chars config option

This commit is contained in:
djaidjai committed 2024-01-21 19:22:22 +01:00
1 parent c56a59b126
commit c074b4279e
3 files changed
+21 -1

No files matched your search

+12 -1
View File
@@ -81,7 +81,18 @@ fn append_fields(b: &mut Builder, cfg: &Config, data: &Data) {
for field in &cfg.metadata_fields {
if let Some(string) = data.field_text.get(&field.field) {
idx += 1;
b.append(field.format.format(&[string.as_str()]));
if cfg.escape_chars {
let s: &String = &string.chars()
.map(|x| match x {
'&' => "&".to_owned(),
_ => x.to_string(),
}).collect();
b.append(field.format.format(&[s.as_str()]));
} else {
b.append(field.format.format(&[string.as_str()]));
}
if idx < len {b.append(cfg.metadata_separator.as_str())};
} else {
info!("failed to get {} value!", field.field);
+5
View File
@@ -140,6 +140,10 @@ pub struct Config {
/// Hashmap which maps Player Identities (strings; key) to prefixes (char; value).
/// If left blank all players will use the default prefix character ('>').
pub player_prefixes: HashMap<String, char>,
/// Boolean which tells the program to escape special characters or not.
/// This is useful for some bar implementations (i.e. waybar needs to escape the '&' character).
/// Currently only escapes '&', i will be adding more as i run into them.
pub escape_chars: bool,
}
/// Defaults for the Config struct.
@@ -158,6 +162,7 @@ impl Default for Config {
rating_icons: Some(Rating::default()),
metadata_fields: Config::default_metadata_fields(),
player_prefixes: Config::default_player_prefixes(),
escape_chars: false,
}
}
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.