From 2e103ee6b3703e120025d43f04fe9a6d7ae92b5e Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sun, 10 Dec 2023 16:39:34 +0000 Subject: able to set terminal title to hardcoded value --- src/pager.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src') 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); -- cgit v1.2.3 From 4863d428dd7004b471960fdf1c6b30417d94383d Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sun, 10 Dec 2023 16:44:47 +0000 Subject: title is being reset on quit, so no need to restore terminal title --- src/pager.rs | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src') 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; -- cgit v1.2.3 From b9b554248daba2134d4355ebc5cd4373ad265abe Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sun, 10 Dec 2023 17:17:19 +0000 Subject: 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(-) (limited to 'src') 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); -- cgit v1.2.3 From 069318b139eaf88c3fdc0819e42953fb63cc7592 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sun, 10 Dec 2023 17:20:42 +0000 Subject: fixed formatting of terminal title --- src/bin/bat/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') 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(); -- cgit v1.2.3 From 6ad800e43a18c5e4274ec63cc022c014506f6397 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sun, 10 Dec 2023 17:24:49 +0000 Subject: tidied commits --- src/controller.rs | 1 - src/pager.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'src') 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)] -- cgit v1.2.3 From 12b74dfb4ec0575664482c714e55e28d3493415d Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Mon, 18 Dec 2023 16:59:12 +0000 Subject: terminal title is only set when pager is being used --- src/bin/bat/main.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') 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) } -- cgit v1.2.3 From 57016f4e044db09161140b50e55a65b35fb3e363 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sun, 31 Dec 2023 22:15:00 +0000 Subject: small refactoring of set terminal title function --- src/bin/bat/main.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src') 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) } -- cgit v1.2.3 From 3b0ade9cb8ade5aa03ca20a250372aba37a1b24f Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sun, 31 Dec 2023 22:24:44 +0000 Subject: slightly changed set terminal command to match docs & broke print line into multiple variables --- src/bin/bat/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') 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(); } -- cgit v1.2.3 From 9239b125b148af1833d85be972fc27d14895e7a6 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sat, 27 Jan 2024 14:14:40 +0000 Subject: 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(+) (limited to 'src') 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"))] -- cgit v1.2.3 From b33e33fe260f44074f4bcac21a0798530b377228 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sat, 27 Jan 2024 14:17:25 +0000 Subject: 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(-) (limited to 'src') 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) -- cgit v1.2.3 From 60e32cf8237abf96b3d6dc78de35b8e904b015f1 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Sat, 27 Jan 2024 14:46:13 +0000 Subject: 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(-) (limited to 'src') 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( -- cgit v1.2.3 From 7f12989127839e07d3dcf5d9f3b154d0e2d7c661 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Mon, 29 Jan 2024 09:47:41 +0000 Subject: added set_terminal_title arg to clap_app.rs to fix ci errors --- src/bin/bat/clap_app.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') 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, -- cgit v1.2.3 From 0af1df52582283201b2b73638a11c14030fd0f44 Mon Sep 17 00:00:00 2001 From: Andy Kipp Date: Wed, 31 Jan 2024 14:07:56 +0100 Subject: Create xonsh.toml --- src/syntax_mapping/builtins/common/xonsh.toml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/syntax_mapping/builtins/common/xonsh.toml (limited to 'src') diff --git a/src/syntax_mapping/builtins/common/xonsh.toml b/src/syntax_mapping/builtins/common/xonsh.toml new file mode 100644 index 00000000..8e472b41 --- /dev/null +++ b/src/syntax_mapping/builtins/common/xonsh.toml @@ -0,0 +1,3 @@ +# Xonsh shell (https://xon.sh/) +[mappings] +"Python" = ["*.xsh", "*.xonshrc"] -- cgit v1.2.3 From 7ce010d9edf6d82f7013af2c711308f38fc680d6 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Thu, 8 Feb 2024 21:33:03 +0000 Subject: Using hypens instead of underscores for set-terminal-title command --- src/bin/bat/app.rs | 2 +- src/bin/bat/clap_app.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') 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."), -- cgit v1.2.3 From 02077db53e36b157e1a12496b8315c77514de0a0 Mon Sep 17 00:00:00 2001 From: Oliver looney Date: Thu, 8 Feb 2024 21:41:20 +0000 Subject: undid unnecessary api visibility changes --- src/bin/bat/main.rs | 2 +- src/input.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') 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 { -- cgit v1.2.3 From a5bd9f51be047089a85eab121e0a1a52d213b203 Mon Sep 17 00:00:00 2001 From: mxaddict Date: Sun, 11 Feb 2024 04:57:42 +0800 Subject: Added JSONC and aws credentials to the syntax mappings --- src/syntax_mapping/builtins/common/50-aws-credentials.toml | 2 ++ src/syntax_mapping/builtins/common/50-json.toml | 3 +++ src/syntax_mapping/builtins/common/50-jsonl.toml | 3 --- 3 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 src/syntax_mapping/builtins/common/50-aws-credentials.toml create mode 100644 src/syntax_mapping/builtins/common/50-json.toml delete mode 100644 src/syntax_mapping/builtins/common/50-jsonl.toml (limited to 'src') 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-json.toml b/src/syntax_mapping/builtins/common/50-json.toml new file mode 100644 index 00000000..e604868a --- /dev/null +++ b/src/syntax_mapping/builtins/common/50-json.toml @@ -0,0 +1,3 @@ +# JSON Lines is a simple variation of JSON #2535 +[mappings] +"JSON" = ["*.jsonl", "*.jsonc"] diff --git a/src/syntax_mapping/builtins/common/50-jsonl.toml b/src/syntax_mapping/builtins/common/50-jsonl.toml deleted file mode 100644 index 4b70a4d0..00000000 --- a/src/syntax_mapping/builtins/common/50-jsonl.toml +++ /dev/null @@ -1,3 +0,0 @@ -# JSON Lines is a simple variation of JSON #2535 -[mappings] -"JSON" = ["*.jsonl"] -- cgit v1.2.3 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: Apply clippy fixes (#2864) * Apply clippy fixes * Write changelog --- src/vscreen.rs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src') 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, -- cgit v1.2.3