successfully setting the terminal title to bat's input's names

This commit is contained in:
Oliver looney 2023-12-10 17:17:19 +00:00
parent 4863d428dd
commit b9b554248d
No known key found for this signature in database
4 changed files with 14 additions and 10 deletions

View File

@ -227,9 +227,19 @@ 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();
for input in inputs.iter() {
input_names = input_names + &input.description.name.to_string() + ", "
}
print!("\x1b]2;{}\x07", input_names);
io::stdout().flush().unwrap();
}
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);
set_terminal_title_to_inputs_names(&inputs);
controller.run(inputs, None)
}

View File

@ -88,6 +88,7 @@ impl<'b> Controller<'b> {
clircle::Identifier::stdout()
};
let mut writer = match output_buffer {
Some(buf) => OutputHandle::FmtWrite(buf),
None => OutputHandle::IoWrite(output_type.handle()?),

View File

@ -13,7 +13,7 @@ use crate::error::*;
/// This tells bat how to refer to the input.
#[derive(Clone)]
pub struct InputDescription {
pub(crate) name: String,
pub name: String,
/// The input title.
/// This replaces the name if provided.
@ -94,7 +94,7 @@ pub(crate) struct InputMetadata {
pub struct Input<'a> {
pub(crate) kind: InputKind<'a>,
pub(crate) metadata: InputMetadata,
pub(crate) description: InputDescription,
pub description: InputDescription,
}
pub(crate) enum OpenedInputKind {

View File

@ -1,6 +1,5 @@
use shell_words::ParseError;
use std::{env, io};
use std::io::Write;
use std::{env};
/// If we use a pager, this enum tells us from where we were told to use it.
#[derive(Debug, PartialEq)]
@ -37,11 +36,6 @@ pub(crate) enum PagerKind {
Unknown,
}
fn set_terminal_title(title: &str) {
print!("\x1b]2;{}\x07", title);
io::stdout().flush().unwrap();
}
impl PagerKind {
fn from_bin(bin: &str) -> PagerKind {
use std::path::Path;
@ -108,7 +102,6 @@ pub(crate) fn get_pager(config_pager: Option<&str>) -> Result<Option<Pager>, Par
};
let parts = shell_words::split(cmd)?;
set_terminal_title("test");
match parts.split_first() {
Some((bin, args)) => {
let kind = PagerKind::from_bin(bin);