feat: added escape_chars config option
This commit is contained in:
parent
c56a59b126
commit
c074b4279e
|
|
@ -126,6 +126,9 @@ fuzzy = false
|
||||||
# whether to display the prefix characters in the output string at all
|
# whether to display the prefix characters in the output string at all
|
||||||
# boolean
|
# boolean
|
||||||
render_prefix = true
|
render_prefix = true
|
||||||
|
# whether to escape special characters like '&' to '&'
|
||||||
|
# boolean
|
||||||
|
escape_chars = false
|
||||||
|
|
||||||
# time taken between updates of the output string, in milliseconds
|
# time taken between updates of the output string, in milliseconds
|
||||||
# u64 (0 <= u64 <= 18446744073709551615)
|
# u64 (0 <= u64 <= 18446744073709551615)
|
||||||
|
|
@ -208,6 +211,7 @@ Whenever a config file is specified that does not actually exist, the script cre
|
||||||
hide_output = true
|
hide_output = true
|
||||||
fuzzy = false
|
fuzzy = false
|
||||||
render_prefix = true
|
render_prefix = true
|
||||||
|
escape_chars = false
|
||||||
update_delay = 300
|
update_delay = 300
|
||||||
metadata_separator = ' | '
|
metadata_separator = ' | '
|
||||||
array_separator = '+'
|
array_separator = '+'
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,18 @@ fn append_fields(b: &mut Builder, cfg: &Config, data: &Data) {
|
||||||
for field in &cfg.metadata_fields {
|
for field in &cfg.metadata_fields {
|
||||||
if let Some(string) = data.field_text.get(&field.field) {
|
if let Some(string) = data.field_text.get(&field.field) {
|
||||||
idx += 1;
|
idx += 1;
|
||||||
|
|
||||||
|
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()]));
|
b.append(field.format.format(&[string.as_str()]));
|
||||||
|
}
|
||||||
if idx < len {b.append(cfg.metadata_separator.as_str())};
|
if idx < len {b.append(cfg.metadata_separator.as_str())};
|
||||||
} else {
|
} else {
|
||||||
info!("failed to get {} value!", field.field);
|
info!("failed to get {} value!", field.field);
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,10 @@ pub struct Config {
|
||||||
/// Hashmap which maps Player Identities (strings; key) to prefixes (char; value).
|
/// Hashmap which maps Player Identities (strings; key) to prefixes (char; value).
|
||||||
/// If left blank all players will use the default prefix character ('>').
|
/// If left blank all players will use the default prefix character ('>').
|
||||||
pub player_prefixes: HashMap<String, char>,
|
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.
|
/// Defaults for the Config struct.
|
||||||
|
|
@ -158,6 +162,7 @@ impl Default for Config {
|
||||||
rating_icons: Some(Rating::default()),
|
rating_icons: Some(Rating::default()),
|
||||||
metadata_fields: Config::default_metadata_fields(),
|
metadata_fields: Config::default_metadata_fields(),
|
||||||
player_prefixes: Config::default_player_prefixes(),
|
player_prefixes: Config::default_player_prefixes(),
|
||||||
|
escape_chars: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue