From 2e103ee6b3703e120025d43f04fe9a6d7ae92b5e Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sun, 10 Dec 2023 16:39:34 +0000 Subject: [PATCH 01/51] 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/51] 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/51] 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/51] 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/51] 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/51] 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/51] 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/51] 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/51] 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/51] 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/51] 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/51] 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/51] 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/51] 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/51] 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/51] 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/51] 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/51] 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/51] 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/51] 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/51] 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/51] 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/51] 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/51] 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/51] 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 196a4cb18f3be9b5a04e47a07bc3d3299158b0fb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 1 Feb 2024 03:15:26 +0000 Subject: [PATCH 26/51] Bump assets/themes/zenburn from `e627f1c` to `86d4ee7` (#2842) Bumps [assets/themes/zenburn](https://github.com/colinta/zenburn) from `e627f1c` to `86d4ee7`. - [Commits](https://github.com/colinta/zenburn/compare/e627f1cb223c1171ab0a6a48d166c87aeae2a1d5...86d4ee7a1f884851a1d21d66249687f527fced32) --- updated-dependencies: - dependency-name: assets/themes/zenburn dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- assets/themes/zenburn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/themes/zenburn b/assets/themes/zenburn index e627f1cb..86d4ee7a 160000 --- a/assets/themes/zenburn +++ b/assets/themes/zenburn @@ -1 +1 @@ -Subproject commit e627f1cb223c1171ab0a6a48d166c87aeae2a1d5 +Subproject commit 86d4ee7a1f884851a1d21d66249687f527fced32 From 23de8e093bd78aa6471fabfc2b30cf1b9f6bedb6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 1 Feb 2024 04:05:59 +0000 Subject: [PATCH 27/51] Bump semver from 1.0.20 to 1.0.21 (#2843) Bumps [semver](https://github.com/dtolnay/semver) from 1.0.20 to 1.0.21. - [Release notes](https://github.com/dtolnay/semver/releases) - [Commits](https://github.com/dtolnay/semver/compare/1.0.20...1.0.21) --- updated-dependencies: - dependency-name: semver dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4aaf7b32..87c6af6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1113,9 +1113,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "semver" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" [[package]] name = "serde" From e3866b1f7e52a09bc9f671e93abaff95f7080bb8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 1 Feb 2024 04:25:19 +0000 Subject: [PATCH 28/51] Bump indexmap from 2.1.0 to 2.2.2 (#2847) Bumps [indexmap](https://github.com/indexmap-rs/indexmap) from 2.1.0 to 2.2.2. - [Changelog](https://github.com/indexmap-rs/indexmap/blob/master/RELEASES.md) - [Commits](https://github.com/indexmap-rs/indexmap/compare/2.1.0...2.2.2) --- updated-dependencies: - dependency-name: indexmap dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 12 ++++++------ Cargo.toml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 87c6af6f..61e81efb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -129,7 +129,7 @@ dependencies = [ "globset", "grep-cli", "home", - "indexmap 2.1.0", + "indexmap 2.2.2", "itertools", "nix", "nu-ansi-term", @@ -646,9 +646,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.1.0" +version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +checksum = "824b2ae422412366ba479e8111fd301f7b5faece8149317bb81925979a53f520" dependencies = [ "equivalent", "hashbrown 0.14.1", @@ -1185,7 +1185,7 @@ version = "0.9.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a15e0ef66bf939a7c890a0bf6d5a733c70202225f9888a89ed5c62298b019129" dependencies = [ - "indexmap 2.1.0", + "indexmap 2.2.2", "itoa", "ryu", "serde", @@ -1378,7 +1378,7 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ff9e3abce27ee2c9a37f9ad37238c1bdd4e789c84ba37df76aa4d528f5072cc" dependencies = [ - "indexmap 2.1.0", + "indexmap 2.2.2", "serde", "serde_spanned", "toml_datetime", @@ -1400,7 +1400,7 @@ version = "0.20.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81" dependencies = [ - "indexmap 2.1.0", + "indexmap 2.2.2", "serde", "serde_spanned", "toml_datetime", diff --git a/Cargo.toml b/Cargo.toml index 3b7f10e6..12debb35 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -100,7 +100,7 @@ nix = { version = "0.26.4", default-features = false, features = ["term"] } [build-dependencies] anyhow = "1.0.78" -indexmap = { version = "2.1.0", features = ["serde"] } +indexmap = { version = "2.2.2", features = ["serde"] } itertools = "0.11.0" once_cell = "1.18" regex = "1.10.2" From 65aae5d0a1ac979ffc7fb940e45e17be97a3ec5f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 1 Feb 2024 04:43:10 +0000 Subject: [PATCH 29/51] Bump toml from 0.8.6 to 0.8.9 (#2844) Bumps [toml](https://github.com/toml-rs/toml) from 0.8.6 to 0.8.9. - [Commits](https://github.com/toml-rs/toml/compare/toml-v0.8.6...toml-v0.8.9) --- updated-dependencies: - dependency-name: toml dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 12 ++++++------ Cargo.toml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 61e81efb..c3beff23 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1150,9 +1150,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12022b835073e5b11e90a14f86838ceb1c8fb0325b72416845c487ac0fa95e80" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" dependencies = [ "serde", ] @@ -1374,9 +1374,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "toml" -version = "0.8.6" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ff9e3abce27ee2c9a37f9ad37238c1bdd4e789c84ba37df76aa4d528f5072cc" +checksum = "c6a4b9e8023eb94392d3dca65d717c53abc5dad49c07cb65bb8fcd87115fa325" dependencies = [ "indexmap 2.2.2", "serde", @@ -1396,9 +1396,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.20.7" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81" +checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" dependencies = [ "indexmap 2.2.2", "serde", diff --git a/Cargo.toml b/Cargo.toml index 12debb35..31487b0f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -106,7 +106,7 @@ once_cell = "1.18" regex = "1.10.2" serde = { version = "1.0", features = ["derive"] } serde_with = { version = "3.4.0", default-features = false, features = ["macros"] } -toml = { version = "0.8.6", features = ["preserve_order"] } +toml = { version = "0.8.9", features = ["preserve_order"] } walkdir = "2.4" [build-dependencies.clap] From f7bea6de5be639adfbe9ee054549ba17aa8f4978 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 1 Feb 2024 05:00:25 +0000 Subject: [PATCH 30/51] Bump clircle from 0.4.0 to 0.5.0 (#2845) Bumps [clircle](https://github.com/niklasmohrin/clircle) from 0.4.0 to 0.5.0. - [Release notes](https://github.com/niklasmohrin/clircle/releases) - [Commits](https://github.com/niklasmohrin/clircle/compare/v0.4.0...v0.5.0) --- updated-dependencies: - dependency-name: clircle dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 5 +++-- Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c3beff23..095948f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -272,13 +272,14 @@ checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" [[package]] name = "clircle" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e87cbed5354f17bd8ca8821a097fb62599787fe8f611743fad7ee156a0a600" +checksum = "ec0b92245ea62a7a751db4b0e4a583f8978e508077ef6de24fcc0d0dc5311a8d" dependencies = [ "cfg-if", "libc", "serde", + "serde_derive", "winapi", ] diff --git a/Cargo.toml b/Cargo.toml index 31487b0f..a3e64dcd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,7 +57,7 @@ serde = { version = "1.0", features = ["derive"] } serde_yaml = "0.9.28" semver = "1.0" path_abs = { version = "0.5", default-features = false } -clircle = "0.4" +clircle = "0.5" bugreport = { version = "0.5.0", optional = true } etcetera = { version = "0.8.0", optional = true } grep-cli = { version = "0.1.10", optional = true } From adfaef19dab98a50be9f277de4d17cae83a1f2c1 Mon Sep 17 00:00:00 2001 From: "Ethan P." Date: Wed, 7 Feb 2024 21:18:12 -0800 Subject: [PATCH 31/51] Clarify when/how default args are added to less --- README.md | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 352ae64d..57baf2b0 100644 --- a/README.md +++ b/README.md @@ -602,7 +602,8 @@ set, `less` is used by default. If you want to use a different pager, you can ei `PAGER` variable or set the `BAT_PAGER` environment variable to override what is specified in `PAGER`. -**Note**: If `PAGER` is `more` or `most`, `bat` will silently use `less` instead to ensure support for colors. +>[!NOTE] +> If `PAGER` is `more` or `most`, `bat` will silently use `less` instead to ensure support for colors. If you want to pass command-line arguments to the pager, you can also set them via the `PAGER`/`BAT_PAGER` variables: @@ -613,20 +614,37 @@ export BAT_PAGER="less -RF" Instead of using environment variables, you can also use `bat`s [configuration file](https://github.com/sharkdp/bat#configuration-file) to configure the pager (`--pager` option). -**Note**: By default, if the pager is set to `less` (and no command-line options are specified), -`bat` will pass the following command line options to the pager: `-R`/`--RAW-CONTROL-CHARS`, -`-F`/`--quit-if-one-screen` and `-X`/`--no-init`. The last option (`-X`) is only used for `less` -versions older than 530. -The `-R` option is needed to interpret ANSI colors correctly. The second option (`-F`) instructs -less to exit immediately if the output size is smaller than the vertical size of the terminal. -This is convenient for small files because you do not have to press `q` to quit the pager. The -third option (`-X`) is needed to fix a bug with the `--quit-if-one-screen` feature in old versions -of `less`. Unfortunately, it also breaks mouse-wheel support in `less`. +### Using `less` as a pager -If you want to enable mouse-wheel scrolling on older versions of `less`, you can pass just `-R` (as -in the example above, this will disable the quit-if-one-screen feature). For less 530 or newer, -it should work out of the box. +When using `less` as a pager, `bat` will automatically pass extra options along to `less` +to improve the experience. Specifically, `-R`/`--RAW-CONTROL-CHARS`, `-F`/`--quit-if-one-screen`, +and under certain conditions, `-X`/`--no-init` and/or `-S`/`--chop-long-lines`. + +>[!IMPORTANT] +> These options will not be added if: +> - The pager is not named `less`. +> - The `--pager` argument contains any command-line arguments (e.g. `--pager="less -R"`). +> - The `BAT_PAGER` environment variable contains any command-line arguments (e.g. `export BAT_PAGER="less -R"`) +> +> The `--quit-if-one-screen` option will not be added when: +> - The `--paging=always` argument is used. +> - The `BAT_PAGING` environment is set to `always`. + +The `-R` option is needed to interpret ANSI colors correctly. + +The `-F` option instructs `less` to exit immediately if the output size is smaller than +the vertical size of the terminal. This is convenient for small files because you do not +have to press `q` to quit the pager. + +The `-X` option is needed to fix a bug with the `--quit-if-one-screen` feature in versions +of `less` older than version 530. Unfortunately, it also breaks mouse-wheel support in `less`. +If you want to enable mouse-wheel scrolling on older versions of `less` and do not mind losing +the quit-if-one-screen feature, you can set the pager (via `--pager` or `BAT_PAGER`) to `less -R`. +For `less` 530 or newer, it should work out of the box. + +The `-S` option is added when `bat`'s `-S`/`--chop-long-lines` option is used. This tells `less` +to truncate any lines larger than the terminal width. ### Indentation From 95993cf37e4c7bd242f1a156ae405aec65da7e8c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Feb 2024 07:54:17 +0000 Subject: [PATCH 32/51] Bump assets/syntaxes/02_Extra/cmd-help from `b150d84` to `209559b` (#2841) Bumps [assets/syntaxes/02_Extra/cmd-help](https://github.com/victor-gp/cmd-help-sublime-syntax) from `b150d84` to `209559b`. - [Commits](https://github.com/victor-gp/cmd-help-sublime-syntax/compare/b150d84534dd060afdcaf3f58977faeaf5917e56...209559b72f7e8848c988828088231b3a4d8b6838) --- updated-dependencies: - dependency-name: assets/syntaxes/02_Extra/cmd-help dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- assets/syntaxes/02_Extra/cmd-help | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/syntaxes/02_Extra/cmd-help b/assets/syntaxes/02_Extra/cmd-help index b150d845..209559b7 160000 --- a/assets/syntaxes/02_Extra/cmd-help +++ b/assets/syntaxes/02_Extra/cmd-help @@ -1 +1 @@ -Subproject commit b150d84534dd060afdcaf3f58977faeaf5917e56 +Subproject commit 209559b72f7e8848c988828088231b3a4d8b6838 From 7ce010d9edf6d82f7013af2c711308f38fc680d6 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Thu, 8 Feb 2024 21:33:03 +0000 Subject: [PATCH 33/51] 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 34/51] 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 1a54c9bf6ddb1daf649e193c1262c28d86ddcc43 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 28 Dec 2023 14:38:35 -0800 Subject: [PATCH 35/51] Eliminate dependency on serde's "derive" feature --- CHANGELOG.md | 1 + Cargo.lock | 29 +++++++++++++---------------- Cargo.toml | 11 +++++++---- build/syntax_mapping.rs | 2 +- src/assets/assets_metadata.rs | 2 +- src/assets/lazy_theme_set.rs | 3 +-- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8015b14d..c56d3112 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ - [BREAKING] `SyntaxMapping::{empty,builtin}` are removed; use `SyntaxMapping::new` instead - [BREAKING] `SyntaxMapping::mappings` is replaced by `SyntaxMapping::{builtin,custom,all}_mappings` - Make `Controller::run_with_error_handler`'s error handler `FnMut`, see #2831 (@rhysd) +- Improve compile time by 20%, see #2815 (@dtolnay) # v0.24.0 diff --git a/Cargo.lock b/Cargo.lock index 095948f1..ccf9bfa3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -142,6 +142,7 @@ dependencies = [ "run_script", "semver", "serde", + "serde_derive", "serde_with", "serde_yaml", "serial_test", @@ -581,7 +582,7 @@ dependencies = [ "bstr", "log", "regex-automata", - "regex-syntax 0.8.2", + "regex-syntax", ] [[package]] @@ -1028,7 +1029,7 @@ dependencies = [ "aho-corasick", "memchr", "regex-automata", - "regex-syntax 0.8.2", + "regex-syntax", ] [[package]] @@ -1039,15 +1040,9 @@ checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.2", + "regex-syntax", ] -[[package]] -name = "regex-syntax" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" - [[package]] name = "regex-syntax" version = "0.8.2" @@ -1160,19 +1155,20 @@ dependencies = [ [[package]] name = "serde_with" -version = "3.4.0" +version = "3.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64cd236ccc1b7a29e7e2739f27c0b2dd199804abc4290e32f59f3b68d6405c23" +checksum = "15d167997bd841ec232f5b2b8e0e26606df2e7caa4c31b95ea9ca52b200bd270" dependencies = [ "serde", + "serde_derive", "serde_with_macros", ] [[package]] name = "serde_with_macros" -version = "3.4.0" +version = "3.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93634eb5f75a2323b16de4748022ac4297f9e76b6dced2be287a099f41b5e788" +checksum = "865f9743393e638991566a8b7a479043c2c8da94a33e0a31f18214c9cae0a64d" dependencies = [ "darling", "proc-macro2", @@ -1259,9 +1255,9 @@ dependencies = [ [[package]] name = "syntect" -version = "5.1.0" +version = "5.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e02b4b303bf8d08bfeb0445cba5068a3d306b6baece1d5582171a9bf49188f91" +checksum = "874dcfa363995604333cf947ae9f751ca3af4522c60886774c4963943b4746b1" dependencies = [ "bincode", "bitflags 1.3.2", @@ -1271,8 +1267,9 @@ dependencies = [ "once_cell", "onig", "plist", - "regex-syntax 0.7.5", + "regex-syntax", "serde", + "serde_derive", "serde_json", "thiserror", "walkdir", diff --git a/Cargo.toml b/Cargo.toml index a3e64dcd..05a2acb7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,7 +53,8 @@ content_inspector = "0.2.4" shell-words = { version = "1.1.0", optional = true } unicode-width = "0.1.11" globset = "0.4" -serde = { version = "1.0", features = ["derive"] } +serde = "1.0" +serde_derive = "1.0" serde_yaml = "0.9.28" semver = "1.0" path_abs = { version = "0.5", default-features = false } @@ -74,7 +75,7 @@ optional = true default-features = false [dependencies.syntect] -version = "5.1.0" +version = "5.2.0" default-features = false features = ["parsing"] @@ -94,6 +95,7 @@ serial_test = { version = "2.0.0", default-features = false } predicates = "3.0.4" wait-timeout = "0.2.0" tempfile = "3.8.1" +serde = { version = "1.0", features = ["derive"] } [target.'cfg(unix)'.dev-dependencies] nix = { version = "0.26.4", default-features = false, features = ["term"] } @@ -104,8 +106,9 @@ indexmap = { version = "2.2.2", features = ["serde"] } itertools = "0.11.0" once_cell = "1.18" regex = "1.10.2" -serde = { version = "1.0", features = ["derive"] } -serde_with = { version = "3.4.0", default-features = false, features = ["macros"] } +serde = "1.0" +serde_derive = "1.0" +serde_with = { version = "3.6.1", default-features = false, features = ["macros"] } toml = { version = "0.8.9", features = ["preserve_order"] } walkdir = "2.4" diff --git a/build/syntax_mapping.rs b/build/syntax_mapping.rs index c29b9225..959caea8 100644 --- a/build/syntax_mapping.rs +++ b/build/syntax_mapping.rs @@ -10,7 +10,7 @@ use indexmap::IndexMap; use itertools::Itertools; use once_cell::sync::Lazy; use regex::Regex; -use serde::Deserialize; +use serde_derive::Deserialize; use serde_with::DeserializeFromStr; use walkdir::WalkDir; diff --git a/src/assets/assets_metadata.rs b/src/assets/assets_metadata.rs index 700c4c3b..cfc7a9e0 100644 --- a/src/assets/assets_metadata.rs +++ b/src/assets/assets_metadata.rs @@ -3,7 +3,7 @@ use std::path::Path; use std::time::SystemTime; use semver::Version; -use serde::{Deserialize, Serialize}; +use serde_derive::{Deserialize, Serialize}; use crate::error::*; diff --git a/src/assets/lazy_theme_set.rs b/src/assets/lazy_theme_set.rs index bf749154..fcc3eb46 100644 --- a/src/assets/lazy_theme_set.rs +++ b/src/assets/lazy_theme_set.rs @@ -3,8 +3,7 @@ use super::*; use std::collections::BTreeMap; use std::convert::TryFrom; -use serde::Deserialize; -use serde::Serialize; +use serde_derive::{Deserialize, Serialize}; use once_cell::unsync::OnceCell; From c29bf2ff281f5190f90ce377eb98dac29045b6c4 Mon Sep 17 00:00:00 2001 From: Ethan P Date: Fri, 9 Feb 2024 21:45:29 -0800 Subject: [PATCH 36/51] Update git2 dependency --- CHANGELOG.md | 1 + Cargo.lock | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c56d3112..7ee759a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - Use proper Architecture for Debian packages built for musl, see #2811 (@Enselic) - 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) ## Syntaxes diff --git a/Cargo.lock b/Cargo.lock index ccf9bfa3..ff674b9d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -695,9 +695,9 @@ checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" [[package]] name = "libgit2-sys" -version = "0.16.1+1.7.1" +version = "0.16.2+1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2a2bb3680b094add03bb3732ec520ece34da31a8cd2d633d1389d0f0fb60d0c" +checksum = "ee4126d8b4ee5c9d9ea891dd875cfdc1e9d0950437179104b183d7d8a74d24e8" dependencies = [ "cc", "libc", From 414403b062ac644ee2b569870f66de49999f9dd3 Mon Sep 17 00:00:00 2001 From: Ethan P Date: Sun, 16 Apr 2023 19:59:52 -0700 Subject: [PATCH 37/51] Add EscapeSequenceOffsetsIterator This can be used to extract a subset of ANSI escape sequences from a string of text. I have big plans for this eventually, but for now, it'll be used to strip OSC before printing. --- src/vscreen.rs | 476 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 475 insertions(+), 1 deletion(-) diff --git a/src/vscreen.rs b/src/vscreen.rs index ea5d4da6..ecf2bd3c 100644 --- a/src/vscreen.rs +++ b/src/vscreen.rs @@ -1,4 +1,8 @@ -use std::fmt::{Display, Formatter}; +use std::{ + fmt::{Display, Formatter}, + iter::Peekable, + str::CharIndices, +}; // Wrapper to avoid unnecessary branching when input doesn't have ANSI escape sequences. pub struct AnsiStyle { @@ -210,3 +214,473 @@ fn join( .collect::>() .join(delimiter) } + +/// A range of indices for a raw ANSI escape sequence. +#[derive(Debug, PartialEq)] +enum EscapeSequenceOffsets { + Text { + start: usize, + end: usize, + }, + Unknown { + start: usize, + end: usize, + }, + NF { + // https://en.wikipedia.org/wiki/ANSI_escape_code#nF_Escape_sequences + start_sequence: usize, + start: usize, + end: usize, + }, + OSC { + // https://en.wikipedia.org/wiki/ANSI_escape_code#OSC_(Operating_System_Command)_sequences + start_sequence: usize, + start_command: usize, + start_terminator: usize, + end: usize, + }, + CSI { + // https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_(Control_Sequence_Introducer)_sequences + start_sequence: usize, + start_parameters: usize, + start_intermediates: usize, + start_final_byte: usize, + end: usize, + }, +} + +/// An iterator over the offests of ANSI/VT escape sequences within a string. +/// +/// ## Example +/// +/// ```ignore +/// let iter = EscapeSequenceOffsetsIterator::new("\x1B[33mThis is yellow text.\x1B[m"); +/// ``` +struct EscapeSequenceOffsetsIterator<'a> { + text: &'a str, + chars: Peekable>, +} + +impl<'a> EscapeSequenceOffsetsIterator<'a> { + pub fn new(text: &'a str) -> EscapeSequenceOffsetsIterator<'a> { + return EscapeSequenceOffsetsIterator { + text, + chars: text.char_indices().peekable(), + }; + } + + /// 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; + } + + let start = self.chars.peek().unwrap().0; + let mut end: usize = start; + while let Some((i, c)) = self.chars.peek() { + if !pred(*c) { + break; + } + + end = *i + c.len_utf8(); + self.chars.next(); + } + + Some((start, end)) + } + + fn next_text(&mut self) -> Option { + match self.chars_take_while(|c| c != '\x1B') { + None => None, + Some((start, end)) => Some(EscapeSequenceOffsets::Text { start, end }), + } + } + + fn next_sequence(&mut self) -> Option { + let (start_sequence, c) = self.chars.next().expect("to not be finished"); + match self.chars.peek() { + None => Some(EscapeSequenceOffsets::Unknown { + start: start_sequence, + end: start_sequence + c.len_utf8(), + }), + + Some((_, ']')) => self.next_osc(start_sequence), + Some((_, '[')) => self.next_csi(start_sequence), + Some((i, c)) => match c { + '\x20'..='\x2F' => self.next_nf(start_sequence), + c => Some(EscapeSequenceOffsets::Unknown { + start: start_sequence, + end: i + c.len_utf8(), + }), + }, + } + } + + fn next_osc(&mut self, start_sequence: usize) -> Option { + let (osc_open_index, osc_open_char) = self.chars.next().expect("to not be finished"); + debug_assert_eq!(osc_open_char, ']'); + + let mut start_terminator: usize; + let mut end_sequence: usize; + + loop { + match self.chars_take_while(|c| !matches!(c, '\x07' | '\x1B')) { + None => { + start_terminator = self.text.len(); + end_sequence = start_terminator; + break; + } + + Some((_, end)) => { + start_terminator = end; + end_sequence = end; + } + } + + match self.chars.next() { + Some((ti, '\x07')) => { + end_sequence = ti + '\x07'.len_utf8(); + break; + } + + Some((ti, '\x1B')) => { + match self.chars.next() { + Some((i, '\\')) => { + end_sequence = i + '\\'.len_utf8(); + break; + } + + None => { + end_sequence = ti + '\x1B'.len_utf8(); + break; + } + + _ => { + // Repeat, since `\\`(anything) isn't a valid ST. + } + } + } + + None => { + // Prematurely ends. + break; + } + + Some((_, tc)) => { + panic!("this should not be reached: char {:?}", tc) + } + } + } + + Some(EscapeSequenceOffsets::OSC { + start_sequence, + start_command: osc_open_index + osc_open_char.len_utf8(), + start_terminator: start_terminator, + end: end_sequence, + }) + } + + fn next_csi(&mut self, start_sequence: usize) -> Option { + let (csi_open_index, csi_open_char) = self.chars.next().expect("to not be finished"); + debug_assert_eq!(csi_open_char, '['); + + let start_parameters: usize = csi_open_index + csi_open_char.len_utf8(); + + // Keep iterating while within the range of `0x30-0x3F`. + let mut start_intermediates: usize = start_parameters; + if let Some((_, end)) = self.chars_take_while(|c| matches!(c, '\x30'..='\x3F')) { + start_intermediates = end; + } + + // Keep iterating while within the range of `0x20-0x2F`. + let mut start_final_byte: usize = start_intermediates; + if let Some((_, end)) = self.chars_take_while(|c| matches!(c, '\x20'..='\x2F')) { + start_final_byte = end; + } + + // Take the last char. + let end_of_sequence = match self.chars.next() { + None => start_final_byte, + Some((i, c)) => i + c.len_utf8(), + }; + + Some(EscapeSequenceOffsets::CSI { + start_sequence, + start_parameters, + start_intermediates, + start_final_byte, + end: end_of_sequence, + }) + } + + fn next_nf(&mut self, start_sequence: usize) -> Option { + let (nf_open_index, nf_open_char) = self.chars.next().expect("to not be finished"); + debug_assert!(matches!(nf_open_char, '\x20'..='\x2F')); + + let start: usize = nf_open_index; + let mut end: usize = start; + + // Keep iterating while within the range of `0x20-0x2F`. + match self.chars_take_while(|c| matches!(c, '\x20'..='\x2F')) { + Some((_, i)) => end = i, + None => { + return Some(EscapeSequenceOffsets::NF { + start_sequence, + start, + end, + }) + } + } + + // Get the final byte. + match self.chars.next() { + Some((i, c)) => end = i + c.len_utf8(), + None => {} + } + + Some(EscapeSequenceOffsets::NF { + start_sequence, + start, + end, + }) + } +} + +impl<'a> Iterator for EscapeSequenceOffsetsIterator<'a> { + type Item = EscapeSequenceOffsets; + fn next(&mut self) -> Option { + match self.chars.peek() { + Some((_, '\x1B')) => self.next_sequence(), + Some((_, _)) => self.next_text(), + None => None, + } + } +} + +#[cfg(test)] +mod tests { + use crate::vscreen::{EscapeSequenceOffsets, EscapeSequenceOffsetsIterator}; + + #[test] + fn test_escape_sequence_offsets_iterator_parses_text() { + let mut iter = EscapeSequenceOffsetsIterator::new("text"); + assert_eq!( + iter.next(), + Some(EscapeSequenceOffsets::Text { start: 0, end: 4 }) + ); + } + + #[test] + fn test_escape_sequence_offsets_iterator_parses_text_stops_at_esc() { + let mut iter = EscapeSequenceOffsetsIterator::new("text\x1B[ming"); + assert_eq!( + iter.next(), + Some(EscapeSequenceOffsets::Text { start: 0, end: 4 }) + ); + } + + #[test] + fn test_escape_sequence_offsets_iterator_parses_osc_with_bel() { + let mut iter = EscapeSequenceOffsetsIterator::new("\x1B]abc\x07"); + assert_eq!( + iter.next(), + Some(EscapeSequenceOffsets::OSC { + start_sequence: 0, + start_command: 2, + start_terminator: 5, + end: 6, + }) + ); + } + + #[test] + fn test_escape_sequence_offsets_iterator_parses_osc_with_st() { + let mut iter = EscapeSequenceOffsetsIterator::new("\x1B]abc\x1B\\"); + assert_eq!( + iter.next(), + Some(EscapeSequenceOffsets::OSC { + start_sequence: 0, + start_command: 2, + start_terminator: 5, + end: 7, + }) + ); + } + + #[test] + fn test_escape_sequence_offsets_iterator_parses_osc_thats_broken() { + let mut iter = EscapeSequenceOffsetsIterator::new("\x1B]ab"); + assert_eq!( + iter.next(), + Some(EscapeSequenceOffsets::OSC { + start_sequence: 0, + start_command: 2, + start_terminator: 4, + end: 4, + }) + ); + } + + #[test] + fn test_escape_sequence_offsets_iterator_parses_csi() { + let mut iter = EscapeSequenceOffsetsIterator::new("\x1B[m"); + assert_eq!( + iter.next(), + Some(EscapeSequenceOffsets::CSI { + start_sequence: 0, + start_parameters: 2, + start_intermediates: 2, + start_final_byte: 2, + end: 3 + }) + ); + } + + #[test] + fn test_escape_sequence_offsets_iterator_parses_csi_with_parameters() { + let mut iter = EscapeSequenceOffsetsIterator::new("\x1B[1;34m"); + assert_eq!( + iter.next(), + Some(EscapeSequenceOffsets::CSI { + start_sequence: 0, + start_parameters: 2, + start_intermediates: 6, + start_final_byte: 6, + end: 7 + }) + ); + } + + #[test] + fn test_escape_sequence_offsets_iterator_parses_csi_with_intermediates() { + let mut iter = EscapeSequenceOffsetsIterator::new("\x1B[$m"); + assert_eq!( + iter.next(), + Some(EscapeSequenceOffsets::CSI { + start_sequence: 0, + start_parameters: 2, + start_intermediates: 2, + start_final_byte: 3, + end: 4 + }) + ); + } + + #[test] + fn test_escape_sequence_offsets_iterator_parses_csi_with_parameters_and_intermediates() { + let mut iter = EscapeSequenceOffsetsIterator::new("\x1B[1$m"); + assert_eq!( + iter.next(), + Some(EscapeSequenceOffsets::CSI { + start_sequence: 0, + start_parameters: 2, + start_intermediates: 3, + start_final_byte: 4, + end: 5 + }) + ); + } + + #[test] + fn test_escape_sequence_offsets_iterator_parses_csi_thats_broken() { + let mut iter = EscapeSequenceOffsetsIterator::new("\x1B["); + assert_eq!( + iter.next(), + Some(EscapeSequenceOffsets::CSI { + start_sequence: 0, + start_parameters: 2, + start_intermediates: 2, + start_final_byte: 2, + end: 2 + }) + ); + + let mut iter = EscapeSequenceOffsetsIterator::new("\x1B[1"); + assert_eq!( + iter.next(), + Some(EscapeSequenceOffsets::CSI { + start_sequence: 0, + start_parameters: 2, + start_intermediates: 3, + start_final_byte: 3, + end: 3 + }) + ); + + let mut iter = EscapeSequenceOffsetsIterator::new("\x1B[1$"); + assert_eq!( + iter.next(), + Some(EscapeSequenceOffsets::CSI { + start_sequence: 0, + start_parameters: 2, + start_intermediates: 3, + start_final_byte: 4, + end: 4 + }) + ); + } + + #[test] + fn test_escape_sequence_offsets_iterator_parses_nf() { + let mut iter = EscapeSequenceOffsetsIterator::new("\x1B($0"); + assert_eq!( + iter.next(), + Some(EscapeSequenceOffsets::NF { + start_sequence: 0, + start: 1, + end: 4 + }) + ); + } + + #[test] + fn test_escape_sequence_offsets_iterator_parses_nf_thats_broken() { + let mut iter = EscapeSequenceOffsetsIterator::new("\x1B("); + assert_eq!( + iter.next(), + Some(EscapeSequenceOffsets::NF { + start_sequence: 0, + start: 1, + end: 1 + }) + ); + } + + #[test] + fn test_escape_sequence_offsets_iterator_iterates() { + let mut iter = EscapeSequenceOffsetsIterator::new("text\x1B[33m\x1B]OSC\x07\x1B(0"); + assert_eq!( + iter.next(), + Some(EscapeSequenceOffsets::Text { start: 0, end: 4 }) + ); + assert_eq!( + iter.next(), + Some(EscapeSequenceOffsets::CSI { + start_sequence: 4, + start_parameters: 6, + start_intermediates: 8, + start_final_byte: 8, + end: 9 + }) + ); + assert_eq!( + iter.next(), + Some(EscapeSequenceOffsets::OSC { + start_sequence: 9, + start_command: 11, + start_terminator: 14, + end: 15 + }) + ); + assert_eq!( + iter.next(), + Some(EscapeSequenceOffsets::NF { + start_sequence: 15, + start: 16, + end: 18 + }) + ); + assert_eq!(iter.next(), None); + } +} From 054421268fff33003b892eb7bcef1a831c6c308d Mon Sep 17 00:00:00 2001 From: Ethan P Date: Sun, 16 Apr 2023 20:18:40 -0700 Subject: [PATCH 38/51] Strip OSC sequences before printing This commit strips OSC (Operating System Command) sequences before printing lines. Eventually when time permits, I want to add back support for printing OSC sequences (and improve it to treat hyperlinks like an attribute). Until then, this should help prevent garbled output :) --- src/printer.rs | 8 +++++--- src/vscreen.rs | 55 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/src/printer.rs b/src/printer.rs index 257cc766..45fd5336 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -33,7 +33,7 @@ use crate::line_range::RangeCheckResult; use crate::preprocessor::{expand_tabs, replace_nonprintable}; use crate::style::StyleComponent; use crate::terminal::{as_terminal_escaped, to_ansi_color}; -use crate::vscreen::AnsiStyle; +use crate::vscreen::{strip_problematic_sequences, AnsiStyle}; use crate::wrapping::WrappingMode; pub enum OutputHandle<'a> { @@ -581,7 +581,8 @@ impl<'a> Printer for InteractivePrinter<'a> { let italics = self.config.use_italic_text; for &(style, region) in ®ions { - let ansi_iterator = AnsiCodeIterator::new(region); + let text = strip_problematic_sequences(region); + let ansi_iterator = AnsiCodeIterator::new(&text); for chunk in ansi_iterator { match chunk { // ANSI escape passthrough. @@ -634,7 +635,8 @@ impl<'a> Printer for InteractivePrinter<'a> { } } else { for &(style, region) in ®ions { - let ansi_iterator = AnsiCodeIterator::new(region); + let text = strip_problematic_sequences(region); + let ansi_iterator = AnsiCodeIterator::new(&text); for chunk in ansi_iterator { match chunk { // ANSI escape passthrough. diff --git a/src/vscreen.rs b/src/vscreen.rs index ecf2bd3c..ccd0bfe8 100644 --- a/src/vscreen.rs +++ b/src/vscreen.rs @@ -458,9 +458,54 @@ impl<'a> Iterator for EscapeSequenceOffsetsIterator<'a> { } } +/// Strips problematic ANSI escape sequences from a string. +/// +/// Ideally, this will be replaced with something that uses [[Attributes]] to create a table of char offsets +/// -> absolute styles and style deltas. Something like that would let us simplify the printer (and support +/// re-printing OSC hyperlink commands). +pub fn strip_problematic_sequences(text: &str) -> String { + use EscapeSequenceOffsets::*; + + let mut buffer = String::with_capacity(text.len()); + for seq in EscapeSequenceOffsetsIterator::new(text) { + match seq { + Text { start, end } => buffer.push_str(&text[start..end]), + Unknown { start, end } => buffer.push_str(&text[start..end]), + + NF { + start_sequence: start, + start: _, + end, + } => buffer.push_str(&text[start..end]), + + CSI { + start_sequence: start, + start_parameters: _, + start_intermediates: _, + start_final_byte: _, + end, + } => buffer.push_str(&text[start..end]), + + OSC { + start_sequence: _, + start_command: _, + start_terminator: _, + end: _, + } => { + // TODO(eth-p): Support re-printing hyperlinks. + // In the meantime, strip these. + } + } + } + + buffer +} + #[cfg(test)] mod tests { - use crate::vscreen::{EscapeSequenceOffsets, EscapeSequenceOffsetsIterator}; + use crate::vscreen::{ + strip_problematic_sequences, EscapeSequenceOffsets, EscapeSequenceOffsetsIterator, + }; #[test] fn test_escape_sequence_offsets_iterator_parses_text() { @@ -683,4 +728,12 @@ mod tests { ); assert_eq!(iter.next(), None); } + + #[test] + fn test_strip_problematic_sequences() { + assert_eq!( + strip_problematic_sequences("text\x1B[33m\x1B]OSC\x1B\\\x1B(0"), + "text\x1B[33m\x1B(0" + ); + } } From 3d04699710540840b36ab964a7bce3597322fa88 Mon Sep 17 00:00:00 2001 From: Ethan P Date: Mon, 17 Apr 2023 15:52:17 -0700 Subject: [PATCH 39/51] Add regression test for #2541 More specifically, the test ensures that OSC sequences don't end up wrapping the line. --- tests/examples/regression_tests/issue_2541.txt | 1 + tests/integration_tests.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 tests/examples/regression_tests/issue_2541.txt diff --git a/tests/examples/regression_tests/issue_2541.txt b/tests/examples/regression_tests/issue_2541.txt new file mode 100644 index 00000000..1059b94e --- /dev/null +++ b/tests/examples/regression_tests/issue_2541.txt @@ -0,0 +1 @@ +]8;;http://example.com\This is a link]8;;\n \ No newline at end of file diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 437ae8e7..3b8bdf7f 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1163,6 +1163,20 @@ fn bom_stripped_when_no_color_and_not_loop_through() { ); } +// Regression test for https://github.com/sharkdp/bat/issues/2541 +#[test] +fn no_broken_osc_emit_with_line_wrapping() { + bat() + .arg("--color=always") + .arg("--decorations=never") + .arg("--wrap=character") + .arg("--terminal-width=40") + .arg("regression_tests/issue_2541.txt") + .assert() + .success() + .stdout(predicate::function(|s: &str| s.lines().count() == 1)); +} + #[test] fn can_print_file_named_cache() { bat_with_config() From 2d46d54ae351045b220abbb88e81eb3dbee9376f Mon Sep 17 00:00:00 2001 From: Ethan P Date: Mon, 17 Apr 2023 17:27:08 -0700 Subject: [PATCH 40/51] Add tests for re-emitting SGR sequences on wrap --- tests/integration_tests.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 3b8bdf7f..d90e724b 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1933,6 +1933,43 @@ fn ansi_passthrough_emit() { } } +// Ensure that a simple ANSI sequence passthrough is emitted properly on wrapped lines. +// This also helps ensure that escape sequences are counted as part of the visible characters when wrapping. +#[test] +fn ansi_sgr_emitted_when_wrapped() { + bat() + .arg("--paging=never") + .arg("--color=never") + .arg("--terminal-width=20") + .arg("--wrap=character") + .arg("--decorations=always") + .arg("--style=plain") + .write_stdin("\x1B[33mColor...............Also color.\n") + .assert() + .success() + .stdout("\x1B[33m\x1B[33mColor...............\n\x1B[33mAlso color.\n") + // FIXME: ~~~~~~~~ should not be emitted twice. + .stderr(""); +} + +// Ensure that multiple ANSI sequence SGR attributes are combined when emitted on wrapped lines. +#[test] +fn ansi_sgr_joins_attributes_when_wrapped() { + bat() + .arg("--paging=never") + .arg("--color=never") + .arg("--terminal-width=20") + .arg("--wrap=character") + .arg("--decorations=always") + .arg("--style=plain") + .write_stdin("\x1B[33mColor. \x1B[1mBold.........Also bold and color.\n") + .assert() + .success() + .stdout("\x1B[33m\x1B[33mColor. \x1B[1m\x1B[33m\x1B[1mBold.........\n\x1B[33m\x1B[1mAlso bold and color.\n") + // FIXME: ~~~~~~~~ ~~~~~~~~~~~~~~~ should not be emitted twice. + .stderr(""); +} + #[test] fn ignored_suffix_arg() { bat() From 6b9b085be3893682e75e3538dbee0d7bd6772b86 Mon Sep 17 00:00:00 2001 From: Ethan P Date: Mon, 17 Apr 2023 16:35:32 -0700 Subject: [PATCH 41/51] Add EscapeSequenceIterator This is an iterator for escape sequences, using EscapeSequenceOffsetsIterator for the underlying parsing of individual escape sequences. --- src/vscreen.rs | 139 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 138 insertions(+), 1 deletion(-) diff --git a/src/vscreen.rs b/src/vscreen.rs index ccd0bfe8..ce7188d7 100644 --- a/src/vscreen.rs +++ b/src/vscreen.rs @@ -458,6 +458,68 @@ impl<'a> Iterator for EscapeSequenceOffsetsIterator<'a> { } } +/// An iterator over ANSI/VT escape sequences within a string. +/// +/// ## Example +/// +/// ```ignore +/// let iter = EscapeSequenceIterator::new("\x1B[33mThis is yellow text.\x1B[m"); +/// ``` +pub struct EscapeSequenceIterator<'a> { + text: &'a str, + offset_iter: EscapeSequenceOffsetsIterator<'a>, +} + +impl<'a> EscapeSequenceIterator<'a> { + pub fn new(text: &'a str) -> EscapeSequenceIterator<'a> { + return EscapeSequenceIterator { + text, + offset_iter: EscapeSequenceOffsetsIterator::new(text), + }; + } +} + +impl<'a> Iterator for EscapeSequenceIterator<'a> { + type Item = EscapeSequence<'a>; + fn next(&mut self) -> Option { + use EscapeSequenceOffsets::*; + self.offset_iter.next().map(|offsets| match offsets { + Unknown { start, end } => EscapeSequence::Unknown(&self.text[start..end]), + Text { start, end } => EscapeSequence::Text(&self.text[start..end]), + NF { + start_sequence, + start, + end, + } => EscapeSequence::NF { + raw_sequence: &self.text[start_sequence..end], + nf_sequence: &self.text[start..end], + }, + OSC { + start_sequence, + start_command, + start_terminator, + end, + } => EscapeSequence::OSC { + raw_sequence: &self.text[start_sequence..end], + command: &self.text[start_command..start_terminator], + terminator: &self.text[start_terminator..end], + }, + CSI { + start_sequence, + start_parameters, + start_intermediates, + start_final_byte, + end, + } => EscapeSequence::CSI { + raw_sequence: &self.text[start_sequence..end], + parameters: &self.text[start_parameters..start_intermediates], + intermediates: &self.text[start_intermediates..start_final_byte], + final_byte: &self.text[start_final_byte..end], + }, + }) + } +} + /// Strips problematic ANSI escape sequences from a string. /// /// Ideally, this will be replaced with something that uses [[Attributes]] to create a table of char offsets @@ -501,10 +563,46 @@ pub fn strip_problematic_sequences(text: &str) -> String { buffer } +/// A parsed ANSI/VT100 escape sequence. +#[derive(Debug, PartialEq)] +pub enum EscapeSequence<'a> { + Text(&'a str), + Unknown(&'a str), + NF { + raw_sequence: &'a str, + nf_sequence: &'a str, + }, + OSC { + raw_sequence: &'a str, + command: &'a str, + terminator: &'a str, + }, + CSI { + raw_sequence: &'a str, + parameters: &'a str, + intermediates: &'a str, + final_byte: &'a str, + }, +} + +impl<'a> EscapeSequence<'a> { + pub fn raw(&self) -> &'a str { + use EscapeSequence::*; + match *self { + Text(raw) => raw, + Unknown(raw) => raw, + NF { raw_sequence, .. } => raw_sequence, + OSC { raw_sequence, .. } => raw_sequence, + CSI { raw_sequence, .. } => raw_sequence, + } + } +} + #[cfg(test)] mod tests { use crate::vscreen::{ - strip_problematic_sequences, EscapeSequenceOffsets, EscapeSequenceOffsetsIterator, + strip_problematic_sequences, EscapeSequence, EscapeSequenceIterator, EscapeSequenceOffsets, + EscapeSequenceOffsetsIterator, }; #[test] @@ -736,4 +834,43 @@ mod tests { "text\x1B[33m\x1B(0" ); } + + #[test] + fn test_escape_sequence_iterator_iterates() { + let mut iter = EscapeSequenceIterator::new("text\x1B[33m\x1B]OSC\x07\x1B]OSC\x1B\\\x1B(0"); + assert_eq!(iter.next(), Some(EscapeSequence::Text("text"))); + assert_eq!( + iter.next(), + Some(EscapeSequence::CSI { + raw_sequence: "\x1B[33m", + parameters: "33", + intermediates: "", + final_byte: "m", + }) + ); + assert_eq!( + iter.next(), + Some(EscapeSequence::OSC { + raw_sequence: "\x1B]OSC\x07", + command: "OSC", + terminator: "\x07", + }) + ); + assert_eq!( + iter.next(), + Some(EscapeSequence::OSC { + raw_sequence: "\x1B]OSC\x1B\\", + command: "OSC", + terminator: "\x1B\\", + }) + ); + assert_eq!( + iter.next(), + Some(EscapeSequence::NF { + raw_sequence: "\x1B(0", + nf_sequence: "(0", + }) + ); + assert_eq!(iter.next(), None); + } } From 165c495e7582e1251802cfc3c05b2fc28151cee8 Mon Sep 17 00:00:00 2001 From: Ethan P Date: Mon, 17 Apr 2023 17:02:42 -0700 Subject: [PATCH 42/51] Replace AnsiCodeIterator in printer.rs This uses the new EscapeSequenceIterator, saving us a preprocessing step for each line. --- src/printer.rs | 58 ++++++++++++++++----------- src/vscreen.rs | 105 +++++++++++++------------------------------------ 2 files changed, 62 insertions(+), 101 deletions(-) diff --git a/src/printer.rs b/src/printer.rs index 45fd5336..6d495777 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -7,8 +7,6 @@ use nu_ansi_term::Style; use bytesize::ByteSize; -use console::AnsiCodeIterator; - use syntect::easy::HighlightLines; use syntect::highlighting::Color; use syntect::highlighting::Theme; @@ -33,9 +31,23 @@ use crate::line_range::RangeCheckResult; use crate::preprocessor::{expand_tabs, replace_nonprintable}; use crate::style::StyleComponent; use crate::terminal::{as_terminal_escaped, to_ansi_color}; -use crate::vscreen::{strip_problematic_sequences, AnsiStyle}; +use crate::vscreen::{AnsiStyle, EscapeSequence, EscapeSequenceIterator}; use crate::wrapping::WrappingMode; +const ANSI_UNDERLINE_ENABLE: EscapeSequence = EscapeSequence::CSI { + raw_sequence: "\x1B[4m", + parameters: "4", + intermediates: "", + final_byte: "m", +}; + +const ANSI_UNDERLINE_DISABLE: EscapeSequence = EscapeSequence::CSI { + raw_sequence: "\x1B[24m", + parameters: "24", + intermediates: "", + final_byte: "m", +}; + pub enum OutputHandle<'a> { IoWrite(&'a mut dyn io::Write), FmtWrite(&'a mut dyn fmt::Write), @@ -554,7 +566,7 @@ impl<'a> Printer for InteractivePrinter<'a> { self.config.highlighted_lines.0.check(line_number) == RangeCheckResult::InRange; if highlight_this_line && self.config.theme == "ansi" { - self.ansi_style.update("^[4m"); + self.ansi_style.update(ANSI_UNDERLINE_ENABLE); } let background_color = self @@ -581,18 +593,11 @@ impl<'a> Printer for InteractivePrinter<'a> { let italics = self.config.use_italic_text; for &(style, region) in ®ions { - let text = strip_problematic_sequences(region); - let ansi_iterator = AnsiCodeIterator::new(&text); + let ansi_iterator = EscapeSequenceIterator::new(region); for chunk in ansi_iterator { match chunk { - // ANSI escape passthrough. - (ansi, true) => { - self.ansi_style.update(ansi); - write!(handle, "{}", ansi)?; - } - // Regular text. - (text, false) => { + EscapeSequence::Text(text) => { let text = &*self.preprocess(text, &mut cursor_total); let text_trimmed = text.trim_end_matches(|c| c == '\r' || c == '\n'); @@ -626,6 +631,12 @@ impl<'a> Printer for InteractivePrinter<'a> { write!(handle, "{}", &text[text_trimmed.len()..])?; } } + + // ANSI escape passthrough. + _ => { + write!(handle, "{}", chunk.raw())?; + self.ansi_style.update(chunk); + } } } } @@ -635,18 +646,11 @@ impl<'a> Printer for InteractivePrinter<'a> { } } else { for &(style, region) in ®ions { - let text = strip_problematic_sequences(region); - let ansi_iterator = AnsiCodeIterator::new(&text); + let ansi_iterator = EscapeSequenceIterator::new(region); for chunk in ansi_iterator { match chunk { - // ANSI escape passthrough. - (ansi, true) => { - self.ansi_style.update(ansi); - write!(handle, "{}", ansi)?; - } - // Regular text. - (text, false) => { + EscapeSequence::Text(text) => { let text = self.preprocess( text.trim_end_matches(|c| c == '\r' || c == '\n'), &mut cursor_total, @@ -726,6 +730,12 @@ impl<'a> Printer for InteractivePrinter<'a> { ) )?; } + + // ANSI escape passthrough. + _ => { + write!(handle, "{}", chunk.raw())?; + self.ansi_style.update(chunk); + } } } } @@ -746,8 +756,8 @@ impl<'a> Printer for InteractivePrinter<'a> { } if highlight_this_line && self.config.theme == "ansi" { - self.ansi_style.update("^[24m"); - write!(handle, "\x1B[24m")?; + write!(handle, "{}", ANSI_UNDERLINE_DISABLE.raw())?; + self.ansi_style.update(ANSI_UNDERLINE_DISABLE); } Ok(()) diff --git a/src/vscreen.rs b/src/vscreen.rs index ce7188d7..ea1f02b4 100644 --- a/src/vscreen.rs +++ b/src/vscreen.rs @@ -14,7 +14,7 @@ impl AnsiStyle { AnsiStyle { attributes: None } } - pub fn update(&mut self, sequence: &str) -> bool { + pub fn update(&mut self, sequence: EscapeSequence) -> bool { match &mut self.attributes { Some(a) => a.update(sequence), None => { @@ -85,26 +85,36 @@ impl Attributes { /// Update the attributes with an escape sequence. /// Returns `false` if the sequence is unsupported. - pub fn update(&mut self, sequence: &str) -> bool { - let mut chars = sequence.char_indices().skip(1); - - if let Some((_, t)) = chars.next() { - match t { - '(' => self.update_with_charset('(', chars.map(|(_, c)| c)), - ')' => self.update_with_charset(')', chars.map(|(_, c)| c)), - '[' => { - if let Some((i, last)) = chars.last() { - // SAFETY: Always starts with ^[ and ends with m. - self.update_with_csi(last, &sequence[2..i]) - } else { - false + pub fn update(&mut self, sequence: EscapeSequence) -> bool { + use EscapeSequence::*; + match sequence { + Text(_) => return false, + Unknown(_) => { /* defer to update_with_unsupported */ } + OSC { .. } => return false, + CSI { + final_byte, + parameters, + .. + } => { + match final_byte { + "m" => return self.update_with_sgr(parameters), + _ => { + // NOTE(eth-p): We might want to ignore these, since they involve cursor or buffer manipulation. + /* defer to update_with_unsupported */ } } - _ => self.update_with_unsupported(sequence), } - } else { - false + NF { nf_sequence, .. } => { + let mut iter = nf_sequence.chars(); + match iter.next() { + Some('(') => return self.update_with_charset('(', iter), + Some(')') => return self.update_with_charset(')', iter), + _ => { /* defer to update_with_unsupported */ } + } + } } + + self.update_with_unsupported(sequence.raw()) } fn sgr_reset(&mut self) { @@ -153,14 +163,6 @@ impl Attributes { true } - fn update_with_csi(&mut self, finalizer: char, sequence: &str) -> bool { - if finalizer == 'm' { - self.update_with_sgr(sequence) - } else { - false - } - } - fn update_with_unsupported(&mut self, sequence: &str) -> bool { self.unknown_buffer.push_str(sequence); false @@ -520,49 +522,6 @@ impl<'a> Iterator for EscapeSequenceIterator<'a> { } } -/// Strips problematic ANSI escape sequences from a string. -/// -/// Ideally, this will be replaced with something that uses [[Attributes]] to create a table of char offsets -/// -> absolute styles and style deltas. Something like that would let us simplify the printer (and support -/// re-printing OSC hyperlink commands). -pub fn strip_problematic_sequences(text: &str) -> String { - use EscapeSequenceOffsets::*; - - let mut buffer = String::with_capacity(text.len()); - for seq in EscapeSequenceOffsetsIterator::new(text) { - match seq { - Text { start, end } => buffer.push_str(&text[start..end]), - Unknown { start, end } => buffer.push_str(&text[start..end]), - - NF { - start_sequence: start, - start: _, - end, - } => buffer.push_str(&text[start..end]), - - CSI { - start_sequence: start, - start_parameters: _, - start_intermediates: _, - start_final_byte: _, - end, - } => buffer.push_str(&text[start..end]), - - OSC { - start_sequence: _, - start_command: _, - start_terminator: _, - end: _, - } => { - // TODO(eth-p): Support re-printing hyperlinks. - // In the meantime, strip these. - } - } - } - - buffer -} - /// A parsed ANSI/VT100 escape sequence. #[derive(Debug, PartialEq)] pub enum EscapeSequence<'a> { @@ -601,7 +560,7 @@ impl<'a> EscapeSequence<'a> { #[cfg(test)] mod tests { use crate::vscreen::{ - strip_problematic_sequences, EscapeSequence, EscapeSequenceIterator, EscapeSequenceOffsets, + EscapeSequence, EscapeSequenceIterator, EscapeSequenceOffsets, EscapeSequenceOffsetsIterator, }; @@ -827,14 +786,6 @@ mod tests { assert_eq!(iter.next(), None); } - #[test] - fn test_strip_problematic_sequences() { - assert_eq!( - strip_problematic_sequences("text\x1B[33m\x1B]OSC\x1B\\\x1B(0"), - "text\x1B[33m\x1B(0" - ); - } - #[test] fn test_escape_sequence_iterator_iterates() { let mut iter = EscapeSequenceIterator::new("text\x1B[33m\x1B]OSC\x07\x1B]OSC\x1B\\\x1B(0"); From 6549e26f5d3923078b482d30bc4ed90b2f5710c9 Mon Sep 17 00:00:00 2001 From: Ethan P Date: Mon, 17 Apr 2023 19:07:58 -0700 Subject: [PATCH 43/51] Re-emit hyperlinks when wrapping lines --- src/vscreen.rs | 34 ++++++++++++++++++++++++++++++++-- tests/integration_tests.rs | 19 +++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/vscreen.rs b/src/vscreen.rs index ea1f02b4..7e2b8cd1 100644 --- a/src/vscreen.rs +++ b/src/vscreen.rs @@ -65,6 +65,13 @@ struct Attributes { /// ON: ^[9m /// OFF: ^[29m strike: String, + + /// The hyperlink sequence. + /// FORMAT: \x1B]8;;\e\\ + /// + /// `\e\\` may be replaced with BEL `\x07`. + /// Setting both and to an empty string represents no hyperlink. + hyperlink: String, } impl Attributes { @@ -80,6 +87,7 @@ impl Attributes { underline: "".to_owned(), italic: "".to_owned(), strike: "".to_owned(), + hyperlink: "".to_owned(), } } @@ -90,7 +98,16 @@ impl Attributes { match sequence { Text(_) => return false, Unknown(_) => { /* defer to update_with_unsupported */ } - OSC { .. } => return false, + OSC { + raw_sequence, + command, + .. + } => { + if command.starts_with("8;") { + return self.update_with_hyperlink(raw_sequence); + } + /* defer to update_with_unsupported */ + } CSI { final_byte, parameters, @@ -168,6 +185,18 @@ impl Attributes { false } + fn update_with_hyperlink(&mut self, sequence: &str) -> bool { + if sequence == "8;;" { + // Empty hyperlink ID and HREF -> end of hyperlink. + self.hyperlink.clear(); + } else { + self.hyperlink.clear(); + self.hyperlink.push_str(sequence); + } + + true + } + fn update_with_charset(&mut self, kind: char, set: impl Iterator) -> bool { self.charset = format!("\x1B{}{}", kind, set.take(1).collect::()); true @@ -191,7 +220,7 @@ impl Display for Attributes { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!( f, - "{}{}{}{}{}{}{}{}{}", + "{}{}{}{}{}{}{}{}{}{}", self.foreground, self.background, self.underlined, @@ -201,6 +230,7 @@ impl Display for Attributes { self.underline, self.italic, self.strike, + self.hyperlink, ) } } diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index d90e724b..bb4c4668 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1952,6 +1952,25 @@ fn ansi_sgr_emitted_when_wrapped() { .stderr(""); } +// Ensure that a simple ANSI sequence passthrough is emitted properly on wrapped lines. +// This also helps ensure that escape sequences are counted as part of the visible characters when wrapping. +#[test] +fn ansi_hyperlink_emitted_when_wrapped() { + bat() + .arg("--paging=never") + .arg("--color=never") + .arg("--terminal-width=20") + .arg("--wrap=character") + .arg("--decorations=always") + .arg("--style=plain") + .write_stdin("\x1B]8;;http://example.com/\x1B\\Hyperlinks..........Wrap across lines.\n") + .assert() + .success() + .stdout("\x1B]8;;http://example.com/\x1B\\\x1B]8;;http://example.com/\x1B\\Hyperlinks..........\n\x1B]8;;http://example.com/\x1B\\Wrap across lines.\n") + // FIXME: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ should not be emitted twice. + .stderr(""); +} + // Ensure that multiple ANSI sequence SGR attributes are combined when emitted on wrapped lines. #[test] fn ansi_sgr_joins_attributes_when_wrapped() { From 1023399c5e20edac8710e9f19dc72b6a95fd257d Mon Sep 17 00:00:00 2001 From: Ethan P Date: Mon, 17 Apr 2023 19:19:49 -0700 Subject: [PATCH 44/51] Remove hyperlink when wrapping lines --- src/printer.rs | 11 +++++++---- src/vscreen.rs | 40 ++++++++++++++++++++++++++++++++++++-- tests/integration_tests.rs | 2 +- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/printer.rs b/src/printer.rs index 6d495777..f413fdc3 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -598,12 +598,12 @@ impl<'a> Printer for InteractivePrinter<'a> { match chunk { // Regular text. EscapeSequence::Text(text) => { - let text = &*self.preprocess(text, &mut cursor_total); + let text = self.preprocess(text, &mut cursor_total); let text_trimmed = text.trim_end_matches(|c| c == '\r' || c == '\n'); write!( handle, - "{}", + "{}{}", as_terminal_escaped( style, &format!("{}{}", self.ansi_style, text_trimmed), @@ -611,9 +611,11 @@ impl<'a> Printer for InteractivePrinter<'a> { colored_output, italics, background_color - ) + ), + self.ansi_style.to_reset_sequence(), )?; + // Pad the rest of the line. if text.len() != text_trimmed.len() { if let Some(background_color) = background_color { let ansi_style = Style { @@ -693,7 +695,7 @@ impl<'a> Printer for InteractivePrinter<'a> { // It wraps. write!( handle, - "{}\n{}", + "{}{}\n{}", as_terminal_escaped( style, &format!("{}{}", self.ansi_style, line_buf), @@ -702,6 +704,7 @@ impl<'a> Printer for InteractivePrinter<'a> { self.config.use_italic_text, background_color ), + self.ansi_style.to_reset_sequence(), panel_wrap.clone().unwrap() )?; diff --git a/src/vscreen.rs b/src/vscreen.rs index 7e2b8cd1..c902d42b 100644 --- a/src/vscreen.rs +++ b/src/vscreen.rs @@ -23,6 +23,13 @@ impl AnsiStyle { } } } + + pub fn to_reset_sequence(&mut self) -> String { + match &mut self.attributes { + Some(a) => a.to_reset_sequence(), + None => String::new(), + } + } } impl Display for AnsiStyle { @@ -35,6 +42,8 @@ impl Display for AnsiStyle { } struct Attributes { + has_sgr_sequences: bool, + foreground: String, background: String, underlined: String, @@ -67,16 +76,18 @@ struct Attributes { strike: String, /// The hyperlink sequence. - /// FORMAT: \x1B]8;;\e\\ + /// FORMAT: \x1B]8;{ID};{URL}\e\\ /// /// `\e\\` may be replaced with BEL `\x07`. - /// Setting both and to an empty string represents no hyperlink. + /// Setting both {ID} and {URL} to an empty string represents no hyperlink. hyperlink: String, } impl Attributes { pub fn new() -> Self { Attributes { + has_sgr_sequences: false, + foreground: "".to_owned(), background: "".to_owned(), underlined: "".to_owned(), @@ -135,6 +146,8 @@ impl Attributes { } fn sgr_reset(&mut self) { + self.has_sgr_sequences = false; + self.foreground.clear(); self.background.clear(); self.underlined.clear(); @@ -152,6 +165,7 @@ impl Attributes { .map(|p| p.parse::()) .map(|p| p.unwrap_or(0)); // Treat errors as 0. + self.has_sgr_sequences = true; while let Some(p) = iter.next() { match p { 0 => self.sgr_reset(), @@ -214,6 +228,28 @@ impl Attributes { _ => format!("\x1B[{}m", color), } } + + /// Gets an ANSI escape sequence to reset all the known attributes. + pub fn to_reset_sequence(&self) -> String { + let mut buf = String::with_capacity(17); + + // TODO: Enable me in a later pull request. + // if self.has_sgr_sequences { + // buf.push_str("\x1B[m"); + // } + + if !self.hyperlink.is_empty() { + buf.push_str("\x1B]8;;\x1B\\"); // Disable hyperlink. + } + + // TODO: Enable me in a later pull request. + // if !self.charset.is_empty() { + // // https://espterm.github.io/docs/VT100%20escape%20codes.html + // buf.push_str("\x1B(B\x1B)B"); // setusg0 and setusg1 + // } + + buf + } } impl Display for Attributes { diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index bb4c4668..ecc37ed7 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1966,7 +1966,7 @@ fn ansi_hyperlink_emitted_when_wrapped() { .write_stdin("\x1B]8;;http://example.com/\x1B\\Hyperlinks..........Wrap across lines.\n") .assert() .success() - .stdout("\x1B]8;;http://example.com/\x1B\\\x1B]8;;http://example.com/\x1B\\Hyperlinks..........\n\x1B]8;;http://example.com/\x1B\\Wrap across lines.\n") + .stdout("\x1B]8;;http://example.com/\x1B\\\x1B]8;;http://example.com/\x1B\\Hyperlinks..........\x1B]8;;\x1B\\\n\x1B]8;;http://example.com/\x1B\\Wrap across lines.\n") // FIXME: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ should not be emitted twice. .stderr(""); } From 61029c8bd264f2bbce1844fd074c8136a9cec2ba Mon Sep 17 00:00:00 2001 From: Ethan P Date: Wed, 7 Feb 2024 17:17:44 -0800 Subject: [PATCH 45/51] Update changelog for fix of ANSI OSC sequences --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ee759a4..b6e13469 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Fix long file name wrapping in header, see #2835 (@FilipRazek) - Fix `NO_COLOR` support, see #2767 (@acuteenvy) +- Fix handling of inputs with OSC ANSI escape sequences, see #2541 and #2544 (@eth-p) ## Other From a5bd9f51be047089a85eab121e0a1a52d213b203 Mon Sep 17 00:00:00 2001 From: mxaddict Date: Sun, 11 Feb 2024 04:57:42 +0800 Subject: [PATCH 46/51] 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 8a51172b119d95fd5984ad46639307140b675c1b Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sun, 11 Feb 2024 22:43:07 +0000 Subject: [PATCH 47/51] 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 9d77c1373c59f9998b9991f1a58ffc6bf679d087 Mon Sep 17 00:00:00 2001 From: "Ethan P." Date: Sun, 11 Feb 2024 13:49:13 -0800 Subject: [PATCH 48/51] Fix off-by-one error in line number continuation --- CHANGELOG.md | 1 + src/decorations.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6e13469..c1d55dce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Fix long file name wrapping in header, see #2835 (@FilipRazek) - Fix `NO_COLOR` support, see #2767 (@acuteenvy) - Fix handling of inputs with OSC ANSI escape sequences, see #2541 and #2544 (@eth-p) +- Fix panel width when line 10000 wraps, see #2854 (@eth-p) ## Other diff --git a/src/decorations.rs b/src/decorations.rs index d3ed9b34..85d8103a 100644 --- a/src/decorations.rs +++ b/src/decorations.rs @@ -46,7 +46,7 @@ impl Decoration for LineNumberDecoration { _printer: &InteractivePrinter, ) -> DecorationText { if continuation { - if line_number > self.cached_wrap_invalid_at { + if line_number >= self.cached_wrap_invalid_at { let new_width = self.cached_wrap.width + 1; return DecorationText { text: self.color.paint(" ".repeat(new_width)).to_string(), From 915dd9fbf8d6acf5e56828e9ce4352e255ee5ad5 Mon Sep 17 00:00:00 2001 From: "Ethan P." Date: Sun, 11 Feb 2024 19:27:04 -0800 Subject: [PATCH 49/51] Fix incorrect categorization of SGR sequences Specifically, prevent other attributes from leaking into the bold/dim/italic/underline attributes, and ensure that bright backgrounds are put into the background attribute instead of the foreground attribute. --- CHANGELOG.md | 1 + src/vscreen.rs | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6e13469..f0d81642 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Fix long file name wrapping in header, see #2835 (@FilipRazek) - Fix `NO_COLOR` support, see #2767 (@acuteenvy) - Fix handling of inputs with OSC ANSI escape sequences, see #2541 and #2544 (@eth-p) +- Fix handling of inputs with combined ANSI color and attribute sequences, see #2185 and #2856 (@eth-p) ## Other diff --git a/src/vscreen.rs b/src/vscreen.rs index c902d42b..f883e655 100644 --- a/src/vscreen.rs +++ b/src/vscreen.rs @@ -169,10 +169,10 @@ impl Attributes { while let Some(p) = iter.next() { match p { 0 => self.sgr_reset(), - 1 => self.bold = format!("\x1B[{}m", parameters), - 2 => self.dim = format!("\x1B[{}m", parameters), - 3 => self.italic = format!("\x1B[{}m", parameters), - 4 => self.underline = format!("\x1B[{}m", parameters), + 1 => self.bold = "\x1B[1m".to_owned(), + 2 => self.dim = "\x1B[2m".to_owned(), + 3 => self.italic = "\x1B[3m".to_owned(), + 4 => self.underline = "\x1B[4m".to_owned(), 23 => self.italic.clear(), 24 => self.underline.clear(), 22 => { @@ -183,7 +183,7 @@ impl Attributes { 40..=49 => self.background = Self::parse_color(p, &mut iter), 58..=59 => self.underlined = Self::parse_color(p, &mut iter), 90..=97 => self.foreground = Self::parse_color(p, &mut iter), - 100..=107 => self.foreground = Self::parse_color(p, &mut iter), + 100..=107 => self.background = Self::parse_color(p, &mut iter), _ => { // Unsupported SGR sequence. // Be compatible and pretend one just wasn't was provided. From 84d80eebd0b224cd799282121e817fa5f0d57d5e Mon Sep 17 00:00:00 2001 From: "Ethan P." Date: Sun, 11 Feb 2024 19:29:09 -0800 Subject: [PATCH 50/51] Test for correct categorization of SGR sequences This adds a regression test for the fix in the previous commit. --- src/vscreen.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/vscreen.rs b/src/vscreen.rs index f883e655..78f6ad4e 100644 --- a/src/vscreen.rs +++ b/src/vscreen.rs @@ -890,4 +890,37 @@ mod tests { ); assert_eq!(iter.next(), None); } + + #[test] + fn test_sgr_attributes_do_not_leak_into_wrong_field() { + let mut attrs = crate::vscreen::Attributes::new(); + + // Bold, Dim, Italic, Underline, Foreground, Background + attrs.update(EscapeSequence::CSI { + raw_sequence: "\x1B[1;2;3;4;31;41m", + parameters: "1;2;3;4;31;41", + intermediates: "", + final_byte: "m", + }); + + assert_eq!(attrs.bold, "\x1B[1m"); + assert_eq!(attrs.dim, "\x1B[2m"); + assert_eq!(attrs.italic, "\x1B[3m"); + assert_eq!(attrs.underline, "\x1B[4m"); + assert_eq!(attrs.foreground, "\x1B[31m"); + assert_eq!(attrs.background, "\x1B[41m"); + + // Bold, Bright Foreground, Bright Background + attrs.sgr_reset(); + attrs.update(EscapeSequence::CSI { + raw_sequence: "\x1B[1;94;103m", + parameters: "1;94;103", + intermediates: "", + final_byte: "m", + }); + + assert_eq!(attrs.bold, "\x1B[1m"); + assert_eq!(attrs.foreground, "\x1B[94m"); + assert_eq!(attrs.background, "\x1B[103m"); + } } 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 51/51] 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",