summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Peter <sharkdp@users.noreply.github.com>2024-02-23 21:52:46 +0100
committerGitHub <noreply@github.com>2024-02-23 21:52:46 +0100
commitb9e249f782bdbbe587067356f12b38319b72cd1e (patch)
treea642a7b63d6b05e865993dc46b8cf59b33e1a070
parent81aa24310cc87cb66bdcdb93cef6b1650394aabb (diff)
parent3ffa3648cf162853e7c1494c72f442c260649651 (diff)
Merge branch 'master' into syntax-mapping-fix
-rw-r--r--CHANGELOG.md7
-rw-r--r--doc/long-help.txt6
-rw-r--r--src/bin/bat/app.rs1
-rw-r--r--src/bin/bat/clap_app.rs9
-rw-r--r--src/bin/bat/main.rs24
-rw-r--r--src/config.rs3
-rw-r--r--src/syntax_mapping/builtins/common/50-aws-credentials.toml2
-rw-r--r--src/syntax_mapping/builtins/common/50-json.toml (renamed from src/syntax_mapping/builtins/common/50-jsonl.toml)2
-rw-r--r--src/syntax_mapping/builtins/common/xonsh.toml3
-rw-r--r--src/syntax_mapping/builtins/linux/50-containers.toml8
-rw-r--r--src/vscreen.rs29
-rw-r--r--tests/integration_tests.rs12
-rw-r--r--tests/tester/mod.rs2
13 files changed, 92 insertions, 16 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 164a5006..e5d0375f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
## Features
+- Set terminal title to file names when Paging is not Paging::Never #2807 (@Oliver-Looney)
+
## Bugfixes
- Fix long file name wrapping in header, see #2835 (@FilipRazek)
@@ -25,11 +27,16 @@
- Update git-version dependency to use Syn v2, see #2816 (@dtolnay)
- Update git2 dependency to v0.18.2, see #2852 (@eth-p)
- Relax syntax mapping rule restrictions to allow brace expansion #2865 (@cyqsimon)
+- Apply clippy fixes #2864 (@cyqsimon)
## Syntaxes
- `cmd-help`: scope subcommands followed by other terms, and other misc improvements, see #2819 (@victor-gp)
- Upgrade JQ syntax, see #2820 (@dependabot[bot])
+- Map containers .conf files to TOML syntax #2867 (@cyqsimon)
+- Associate `xsh` files with `xonsh` syntax that is Python, see #2840 (@anki-code).
+- Added auto detect syntax for `.jsonc` #2795 (@mxaddict)
+- Added auto detect syntax for `.aws/{config,credentials}` #2795 (@mxaddict)
## Themes
diff --git a/doc/long-help.txt b/doc/long-help.txt
index 247120fb..1aae60d8 100644
--- a/doc/long-help.txt
+++ b/doc/long-help.txt
@@ -123,6 +123,9 @@ Options:
set a default style, add the '--style=".."' option to the configuration file or export the
BAT_STYLE environment variable (e.g.: export BAT_STYLE="..").
+ By default, the following components are enabled:
+ changes, grid, header-filename, numbers, snip
+
Possible values:
* default: enables recommended style components (default).
@@ -160,6 +163,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/src/bin/bat/app.rs b/src/bin/bat/app.rs
index a2c09770..8843d53b 100644
--- a/src/bin/bat/app.rs
+++ b/src/bin/bat/app.rs
@@ -289,6 +289,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..d3cb9276 100644
--- a/src/bin/bat/clap_app.rs
+++ b/src/bin/bat/clap_app.rs
@@ -432,6 +432,8 @@ pub fn build_app(interactive_output: bool) -> Command {
pre-defined style ('full'). To set a default style, add the \
'--style=\"..\"' option to the configuration file or export the \
BAT_STYLE environment variable (e.g.: export BAT_STYLE=\"..\").\n\n\
+ By default, the following components are enabled:\n \
+ changes, grid, header-filename, numbers, snip\n\n\
Possible values:\n\n \
* default: enables recommended style components (default).\n \
* full: enables all available components.\n \
@@ -567,6 +569,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,
diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs
index f48abdc1..d877bb9b 100644
--- a/src/bin/bat/main.rs
+++ b/src/bin/bat/main.rs
@@ -229,9 +229,33 @@ pub fn list_themes(cfg: &Config, config_dir: &Path, cache_dir: &Path) -> Result<
Ok(())
}
+fn set_terminal_title_to(new_terminal_title: String) {
+ 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();
+}
+
+fn get_new_terminal_title(inputs: &Vec<Input>) -> String {
+ let mut new_terminal_title = "bat: ".to_string();
+ for (index, input) in inputs.iter().enumerate() {
+ new_terminal_title += input.description().title();
+ if index < inputs.len() - 1 {
+ new_terminal_title += ", ";
+ }
+ }
+ new_terminal_title
+}
+
fn run_controller(inputs: Vec<Input>, config: &Config, cache_dir: &Path) -> Result<bool> {
let assets = assets_from_cache_or_binary(config.use_custom_assets, cache_dir)?;
let controller = Controller::new(config, &assets);
+ if config.paging_mode != PagingMode::Never && config.set_terminal_title {
+ set_terminal_title_to(get_new_terminal_title(&inputs));
+ }
controller.run(inputs, None)
}
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"))]
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
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"]
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"]
diff --git a/src/syntax_mapping/builtins/linux/50-containers.toml b/src/syntax_mapping/builtins/linux/50-containers.toml
new file mode 100644
index 00000000..b7170b87
--- /dev/null
+++ b/src/syntax_mapping/builtins/linux/50-containers.toml
@@ -0,0 +1,8 @@
+# see https://github.com/containers/image/tree/main/docs
+[mappings]
+"TOML" = [
+ "/usr/share/containers/**/*.conf",
+ "/etc/containers/**/*.conf",
+ "${HOME}/.config/containers/**/*.conf",
+ "${XDG_CONFIG_HOME}/containers/**/*.conf",
+]
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<EscapeSequenceOffsets> {
- 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<EscapeSequenceOffsets> {
@@ -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/integration_tests.rs b/tests/integration_tests.rs
index ecc37ed7..3612654b 100644
--- a/tests/integration_tests.rs
+++ b/tests/integration_tests.rs
@@ -937,6 +937,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()
.arg("--diagnostic")
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",