updated field names in Data struct
This commit is contained in:
parent
8b4662de7c
commit
dcb8c04513
|
|
@ -37,14 +37,14 @@ fn cutoff(fields: &Vec<Field>, brk: Option<char>, fuzzy: bool, strings: &mut Has
|
|||
}
|
||||
|
||||
fn append_prefix(b: &mut Builder, data: &Data) {
|
||||
b.append(data.display_prefix);
|
||||
b.append(data.prefix);
|
||||
b.append(" ");
|
||||
}
|
||||
|
||||
fn append_fields(b: &mut Builder, cfg: &Config, data: &Data) {
|
||||
let mut idx = 0; let len = data.display_text.len() as i32;
|
||||
let mut idx = 0; let len = data.field_text.len() as i32;
|
||||
for string in &cfg.metadata_fields {
|
||||
if let Some(string) = data.display_text.get(&string.field) {
|
||||
if let Some(string) = data.field_text.get(&string.field) {
|
||||
idx += 1;
|
||||
b.append(string.clone());
|
||||
if idx < len {b.append(format!("{}", cfg.metadata_separator))};
|
||||
|
|
@ -66,10 +66,10 @@ fn build_string(cfg: &Config, data: &mut Data) -> String {
|
|||
}
|
||||
|
||||
pub fn print_text(cfg: &Config, data: &mut Data) {
|
||||
if (cfg.hide_output && data.current_player.is_none()) || data.display_text.is_empty() || cfg.metadata_fields.is_empty() {
|
||||
if (cfg.hide_output && data.current_player.is_none()) || data.field_text.is_empty() || cfg.metadata_fields.is_empty() {
|
||||
println!("");
|
||||
} else {
|
||||
cutoff(&cfg.metadata_fields, cfg.break_character, cfg.fuzzy, &mut data.display_text);
|
||||
cutoff(&cfg.metadata_fields, cfg.break_character, cfg.fuzzy, &mut data.field_text);
|
||||
println!("{}", build_string(cfg, data));
|
||||
}
|
||||
}
|
||||
|
|
@ -4,16 +4,16 @@ use mpris::Player;
|
|||
|
||||
pub struct Data {
|
||||
pub current_player: Option<Player>,
|
||||
pub display_text: HashMap<String, String>,
|
||||
pub display_prefix: char,
|
||||
pub field_text: HashMap<String, String>,
|
||||
pub prefix: char,
|
||||
}
|
||||
|
||||
impl Default for Data {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
current_player: None,
|
||||
display_text: HashMap::new(),
|
||||
display_prefix: ' ',
|
||||
field_text: HashMap::new(),
|
||||
prefix: ' ',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -56,14 +56,14 @@ pub fn update_message(cfg: &Config, data: &mut Data, ratings: &Vec<String>) {
|
|||
let key = field.field.clone();
|
||||
if field.field.eq("xesam:userRating") {
|
||||
if let Some(rating_string) = rating_to_string(meta.get(&key), ratings) {
|
||||
data.display_text.insert(key, rating_string);
|
||||
data.field_text.insert(key, rating_string);
|
||||
} else {
|
||||
data.display_text.remove(&key);
|
||||
data.field_text.remove(&key);
|
||||
}
|
||||
} else {
|
||||
match meta.get(&key) {
|
||||
Some(value) => data.display_text.insert(key, value_to_string(value, cfg.array_separator)),
|
||||
None => data.display_text.insert(key, format!("No {}", field.field.clone().trim_start_matches("xesam:"))),
|
||||
Some(value) => data.field_text.insert(key, value_to_string(value, cfg.array_separator)),
|
||||
None => data.field_text.insert(key, format!("No {}", field.field.clone().trim_start_matches("xesam:"))),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ pub fn update_players(
|
|||
}
|
||||
|
||||
if let Some((_, player)) = active.pop_first() {
|
||||
update_prefix(cfg, &mut data.display_prefix, player.identity());
|
||||
update_prefix(cfg, &mut data.prefix, player.identity());
|
||||
data.current_player = Some(player);
|
||||
} else {
|
||||
data.current_player = None;
|
||||
|
|
|
|||
Loading…
Reference in New Issue