47 lines
No EOL
2 KiB
Rust
47 lines
No EOL
2 KiB
Rust
use serde_json::json;
|
|
use swayipc::Node;
|
|
use crate::{config::Config, Cli, ErrorMessage};
|
|
|
|
#[derive(serde::Serialize)]
|
|
pub struct WindowInfo {
|
|
pub title: String
|
|
}
|
|
|
|
pub fn get_window_name(window_node: Node, cli: &Cli, config: &Config) -> Result<String,ErrorMessage> {
|
|
// println!("{:#?}",window_node);
|
|
match window_node.name {
|
|
Some(mut window_title) => {
|
|
for pair in config.window_icons.clone() {
|
|
if window_title.contains(&pair.substring) {
|
|
window_title = format!("{} {}", pair.icon, window_title.replace(&pair.substring,""))
|
|
}
|
|
}
|
|
if cli.no_truncate_title.is_some_and(|x|!x) && config.title_length.is_some_and(|x|x.lt(&window_title.chars().count())) {
|
|
let trunc_point = window_title.char_indices().map(|(i, _)| i).nth(config.title_length.unwrap()).unwrap_or(window_title.chars().count());
|
|
window_title.truncate(trunc_point);
|
|
window_title.push('…');
|
|
}
|
|
Ok(window_title)
|
|
},
|
|
None => {
|
|
Ok("".to_string())
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn print_window_title(window_node: Node,cli: &Cli,config: &Config) {
|
|
// let mut window_title_display: String = window_node.name.unwrap();
|
|
/* for pair in &config.window_icons {
|
|
if window_title_display.contains(&pair.substring) {
|
|
window_title_display = pair.icon.clone() + " " + &window_title_display.replace(&pair.substring, "");
|
|
}
|
|
}
|
|
if !cli.no_truncate_title.unwrap() && window_title_display.chars().count().gt(&config.title_length) {
|
|
let trunc_point = window_title_display.char_indices().map(|(i, _)| i).nth(config.title_length).unwrap_or(window_title_display.chars().count());
|
|
window_title_display.truncate(trunc_point);
|
|
let _ = window_title_display.write_char('…');
|
|
} */
|
|
let window_info = WindowInfo { title: get_window_name(window_node, cli, config).unwrap() };
|
|
let window_output = json!(window_info);
|
|
println!("{}",window_output)
|
|
} |