Skip to content

Commit

Permalink
fix: default class formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-fff committed Jan 13, 2025
1 parent ba126d5 commit 1d448b1
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 15 deletions.
15 changes: 1 addition & 14 deletions src/renamer/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ impl IconConfig {
icon
}

pub fn rule(&self) -> Rule {
let (rule, _, _) = self.get();
rule
}

pub fn captures(&self) -> Captures {
let (_, _, captures) = self.get();
captures
Expand Down Expand Up @@ -67,12 +62,6 @@ impl IconStatus {
}
}

pub fn rule(&self) -> Rule {
match self {
Active(config) | Inactive(config) => config.rule(),
}
}

pub fn captures(&self) -> Captures {
match self {
Active(config) | Inactive(config) => config.captures(),
Expand Down Expand Up @@ -213,9 +202,7 @@ impl Renamer {
let icon_default_active = self
.find_icon("DEFAULT", "DEFAULT", "", "", true, config)
.unwrap_or({
self.find_icon("DEFAULT", "DEFAULT", "", "", false, config)
.map(|i| Active(Class(i.rule(), i.icon())))
.unwrap_or(Active(Default("no icon".to_string())))
icon_default.clone()
});

if is_active {
Expand Down
78 changes: 77 additions & 1 deletion src/renamer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1900,8 +1900,81 @@ mod tests {
assert_eq!(actual, expected);
}

#[test]
fn test_no_default_class_active_fallback_to_formatted_default_class_inactive() {
// Test inactive default configuration
let mut config = crate::config::read_config_file(None, false, false).unwrap();

// Find and replace the DEFAULT entry
if let Some(idx) = config.class.iter().position(|(regex, _)| regex.as_str() == "DEFAULT") {
config.class[idx] = (Regex::new("DEFAULT").unwrap(), "default inactive".to_string());
}

let renamer = Renamer::new(
Config {
cfg_path: None,
config: config.clone(),
},
Args {
verbose: false,
debug: false,
config: None,
dump: false,
migrate_config: false,
},
);

let expected = [(1, "*default inactive* default inactive".to_string())].into_iter().collect();

let actual = renamer.generate_workspaces_string(
vec![AppWorkspace {
id: 1,
clients: vec![AppClient {
initial_class: "fake-app-unknown".to_string(),
class: "fake-app-unknown".to_string(),
title: "~".to_string(),
initial_title: "zsh".to_string(),
is_active: true,
is_fullscreen: FullscreenMode::None,
matched_rule: renamer.parse_icon(
"fake-app-unknown".to_string(),
"fake-app-unknown".to_string(),
"zsh".to_string(),
"~".to_string(),
true,
&config,
),
is_dedup_inactive_fullscreen: false,
},
AppClient {
initial_class: "fake-app-unknown".to_string(),
class: "fake-app-unknown".to_string(),
title: "~".to_string(),
initial_title: "zsh".to_string(),
is_active: false,
is_fullscreen: FullscreenMode::None,
matched_rule: renamer.parse_icon(
"fake-app-unknown".to_string(),
"fake-app-unknown".to_string(),
"zsh".to_string(),
"~".to_string(),
true,
&config,
),
is_dedup_inactive_fullscreen: false,
},
],
}],
&config,
);

assert_eq!(actual, expected);

}

#[test]
fn test_no_default_class_active_fallback_to_class_default() {
// Test active default configuration
let mut config = crate::config::read_config_file(None, false, false).unwrap();

config
Expand Down Expand Up @@ -1950,6 +2023,7 @@ mod tests {

assert_eq!(actual, expected);

// Test no active default configuration
let config = crate::config::read_config_file(None, false, false).unwrap();

let renamer = Renamer::new(
Expand Down Expand Up @@ -1990,7 +2064,9 @@ mod tests {
&config,
);

let expected = [(1, "\u{f059} kitty".to_string())].into_iter().collect();
// When no active default is configured, the inactive default is used
// and run through the same formatter as a normal inactive client.
let expected = [(1, "*\u{f059} kitty*".to_string())].into_iter().collect();

assert_eq!(actual, expected);
}
Expand Down

0 comments on commit 1d448b1

Please sign in to comment.