From 2e103ee6b3703e120025d43f04fe9a6d7ae92b5e Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sun, 10 Dec 2023 16:39:34 +0000 Subject: [PATCH 01/35] able to set terminal title to hardcoded value --- src/pager.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/pager.rs b/src/pager.rs index 5b707779..bdd5eb7f 100644 --- a/src/pager.rs +++ b/src/pager.rs @@ -1,5 +1,6 @@ use shell_words::ParseError; -use std::env; +use std::{env, io}; +use std::io::Write; /// If we use a pager, this enum tells us from where we were told to use it. #[derive(Debug, PartialEq)] @@ -36,6 +37,16 @@ pub(crate) enum PagerKind { Unknown, } +fn set_terminal_title(title: &str) { + print!("\x1b]2;{}\x07", title); + io::stdout().flush().unwrap(); +} + +fn restore_terminal_title() { + print!("\x1b]2;\x07"); + io::stdout().flush().unwrap(); +} + impl PagerKind { fn from_bin(bin: &str) -> PagerKind { use std::path::Path; @@ -102,6 +113,7 @@ pub(crate) fn get_pager(config_pager: Option<&str>) -> Result, Par }; let parts = shell_words::split(cmd)?; + set_terminal_title("test"); match parts.split_first() { Some((bin, args)) => { let kind = PagerKind::from_bin(bin); From 4863d428dd7004b471960fdf1c6b30417d94383d Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sun, 10 Dec 2023 16:44:47 +0000 Subject: [PATCH 02/35] title is being reset on quit, so no need to restore terminal title --- src/pager.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/pager.rs b/src/pager.rs index bdd5eb7f..052cdbff 100644 --- a/src/pager.rs +++ b/src/pager.rs @@ -42,11 +42,6 @@ fn set_terminal_title(title: &str) { io::stdout().flush().unwrap(); } -fn restore_terminal_title() { - print!("\x1b]2;\x07"); - io::stdout().flush().unwrap(); -} - impl PagerKind { fn from_bin(bin: &str) -> PagerKind { use std::path::Path; From b9b554248daba2134d4355ebc5cd4373ad265abe Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sun, 10 Dec 2023 17:17:19 +0000 Subject: [PATCH 03/35] successfully setting the terminal title to bat's input's names --- src/bin/bat/main.rs | 10 ++++++++++ src/controller.rs | 1 + src/input.rs | 4 ++-- src/pager.rs | 9 +-------- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs index 43e9d288..6e5b71be 100644 --- a/src/bin/bat/main.rs +++ b/src/bin/bat/main.rs @@ -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) { + 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, config: &Config, cache_dir: &Path) -> Result { 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) } diff --git a/src/controller.rs b/src/controller.rs index f378cbc6..6333ebb1 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -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()?), diff --git a/src/input.rs b/src/input.rs index ccab98bf..724c5e15 100644 --- a/src/input.rs +++ b/src/input.rs @@ -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 { diff --git a/src/pager.rs b/src/pager.rs index 052cdbff..d627e903 100644 --- a/src/pager.rs +++ b/src/pager.rs @@ -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, Par }; let parts = shell_words::split(cmd)?; - set_terminal_title("test"); match parts.split_first() { Some((bin, args)) => { let kind = PagerKind::from_bin(bin); From 069318b139eaf88c3fdc0819e42953fb63cc7592 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sun, 10 Dec 2023 17:20:42 +0000 Subject: [PATCH 04/35] fixed formatting of terminal title --- src/bin/bat/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs index 6e5b71be..fb6abd11 100644 --- a/src/bin/bat/main.rs +++ b/src/bin/bat/main.rs @@ -229,8 +229,11 @@ pub fn list_themes(cfg: &Config, config_dir: &Path, cache_dir: &Path) -> Result< fn set_terminal_title_to_inputs_names(inputs: &Vec) { let mut input_names = "bat: ".to_string(); - for input in inputs.iter() { - input_names = input_names + &input.description.name.to_string() + ", " + for (index, input) in inputs.iter().enumerate() { + input_names += &input.description.name.to_string(); + if index < inputs.len() - 1 { + input_names += ", "; + } } print!("\x1b]2;{}\x07", input_names); io::stdout().flush().unwrap(); From 6ad800e43a18c5e4274ec63cc022c014506f6397 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sun, 10 Dec 2023 17:24:49 +0000 Subject: [PATCH 05/35] tidied commits --- src/controller.rs | 1 - src/pager.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/controller.rs b/src/controller.rs index 6333ebb1..f378cbc6 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -88,7 +88,6 @@ impl<'b> Controller<'b> { clircle::Identifier::stdout() }; - let mut writer = match output_buffer { Some(buf) => OutputHandle::FmtWrite(buf), None => OutputHandle::IoWrite(output_type.handle()?), diff --git a/src/pager.rs b/src/pager.rs index d627e903..5b707779 100644 --- a/src/pager.rs +++ b/src/pager.rs @@ -1,5 +1,5 @@ use shell_words::ParseError; -use std::{env}; +use std::env; /// If we use a pager, this enum tells us from where we were told to use it. #[derive(Debug, PartialEq)] From fd84e4f49fdb363e245eceb96a50080a589eb993 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Mon, 11 Dec 2023 19:09:48 +0000 Subject: [PATCH 06/35] fixed all but two failing tests. Last two tests are erroring because of IO circle detected error --- tests/integration_tests.rs | 180 ++++++++++++++++++------------------- 1 file changed, 90 insertions(+), 90 deletions(-) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index be70fdca..96540cc6 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -48,7 +48,7 @@ fn basic() { .arg("test.txt") .assert() .success() - .stdout("hello world\n") + .stdout("\u{1b}]2;bat: test.txt\x07hello world\n") .stderr(""); } @@ -58,7 +58,7 @@ fn stdin() { .write_stdin("foo\nbar\n") .assert() .success() - .stdout("foo\nbar\n"); + .stdout("\u{1b}]2;bat: STDIN\x07foo\nbar\n"); } #[test] @@ -68,7 +68,7 @@ fn concatenate() { .arg("test.txt") .assert() .success() - .stdout("hello world\nhello world\n"); + .stdout("\u{1b}]2;bat: test.txt, test.txt\x07hello world\nhello world\n"); } #[test] @@ -80,7 +80,7 @@ fn concatenate_stdin() { .write_stdin("stdin\n") .assert() .success() - .stdout("hello world\nstdin\nhello world\n"); + .stdout("\u{1b}]2;bat: test.txt, STDIN, test.txt\x07hello world\nstdin\nhello world\n"); } #[test] @@ -90,7 +90,7 @@ fn concatenate_empty_first() { .arg("test.txt") .assert() .success() - .stdout("hello world\n"); + .stdout("\u{1b}]2;bat: empty.txt, test.txt\x07hello world\n"); } #[test] @@ -100,7 +100,7 @@ fn concatenate_empty_last() { .arg("empty.txt") .assert() .success() - .stdout("hello world\n"); + .stdout("\u{1b}]2;bat: test.txt, empty.txt\x07hello world\n"); } #[test] @@ -110,7 +110,7 @@ fn concatenate_empty_both() { .arg("empty.txt") .assert() .success() - .stdout(""); + .stdout("\u{1b}]2;bat: empty.txt, empty.txt\x07"); } #[test] @@ -121,7 +121,7 @@ fn concatenate_empty_between() { .arg("test.txt") .assert() .success() - .stdout("hello world\nhello world\n"); + .stdout("\u{1b}]2;bat: test.txt, empty.txt, test.txt\x07hello world\nhello world\n"); } #[test] @@ -132,7 +132,7 @@ fn concatenate_empty_first_and_last() { .arg("empty.txt") .assert() .success() - .stdout("hello world\n"); + .stdout("\u{1b}]2;bat: empty.txt, test.txt, empty.txt\x07hello world\n"); } #[test] @@ -142,7 +142,7 @@ fn concatenate_single_line() { .arg("single-line.txt") .assert() .success() - .stdout("Single LineSingle Line"); + .stdout("\u{1b}]2;bat: single-line.txt, single-line.txt\x07Single LineSingle Line"); } #[test] @@ -153,7 +153,7 @@ fn concatenate_single_line_empty() { .arg("single-line.txt") .assert() .success() - .stdout("Single LineSingle Line"); + .stdout("\u{1b}]2;bat: single-line.txt, empty.txt, single-line.txt\x07Single LineSingle Line"); } #[test] @@ -164,7 +164,7 @@ fn line_numbers() { .arg("--decorations=always") .assert() .success() - .stdout(" 1 line 1\n 2 line 2\n 3 line 3\n 4 line 4\n"); + .stdout("\u{1b}]2;bat: multiline.txt\x07 1 line 1\n 2 line 2\n 3 line 3\n 4 line 4\n"); } #[test] @@ -174,7 +174,7 @@ fn line_range_2_3() { .arg("--line-range=2:3") .assert() .success() - .stdout("line 2\nline 3\n"); + .stdout("\u{1b}]2;bat: multiline.txt\x07line 2\nline 3\n"); } #[test] @@ -184,7 +184,7 @@ fn line_range_first_two() { .arg("--line-range=:2") .assert() .success() - .stdout("line 1\nline 2\n"); + .stdout("\u{1b}]2;bat: multiline.txt\x07line 1\nline 2\n"); } #[test] @@ -194,7 +194,7 @@ fn line_range_last_3() { .arg("--line-range=2:") .assert() .success() - .stdout("line 2\nline 3\nline 4\n"); + .stdout("\u{1b}]2;bat: multiline.txt\x07line 2\nline 3\nline 4\n"); } #[test] @@ -205,7 +205,7 @@ fn line_range_multiple() { .arg("--line-range=4:4") .assert() .success() - .stdout("line 1\nline 2\nline 4\n"); + .stdout("\u{1b}]2;bat: multiline.txt\x07line 1\nline 2\nline 4\n"); } #[test] @@ -354,7 +354,7 @@ fn tabs_numbers() { .assert() .success() .stdout( - " 1 1 2 3 4 + "\u{1b}]2;bat: tabs.txt\x07 1 1 2 3 4 2 1 ? 3 22 ? 4 333 ? @@ -377,7 +377,7 @@ fn tabs_passthrough_wrapped() { .assert() .success() .stdout( - " 1 2 3 4 + "\u{1b}]2;bat: tabs.txt\x07 1 2 3 4 1 ? 22 ? 333 ? @@ -400,7 +400,7 @@ fn tabs_4_wrapped() { .assert() .success() .stdout( - " 1 2 3 4 + "\u{1b}]2;bat: tabs.txt\x07 1 2 3 4 1 ? 22 ? 333 ? @@ -423,7 +423,7 @@ fn tabs_8_wrapped() { .assert() .success() .stdout( - " 1 2 3 4 + "\u{1b}]2;bat: tabs.txt\x07 1 2 3 4 1 ? 22 ? 333 ? @@ -446,7 +446,7 @@ fn tabs_passthrough() { .assert() .success() .stdout( - " 1 2 3 4 + "\u{1b}]2;bat: tabs.txt\x07 1 2 3 4 1 ? 22 ? 333 ? @@ -469,7 +469,7 @@ fn tabs_4() { .assert() .success() .stdout( - " 1 2 3 4 + "\u{1b}]2;bat: tabs.txt\x07 1 2 3 4 1 ? 22 ? 333 ? @@ -492,7 +492,7 @@ fn tabs_8() { .assert() .success() .stdout( - " 1 2 3 4 + "\u{1b}]2;bat: tabs.txt\x07 1 2 3 4 1 ? 22 ? 333 ? @@ -516,7 +516,7 @@ fn tabs_4_env_overrides_config() { .assert() .success() .stdout( - " 1 2 3 4 + "\u{1b}]2;bat: tabs.txt\x07 1 2 3 4 1 ? 22 ? 333 ? @@ -541,7 +541,7 @@ fn tabs_4_arg_overrides_env() { .assert() .success() .stdout( - " 1 2 3 4 + "\u{1b}]2;bat: tabs.txt\x07 1 2 3 4 1 ? 22 ? 333 ? @@ -565,7 +565,7 @@ fn tabs_4_arg_overrides_env_noconfig() { .assert() .success() .stdout( - " 1 2 3 4 + "\u{1b}]2;bat: tabs.txt\x07 1 2 3 4 1 ? 22 ? 333 ? @@ -594,7 +594,7 @@ fn do_not_exit_directory() { .arg("sub_directory") .arg("test.txt") .assert() - .stdout("hello world\n") + .stdout("\u{1b}]2;bat: sub_directory, test.txt\x07hello world\n") .failure(); } @@ -653,7 +653,7 @@ fn pager_disable() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("hello world\n").normalize()); + .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07hello world\n").normalize()); } #[test] @@ -734,7 +734,7 @@ fn env_var_pager_value_bat() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("hello world\n").normalize()); + .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07hello world\n").normalize()); } #[test] @@ -772,7 +772,7 @@ fn pager_most_from_pager_env_var() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("hello world\n").normalize()); + .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07hello world\n").normalize()); }); } @@ -818,7 +818,7 @@ fn pager_most_with_arg() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("hello world\n").normalize()); + .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07hello world\n").normalize()); }); } @@ -833,7 +833,7 @@ fn pager_more() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("hello world\n").normalize()); + .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07hello world\n").normalize()); }); } @@ -845,7 +845,7 @@ fn alias_pager_disable() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("hello world\n").normalize()); + .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07hello world\n").normalize()); } #[test] @@ -872,7 +872,7 @@ fn disable_pager_if_disable_paging_flag_comes_after_paging() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("hello world\n").normalize()); + .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07hello world\n").normalize()); } #[test] @@ -884,7 +884,7 @@ fn disable_pager_if_pp_flag_comes_after_paging() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("hello world\n").normalize()); + .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07hello world\n").normalize()); } #[test] @@ -896,7 +896,7 @@ fn enable_pager_if_disable_paging_flag_comes_before_paging() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("pager-output\n").normalize()); + .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07pager-output\n").normalize()); } #[test] @@ -908,7 +908,7 @@ fn enable_pager_if_pp_flag_comes_before_paging() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("pager-output\n").normalize()); + .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07pager-output\n").normalize()); } #[test] @@ -1111,7 +1111,7 @@ fn utf16() { .arg("test_UTF-16LE.txt") .assert() .success() - .stdout("hello world\n"); + .stdout("\u{1b}]2;bat: test_UTF-16LE.txt\x07hello world\n"); } // Regression test for https://github.com/sharkdp/bat/issues/1922 @@ -1124,7 +1124,7 @@ fn bom_not_stripped_in_loop_through_mode() { .arg("test_BOM.txt") .assert() .success() - .stdout("\u{feff}hello world\n"); + .stdout("\u{1b}]2;bat: test_BOM.txt\x07\u{feff}hello world\n"); } // Regression test for https://github.com/sharkdp/bat/issues/1922 @@ -1153,7 +1153,7 @@ fn bom_stripped_when_no_color_and_not_loop_through() { .assert() .success() .stdout( - "\ + "\u{1b}]2;bat: test_BOM.txt\x07\ ─────┬────────────────────────────────────────────────────────────────────────── │ File: test_BOM.txt ─────┼────────────────────────────────────────────────────────────────────────── @@ -1169,7 +1169,7 @@ fn can_print_file_named_cache() { .arg("cache") .assert() .success() - .stdout("test\n") + .stdout("\u{1b}]2;bat: cache\x07test\n") .stderr(""); } @@ -1180,7 +1180,7 @@ fn can_print_file_named_cache_with_additional_argument() { .arg("test.txt") .assert() .success() - .stdout("test\nhello world\n") + .stdout("\u{1b}]2;bat: cache, test.txt\x07test\nhello world\n") .stderr(""); } @@ -1190,7 +1190,7 @@ fn can_print_file_starting_with_cache() { .arg("cache.c") .assert() .success() - .stdout("test\n") + .stdout("\u{1b}]2;bat: cache.c\x07test\n") .stderr(""); } @@ -1220,7 +1220,7 @@ fn unicode_wrap() { .assert() .success() .stdout( - " 1 ビタミンA ビタミンD ビタミンE ビ + "\u{1b}]2;bat: unicode-wrap.txt\x07 1 ビタミンA ビタミンD ビタミンE ビ タミンK ビタミンB1 ビタミンB2 ナ イアシン パントテン酸 ビタミンB6 ビタミンB12 葉酸 ビオチン ビタ @@ -1264,7 +1264,7 @@ fn snip() { .assert() .success() .stdout( - " 1 line 1 + "\u{1b}]2;bat: multiline.txt\x07 1 line 1 2 line 2 ...─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ 8< ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ 4 line 4 @@ -1281,7 +1281,7 @@ fn empty_file_leads_to_empty_output_with_grid_enabled() { .arg("--terminal-width=80") .assert() .success() - .stdout(""); + .stdout("\u{1b}]2;bat: empty.txt\x07"); } #[test] @@ -1293,7 +1293,7 @@ fn empty_file_leads_to_empty_output_with_rule_enabled() { .arg("--terminal-width=80") .assert() .success() - .stdout(""); + .stdout("\u{1b}]2;bat: empty.txt\x07"); } #[test] @@ -1306,7 +1306,7 @@ fn header_basic() { .arg("--file-name=foo") .assert() .success() - .stdout("File: foo\n") + .stdout("\u{1b}]2;bat: foo\x07File: foo\n") .stderr(""); } @@ -1320,7 +1320,7 @@ fn header_full_basic() { .arg("--file-name=foo") .assert() .success() - .stdout("File: foo\nSize: 12 B\n") + .stdout("\u{1b}]2;bat: foo\x07File: foo\nSize: 12 B\n") .stderr(""); } @@ -1334,7 +1334,7 @@ fn header_env_basic() { .arg("--file-name=foo") .assert() .success() - .stdout("File: foo\nSize: 12 B\n") + .stdout("\u{1b}]2;bat: foo\x07File: foo\nSize: 12 B\n") .stderr(""); } @@ -1349,7 +1349,7 @@ fn header_arg_overrides_env() { .arg("--file-name=foo") .assert() .success() - .stdout("File: foo\n") + .stdout("\u{1b}]2;bat: foo\x07File: foo\n") .stderr(""); } @@ -1363,7 +1363,7 @@ fn header_binary() { .arg("--file-name=foo") .assert() .success() - .stdout("File: foo \n") + .stdout("\u{1b}]2;bat: foo\x07File: foo \n") .stderr(""); } @@ -1377,7 +1377,7 @@ fn header_full_binary() { .arg("--file-name=foo") .assert() .success() - .stdout("File: foo \nSize: 4 B\n") + .stdout("\u{1b}]2;bat: foo\x07File: foo \nSize: 4 B\n") .stderr(""); } @@ -1395,7 +1395,7 @@ fn header_default() { .assert() .success() .stdout( - "\ + "\u{1b}]2;bat: single-line.txt\x07\ ───────┬──────────────────────────────────────────────────────────────────────── │ File: single-line.txt ───────┼──────────────────────────────────────────────────────────────────────── @@ -1419,7 +1419,7 @@ fn header_default_is_default() { .assert() .success() .stdout( - "\ + "\u{1b}]2;bat: single-line.txt\x07\ ───────┬──────────────────────────────────────────────────────────────────────── │ File: single-line.txt ───────┼──────────────────────────────────────────────────────────────────────── @@ -1441,7 +1441,7 @@ fn filename_stdin() { .arg("--file-name=foo") .assert() .success() - .stdout("File: foo\n") + .stdout("\u{1b}]2;bat: foo\x07File: foo\n") .stderr(""); } @@ -1455,7 +1455,7 @@ fn filename_stdin_binary() { .arg("--file-name=foo") .assert() .success() - .stdout("File: foo \n") + .stdout("\u{1b}]2;bat: foo\x07File: foo \n") .stderr(""); } @@ -1471,7 +1471,7 @@ fn filename_multiple_ok() { .arg("--file-name=bar") .assert() .success() - .stdout("File: foo\n\nFile: bar\n") + .stdout("\u{1b}]2;bat: foo, bar\x07File: foo\n\nFile: bar\n") .stderr(""); } @@ -1496,7 +1496,7 @@ fn header_padding() { .arg("test.txt") .arg("single-line.txt") .assert() - .stdout("File: test.txt\nhello world\n\nFile: single-line.txt\nSingle Line\n") + .stdout("\u{1b}]2;bat: test.txt, single-line.txt\x07File: test.txt\nhello world\n\nFile: single-line.txt\nSingle Line\n") .stderr(""); } @@ -1508,7 +1508,7 @@ fn header_full_padding() { .arg("test.txt") .arg("single-line.txt") .assert() - .stdout("File: test.txt\nSize: 12 B\nhello world\n\nFile: single-line.txt\nSize: 11 B\nSingle Line\n") + .stdout("\u{1b}]2;bat: test.txt, single-line.txt\x07File: test.txt\nSize: 12 B\nhello world\n\nFile: single-line.txt\nSize: 11 B\nSingle Line\n") .stderr(""); } @@ -1522,7 +1522,7 @@ fn header_padding_rule() { .arg("single-line.txt") .assert() .stdout( - "File: test.txt + "\u{1b}]2;bat: test.txt, single-line.txt\x07File: test.txt hello world ──────────────────────────────────────────────────────────────────────────────── File: single-line.txt @@ -1542,7 +1542,7 @@ fn header_full_padding_rule() { .arg("single-line.txt") .assert() .stdout( - "File: test.txt + "\u{1b}]2;bat: test.txt, single-line.txt\x07File: test.txt Size: 12 B hello world ──────────────────────────────────────────────────────────────────────────────── @@ -1564,7 +1564,7 @@ fn grid_overrides_rule() { .arg("single-line.txt") .assert() .stdout( - "\ + "\u{1b}]2;bat: test.txt, single-line.txt\x07\ ──────────────────────────────────────────────────────────────────────────────── hello world ──────────────────────────────────────────────────────────────────────────────── @@ -1669,7 +1669,7 @@ fn show_all_mode() { .arg("--show-all") .arg("nonprintable.txt") .assert() - .stdout("hello·world␊\n├──┤␍␀␇␈␛") + .stdout("\u{1b}]2;bat: nonprintable.txt\x07hello·world␊\n├──┤␍␀␇␈␛") .stderr(""); } @@ -1683,7 +1683,7 @@ fn show_all_extends_tab_markers_to_next_tabstop() { .assert() .success() .stdout( - "├──┤1├─┤2├─┤3├─┤4␊ + "\u{1b}]2;bat: tabs.txt\x07├──┤1├─┤2├─┤3├─┤4␊ 1├─┤?␊ 22├┤?␊ 333↹?␊ @@ -1706,7 +1706,7 @@ fn show_all_extends_tab_markers_to_next_tabstop_width_8() { .assert() .success() .stdout( - "├──────┤1├─────┤2├─────┤3├─────┤4␊ + "\u{1b}]2;bat: tabs.txt\x07├──────┤1├─────┤2├─────┤3├─────┤4␊ 1├─────┤?␊ 22├────┤?␊ 333├───┤?␊ @@ -1726,7 +1726,7 @@ fn show_all_with_caret_notation() { .arg("--nonprintable-notation=caret") .arg("nonprintable.txt") .assert() - .stdout("hello·world^J\n├──┤^M^@^G^H^[") + .stdout("\u{1b}]2;bat: nonprintable.txt\x07hello·world^J\n├──┤^M^@^G^H^[") .stderr(""); bat() @@ -1734,7 +1734,7 @@ fn show_all_with_caret_notation() { .arg("--nonprintable-notation=caret") .arg("control_characters.txt") .assert() - .stdout("^@^A^B^C^D^E^F^G^H├─┤^J\n^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\\^]^^^_^?") + .stdout("\u{1b}]2;bat: control_characters.txt\x07^@^A^B^C^D^E^F^G^H├─┤^J\n^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\\^]^^^_^?") .stderr(""); } @@ -1745,7 +1745,7 @@ fn show_all_with_unicode() { .arg("--nonprintable-notation=unicode") .arg("control_characters.txt") .assert() - .stdout("␀␁␂␃␄␅␆␇␈├─┤␊\n␋␌␍␎␏␐␑␒␓␔␕␖␗␘␙␚␛␜␝␞␟␡") + .stdout("\u{1b}]2;bat: control_characters.txt\x07␀␁␂␃␄␅␆␇␈├─┤␊\n␋␌␍␎␏␐␑␒␓␔␕␖␗␘␙␚␛␜␝␞␟␡") .stderr(""); } @@ -1758,7 +1758,7 @@ fn no_paging_arg() { .arg("single-line.txt") .assert() .success() - .stdout("Single Line"); + .stdout("\u{1b}]2;bat: single-line.txt\x07Single Line"); } #[test] @@ -1770,7 +1770,7 @@ fn no_paging_short_arg() { .arg("single-line.txt") .assert() .success() - .stdout("Single Line"); + .stdout("\u{1b}]2;bat: single-line.txt\x07Single Line"); } #[test] @@ -1782,7 +1782,7 @@ fn no_pager_arg() { .arg("single-line.txt") .assert() .success() - .stdout("Single Line"); + .stdout("\u{1b}]2;bat: single-line.txt\x07Single Line"); } #[test] @@ -1795,7 +1795,7 @@ fn plain_mode_does_not_add_nonexisting_newline() { .arg("single-line.txt") .assert() .success() - .stdout("Single Line"); + .stdout("\u{1b}]2;bat: single-line.txt\x07Single Line"); } // Regression test for https://github.com/sharkdp/bat/issues/299 @@ -1813,7 +1813,7 @@ fn grid_for_file_without_newline() { .assert() .success() .stdout( - "\ + "\u{1b}]2;bat: single-line.txt\x07\ ───────┬──────────────────────────────────────────────────────────────────────── │ File: single-line.txt │ Size: 11 B @@ -1840,7 +1840,7 @@ fn ansi_highlight_underline() { .write_stdin("Ansi Underscore Test\nAnother Line") .assert() .success() - .stdout("\x1B[4mAnsi Underscore Test\n\x1B[24mAnother Line") + .stdout("\u{1b}]2;bat: STDIN\x07\x1B[4mAnsi Underscore Test\n\x1B[24mAnother Line") .stderr(""); } @@ -1859,7 +1859,7 @@ fn ansi_passthrough_emit() { .write_stdin("\x1B[33mColor\nColor \x1B[m\nPlain\n") .assert() .success() - .stdout("\x1B[33m\x1B[33mColor\n\x1B[33mColor \x1B[m\nPlain\n") + .stdout("\u{1b}]2;bat: STDIN\x07\x1B[33m\x1B[33mColor\n\x1B[33mColor \x1B[m\nPlain\n") .stderr(""); } } @@ -1874,7 +1874,7 @@ fn ignored_suffix_arg() { .arg("test.json~") .assert() .success() - .stdout("\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mtest\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;186mvalue\u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;231m}\u{1b}[0m") + .stdout("\u{1b}]2;bat: test.json~\x07\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mtest\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;186mvalue\u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;231m}\u{1b}[0m") .stderr(""); bat() @@ -1886,7 +1886,7 @@ fn ignored_suffix_arg() { .arg("test.json.suffix") .assert() .success() - .stdout("\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mtest\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;186mvalue\u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;231m}\u{1b}[0m") + .stdout("\u{1b}]2;bat: test.json.suffix\x07\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mtest\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;186mvalue\u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;231m}\u{1b}[0m") .stderr(""); bat() @@ -1897,16 +1897,16 @@ fn ignored_suffix_arg() { .arg("test.json.suffix") .assert() .success() - .stdout("\u{1b}[38;5;231m{\"test\": \"value\"}\u{1b}[0m") + .stdout("\u{1b}]2;bat: test.json.suffix\x07\u{1b}[38;5;231m{\"test\": \"value\"}\u{1b}[0m") .stderr(""); } fn wrapping_test(wrap_flag: &str, expect_wrap: bool) { let expected = match expect_wrap { true => - "abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcde\nfghigklmnopqrstuvxyz\n", + "\u{1b}]2;bat: long-single-line.txt\x07abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcde\nfghigklmnopqrstuvxyz\n", false => - "abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyz\n", + "\u{1b}]2;bat: long-single-line.txt\x07abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyz\n", }; bat() @@ -1957,7 +1957,7 @@ fn theme_arg_overrides_env() { .write_stdin("Ansi Underscore Test\nAnother Line") .assert() .success() - .stdout("\x1B[4mAnsi Underscore Test\n\x1B[24mAnother Line") + .stdout("\u{1b}]2;bat: STDIN\x07\x1B[4mAnsi Underscore Test\n\x1B[24mAnother Line") .stderr(""); } @@ -1977,7 +1977,7 @@ fn theme_arg_overrides_env_withconfig() { .write_stdin("Ansi Underscore Test\nAnother Line") .assert() .success() - .stdout("\x1B[4mAnsi Underscore Test\n\x1B[24mAnother Line") + .stdout("\u{1b}]2;bat: STDIN\x07\x1B[4mAnsi Underscore Test\n\x1B[24mAnother Line") .stderr(""); } @@ -1996,13 +1996,13 @@ fn theme_env_overrides_config() { .write_stdin("Ansi Underscore Test\nAnother Line") .assert() .success() - .stdout("\x1B[4mAnsi Underscore Test\n\x1B[24mAnother Line") + .stdout("\u{1b}]2;bat: STDIN\x07\x1B[4mAnsi Underscore Test\n\x1B[24mAnother Line") .stderr(""); } #[test] fn highlighting_is_skipped_on_long_lines() { - let expected = "\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mapi\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\n".to_owned() + + let expected = "\u{1b}]2;bat: longline.json\x07\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mapi\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\n".to_owned() + "\u{1b}" + r#"[38;5;231m {"ANGLE_instanced_arrays":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/ANGLE_instanced_arrays","spec_url":"https://www.khronos.org/registry/webgl/extensions/ANGLE_instanced_arrays/","support":{"chrome":{"version_added":"32"},"chrome_android":{"version_added":"32"},"edge":{"version_added":"12"},"firefox":{"version_added":"47"},"firefox_android":{"version_added":true},"ie":{"version_added":"11"},"opera":{"version_added":"19"},"opera_android":{"version_added":"19"},"safari":{"version_added":"8"},"safari_ios":{"version_added":"8"},"samsunginternet_android":{"version_added":"2.0"},"webview_android":{"version_added":"4.4"}},"status":{"experimental":false,"standard_track":true,"deprecated":false}},"drawArraysInstancedANGLE":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/ANGLE_instanced_arrays/drawArraysInstancedANGLE","spec_url":"https://www.khronos.org/registry/webgl/extensions/ANGLE_instanced_arrays/","support":{"chrome":{"version_added":"32"},"chrome_android":{"version_added":"32"},"edge":{"version_added":"12"},"firefox":{"version_added":"47"},"firefox_android":{"version_added":true},"ie":{"version_added":"11"},"opera":{"version_added":"19"},"opera_android":{"version_added":"19"},"safari":{"version_added":"8"},"safari_ios":{"version_added":"8"},"samsunginternet_android":{"version_added":"2.0"},"webview_android":{"version_added":"4.4"}},"status":{"experimental":false,"standard_track":true,"deprecated":false}}},"drawElementsInstancedANGLE":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/ANGLE_instanced_arrays/drawElementsInstancedANGLE","spec_url":"https://www.khronos.org/registry/webgl/extensions/ANGLE_instanced_arrays/","support":{"chrome":{"version_added":"32"},"chrome_android":{"version_added":"32"},"edge":{"version_added":"12"},"firefox":{"version_added":"47"},"firefox_android":{"version_added":true},"ie":{"version_added":"11"},"opera":{"version_added":"19"},"opera_android":{"version_added":"19"},"safari":{"version_added":"8"},"safari_ios":{"version_added":"8"},"samsunginternet_android":{"version_added":"2.0"},"webview_android":{"version_added":"4.4"}},"status":{"experimental":false,"standard_track":true,"deprecated":false}}},"vertexAttribDivisorANGLE":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/ANGLE_instanced_arrays/vertexAttribDivisorANGLE","spec_url":"https://www.khronos.org/registry/webgl/extensions/ANGLE_instanced_arrays/","support":{"chrome":{"version_added":"32"},"chrome_android":{"version_added":"32"},"edge":{"version_added":"12"},"firefox":{"version_added":"47"},"firefox_android":{"version_added":true},"ie":{"version_added":"11"},"opera":{"version_added":"19"},"opera_android":{"version_added":"19"},"safari":{"version_added":"8"},"safari_ios":{"version_added":"8"},"samsunginternet_android":{"version_added":"2.0"},"webview_android":{"version_added":"4.4"}},"status":{"experimental":false,"standard_track":true,"deprecated":false}}}},"AbortController":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortController","spec_url":"https://dom.spec.whatwg.org/#interface-abortcontroller","support":{"chrome":{"version_added":"66"},"chrome_android":{"version_added":"66"},"edge":{"version_added":"16"},"firefox":{"version_added":"57"},"firefox_android":{"version_added":"57"},"ie":{"version_added":false},"nodejs":{"version_added":"15.0.0"},"opera":{"version_added":"53"},"opera_android":{"version_added":"47"},"safari":[{"version_added":"12.1"},{"version_added":"11.1","partial_implementation":true,"notes":"Even though window.AbortController is defined, it doesn't really abort fetch requests. See bug 174980."}],"safari_ios":[{"version_added":"12.2"},{"version_added":"11.3","partial_implementation":true,"notes":"Even though window.AbortController is defined, it doesn't really abort fetch requests. See bug 174980."}],"samsunginternet_android":{"version_added":"9.0"},"webview_android":{"version_added":"66"}},"status":{"experimental":true,"standard_track":true,"deprecated":false}},"AbortController":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortController/AbortController","spec_url":"https://dom.spec.whatwg.org/#ref-for-dom-abortcontroller-abortcontroller①","description":"AbortController() constructor","support":{"chrome":{"version_added":"66"},"chrome_android":{"version_added":"66"},"edge":{"version_added":"16"},"firefox":{"version_added":"57"},"firefox_android":{"version_added":"57"},"ie":{"version_added":false},"nodejs":{"version_added":"15.0.0"},"opera":{"version_added":"53"},"opera_android":{"version_added":"47"},"safari":[{"version_added":"12.1"},{"version_added":"11.1","partial_implementation":true,"notes":"Even though window.AbortController is defined, it doesn't really abort fetch requests. See bug 174980."}],"safari_ios":[{"version_added":"12.2"},{"version_added":"11.3","partial_implementation":true,"notes":"Even though window.AbortController is defined, it doesn't really abort fetch requests. See bug 174980."}],"samsunginternet_android":{"version_added":"9.0"},"webview_android":{"version_added":"66"}},"status":{"experimental":true,"standard_track":true,"deprecated":false}}},"abort":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortController/abort","spec_url":"https://dom.spec.whatwg.org/#ref-for-dom-abortcontroller-abortcontroller①","support":{"chrome":{"version_added":"66"},"chrome_android":{"version_added":"66"},"edge":{"version_added":"16"},"firefox":{"version_added":"57"},"firefox_android":{"version_added":"57"},"ie":{"version_added":false},"nodejs":{"version_added":"15.0.0"},"opera":{"version_added":"53"},"opera_android":{"version_added":"47"},"safari":[{"version_added":"12.1"},{"version_added":"11.1","partial_implementation":true,"notes":"Even though window.AbortController is defined, it doesn't really abort fetch requests. See bug 174980."}],"safari_ios":[{"version_added":"12.2"},{"version_added":"11.3","partial_implementation":true,"notes":"Even though window.AbortController is defined, it doesn't really abort fetch requests. See bug 174980."}],"samsunginternet_android":{"version_added":"9.0"},"webview_android":{"version_added":"66"}},"status":{"experimental":true,"standard_track":true,"deprecated":false}}},"signal":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortController/signal","spec_url":"https://dom.spec.whatwg.org/#ref-for-dom-abortcontroller-signal②","support":{"chrome":{"version_added":"66"},"chrome_android":{"version_added":"66"},"edge":{"version_added":"16"},"firefox":{"version_added":"57"},"firefox_android":{"version_added":"57"},"ie":{"version_added":false},"nodejs":{"version_added":"15.0.0"},"opera":{"version_added":"53"},"opera_android":{"version_added":"47"},"safari":[{"version_added":"12.1"},{"version_added":"11.1","partial_implementation":true,"notes":"Even though window.AbortController is defined, it doesn't really abort fetch requests. See bug 174980."}],"safari_ios":[{"version_added":"12.2"},{"version_added":"11.3","partial_implementation":true,"notes":"Even though window.AbortController is defined, it doesn't really abort fetch requests. See bug 174980."}],"samsunginternet_android":{"version_added":"9.0"},"webview_android":{"version_added":"66"}},"status":{"experimental":true,"standard_track":true,"deprecated":false}}}},"AbortPaymentEvent":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortPaymentEvent","support":{"chrome":{"version_added":"70"},"chrome_android":{"version_added":"70"},"edge":{"version_added":"79"},"firefox":{"version_added":false},"firefox_android":{"version_added":false},"ie":{"version_added":false},"opera":{"version_added":"57"},"opera_android":{"version_added":"49"},"safari":{"version_added":false},"safari_ios":{"version_added":false},"samsunginternet_android":{"version_added":"10.0"},"webview_android":{"version_added":false}},"status":{"experimental":true,"standard_track":false,"deprecated":false}},"AbortPaymentEvent":{"__compat":{"description":"AbortPaymentEvent() constructor","mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortPaymentEvent/AbortPaymentEvent","support":{"chrome":{"version_added":"70"},"chrome_android":{"version_added":"70"},"edge":{"version_added":"79"},"firefox":{"version_added":false},"firefox_android":{"version_added":false},"ie":{"version_added":false},"opera":{"version_added":"57"},"opera_android":{"version_added":"49"},"safari":{"version_added":false},"safari_ios":{"version_added":false},"samsunginternet_android":{"version_added":"10.0"},"webview_android":{"version_added":false}},"status":{"experimental":true,"standard_track":false,"deprecated":false}}},"respondWith":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortPaymentEvent/respondWith","support":{"chrome":{"version_added":"70"},"chrome_android":{"version_added":"70"},"edge":{"version_added":"79"},"firefox":{"version_added":false},"firefox_android":{"version_added":false},"ie":{"version_added":false},"opera":{"version_added":"57"},"opera_android":{"version_added":"49"},"safari":{"version_added":false},"safari_ios":{"version_added":false},"samsunginternet_android":{"version_added":"10.0"},"webview_android":{"version_added":false}},"status":{"experimental":true,"standard_track":false,"deprecated":false}}}},"AbortSignal":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortSignal","spec_url":"https://dom.spec.whatwg.org/#interface-AbortSignal","support":{"chrome":{"version_added":"66"},"chrome_android":{"version_added":"66"},"edge":{"version_added":"16"},"firefox":{"version_added":"57"},"firefox_android":{"version_added":"57"},"ie":{"version_added":false},"nodejs":{"version_added":"15.0.0"},"opera":{"version_added":"53"},"opera_android":{"version_added":"47"},"safari":{"version_added":"11.1"},"safari_ios":{"version_added":"11.3"},"samsunginternet_android":{"version_added":"9.0"},"webview_android":{"version_added":"66"}},"status":{"experimental":false,"standard_track":true,"deprecated":false}},"abort":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortSignal/abort","spec_url":"https://dom.spec.whatwg.org/#ref-for-dom-abortsignal-abort①","support":{"chrome":{"version_added":false},"chrome_android":{"version_added":false},"edge":{"version_added":false},"firefox":{"version_added":"88"},"firefox_android":{"version_added":"88"},"ie":{"version_added":false},"nodejs":{"version_added":false},"opera":{"version_added":false},"opera_android":{"version_added":false},"safari":{"version_added":false},"safari_ios":{"version_added":false},"samsunginternet_android":{"version_added":false},"webview_android":{"version_added":false}},"status":{"experimental":false,"standard_track":true,"deprecated":false}}},"abort_event":{"__compat":{"description":"abort event","mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortSignal/abort_event","spec_url":"https://dom.spec.whatwg.org/#eventdef-abortsignal-abort","support":{"chrome":{"version_added":"66"},"chrome_android":{"version_added":"66"},"edge":{"version_added":"16"},"firefox":{"version_added":"57"},"firefox_android":{"version_added":"57"},"ie":{"version_added":false},"nodejs":{"version_added":"15.0.0"},"opera":{"version_added":"53"},"opera_android":{"version_added":"47"},"safari":{"version_added":"11.1"},"safari_ios":{"version_added":"11.3"},"samsunginternet_android":{"version_added":"9.0"},"webview_android":{"version_added":"66"}},"status":{"experimental":false,"standard_track":true,"deprecated":false}}},"aborted":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortSignal/aborted","spec_url":"https://dom.spec.whatwg.org/#ref-for-dom-abortsignal-aborted①","support":{"chrome":{"version_added":"66"},"chrome_android":{"version_added":"66"},"edge":{"version_added":"16"},"firefox":{"version_added":"57"},"firefox_android":{"version_added":"57"},"ie":{"version_added":false},"nodejs":{"version_added":"15.0.0"},"opera":{"version_added":"53"},"opera_android":{"version_added":"47"},"safari":{"version_added":"11.1"},"safari_ios":{"version_added":"11.3"},"samsunginternet_android":{"version_added":"9.0"},"webview_android":{"version_added":"66"}},"status":{"experimental":false,"standard_track":true,"deprecated":false}}},"onabort":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortSignal/onabort","spec_url":"https://dom.spec.whatwg.org/#abortsignal-onabort","support":{"chrome":{"version_added":"66"},"chrome_android":{"version_added":"66"},"edge":{"version_added":"16"},"firefox":{"version_added":"57"},"firefox_android":{"version_added":"57"},"ie":{"version_added":false},"nodejs":{"version_added":"15.0.0"},"opera":{"version_added":"53"},"opera_android":{"version_added":"47"},"safari":{"version_added":"11.1"},"safari_ios":{"version_added":"11.3"},"samsunginternet_android":{"version_added":"9.0"},"webview_android":{"version_added":"66"}},"status":{"experimental":false,"standard_track":true,"deprecated":false}}}},"AbsoluteOrientationSensor":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbsoluteOrientationSensor","spec_url":"https://w3c.github.io/orientation-sensor/#absoluteorientationsensor-interface","support":{"chrome":{"version_added":"67"},"chrome_android":{"version_added":"67"},"edge":{"version_added":"79"},"firefox":{"version_added":false},"firefox_android":{"version_added":false},"ie":{"version_added":false},"opera":{"version_added":"54"},"opera_android":{"version_added":"48"},"safari":{"version_added":false},"safari_ios":{"version_added":false},"samsunginternet_android":{"version_added":"9.0"},"webview_android":{"version_added":"67"}},"status":{"experimental":false,"standard_track":true,"deprecated":false}},"AbsoluteOrientationSensor":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbsoluteOrientationSensor/AbsoluteOrientationSensor","spec_url":"https://w3c.github.io/orientation-sensor/#dom-absoluteorientationsensor-absoluteorientationsensor","description":"AbsoluteOrientationSensor() constructor","support":{"chrome":{"version_added":"67"},"chrome_android":{"version_added":"67"},"edge":{"version_added":"79"},"firefox":{"version_added":false},"firefox_android":{"version_added":false},"ie":{"version_added":false},"opera":{"version_added":"54"},"opera_android":{"version_added":"48"},"safari":{"version_added":false},"safari_ios":{"version_added":false},"samsunginternet_android":{"version_added":"9.0"},"webview_android":{"version_added":"67"}},"status":{"experimental":false,"standard_track":true,"deprecated":false}}}},"AbstractRange":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbstractRange","spec_url":"https://dom.spec.whatwg.org/#interface-abstractrange","support":{"chrome":{"version_added":"90"},"chrome_android":{"version_added":"90"},"edge":[{"version_added":"90"},{"version_added":"18","version_removed":"79"}],"firefox":{"version_added":"69"},"firefox_android":{"version_added":false},"ie":{"version_added":false},"opera":{"version_added":false},"opera_android":{"version_added":false},"safari":{"version_added":"14.1"},"safari_ios":{"version_added":"14.5"},"samsunginternet_android":{"version_added":false},"webview_android":{"version_added":"90"}},"status":{"experimental":false,"standard_track":true,"deprecated":false}},"collapsed":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbstractRange/collapsed","spec_url":"https://dom.spec.whatwg.org/#ref-for-dom-range-collapsed①","support":{"chrome":{"version_added":"90"},"chrome_android":{"version_added":"90"},"edge":[{"version_added":"90"},{"version_added":"18","version_removed":"79"}],"firefox":{"version_added":"69"},"firefox_android":{"version_added":false},"ie":{"version_added":false},"opera":{"version_added":false},"opera_android":"# + "\u{1b}[0m\n\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mversion_added\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\u{1b}[38;5;141mfalse\u{1b}[0m\u{1b}[38;5;231m}\u{1b}[0m\n"; @@ -2036,7 +2036,7 @@ fn all_global_git_config_locations_syntax_mapping_work() { .arg("git/.config/git/config") .assert() .success() - .stdout(expected) + .stdout("\u{1b}]2;bat: git/.config/git/config\x07".to_owned() + expected) .stderr(""); bat() @@ -2048,7 +2048,7 @@ fn all_global_git_config_locations_syntax_mapping_work() { .arg("git/.config/git/config") .assert() .success() - .stdout(expected) + .stdout("\u{1b}]2;bat: git/.config/git/config\x07".to_owned() + expected) .stderr(""); bat() @@ -2060,7 +2060,7 @@ fn all_global_git_config_locations_syntax_mapping_work() { .arg("git/.gitconfig") .assert() .success() - .stdout(expected) + .stdout("\u{1b}]2;bat: git/.gitconfig\x07".to_owned() + expected) .stderr(""); } @@ -2076,7 +2076,7 @@ fn map_syntax_and_ignored_suffix_work_together() { .arg("test.demo.suffix") .assert() .success() - .stdout("\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mtest\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;186mvalue\u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;231m}\u{1b}[0m") + .stdout("\u{1b}]2;bat: test.demo.suffix\x07\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mtest\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;186mvalue\u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;231m}\u{1b}[0m") .stderr(""); bat() @@ -2090,7 +2090,7 @@ fn map_syntax_and_ignored_suffix_work_together() { .arg("test.demo.foo.suffix") .assert() .success() - .stdout("\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mtest\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;186mvalue\u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;231m}\u{1b}[0m") + .stdout("\u{1b}]2;bat: test.demo.foo.suffix\x07\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mtest\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;186mvalue\u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;231m}\u{1b}[0m") .stderr(""); } From 12b74dfb4ec0575664482c714e55e28d3493415d Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Mon, 18 Dec 2023 16:59:12 +0000 Subject: [PATCH 07/35] terminal title is only set when pager is being used --- src/bin/bat/main.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs index fb6abd11..97ea48f8 100644 --- a/src/bin/bat/main.rs +++ b/src/bin/bat/main.rs @@ -242,7 +242,9 @@ fn set_terminal_title_to_inputs_names(inputs: &Vec) { fn run_controller(inputs: Vec, config: &Config, cache_dir: &Path) -> Result { 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); + if config.paging_mode != PagingMode::Never { + set_terminal_title_to_inputs_names(&inputs); + } controller.run(inputs, None) } From 907af9e35f6c8e117533161c1a6a62d45dea6f38 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Mon, 18 Dec 2023 17:27:51 +0000 Subject: [PATCH 08/35] updated tests since terminal title is set conditionally --- tests/integration_tests.rs | 166 ++++++++++++++++++------------------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 96540cc6..43a75d8b 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -48,7 +48,7 @@ fn basic() { .arg("test.txt") .assert() .success() - .stdout("\u{1b}]2;bat: test.txt\x07hello world\n") + .stdout("hello world\n") .stderr(""); } @@ -58,7 +58,7 @@ fn stdin() { .write_stdin("foo\nbar\n") .assert() .success() - .stdout("\u{1b}]2;bat: STDIN\x07foo\nbar\n"); + .stdout("foo\nbar\n"); } #[test] @@ -68,7 +68,7 @@ fn concatenate() { .arg("test.txt") .assert() .success() - .stdout("\u{1b}]2;bat: test.txt, test.txt\x07hello world\nhello world\n"); + .stdout("hello world\nhello world\n"); } #[test] @@ -80,7 +80,7 @@ fn concatenate_stdin() { .write_stdin("stdin\n") .assert() .success() - .stdout("\u{1b}]2;bat: test.txt, STDIN, test.txt\x07hello world\nstdin\nhello world\n"); + .stdout("hello world\nstdin\nhello world\n"); } #[test] @@ -90,7 +90,7 @@ fn concatenate_empty_first() { .arg("test.txt") .assert() .success() - .stdout("\u{1b}]2;bat: empty.txt, test.txt\x07hello world\n"); + .stdout("hello world\n"); } #[test] @@ -100,7 +100,7 @@ fn concatenate_empty_last() { .arg("empty.txt") .assert() .success() - .stdout("\u{1b}]2;bat: test.txt, empty.txt\x07hello world\n"); + .stdout("hello world\n"); } #[test] @@ -110,7 +110,7 @@ fn concatenate_empty_both() { .arg("empty.txt") .assert() .success() - .stdout("\u{1b}]2;bat: empty.txt, empty.txt\x07"); + .stdout(""); } #[test] @@ -121,7 +121,7 @@ fn concatenate_empty_between() { .arg("test.txt") .assert() .success() - .stdout("\u{1b}]2;bat: test.txt, empty.txt, test.txt\x07hello world\nhello world\n"); + .stdout("hello world\nhello world\n"); } #[test] @@ -132,7 +132,7 @@ fn concatenate_empty_first_and_last() { .arg("empty.txt") .assert() .success() - .stdout("\u{1b}]2;bat: empty.txt, test.txt, empty.txt\x07hello world\n"); + .stdout("hello world\n"); } #[test] @@ -142,7 +142,7 @@ fn concatenate_single_line() { .arg("single-line.txt") .assert() .success() - .stdout("\u{1b}]2;bat: single-line.txt, single-line.txt\x07Single LineSingle Line"); + .stdout("Single LineSingle Line"); } #[test] @@ -153,7 +153,7 @@ fn concatenate_single_line_empty() { .arg("single-line.txt") .assert() .success() - .stdout("\u{1b}]2;bat: single-line.txt, empty.txt, single-line.txt\x07Single LineSingle Line"); + .stdout("Single LineSingle Line"); } #[test] @@ -164,7 +164,7 @@ fn line_numbers() { .arg("--decorations=always") .assert() .success() - .stdout("\u{1b}]2;bat: multiline.txt\x07 1 line 1\n 2 line 2\n 3 line 3\n 4 line 4\n"); + .stdout(" 1 line 1\n 2 line 2\n 3 line 3\n 4 line 4\n"); } #[test] @@ -174,7 +174,7 @@ fn line_range_2_3() { .arg("--line-range=2:3") .assert() .success() - .stdout("\u{1b}]2;bat: multiline.txt\x07line 2\nline 3\n"); + .stdout("line 2\nline 3\n"); } #[test] @@ -184,7 +184,7 @@ fn line_range_first_two() { .arg("--line-range=:2") .assert() .success() - .stdout("\u{1b}]2;bat: multiline.txt\x07line 1\nline 2\n"); + .stdout("line 1\nline 2\n"); } #[test] @@ -194,7 +194,7 @@ fn line_range_last_3() { .arg("--line-range=2:") .assert() .success() - .stdout("\u{1b}]2;bat: multiline.txt\x07line 2\nline 3\nline 4\n"); + .stdout("line 2\nline 3\nline 4\n"); } #[test] @@ -205,7 +205,7 @@ fn line_range_multiple() { .arg("--line-range=4:4") .assert() .success() - .stdout("\u{1b}]2;bat: multiline.txt\x07line 1\nline 2\nline 4\n"); + .stdout("line 1\nline 2\nline 4\n"); } #[test] @@ -354,7 +354,7 @@ fn tabs_numbers() { .assert() .success() .stdout( - "\u{1b}]2;bat: tabs.txt\x07 1 1 2 3 4 + " 1 1 2 3 4 2 1 ? 3 22 ? 4 333 ? @@ -377,7 +377,7 @@ fn tabs_passthrough_wrapped() { .assert() .success() .stdout( - "\u{1b}]2;bat: tabs.txt\x07 1 2 3 4 + " 1 2 3 4 1 ? 22 ? 333 ? @@ -400,7 +400,7 @@ fn tabs_4_wrapped() { .assert() .success() .stdout( - "\u{1b}]2;bat: tabs.txt\x07 1 2 3 4 + " 1 2 3 4 1 ? 22 ? 333 ? @@ -423,7 +423,7 @@ fn tabs_8_wrapped() { .assert() .success() .stdout( - "\u{1b}]2;bat: tabs.txt\x07 1 2 3 4 + " 1 2 3 4 1 ? 22 ? 333 ? @@ -446,7 +446,7 @@ fn tabs_passthrough() { .assert() .success() .stdout( - "\u{1b}]2;bat: tabs.txt\x07 1 2 3 4 + " 1 2 3 4 1 ? 22 ? 333 ? @@ -469,7 +469,7 @@ fn tabs_4() { .assert() .success() .stdout( - "\u{1b}]2;bat: tabs.txt\x07 1 2 3 4 + " 1 2 3 4 1 ? 22 ? 333 ? @@ -492,7 +492,7 @@ fn tabs_8() { .assert() .success() .stdout( - "\u{1b}]2;bat: tabs.txt\x07 1 2 3 4 + " 1 2 3 4 1 ? 22 ? 333 ? @@ -516,7 +516,7 @@ fn tabs_4_env_overrides_config() { .assert() .success() .stdout( - "\u{1b}]2;bat: tabs.txt\x07 1 2 3 4 + " 1 2 3 4 1 ? 22 ? 333 ? @@ -541,7 +541,7 @@ fn tabs_4_arg_overrides_env() { .assert() .success() .stdout( - "\u{1b}]2;bat: tabs.txt\x07 1 2 3 4 + " 1 2 3 4 1 ? 22 ? 333 ? @@ -565,7 +565,7 @@ fn tabs_4_arg_overrides_env_noconfig() { .assert() .success() .stdout( - "\u{1b}]2;bat: tabs.txt\x07 1 2 3 4 + " 1 2 3 4 1 ? 22 ? 333 ? @@ -594,7 +594,7 @@ fn do_not_exit_directory() { .arg("sub_directory") .arg("test.txt") .assert() - .stdout("\u{1b}]2;bat: sub_directory, test.txt\x07hello world\n") + .stdout("hello world\n") .failure(); } @@ -845,7 +845,7 @@ fn alias_pager_disable() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07hello world\n").normalize()); + .stdout(predicate::eq("hello world\n").normalize()); } #[test] @@ -872,7 +872,7 @@ fn disable_pager_if_disable_paging_flag_comes_after_paging() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07hello world\n").normalize()); + .stdout(predicate::eq("hello world\n").normalize()); } #[test] @@ -884,7 +884,7 @@ fn disable_pager_if_pp_flag_comes_after_paging() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07hello world\n").normalize()); + .stdout(predicate::eq("hello world\n").normalize()); } #[test] @@ -1111,7 +1111,7 @@ fn utf16() { .arg("test_UTF-16LE.txt") .assert() .success() - .stdout("\u{1b}]2;bat: test_UTF-16LE.txt\x07hello world\n"); + .stdout("hello world\n"); } // Regression test for https://github.com/sharkdp/bat/issues/1922 @@ -1124,7 +1124,7 @@ fn bom_not_stripped_in_loop_through_mode() { .arg("test_BOM.txt") .assert() .success() - .stdout("\u{1b}]2;bat: test_BOM.txt\x07\u{feff}hello world\n"); + .stdout("\u{feff}hello world\n"); } // Regression test for https://github.com/sharkdp/bat/issues/1922 @@ -1153,7 +1153,7 @@ fn bom_stripped_when_no_color_and_not_loop_through() { .assert() .success() .stdout( - "\u{1b}]2;bat: test_BOM.txt\x07\ + "\ ─────┬────────────────────────────────────────────────────────────────────────── │ File: test_BOM.txt ─────┼────────────────────────────────────────────────────────────────────────── @@ -1169,7 +1169,7 @@ fn can_print_file_named_cache() { .arg("cache") .assert() .success() - .stdout("\u{1b}]2;bat: cache\x07test\n") + .stdout("test\n") .stderr(""); } @@ -1180,7 +1180,7 @@ fn can_print_file_named_cache_with_additional_argument() { .arg("test.txt") .assert() .success() - .stdout("\u{1b}]2;bat: cache, test.txt\x07test\nhello world\n") + .stdout("test\nhello world\n") .stderr(""); } @@ -1190,7 +1190,7 @@ fn can_print_file_starting_with_cache() { .arg("cache.c") .assert() .success() - .stdout("\u{1b}]2;bat: cache.c\x07test\n") + .stdout("test\n") .stderr(""); } @@ -1220,7 +1220,7 @@ fn unicode_wrap() { .assert() .success() .stdout( - "\u{1b}]2;bat: unicode-wrap.txt\x07 1 ビタミンA ビタミンD ビタミンE ビ + " 1 ビタミンA ビタミンD ビタミンE ビ タミンK ビタミンB1 ビタミンB2 ナ イアシン パントテン酸 ビタミンB6 ビタミンB12 葉酸 ビオチン ビタ @@ -1264,7 +1264,7 @@ fn snip() { .assert() .success() .stdout( - "\u{1b}]2;bat: multiline.txt\x07 1 line 1 + " 1 line 1 2 line 2 ...─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ 8< ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ 4 line 4 @@ -1281,7 +1281,7 @@ fn empty_file_leads_to_empty_output_with_grid_enabled() { .arg("--terminal-width=80") .assert() .success() - .stdout("\u{1b}]2;bat: empty.txt\x07"); + .stdout(""); } #[test] @@ -1293,7 +1293,7 @@ fn empty_file_leads_to_empty_output_with_rule_enabled() { .arg("--terminal-width=80") .assert() .success() - .stdout("\u{1b}]2;bat: empty.txt\x07"); + .stdout(""); } #[test] @@ -1306,7 +1306,7 @@ fn header_basic() { .arg("--file-name=foo") .assert() .success() - .stdout("\u{1b}]2;bat: foo\x07File: foo\n") + .stdout("File: foo\n") .stderr(""); } @@ -1320,7 +1320,7 @@ fn header_full_basic() { .arg("--file-name=foo") .assert() .success() - .stdout("\u{1b}]2;bat: foo\x07File: foo\nSize: 12 B\n") + .stdout("File: foo\nSize: 12 B\n") .stderr(""); } @@ -1334,7 +1334,7 @@ fn header_env_basic() { .arg("--file-name=foo") .assert() .success() - .stdout("\u{1b}]2;bat: foo\x07File: foo\nSize: 12 B\n") + .stdout("File: foo\nSize: 12 B\n") .stderr(""); } @@ -1349,7 +1349,7 @@ fn header_arg_overrides_env() { .arg("--file-name=foo") .assert() .success() - .stdout("\u{1b}]2;bat: foo\x07File: foo\n") + .stdout("File: foo\n") .stderr(""); } @@ -1363,7 +1363,7 @@ fn header_binary() { .arg("--file-name=foo") .assert() .success() - .stdout("\u{1b}]2;bat: foo\x07File: foo \n") + .stdout("File: foo \n") .stderr(""); } @@ -1377,7 +1377,7 @@ fn header_full_binary() { .arg("--file-name=foo") .assert() .success() - .stdout("\u{1b}]2;bat: foo\x07File: foo \nSize: 4 B\n") + .stdout("File: foo \nSize: 4 B\n") .stderr(""); } @@ -1395,7 +1395,7 @@ fn header_default() { .assert() .success() .stdout( - "\u{1b}]2;bat: single-line.txt\x07\ + "\ ───────┬──────────────────────────────────────────────────────────────────────── │ File: single-line.txt ───────┼──────────────────────────────────────────────────────────────────────── @@ -1419,7 +1419,7 @@ fn header_default_is_default() { .assert() .success() .stdout( - "\u{1b}]2;bat: single-line.txt\x07\ + "\ ───────┬──────────────────────────────────────────────────────────────────────── │ File: single-line.txt ───────┼──────────────────────────────────────────────────────────────────────── @@ -1441,7 +1441,7 @@ fn filename_stdin() { .arg("--file-name=foo") .assert() .success() - .stdout("\u{1b}]2;bat: foo\x07File: foo\n") + .stdout("File: foo\n") .stderr(""); } @@ -1455,7 +1455,7 @@ fn filename_stdin_binary() { .arg("--file-name=foo") .assert() .success() - .stdout("\u{1b}]2;bat: foo\x07File: foo \n") + .stdout("File: foo \n") .stderr(""); } @@ -1471,7 +1471,7 @@ fn filename_multiple_ok() { .arg("--file-name=bar") .assert() .success() - .stdout("\u{1b}]2;bat: foo, bar\x07File: foo\n\nFile: bar\n") + .stdout("File: foo\n\nFile: bar\n") .stderr(""); } @@ -1496,7 +1496,7 @@ fn header_padding() { .arg("test.txt") .arg("single-line.txt") .assert() - .stdout("\u{1b}]2;bat: test.txt, single-line.txt\x07File: test.txt\nhello world\n\nFile: single-line.txt\nSingle Line\n") + .stdout("File: test.txt\nhello world\n\nFile: single-line.txt\nSingle Line\n") .stderr(""); } @@ -1508,7 +1508,7 @@ fn header_full_padding() { .arg("test.txt") .arg("single-line.txt") .assert() - .stdout("\u{1b}]2;bat: test.txt, single-line.txt\x07File: test.txt\nSize: 12 B\nhello world\n\nFile: single-line.txt\nSize: 11 B\nSingle Line\n") + .stdout("File: test.txt\nSize: 12 B\nhello world\n\nFile: single-line.txt\nSize: 11 B\nSingle Line\n") .stderr(""); } @@ -1522,7 +1522,7 @@ fn header_padding_rule() { .arg("single-line.txt") .assert() .stdout( - "\u{1b}]2;bat: test.txt, single-line.txt\x07File: test.txt + "File: test.txt hello world ──────────────────────────────────────────────────────────────────────────────── File: single-line.txt @@ -1542,7 +1542,7 @@ fn header_full_padding_rule() { .arg("single-line.txt") .assert() .stdout( - "\u{1b}]2;bat: test.txt, single-line.txt\x07File: test.txt + "File: test.txt Size: 12 B hello world ──────────────────────────────────────────────────────────────────────────────── @@ -1564,7 +1564,7 @@ fn grid_overrides_rule() { .arg("single-line.txt") .assert() .stdout( - "\u{1b}]2;bat: test.txt, single-line.txt\x07\ + "\ ──────────────────────────────────────────────────────────────────────────────── hello world ──────────────────────────────────────────────────────────────────────────────── @@ -1669,7 +1669,7 @@ fn show_all_mode() { .arg("--show-all") .arg("nonprintable.txt") .assert() - .stdout("\u{1b}]2;bat: nonprintable.txt\x07hello·world␊\n├──┤␍␀␇␈␛") + .stdout("hello·world␊\n├──┤␍␀␇␈␛") .stderr(""); } @@ -1683,7 +1683,7 @@ fn show_all_extends_tab_markers_to_next_tabstop() { .assert() .success() .stdout( - "\u{1b}]2;bat: tabs.txt\x07├──┤1├─┤2├─┤3├─┤4␊ + "├──┤1├─┤2├─┤3├─┤4␊ 1├─┤?␊ 22├┤?␊ 333↹?␊ @@ -1706,7 +1706,7 @@ fn show_all_extends_tab_markers_to_next_tabstop_width_8() { .assert() .success() .stdout( - "\u{1b}]2;bat: tabs.txt\x07├──────┤1├─────┤2├─────┤3├─────┤4␊ + "├──────┤1├─────┤2├─────┤3├─────┤4␊ 1├─────┤?␊ 22├────┤?␊ 333├───┤?␊ @@ -1726,7 +1726,7 @@ fn show_all_with_caret_notation() { .arg("--nonprintable-notation=caret") .arg("nonprintable.txt") .assert() - .stdout("\u{1b}]2;bat: nonprintable.txt\x07hello·world^J\n├──┤^M^@^G^H^[") + .stdout("hello·world^J\n├──┤^M^@^G^H^[") .stderr(""); bat() @@ -1734,7 +1734,7 @@ fn show_all_with_caret_notation() { .arg("--nonprintable-notation=caret") .arg("control_characters.txt") .assert() - .stdout("\u{1b}]2;bat: control_characters.txt\x07^@^A^B^C^D^E^F^G^H├─┤^J\n^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\\^]^^^_^?") + .stdout("^@^A^B^C^D^E^F^G^H├─┤^J\n^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\\^]^^^_^?") .stderr(""); } @@ -1745,7 +1745,7 @@ fn show_all_with_unicode() { .arg("--nonprintable-notation=unicode") .arg("control_characters.txt") .assert() - .stdout("\u{1b}]2;bat: control_characters.txt\x07␀␁␂␃␄␅␆␇␈├─┤␊\n␋␌␍␎␏␐␑␒␓␔␕␖␗␘␙␚␛␜␝␞␟␡") + .stdout("␀␁␂␃␄␅␆␇␈├─┤␊\n␋␌␍␎␏␐␑␒␓␔␕␖␗␘␙␚␛␜␝␞␟␡") .stderr(""); } @@ -1758,7 +1758,7 @@ fn no_paging_arg() { .arg("single-line.txt") .assert() .success() - .stdout("\u{1b}]2;bat: single-line.txt\x07Single Line"); + .stdout("Single Line"); } #[test] @@ -1770,7 +1770,7 @@ fn no_paging_short_arg() { .arg("single-line.txt") .assert() .success() - .stdout("\u{1b}]2;bat: single-line.txt\x07Single Line"); + .stdout("Single Line"); } #[test] @@ -1782,7 +1782,7 @@ fn no_pager_arg() { .arg("single-line.txt") .assert() .success() - .stdout("\u{1b}]2;bat: single-line.txt\x07Single Line"); + .stdout("Single Line"); } #[test] @@ -1795,7 +1795,7 @@ fn plain_mode_does_not_add_nonexisting_newline() { .arg("single-line.txt") .assert() .success() - .stdout("\u{1b}]2;bat: single-line.txt\x07Single Line"); + .stdout("Single Line"); } // Regression test for https://github.com/sharkdp/bat/issues/299 @@ -1813,7 +1813,7 @@ fn grid_for_file_without_newline() { .assert() .success() .stdout( - "\u{1b}]2;bat: single-line.txt\x07\ + "\ ───────┬──────────────────────────────────────────────────────────────────────── │ File: single-line.txt │ Size: 11 B @@ -1840,7 +1840,7 @@ fn ansi_highlight_underline() { .write_stdin("Ansi Underscore Test\nAnother Line") .assert() .success() - .stdout("\u{1b}]2;bat: STDIN\x07\x1B[4mAnsi Underscore Test\n\x1B[24mAnother Line") + .stdout("\x1B[4mAnsi Underscore Test\n\x1B[24mAnother Line") .stderr(""); } @@ -1859,7 +1859,7 @@ fn ansi_passthrough_emit() { .write_stdin("\x1B[33mColor\nColor \x1B[m\nPlain\n") .assert() .success() - .stdout("\u{1b}]2;bat: STDIN\x07\x1B[33m\x1B[33mColor\n\x1B[33mColor \x1B[m\nPlain\n") + .stdout("\x1B[33m\x1B[33mColor\n\x1B[33mColor \x1B[m\nPlain\n") .stderr(""); } } @@ -1874,7 +1874,7 @@ fn ignored_suffix_arg() { .arg("test.json~") .assert() .success() - .stdout("\u{1b}]2;bat: test.json~\x07\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mtest\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;186mvalue\u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;231m}\u{1b}[0m") + .stdout("\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mtest\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;186mvalue\u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;231m}\u{1b}[0m") .stderr(""); bat() @@ -1886,7 +1886,7 @@ fn ignored_suffix_arg() { .arg("test.json.suffix") .assert() .success() - .stdout("\u{1b}]2;bat: test.json.suffix\x07\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mtest\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;186mvalue\u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;231m}\u{1b}[0m") + .stdout("\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mtest\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;186mvalue\u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;231m}\u{1b}[0m") .stderr(""); bat() @@ -1897,16 +1897,16 @@ fn ignored_suffix_arg() { .arg("test.json.suffix") .assert() .success() - .stdout("\u{1b}]2;bat: test.json.suffix\x07\u{1b}[38;5;231m{\"test\": \"value\"}\u{1b}[0m") + .stdout("\u{1b}[38;5;231m{\"test\": \"value\"}\u{1b}[0m") .stderr(""); } fn wrapping_test(wrap_flag: &str, expect_wrap: bool) { let expected = match expect_wrap { true => - "\u{1b}]2;bat: long-single-line.txt\x07abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcde\nfghigklmnopqrstuvxyz\n", + "abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcde\nfghigklmnopqrstuvxyz\n", false => - "\u{1b}]2;bat: long-single-line.txt\x07abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyz\n", + "abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyz\n", }; bat() @@ -1957,7 +1957,7 @@ fn theme_arg_overrides_env() { .write_stdin("Ansi Underscore Test\nAnother Line") .assert() .success() - .stdout("\u{1b}]2;bat: STDIN\x07\x1B[4mAnsi Underscore Test\n\x1B[24mAnother Line") + .stdout("\x1B[4mAnsi Underscore Test\n\x1B[24mAnother Line") .stderr(""); } @@ -1977,7 +1977,7 @@ fn theme_arg_overrides_env_withconfig() { .write_stdin("Ansi Underscore Test\nAnother Line") .assert() .success() - .stdout("\u{1b}]2;bat: STDIN\x07\x1B[4mAnsi Underscore Test\n\x1B[24mAnother Line") + .stdout("\x1B[4mAnsi Underscore Test\n\x1B[24mAnother Line") .stderr(""); } @@ -1996,13 +1996,13 @@ fn theme_env_overrides_config() { .write_stdin("Ansi Underscore Test\nAnother Line") .assert() .success() - .stdout("\u{1b}]2;bat: STDIN\x07\x1B[4mAnsi Underscore Test\n\x1B[24mAnother Line") + .stdout("\x1B[4mAnsi Underscore Test\n\x1B[24mAnother Line") .stderr(""); } #[test] fn highlighting_is_skipped_on_long_lines() { - let expected = "\u{1b}]2;bat: longline.json\x07\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mapi\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\n".to_owned() + + let expected = "\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mapi\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\n".to_owned() + "\u{1b}" + r#"[38;5;231m {"ANGLE_instanced_arrays":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/ANGLE_instanced_arrays","spec_url":"https://www.khronos.org/registry/webgl/extensions/ANGLE_instanced_arrays/","support":{"chrome":{"version_added":"32"},"chrome_android":{"version_added":"32"},"edge":{"version_added":"12"},"firefox":{"version_added":"47"},"firefox_android":{"version_added":true},"ie":{"version_added":"11"},"opera":{"version_added":"19"},"opera_android":{"version_added":"19"},"safari":{"version_added":"8"},"safari_ios":{"version_added":"8"},"samsunginternet_android":{"version_added":"2.0"},"webview_android":{"version_added":"4.4"}},"status":{"experimental":false,"standard_track":true,"deprecated":false}},"drawArraysInstancedANGLE":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/ANGLE_instanced_arrays/drawArraysInstancedANGLE","spec_url":"https://www.khronos.org/registry/webgl/extensions/ANGLE_instanced_arrays/","support":{"chrome":{"version_added":"32"},"chrome_android":{"version_added":"32"},"edge":{"version_added":"12"},"firefox":{"version_added":"47"},"firefox_android":{"version_added":true},"ie":{"version_added":"11"},"opera":{"version_added":"19"},"opera_android":{"version_added":"19"},"safari":{"version_added":"8"},"safari_ios":{"version_added":"8"},"samsunginternet_android":{"version_added":"2.0"},"webview_android":{"version_added":"4.4"}},"status":{"experimental":false,"standard_track":true,"deprecated":false}}},"drawElementsInstancedANGLE":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/ANGLE_instanced_arrays/drawElementsInstancedANGLE","spec_url":"https://www.khronos.org/registry/webgl/extensions/ANGLE_instanced_arrays/","support":{"chrome":{"version_added":"32"},"chrome_android":{"version_added":"32"},"edge":{"version_added":"12"},"firefox":{"version_added":"47"},"firefox_android":{"version_added":true},"ie":{"version_added":"11"},"opera":{"version_added":"19"},"opera_android":{"version_added":"19"},"safari":{"version_added":"8"},"safari_ios":{"version_added":"8"},"samsunginternet_android":{"version_added":"2.0"},"webview_android":{"version_added":"4.4"}},"status":{"experimental":false,"standard_track":true,"deprecated":false}}},"vertexAttribDivisorANGLE":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/ANGLE_instanced_arrays/vertexAttribDivisorANGLE","spec_url":"https://www.khronos.org/registry/webgl/extensions/ANGLE_instanced_arrays/","support":{"chrome":{"version_added":"32"},"chrome_android":{"version_added":"32"},"edge":{"version_added":"12"},"firefox":{"version_added":"47"},"firefox_android":{"version_added":true},"ie":{"version_added":"11"},"opera":{"version_added":"19"},"opera_android":{"version_added":"19"},"safari":{"version_added":"8"},"safari_ios":{"version_added":"8"},"samsunginternet_android":{"version_added":"2.0"},"webview_android":{"version_added":"4.4"}},"status":{"experimental":false,"standard_track":true,"deprecated":false}}}},"AbortController":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortController","spec_url":"https://dom.spec.whatwg.org/#interface-abortcontroller","support":{"chrome":{"version_added":"66"},"chrome_android":{"version_added":"66"},"edge":{"version_added":"16"},"firefox":{"version_added":"57"},"firefox_android":{"version_added":"57"},"ie":{"version_added":false},"nodejs":{"version_added":"15.0.0"},"opera":{"version_added":"53"},"opera_android":{"version_added":"47"},"safari":[{"version_added":"12.1"},{"version_added":"11.1","partial_implementation":true,"notes":"Even though window.AbortController is defined, it doesn't really abort fetch requests. See bug 174980."}],"safari_ios":[{"version_added":"12.2"},{"version_added":"11.3","partial_implementation":true,"notes":"Even though window.AbortController is defined, it doesn't really abort fetch requests. See bug 174980."}],"samsunginternet_android":{"version_added":"9.0"},"webview_android":{"version_added":"66"}},"status":{"experimental":true,"standard_track":true,"deprecated":false}},"AbortController":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortController/AbortController","spec_url":"https://dom.spec.whatwg.org/#ref-for-dom-abortcontroller-abortcontroller①","description":"AbortController() constructor","support":{"chrome":{"version_added":"66"},"chrome_android":{"version_added":"66"},"edge":{"version_added":"16"},"firefox":{"version_added":"57"},"firefox_android":{"version_added":"57"},"ie":{"version_added":false},"nodejs":{"version_added":"15.0.0"},"opera":{"version_added":"53"},"opera_android":{"version_added":"47"},"safari":[{"version_added":"12.1"},{"version_added":"11.1","partial_implementation":true,"notes":"Even though window.AbortController is defined, it doesn't really abort fetch requests. See bug 174980."}],"safari_ios":[{"version_added":"12.2"},{"version_added":"11.3","partial_implementation":true,"notes":"Even though window.AbortController is defined, it doesn't really abort fetch requests. See bug 174980."}],"samsunginternet_android":{"version_added":"9.0"},"webview_android":{"version_added":"66"}},"status":{"experimental":true,"standard_track":true,"deprecated":false}}},"abort":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortController/abort","spec_url":"https://dom.spec.whatwg.org/#ref-for-dom-abortcontroller-abortcontroller①","support":{"chrome":{"version_added":"66"},"chrome_android":{"version_added":"66"},"edge":{"version_added":"16"},"firefox":{"version_added":"57"},"firefox_android":{"version_added":"57"},"ie":{"version_added":false},"nodejs":{"version_added":"15.0.0"},"opera":{"version_added":"53"},"opera_android":{"version_added":"47"},"safari":[{"version_added":"12.1"},{"version_added":"11.1","partial_implementation":true,"notes":"Even though window.AbortController is defined, it doesn't really abort fetch requests. See bug 174980."}],"safari_ios":[{"version_added":"12.2"},{"version_added":"11.3","partial_implementation":true,"notes":"Even though window.AbortController is defined, it doesn't really abort fetch requests. See bug 174980."}],"samsunginternet_android":{"version_added":"9.0"},"webview_android":{"version_added":"66"}},"status":{"experimental":true,"standard_track":true,"deprecated":false}}},"signal":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortController/signal","spec_url":"https://dom.spec.whatwg.org/#ref-for-dom-abortcontroller-signal②","support":{"chrome":{"version_added":"66"},"chrome_android":{"version_added":"66"},"edge":{"version_added":"16"},"firefox":{"version_added":"57"},"firefox_android":{"version_added":"57"},"ie":{"version_added":false},"nodejs":{"version_added":"15.0.0"},"opera":{"version_added":"53"},"opera_android":{"version_added":"47"},"safari":[{"version_added":"12.1"},{"version_added":"11.1","partial_implementation":true,"notes":"Even though window.AbortController is defined, it doesn't really abort fetch requests. See bug 174980."}],"safari_ios":[{"version_added":"12.2"},{"version_added":"11.3","partial_implementation":true,"notes":"Even though window.AbortController is defined, it doesn't really abort fetch requests. See bug 174980."}],"samsunginternet_android":{"version_added":"9.0"},"webview_android":{"version_added":"66"}},"status":{"experimental":true,"standard_track":true,"deprecated":false}}}},"AbortPaymentEvent":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortPaymentEvent","support":{"chrome":{"version_added":"70"},"chrome_android":{"version_added":"70"},"edge":{"version_added":"79"},"firefox":{"version_added":false},"firefox_android":{"version_added":false},"ie":{"version_added":false},"opera":{"version_added":"57"},"opera_android":{"version_added":"49"},"safari":{"version_added":false},"safari_ios":{"version_added":false},"samsunginternet_android":{"version_added":"10.0"},"webview_android":{"version_added":false}},"status":{"experimental":true,"standard_track":false,"deprecated":false}},"AbortPaymentEvent":{"__compat":{"description":"AbortPaymentEvent() constructor","mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortPaymentEvent/AbortPaymentEvent","support":{"chrome":{"version_added":"70"},"chrome_android":{"version_added":"70"},"edge":{"version_added":"79"},"firefox":{"version_added":false},"firefox_android":{"version_added":false},"ie":{"version_added":false},"opera":{"version_added":"57"},"opera_android":{"version_added":"49"},"safari":{"version_added":false},"safari_ios":{"version_added":false},"samsunginternet_android":{"version_added":"10.0"},"webview_android":{"version_added":false}},"status":{"experimental":true,"standard_track":false,"deprecated":false}}},"respondWith":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortPaymentEvent/respondWith","support":{"chrome":{"version_added":"70"},"chrome_android":{"version_added":"70"},"edge":{"version_added":"79"},"firefox":{"version_added":false},"firefox_android":{"version_added":false},"ie":{"version_added":false},"opera":{"version_added":"57"},"opera_android":{"version_added":"49"},"safari":{"version_added":false},"safari_ios":{"version_added":false},"samsunginternet_android":{"version_added":"10.0"},"webview_android":{"version_added":false}},"status":{"experimental":true,"standard_track":false,"deprecated":false}}}},"AbortSignal":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortSignal","spec_url":"https://dom.spec.whatwg.org/#interface-AbortSignal","support":{"chrome":{"version_added":"66"},"chrome_android":{"version_added":"66"},"edge":{"version_added":"16"},"firefox":{"version_added":"57"},"firefox_android":{"version_added":"57"},"ie":{"version_added":false},"nodejs":{"version_added":"15.0.0"},"opera":{"version_added":"53"},"opera_android":{"version_added":"47"},"safari":{"version_added":"11.1"},"safari_ios":{"version_added":"11.3"},"samsunginternet_android":{"version_added":"9.0"},"webview_android":{"version_added":"66"}},"status":{"experimental":false,"standard_track":true,"deprecated":false}},"abort":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortSignal/abort","spec_url":"https://dom.spec.whatwg.org/#ref-for-dom-abortsignal-abort①","support":{"chrome":{"version_added":false},"chrome_android":{"version_added":false},"edge":{"version_added":false},"firefox":{"version_added":"88"},"firefox_android":{"version_added":"88"},"ie":{"version_added":false},"nodejs":{"version_added":false},"opera":{"version_added":false},"opera_android":{"version_added":false},"safari":{"version_added":false},"safari_ios":{"version_added":false},"samsunginternet_android":{"version_added":false},"webview_android":{"version_added":false}},"status":{"experimental":false,"standard_track":true,"deprecated":false}}},"abort_event":{"__compat":{"description":"abort event","mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortSignal/abort_event","spec_url":"https://dom.spec.whatwg.org/#eventdef-abortsignal-abort","support":{"chrome":{"version_added":"66"},"chrome_android":{"version_added":"66"},"edge":{"version_added":"16"},"firefox":{"version_added":"57"},"firefox_android":{"version_added":"57"},"ie":{"version_added":false},"nodejs":{"version_added":"15.0.0"},"opera":{"version_added":"53"},"opera_android":{"version_added":"47"},"safari":{"version_added":"11.1"},"safari_ios":{"version_added":"11.3"},"samsunginternet_android":{"version_added":"9.0"},"webview_android":{"version_added":"66"}},"status":{"experimental":false,"standard_track":true,"deprecated":false}}},"aborted":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortSignal/aborted","spec_url":"https://dom.spec.whatwg.org/#ref-for-dom-abortsignal-aborted①","support":{"chrome":{"version_added":"66"},"chrome_android":{"version_added":"66"},"edge":{"version_added":"16"},"firefox":{"version_added":"57"},"firefox_android":{"version_added":"57"},"ie":{"version_added":false},"nodejs":{"version_added":"15.0.0"},"opera":{"version_added":"53"},"opera_android":{"version_added":"47"},"safari":{"version_added":"11.1"},"safari_ios":{"version_added":"11.3"},"samsunginternet_android":{"version_added":"9.0"},"webview_android":{"version_added":"66"}},"status":{"experimental":false,"standard_track":true,"deprecated":false}}},"onabort":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbortSignal/onabort","spec_url":"https://dom.spec.whatwg.org/#abortsignal-onabort","support":{"chrome":{"version_added":"66"},"chrome_android":{"version_added":"66"},"edge":{"version_added":"16"},"firefox":{"version_added":"57"},"firefox_android":{"version_added":"57"},"ie":{"version_added":false},"nodejs":{"version_added":"15.0.0"},"opera":{"version_added":"53"},"opera_android":{"version_added":"47"},"safari":{"version_added":"11.1"},"safari_ios":{"version_added":"11.3"},"samsunginternet_android":{"version_added":"9.0"},"webview_android":{"version_added":"66"}},"status":{"experimental":false,"standard_track":true,"deprecated":false}}}},"AbsoluteOrientationSensor":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbsoluteOrientationSensor","spec_url":"https://w3c.github.io/orientation-sensor/#absoluteorientationsensor-interface","support":{"chrome":{"version_added":"67"},"chrome_android":{"version_added":"67"},"edge":{"version_added":"79"},"firefox":{"version_added":false},"firefox_android":{"version_added":false},"ie":{"version_added":false},"opera":{"version_added":"54"},"opera_android":{"version_added":"48"},"safari":{"version_added":false},"safari_ios":{"version_added":false},"samsunginternet_android":{"version_added":"9.0"},"webview_android":{"version_added":"67"}},"status":{"experimental":false,"standard_track":true,"deprecated":false}},"AbsoluteOrientationSensor":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbsoluteOrientationSensor/AbsoluteOrientationSensor","spec_url":"https://w3c.github.io/orientation-sensor/#dom-absoluteorientationsensor-absoluteorientationsensor","description":"AbsoluteOrientationSensor() constructor","support":{"chrome":{"version_added":"67"},"chrome_android":{"version_added":"67"},"edge":{"version_added":"79"},"firefox":{"version_added":false},"firefox_android":{"version_added":false},"ie":{"version_added":false},"opera":{"version_added":"54"},"opera_android":{"version_added":"48"},"safari":{"version_added":false},"safari_ios":{"version_added":false},"samsunginternet_android":{"version_added":"9.0"},"webview_android":{"version_added":"67"}},"status":{"experimental":false,"standard_track":true,"deprecated":false}}}},"AbstractRange":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbstractRange","spec_url":"https://dom.spec.whatwg.org/#interface-abstractrange","support":{"chrome":{"version_added":"90"},"chrome_android":{"version_added":"90"},"edge":[{"version_added":"90"},{"version_added":"18","version_removed":"79"}],"firefox":{"version_added":"69"},"firefox_android":{"version_added":false},"ie":{"version_added":false},"opera":{"version_added":false},"opera_android":{"version_added":false},"safari":{"version_added":"14.1"},"safari_ios":{"version_added":"14.5"},"samsunginternet_android":{"version_added":false},"webview_android":{"version_added":"90"}},"status":{"experimental":false,"standard_track":true,"deprecated":false}},"collapsed":{"__compat":{"mdn_url":"https://developer.mozilla.org/docs/Web/API/AbstractRange/collapsed","spec_url":"https://dom.spec.whatwg.org/#ref-for-dom-range-collapsed①","support":{"chrome":{"version_added":"90"},"chrome_android":{"version_added":"90"},"edge":[{"version_added":"90"},{"version_added":"18","version_removed":"79"}],"firefox":{"version_added":"69"},"firefox_android":{"version_added":false},"ie":{"version_added":false},"opera":{"version_added":false},"opera_android":"# + "\u{1b}[0m\n\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mversion_added\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\u{1b}[38;5;141mfalse\u{1b}[0m\u{1b}[38;5;231m}\u{1b}[0m\n"; @@ -2036,7 +2036,7 @@ fn all_global_git_config_locations_syntax_mapping_work() { .arg("git/.config/git/config") .assert() .success() - .stdout("\u{1b}]2;bat: git/.config/git/config\x07".to_owned() + expected) + .stdout(expected) .stderr(""); bat() @@ -2048,7 +2048,7 @@ fn all_global_git_config_locations_syntax_mapping_work() { .arg("git/.config/git/config") .assert() .success() - .stdout("\u{1b}]2;bat: git/.config/git/config\x07".to_owned() + expected) + .stdout(expected) .stderr(""); bat() @@ -2060,7 +2060,7 @@ fn all_global_git_config_locations_syntax_mapping_work() { .arg("git/.gitconfig") .assert() .success() - .stdout("\u{1b}]2;bat: git/.gitconfig\x07".to_owned() + expected) + .stdout(expected) .stderr(""); } @@ -2076,7 +2076,7 @@ fn map_syntax_and_ignored_suffix_work_together() { .arg("test.demo.suffix") .assert() .success() - .stdout("\u{1b}]2;bat: test.demo.suffix\x07\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mtest\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;186mvalue\u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;231m}\u{1b}[0m") + .stdout("\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mtest\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;186mvalue\u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;231m}\u{1b}[0m") .stderr(""); bat() @@ -2090,7 +2090,7 @@ fn map_syntax_and_ignored_suffix_work_together() { .arg("test.demo.foo.suffix") .assert() .success() - .stdout("\u{1b}]2;bat: test.demo.foo.suffix\x07\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mtest\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;186mvalue\u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;231m}\u{1b}[0m") + .stdout("\u{1b}[38;5;231m{\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;208mtest\u{1b}[0m\u{1b}[38;5;208m\"\u{1b}[0m\u{1b}[38;5;231m:\u{1b}[0m\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;186mvalue\u{1b}[0m\u{1b}[38;5;186m\"\u{1b}[0m\u{1b}[38;5;231m}\u{1b}[0m") .stderr(""); } From 1679460f422bba3eeff629d543b79090fd0bd376 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Mon, 18 Dec 2023 17:32:08 +0000 Subject: [PATCH 09/35] updated CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 838bcf23..5cb36ca8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Features +- Set terminal title to file names when Paging is not Paging::Never #2783 (@Oliver-Looney) + ## Bugfixes - Fix `NO_COLOR` support, see #2767 (@acuteenvy) From 321b3ec81b706ad4302b0d16780d9eaf887773e7 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Mon, 18 Dec 2023 17:38:11 +0000 Subject: [PATCH 10/35] updated CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cb36ca8..b084c7f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Features -- Set terminal title to file names when Paging is not Paging::Never #2783 (@Oliver-Looney) +- Set terminal title to file names when Paging is not Paging::Never #2807 (@Oliver-Looney) ## Bugfixes From 0027055a831febf3d728514b601cefc6b00d5b66 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Mon, 18 Dec 2023 17:44:52 +0000 Subject: [PATCH 11/35] fixed system_wide_config.rs tests --- tests/system_wide_config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/system_wide_config.rs b/tests/system_wide_config.rs index 7c2a9972..1bbc64ad 100644 --- a/tests/system_wide_config.rs +++ b/tests/system_wide_config.rs @@ -12,7 +12,7 @@ fn use_systemwide_config() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("dummy-pager-from-system-config\n").normalize()); + .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07dummy-pager-from-system-config\n").normalize()); } // This test is ignored, as it needs a special system wide config put into place @@ -25,5 +25,5 @@ fn config_overrides_system_config() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("dummy-pager-from-config\n").normalize()); + .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07dummy-pager-from-config\n").normalize()); } From 5b4ce684a100a8b28127c52cfe1f306685dedd97 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Mon, 18 Dec 2023 17:47:09 +0000 Subject: [PATCH 12/35] ran cargo fmt --- tests/system_wide_config.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/system_wide_config.rs b/tests/system_wide_config.rs index 1bbc64ad..c774aa2e 100644 --- a/tests/system_wide_config.rs +++ b/tests/system_wide_config.rs @@ -8,11 +8,9 @@ use utils::command::bat_with_config; #[test] #[ignore] fn use_systemwide_config() { - bat_with_config() - .arg("test.txt") - .assert() - .success() - .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07dummy-pager-from-system-config\n").normalize()); + bat_with_config().arg("test.txt").assert().success().stdout( + predicate::eq("\u{1b}]2;bat: test.txt\x07dummy-pager-from-system-config\n").normalize(), + ); } // This test is ignored, as it needs a special system wide config put into place From 57016f4e044db09161140b50e55a65b35fb3e363 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sun, 31 Dec 2023 22:15:00 +0000 Subject: [PATCH 13/35] small refactoring of set terminal title function --- src/bin/bat/main.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs index 97ea48f8..8998ad7b 100644 --- a/src/bin/bat/main.rs +++ b/src/bin/bat/main.rs @@ -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) { - 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) -> 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, config: &Config, cache_dir: &Path) -> Result { 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) } From 3b0ade9cb8ade5aa03ca20a250372aba37a1b24f Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sun, 31 Dec 2023 22:24:44 +0000 Subject: [PATCH 14/35] slightly changed set terminal command to match docs & broke print line into multiple variables --- src/bin/bat/main.rs | 7 ++++++- tests/integration_tests.rs | 14 +++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs index 8998ad7b..4a8ff421 100644 --- a/src/bin/bat/main.rs +++ b/src/bin/bat/main.rs @@ -228,7 +228,12 @@ pub fn list_themes(cfg: &Config, config_dir: &Path, cache_dir: &Path) -> Result< } fn set_terminal_title_to(new_terminal_title: String) { - print!("\x1b]2;{}\x07", new_terminal_title); + let osc_command_for_setting_terminal_title = "\x1b]0;"; + let osc_end_command = "\x07"; + print!( + "{}{}{}", + osc_command_for_setting_terminal_title, new_terminal_title, osc_end_command + ); io::stdout().flush().unwrap(); } diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 43a75d8b..47a75e5c 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -653,7 +653,7 @@ fn pager_disable() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07hello world\n").normalize()); + .stdout(predicate::eq("\u{1b}]0;bat: test.txt\x07hello world\n").normalize()); } #[test] @@ -734,7 +734,7 @@ fn env_var_pager_value_bat() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07hello world\n").normalize()); + .stdout(predicate::eq("\u{1b}]0;bat: test.txt\x07hello world\n").normalize()); } #[test] @@ -772,7 +772,7 @@ fn pager_most_from_pager_env_var() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07hello world\n").normalize()); + .stdout(predicate::eq("\u{1b}]0;bat: test.txt\x07hello world\n").normalize()); }); } @@ -818,7 +818,7 @@ fn pager_most_with_arg() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07hello world\n").normalize()); + .stdout(predicate::eq("\u{1b}]0;bat: test.txt\x07hello world\n").normalize()); }); } @@ -833,7 +833,7 @@ fn pager_more() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07hello world\n").normalize()); + .stdout(predicate::eq("\u{1b}]0;bat: test.txt\x07hello world\n").normalize()); }); } @@ -896,7 +896,7 @@ fn enable_pager_if_disable_paging_flag_comes_before_paging() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07pager-output\n").normalize()); + .stdout(predicate::eq("\u{1b}]0;bat: test.txt\x07pager-output\n").normalize()); } #[test] @@ -908,7 +908,7 @@ fn enable_pager_if_pp_flag_comes_before_paging() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07pager-output\n").normalize()); + .stdout(predicate::eq("\u{1b}]0;bat: test.txt\x07pager-output\n").normalize()); } #[test] From c261b41578f662886d14fce690837626ec328e96 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sun, 31 Dec 2023 22:44:17 +0000 Subject: [PATCH 15/35] trying to fix failing system_wide_config.rs tests --- tests/system_wide_config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/system_wide_config.rs b/tests/system_wide_config.rs index c774aa2e..fbb3b259 100644 --- a/tests/system_wide_config.rs +++ b/tests/system_wide_config.rs @@ -9,7 +9,7 @@ use utils::command::bat_with_config; #[ignore] fn use_systemwide_config() { bat_with_config().arg("test.txt").assert().success().stdout( - predicate::eq("\u{1b}]2;bat: test.txt\x07dummy-pager-from-system-config\n").normalize(), + predicate::eq("\u{1b}]0;bat: test.txt\x07dummy-pager-from-system-config\n").normalize(), ); } @@ -23,5 +23,5 @@ fn config_overrides_system_config() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("\u{1b}]2;bat: test.txt\x07dummy-pager-from-config\n").normalize()); + .stdout(predicate::eq("\u{1b}]0;bat: test.txt\x07dummy-pager-from-config\n").normalize()); } From 9239b125b148af1833d85be972fc27d14895e7a6 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sat, 27 Jan 2024 14:14:40 +0000 Subject: [PATCH 16/35] added a flag to config for setting terminal title --- src/bin/bat/app.rs | 1 + src/bin/bat/clap_app.rs | 6 ++++++ src/config.rs | 3 +++ 3 files changed, 10 insertions(+) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 09430623..ef22e93d 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -287,6 +287,7 @@ impl App { use_custom_assets: !self.matches.get_flag("no-custom-assets"), #[cfg(feature = "lessopen")] use_lessopen: self.matches.get_flag("lessopen"), + set_terminal_title: self.matches.get_flag("set_terminal_title"), }) } diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index e8222a1d..ba463996 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -168,6 +168,12 @@ pub fn build_app(interactive_output: bool) -> Command { "Include N lines of context around added/removed/modified lines when using '--diff'.", ), ) + .arg( + Arg::new("set_terminal_title") + .long("set_terminal_title") + .action(ArgAction::SetTrue) + .help("Sets terminal title when using a pager") + .long_help("Sets terminal title to filenames when using a pager."),) } app = app.arg( diff --git a/src/config.rs b/src/config.rs index 83acc7df..c5cc2abd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -94,6 +94,9 @@ pub struct Config<'a> { // Whether or not to use $LESSOPEN if set #[cfg(feature = "lessopen")] pub use_lessopen: bool, + + // Weather or not to set terminal title when using a pager + pub set_terminal_title: bool, } #[cfg(all(feature = "minimal-application", feature = "paging"))] From b33e33fe260f44074f4bcac21a0798530b377228 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sat, 27 Jan 2024 14:17:25 +0000 Subject: [PATCH 17/35] terminal title is only set if user opts in with --set_terminal_title flag --- src/bin/bat/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs index 4a8ff421..a21009f0 100644 --- a/src/bin/bat/main.rs +++ b/src/bin/bat/main.rs @@ -251,7 +251,7 @@ fn get_new_terminal_title(inputs: &Vec) -> String { fn run_controller(inputs: Vec, config: &Config, cache_dir: &Path) -> Result { 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 { + if config.paging_mode != PagingMode::Never && config.set_terminal_title { set_terminal_title_to(get_new_terminal_title(&inputs)); } controller.run(inputs, None) From c91182977159cfec891e4fb0be2a681bd33dcdba Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sat, 27 Jan 2024 14:23:24 +0000 Subject: [PATCH 18/35] fixed failing tests --- doc/long-help.txt | 3 +++ doc/short-help.txt | 2 ++ tests/integration_tests.rs | 14 +++++++------- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/doc/long-help.txt b/doc/long-help.txt index 247120fb..cb43e520 100644 --- a/doc/long-help.txt +++ b/doc/long-help.txt @@ -50,6 +50,9 @@ Options: --diff-context Include N lines of context around added/removed/modified lines when using '--diff'. + --set_terminal_title + Sets terminal title to filenames when using a pager. + --tabs Set the tab width to T spaces. Use a width of 0 to pass tabs through directly diff --git a/doc/short-help.txt b/doc/short-help.txt index 118dbce2..2318fa58 100644 --- a/doc/short-help.txt +++ b/doc/short-help.txt @@ -21,6 +21,8 @@ Options: Specify the name to display for a file. -d, --diff Only show lines that have been added/removed/modified. + --set_terminal_title + Sets terminal title when using a pager --tabs Set the tab width to T spaces. --wrap diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 47a75e5c..be70fdca 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -653,7 +653,7 @@ fn pager_disable() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("\u{1b}]0;bat: test.txt\x07hello world\n").normalize()); + .stdout(predicate::eq("hello world\n").normalize()); } #[test] @@ -734,7 +734,7 @@ fn env_var_pager_value_bat() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("\u{1b}]0;bat: test.txt\x07hello world\n").normalize()); + .stdout(predicate::eq("hello world\n").normalize()); } #[test] @@ -772,7 +772,7 @@ fn pager_most_from_pager_env_var() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("\u{1b}]0;bat: test.txt\x07hello world\n").normalize()); + .stdout(predicate::eq("hello world\n").normalize()); }); } @@ -818,7 +818,7 @@ fn pager_most_with_arg() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("\u{1b}]0;bat: test.txt\x07hello world\n").normalize()); + .stdout(predicate::eq("hello world\n").normalize()); }); } @@ -833,7 +833,7 @@ fn pager_more() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("\u{1b}]0;bat: test.txt\x07hello world\n").normalize()); + .stdout(predicate::eq("hello world\n").normalize()); }); } @@ -896,7 +896,7 @@ fn enable_pager_if_disable_paging_flag_comes_before_paging() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("\u{1b}]0;bat: test.txt\x07pager-output\n").normalize()); + .stdout(predicate::eq("pager-output\n").normalize()); } #[test] @@ -908,7 +908,7 @@ fn enable_pager_if_pp_flag_comes_before_paging() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("\u{1b}]0;bat: test.txt\x07pager-output\n").normalize()); + .stdout(predicate::eq("pager-output\n").normalize()); } #[test] From f6d76e01041bda2cb505eab16a643d1dc4c0ce38 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sat, 27 Jan 2024 14:31:28 +0000 Subject: [PATCH 19/35] added integration test for setting terminal title --- tests/integration_tests.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index be70fdca..b6150a77 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -922,6 +922,21 @@ fn pager_failed_to_parse() { .stderr(predicate::str::contains("Could not parse pager command")); } +#[test] +fn pager_set_terminal_title() { + mocked_pagers::with_mocked_versions_of_more_and_most_in_path(|| { + bat() + .env("PAGER", mocked_pagers::from("echo pager-output")) + .arg("--paging=always") + .arg("--set_terminal_title") + .arg("test.txt") + .assert() + .success() + .stdout(predicate::str::contains("\u{1b}]0;bat: test.txt\x07pager-output\n").normalize()); + }); +} + + #[test] #[serial] fn env_var_bat_paging() { @@ -2430,3 +2445,5 @@ fn highlighting_independant_from_map_syntax_case() { .stdout(expected) .stderr(""); } + + From 22254936a2a039fe65262f6c9a415569d9f83b0c Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sat, 27 Jan 2024 14:32:34 +0000 Subject: [PATCH 20/35] ran cargo fmt --- tests/integration_tests.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index b6150a77..df9969b4 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -932,11 +932,12 @@ fn pager_set_terminal_title() { .arg("test.txt") .assert() .success() - .stdout(predicate::str::contains("\u{1b}]0;bat: test.txt\x07pager-output\n").normalize()); + .stdout( + predicate::str::contains("\u{1b}]0;bat: test.txt\x07pager-output\n").normalize(), + ); }); } - #[test] #[serial] fn env_var_bat_paging() { @@ -2445,5 +2446,3 @@ fn highlighting_independant_from_map_syntax_case() { .stdout(expected) .stderr(""); } - - From 9be2a36a01960af0688d740fd0a047bd28b5b6a9 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sat, 27 Jan 2024 14:38:09 +0000 Subject: [PATCH 21/35] fixed system wide config tests failing --- tests/system_wide_config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/system_wide_config.rs b/tests/system_wide_config.rs index fbb3b259..66c96c06 100644 --- a/tests/system_wide_config.rs +++ b/tests/system_wide_config.rs @@ -9,7 +9,7 @@ use utils::command::bat_with_config; #[ignore] fn use_systemwide_config() { bat_with_config().arg("test.txt").assert().success().stdout( - predicate::eq("\u{1b}]0;bat: test.txt\x07dummy-pager-from-system-config\n").normalize(), + predicate::eq("dummy-pager-from-system-config\n").normalize(), ); } @@ -23,5 +23,5 @@ fn config_overrides_system_config() { .arg("test.txt") .assert() .success() - .stdout(predicate::eq("\u{1b}]0;bat: test.txt\x07dummy-pager-from-config\n").normalize()); + .stdout(predicate::eq("dummy-pager-from-config\n").normalize()); } From e9a6aaa30f9433d9b715f8aaf0b40f9bd09c5418 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sat, 27 Jan 2024 14:44:54 +0000 Subject: [PATCH 22/35] cargo fmt --- tests/system_wide_config.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/system_wide_config.rs b/tests/system_wide_config.rs index 66c96c06..7c2a9972 100644 --- a/tests/system_wide_config.rs +++ b/tests/system_wide_config.rs @@ -8,9 +8,11 @@ use utils::command::bat_with_config; #[test] #[ignore] fn use_systemwide_config() { - bat_with_config().arg("test.txt").assert().success().stdout( - predicate::eq("dummy-pager-from-system-config\n").normalize(), - ); + bat_with_config() + .arg("test.txt") + .assert() + .success() + .stdout(predicate::eq("dummy-pager-from-system-config\n").normalize()); } // This test is ignored, as it needs a special system wide config put into place From 60e32cf8237abf96b3d6dc78de35b8e904b015f1 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sat, 27 Jan 2024 14:46:13 +0000 Subject: [PATCH 23/35] removed set_terminal_title arg from clap_app.rs since other boolean args aren't in clap_app.rs --- src/bin/bat/clap_app.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index ba463996..e8222a1d 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -168,12 +168,6 @@ pub fn build_app(interactive_output: bool) -> Command { "Include N lines of context around added/removed/modified lines when using '--diff'.", ), ) - .arg( - Arg::new("set_terminal_title") - .long("set_terminal_title") - .action(ArgAction::SetTrue) - .help("Sets terminal title when using a pager") - .long_help("Sets terminal title to filenames when using a pager."),) } app = app.arg( From 7f12989127839e07d3dcf5d9f3b154d0e2d7c661 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Mon, 29 Jan 2024 09:47:41 +0000 Subject: [PATCH 24/35] added set_terminal_title arg to clap_app.rs to fix ci errors --- doc/long-help.txt | 6 +++--- doc/short-help.txt | 2 -- src/bin/bat/clap_app.rs | 7 +++++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/doc/long-help.txt b/doc/long-help.txt index cb43e520..700f547b 100644 --- a/doc/long-help.txt +++ b/doc/long-help.txt @@ -50,9 +50,6 @@ Options: --diff-context Include N lines of context around added/removed/modified lines when using '--diff'. - --set_terminal_title - Sets terminal title to filenames when using a pager. - --tabs Set the tab width to T spaces. Use a width of 0 to pass tabs through directly @@ -163,6 +160,9 @@ Options: --acknowledgements Show acknowledgements. + --set_terminal_title + Sets terminal title to filenames when using a pager. + -h, --help Print help (see a summary with '-h') diff --git a/doc/short-help.txt b/doc/short-help.txt index 2318fa58..118dbce2 100644 --- a/doc/short-help.txt +++ b/doc/short-help.txt @@ -21,8 +21,6 @@ Options: Specify the name to display for a file. -d, --diff Only show lines that have been added/removed/modified. - --set_terminal_title - Sets terminal title when using a pager --tabs Set the tab width to T spaces. --wrap diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index e8222a1d..3f83bf63 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -567,6 +567,13 @@ pub fn build_app(interactive_output: bool) -> Command { .action(ArgAction::SetTrue) .hide_short_help(true) .help("Show acknowledgements."), + ) + .arg( + Arg::new("set_terminal_title") + .long("set_terminal_title") + .action(ArgAction::SetTrue) + .hide_short_help(true) + .help("Sets terminal title to filenames when using a pager."), ); // Check if the current directory contains a file name cache. Otherwise, From a8d07333e9391c75406e9ac2d03d80f70d32e8fb Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Tue, 30 Jan 2024 19:29:28 +0000 Subject: [PATCH 25/35] updated integration_tests.rs --- tests/integration_tests.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index df9969b4..dd670399 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -924,18 +924,14 @@ fn pager_failed_to_parse() { #[test] fn pager_set_terminal_title() { - mocked_pagers::with_mocked_versions_of_more_and_most_in_path(|| { - bat() - .env("PAGER", mocked_pagers::from("echo pager-output")) - .arg("--paging=always") - .arg("--set_terminal_title") - .arg("test.txt") - .assert() - .success() - .stdout( - predicate::str::contains("\u{1b}]0;bat: test.txt\x07pager-output\n").normalize(), - ); - }); + bat() + .env("PAGER", mocked_pagers::from("echo pager-output")) + .arg("--paging=always") + .arg("--set_terminal_title") + .arg("test.txt") + .assert() + .success() + .stdout(predicate::str::contains("\u{1b}]0;bat: test.txt\x07pager-output\n").normalize()); } #[test] From 0af1df52582283201b2b73638a11c14030fd0f44 Mon Sep 17 00:00:00 2001 From: Andy Kipp Date: Wed, 31 Jan 2024 14:07:56 +0100 Subject: [PATCH 26/35] Create xonsh.toml --- src/syntax_mapping/builtins/common/xonsh.toml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/syntax_mapping/builtins/common/xonsh.toml diff --git a/src/syntax_mapping/builtins/common/xonsh.toml b/src/syntax_mapping/builtins/common/xonsh.toml new file mode 100644 index 00000000..8e472b41 --- /dev/null +++ b/src/syntax_mapping/builtins/common/xonsh.toml @@ -0,0 +1,3 @@ +# Xonsh shell (https://xon.sh/) +[mappings] +"Python" = ["*.xsh", "*.xonshrc"] From 695cf1f387a970e2706c908d9597bfad85eb97ee Mon Sep 17 00:00:00 2001 From: Andy Kipp Date: Wed, 31 Jan 2024 14:12:00 +0100 Subject: [PATCH 27/35] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8015b14d..06db2cbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - `cmd-help`: scope subcommands followed by other terms, and other misc improvements, see #2819 (@victor-gp) - Upgrade JQ syntax, see #2820 (@dependabot[bot]) +- Associate `xsh` files with `xonsh` syntax that is Python, see #2840 (@anki-code). ## Themes From 7ce010d9edf6d82f7013af2c711308f38fc680d6 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Thu, 8 Feb 2024 21:33:03 +0000 Subject: [PATCH 28/35] Using hypens instead of underscores for set-terminal-title command --- doc/long-help.txt | 2 +- src/bin/bat/app.rs | 2 +- src/bin/bat/clap_app.rs | 4 ++-- tests/integration_tests.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/long-help.txt b/doc/long-help.txt index 700f547b..3ac4a40f 100644 --- a/doc/long-help.txt +++ b/doc/long-help.txt @@ -160,7 +160,7 @@ Options: --acknowledgements Show acknowledgements. - --set_terminal_title + --set-terminal-title Sets terminal title to filenames when using a pager. -h, --help diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index ef22e93d..8ec3caa5 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -287,7 +287,7 @@ impl App { use_custom_assets: !self.matches.get_flag("no-custom-assets"), #[cfg(feature = "lessopen")] use_lessopen: self.matches.get_flag("lessopen"), - set_terminal_title: self.matches.get_flag("set_terminal_title"), + set_terminal_title: self.matches.get_flag("set-terminal-title"), }) } diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index 3f83bf63..6ceed784 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -569,8 +569,8 @@ pub fn build_app(interactive_output: bool) -> Command { .help("Show acknowledgements."), ) .arg( - Arg::new("set_terminal_title") - .long("set_terminal_title") + Arg::new("set-terminal-title") + .long("set-terminal-title") .action(ArgAction::SetTrue) .hide_short_help(true) .help("Sets terminal title to filenames when using a pager."), diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index dd670399..1ba51d19 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -927,7 +927,7 @@ fn pager_set_terminal_title() { bat() .env("PAGER", mocked_pagers::from("echo pager-output")) .arg("--paging=always") - .arg("--set_terminal_title") + .arg("--set-terminal-title") .arg("test.txt") .assert() .success() From 02077db53e36b157e1a12496b8315c77514de0a0 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Thu, 8 Feb 2024 21:41:20 +0000 Subject: [PATCH 29/35] undid unnecessary api visibility changes --- src/bin/bat/main.rs | 2 +- src/input.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs index a21009f0..afc0d59b 100644 --- a/src/bin/bat/main.rs +++ b/src/bin/bat/main.rs @@ -240,7 +240,7 @@ fn set_terminal_title_to(new_terminal_title: String) { fn get_new_terminal_title(inputs: &Vec) -> String { let mut new_terminal_title = "bat: ".to_string(); for (index, input) in inputs.iter().enumerate() { - new_terminal_title += &input.description.name.to_string(); + new_terminal_title += input.description().title(); if index < inputs.len() - 1 { new_terminal_title += ", "; } diff --git a/src/input.rs b/src/input.rs index 724c5e15..ccab98bf 100644 --- a/src/input.rs +++ b/src/input.rs @@ -13,7 +13,7 @@ use crate::error::*; /// This tells bat how to refer to the input. #[derive(Clone)] pub struct InputDescription { - pub name: String, + pub(crate) 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 description: InputDescription, + pub(crate) description: InputDescription, } pub(crate) enum OpenedInputKind { From a5bd9f51be047089a85eab121e0a1a52d213b203 Mon Sep 17 00:00:00 2001 From: mxaddict Date: Sun, 11 Feb 2024 04:57:42 +0800 Subject: [PATCH 30/35] Added JSONC and aws credentials to the syntax mappings --- CHANGELOG.md | 2 ++ src/syntax_mapping/builtins/common/50-aws-credentials.toml | 2 ++ .../builtins/common/{50-jsonl.toml => 50-json.toml} | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 src/syntax_mapping/builtins/common/50-aws-credentials.toml rename src/syntax_mapping/builtins/common/{50-jsonl.toml => 50-json.toml} (65%) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6e13469..80923878 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ - Pull in fix for unsafe-libyaml security advisory, see #2812 (@dtolnay) - Update git-version dependency to use Syn v2, see #2816 (@dtolnay) - Update git2 dependency to v0.18.2, see #2852 (@eth-p) +- Added auto detect syntax for `.jsonc` #2795 (@mxaddict) +- Added auto detect syntax for `.aws/{config,credentials}` #2795 (@mxaddict) ## Syntaxes diff --git a/src/syntax_mapping/builtins/common/50-aws-credentials.toml b/src/syntax_mapping/builtins/common/50-aws-credentials.toml new file mode 100644 index 00000000..a16e6e8f --- /dev/null +++ b/src/syntax_mapping/builtins/common/50-aws-credentials.toml @@ -0,0 +1,2 @@ +[mappings] +"INI" = ["**/.aws/credentials", "**/.aws/config"] diff --git a/src/syntax_mapping/builtins/common/50-jsonl.toml b/src/syntax_mapping/builtins/common/50-json.toml similarity index 65% rename from src/syntax_mapping/builtins/common/50-jsonl.toml rename to src/syntax_mapping/builtins/common/50-json.toml index 4b70a4d0..e604868a 100644 --- a/src/syntax_mapping/builtins/common/50-jsonl.toml +++ b/src/syntax_mapping/builtins/common/50-json.toml @@ -1,3 +1,3 @@ # JSON Lines is a simple variation of JSON #2535 [mappings] -"JSON" = ["*.jsonl"] +"JSON" = ["*.jsonl", "*.jsonc"] From 875046e4cdf002b86c36c67fa78442d3090b87ee Mon Sep 17 00:00:00 2001 From: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com> Date: Sat, 3 Feb 2024 22:51:02 +0100 Subject: [PATCH 31/35] Mention which style components are the default --- doc/long-help.txt | 3 +++ src/bin/bat/clap_app.rs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/doc/long-help.txt b/doc/long-help.txt index 247120fb..a68fa175 100644 --- a/doc/long-help.txt +++ b/doc/long-help.txt @@ -123,6 +123,9 @@ Options: set a default style, add the '--style=".."' option to the configuration file or export the BAT_STYLE environment variable (e.g.: export BAT_STYLE=".."). + By default, the following components are enabled: + changes, grid, header-filename, numbers, snip + Possible values: * default: enables recommended style components (default). diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index e8222a1d..0bd876ff 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -432,6 +432,8 @@ pub fn build_app(interactive_output: bool) -> Command { pre-defined style ('full'). To set a default style, add the \ '--style=\"..\"' option to the configuration file or export the \ BAT_STYLE environment variable (e.g.: export BAT_STYLE=\"..\").\n\n\ + By default, the following components are enabled:\n \ + changes, grid, header-filename, numbers, snip\n\n\ Possible values:\n\n \ * default: enables recommended style components (default).\n \ * full: enables all available components.\n \ From 8a51172b119d95fd5984ad46639307140b675c1b Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sun, 11 Feb 2024 22:43:07 +0000 Subject: [PATCH 32/35] simplified basic_set_terminal_title --- tests/integration_tests.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 1ba51d19..f1a22d9d 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -922,18 +922,6 @@ fn pager_failed_to_parse() { .stderr(predicate::str::contains("Could not parse pager command")); } -#[test] -fn pager_set_terminal_title() { - bat() - .env("PAGER", mocked_pagers::from("echo pager-output")) - .arg("--paging=always") - .arg("--set-terminal-title") - .arg("test.txt") - .assert() - .success() - .stdout(predicate::str::contains("\u{1b}]0;bat: test.txt\x07pager-output\n").normalize()); -} - #[test] #[serial] fn env_var_bat_paging() { @@ -948,6 +936,18 @@ fn env_var_bat_paging() { }); } +#[test] +fn basic_set_terminal_title() { + bat() + .arg("--paging=always") + .arg("--set-terminal-title") + .arg("test.txt") + .assert() + .success() + .stdout("\u{1b}]0;bat: test.txt\x07hello world\n") + .stderr(""); +} + #[test] fn diagnostic_sanity_check() { bat() From 92915e22e72496ab256146708f711ad3322f12d7 Mon Sep 17 00:00:00 2001 From: cyqsimon <28627918+cyqsimon@users.noreply.github.com> Date: Wed, 21 Feb 2024 00:18:45 +0800 Subject: [PATCH 33/35] Map containers `.conf` files to TOML syntax --- src/syntax_mapping/builtins/linux/50-containers.toml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/syntax_mapping/builtins/linux/50-containers.toml diff --git a/src/syntax_mapping/builtins/linux/50-containers.toml b/src/syntax_mapping/builtins/linux/50-containers.toml new file mode 100644 index 00000000..b7170b87 --- /dev/null +++ b/src/syntax_mapping/builtins/linux/50-containers.toml @@ -0,0 +1,8 @@ +# see https://github.com/containers/image/tree/main/docs +[mappings] +"TOML" = [ + "/usr/share/containers/**/*.conf", + "/etc/containers/**/*.conf", + "${HOME}/.config/containers/**/*.conf", + "${XDG_CONFIG_HOME}/containers/**/*.conf", +] From 511cd30105aa2529efcd040a4516c6a0a2a8107f Mon Sep 17 00:00:00 2001 From: cyqsimon <28627918+cyqsimon@users.noreply.github.com> Date: Wed, 21 Feb 2024 00:26:23 +0800 Subject: [PATCH 34/35] Write changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec8348d5..f00204c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ - `cmd-help`: scope subcommands followed by other terms, and other misc improvements, see #2819 (@victor-gp) - Upgrade JQ syntax, see #2820 (@dependabot[bot]) +- Map containers .conf files to TOML syntax #2867 (@cyqsimon) ## Themes From 6a6b02117b577df90c483aac406952a3814462da Mon Sep 17 00:00:00 2001 From: cyqsimon <28627918+cyqsimon@users.noreply.github.com> Date: Wed, 21 Feb 2024 02:39:22 +0800 Subject: [PATCH 35/35] Apply clippy fixes (#2864) * Apply clippy fixes * Write changelog --- CHANGELOG.md | 1 + src/vscreen.rs | 29 +++++++++++++++-------------- tests/tester/mod.rs | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec8348d5..a672edcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Pull in fix for unsafe-libyaml security advisory, see #2812 (@dtolnay) - Update git-version dependency to use Syn v2, see #2816 (@dtolnay) - Update git2 dependency to v0.18.2, see #2852 (@eth-p) +- Apply clippy fixes #2864 (@cyqsimon) ## Syntaxes diff --git a/src/vscreen.rs b/src/vscreen.rs index 78f6ad4e..f7ba3f91 100644 --- a/src/vscreen.rs +++ b/src/vscreen.rs @@ -24,9 +24,9 @@ impl AnsiStyle { } } - pub fn to_reset_sequence(&mut self) -> String { - match &mut self.attributes { - Some(a) => a.to_reset_sequence(), + pub fn to_reset_sequence(&self) -> String { + match self.attributes { + Some(ref a) => a.to_reset_sequence(), None => String::new(), } } @@ -294,12 +294,14 @@ enum EscapeSequenceOffsets { start: usize, end: usize, }, + #[allow(clippy::upper_case_acronyms)] NF { // https://en.wikipedia.org/wiki/ANSI_escape_code#nF_Escape_sequences start_sequence: usize, start: usize, end: usize, }, + #[allow(clippy::upper_case_acronyms)] OSC { // https://en.wikipedia.org/wiki/ANSI_escape_code#OSC_(Operating_System_Command)_sequences start_sequence: usize, @@ -307,6 +309,7 @@ enum EscapeSequenceOffsets { start_terminator: usize, end: usize, }, + #[allow(clippy::upper_case_acronyms)] CSI { // https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_(Control_Sequence_Introducer)_sequences start_sequence: usize, @@ -340,9 +343,7 @@ impl<'a> EscapeSequenceOffsetsIterator<'a> { /// Takes values from the iterator while the predicate returns true. /// If the predicate returns false, that value is left. fn chars_take_while(&mut self, pred: impl Fn(char) -> bool) -> Option<(usize, usize)> { - if self.chars.peek().is_none() { - return None; - } + self.chars.peek()?; let start = self.chars.peek().unwrap().0; let mut end: usize = start; @@ -359,10 +360,8 @@ impl<'a> EscapeSequenceOffsetsIterator<'a> { } fn next_text(&mut self) -> Option { - match self.chars_take_while(|c| c != '\x1B') { - None => None, - Some((start, end)) => Some(EscapeSequenceOffsets::Text { start, end }), - } + self.chars_take_while(|c| c != '\x1B') + .map(|(start, end)| EscapeSequenceOffsets::Text { start, end }) } fn next_sequence(&mut self) -> Option { @@ -444,7 +443,7 @@ impl<'a> EscapeSequenceOffsetsIterator<'a> { Some(EscapeSequenceOffsets::OSC { start_sequence, start_command: osc_open_index + osc_open_char.len_utf8(), - start_terminator: start_terminator, + start_terminator, end: end_sequence, }) } @@ -502,9 +501,8 @@ impl<'a> EscapeSequenceOffsetsIterator<'a> { } // Get the final byte. - match self.chars.next() { - Some((i, c)) => end = i + c.len_utf8(), - None => {} + if let Some((i, c)) = self.chars.next() { + end = i + c.len_utf8() } Some(EscapeSequenceOffsets::NF { @@ -593,15 +591,18 @@ impl<'a> Iterator for EscapeSequenceIterator<'a> { pub enum EscapeSequence<'a> { Text(&'a str), Unknown(&'a str), + #[allow(clippy::upper_case_acronyms)] NF { raw_sequence: &'a str, nf_sequence: &'a str, }, + #[allow(clippy::upper_case_acronyms)] OSC { raw_sequence: &'a str, command: &'a str, terminator: &'a str, }, + #[allow(clippy::upper_case_acronyms)] CSI { raw_sequence: &'a str, parameters: &'a str, diff --git a/tests/tester/mod.rs b/tests/tester/mod.rs index 8ddea11f..c4e916a6 100644 --- a/tests/tester/mod.rs +++ b/tests/tester/mod.rs @@ -22,7 +22,7 @@ impl BatTester { pub fn test_snapshot(&self, name: &str, style: &str) { let output = Command::new(&self.exe) .current_dir(self.temp_dir.path()) - .args(&[ + .args([ "sample.rs", "--no-config", "--paging=never",