small refactoring of set terminal title function

This commit is contained in:
Oliver looney 2023-12-31 22:15:00 +00:00
parent d7503bfc09
commit 57016f4e04
No known key found for this signature in database

View file

@ -227,23 +227,27 @@ pub fn list_themes(cfg: &Config, config_dir: &Path, cache_dir: &Path) -> Result<
Ok(())
}
fn set_terminal_title_to_inputs_names(inputs: &Vec<Input>) {
let mut input_names = "bat: ".to_string();
fn set_terminal_title_to(new_terminal_title: String) {
print!("\x1b]2;{}\x07", new_terminal_title);
io::stdout().flush().unwrap();
}
fn get_new_terminal_title(inputs: &Vec<Input>) -> String {
let mut new_terminal_title = "bat: ".to_string();
for (index, input) in inputs.iter().enumerate() {
input_names += &input.description.name.to_string();
new_terminal_title += &input.description.name.to_string();
if index < inputs.len() - 1 {
input_names += ", ";
new_terminal_title += ", ";
}
}
print!("\x1b]2;{}\x07", input_names);
io::stdout().flush().unwrap();
new_terminal_title
}
fn run_controller(inputs: Vec<Input>, config: &Config, cache_dir: &Path) -> Result<bool> {
let assets = assets_from_cache_or_binary(config.use_custom_assets, cache_dir)?;
let controller = Controller::new(config, &assets);
if config.paging_mode != PagingMode::Never {
set_terminal_title_to_inputs_names(&inputs);
set_terminal_title_to(get_new_terminal_title(&inputs));
}
controller.run(inputs, None)
}