diff --git a/README.md b/README.md index b2d02f7..6aadb00 100644 --- a/README.md +++ b/README.md @@ -324,10 +324,11 @@ right now. * `fallback_icon` is a path to some PNG/SVG icon which will be used as `{app_icon}` if no application-specific icon can be determined. -The placeholders `{app_name}`, `{name}`, `{output_name}`, and `{workspace_name}` -allow to specify the maximum string length using format `{:}` (e.g. -`{app_name:10}`). If the string is longer than the specified length, it will -be truncated and an ellipsis ("…") will be inserted at the end. +The placeholders `{app_name}`, `{name}`, `{output_name}`, and +`{workspace_name}` allow to specify the maximum string length using format +`{:}` (e.g. `{app_name:10}`). If the string is longer than the +specified length, it will be truncated and an ellipsis ("…") will be inserted +at the end. It is crucial that during selection (using wofi or some other menu program) each window has a different display string. Therefore, it is highly diff --git a/src/tree.rs b/src/tree.rs index 418ba0a..ea02070 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -518,33 +518,38 @@ impl DisplayFormat for DisplayNode<'_> { .unwrap_or_else(String::new) .as_str(), ); - PLACEHOLDER_RX.replace_all(&fmt, |caps: ®ex::Captures| { - let value = match &caps["name"] { - "app_name" => self.node.get_app_name(), - "name" | "title" => self.node.get_name(), - "output_name" => { - self.tree + + PLACEHOLDER_RX + .replace_all(&fmt, |caps: ®ex::Captures| { + let value = match &caps["name"] { + "app_name" => self.node.get_app_name(), + "name" | "title" => self.node.get_name(), + "output_name" => self + .tree .get_parent_node_of_type(self.node.id, Type::Output) - .map_or("", |w| w.get_name()) - }, - "workspace_name" => { - self.tree + .map_or("", |w| w.get_name()), + "workspace_name" => self + .tree .get_parent_node_of_type(self.node.id, Type::Workspace) - .map_or("", |w| w.get_name()) - }, - _ => &caps[0], - }; - let width = caps.name("width") - .map_or("0", |m| m.as_str()) - .parse::() - .unwrap(); - - if width > 0 && value.len() > width { - maybe_html_escape(html_escape, &format!("{}…", &value[..width - 1])) - } else { - maybe_html_escape(html_escape, &value) - } - }).into() + .map_or("", |w| w.get_name()), + _ => &caps[0], + }; + let width = caps + .name("width") + .map_or("0", |m| m.as_str()) + .parse::() + .unwrap(); + + if width > 0 && value.len() > width { + maybe_html_escape( + html_escape, + &format!("{}…", &value[..width - 1]), + ) + } else { + maybe_html_escape(html_escape, value) + } + }) + .into() } fn get_indent_level(&self) -> usize {