summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2021-02-12 14:03:45 -0500
committerDan Davison <dandavison7@gmail.com>2021-02-17 10:23:03 -0500
commit97c58c4586508bdb84cc68873ac1294309a7268f (patch)
treec8a672502a94eb73c93150c787a314d081a7ca93
parent64c93a7f8a4babe7ef794ed053cb06baef1dcd3b (diff)
Allow user to specify tab replacement string522-tab-string
Fixes #522
-rw-r--r--src/cli.rs14
-rw-r--r--src/config.rs8
-rw-r--r--src/main.rs4
-rw-r--r--src/options/set.rs1
-rw-r--r--src/paint.rs13
5 files changed, 28 insertions, 12 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 41f6eb89..3fd9de57 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -470,10 +470,16 @@ pub struct Opt {
#[structopt(short = "w", long = "width")]
pub width: Option<String>,
- /// The number of spaces to replace tab characters with. Use --tabs=0 to pass tab characters
- /// through directly, but note that in that case delta will calculate line widths assuming tabs
- /// occupy one character's width on the screen: if your terminal renders tabs as more than than
- /// one character wide then delta's output will look incorrect.
+ /// A string to use to display tab characters with. By default, each tab character will be
+ /// replaced by space characters. (See `tabs`)
+ #[structopt(long = "tab-string")]
+ pub tab_string: Option<String>,
+
+ /// The number of spaces to replace tab characters with, if tab-string has not been
+ /// supplied. Use --tabs=0 to pass tab characters through directly, but note that in that case
+ /// delta will calculate line widths assuming tabs occupy one character's width on the screen:
+ /// if your terminal renders tabs as more than than one character wide then delta's output will
+ /// look incorrect.
#[structopt(long = "tabs", default_value = "4")]
pub tab_width: usize,
diff --git a/src/config.rs b/src/config.rs
index 23b7b97d..02608eb2 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -73,7 +73,7 @@ pub struct Config {
pub syntax_dummy_theme: SyntaxTheme,
pub syntax_set: SyntaxSet,
pub syntax_theme: Option<SyntaxTheme>,
- pub tab_width: usize,
+ pub tab_string: String,
pub tokenization_regex: Regex,
pub true_color: bool,
pub truncation_symbol: String,
@@ -218,7 +218,11 @@ impl From<cli::Opt> for Config {
syntax_dummy_theme: SyntaxTheme::default(),
syntax_set: opt.computed.syntax_set,
syntax_theme: opt.computed.syntax_theme,
- tab_width: opt.tab_width,
+ tab_string: if let Some(s) = opt.tab_string {
+ s
+ } else {
+ " ".repeat(opt.tab_width)
+ },
tokenization_regex,
true_color: opt.computed.true_color,
truncation_symbol: "→".to_string(),
diff --git a/src/main.rs b/src/main.rs
index 5757fbab..3587d184 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -258,7 +258,7 @@ fn show_config(config: &config::Config, writer: &mut dyn Write) -> std::io::Resu
side-by-side = {side_by_side}
syntax-theme = {syntax_theme}
width = {width}
- tabs = {tab_width}
+ tab_string = '{tab_string}'
word-diff-regex = {tokenization_regex}",
max_line_distance = config.max_line_distance,
max_line_length = config.max_line_length,
@@ -278,7 +278,7 @@ fn show_config(config: &config::Config, writer: &mut dyn Write) -> std::io::Resu
cli::Width::Fixed(width) => width.to_string(),
cli::Width::Variable => "variable".to_string(),
},
- tab_width = config.tab_width,
+ tab_string = config.tab_string,
tokenization_regex = format_option_value(&config.tokenization_regex.to_string()),
)?;
Ok(())
diff --git a/src/options/set.rs b/src/options/set.rs
index 354eeea6..24c4901b 100644
--- a/src/options/set.rs
+++ b/src/options/set.rs
@@ -170,6 +170,7 @@ pub fn set_options(
plus_non_emph_style,
raw,
side_by_side,
+ tab_string,
tab_width,
tokenization_regex,
true_color,
diff --git a/src/paint.rs b/src/paint.rs
index bf85fb13..415726a1 100644
--- a/src/paint.rs
+++ b/src/paint.rs
@@ -114,10 +114,15 @@ impl<'a> Painter<'a> {
where
I: Iterator<Item = &'b str>,
{
- if self.config.tab_width > 0 {
- let tab_replacement = " ".repeat(self.config.tab_width);
- line.map(|s| if s == "\t" { &tab_replacement } else { s })
- .collect::<String>()
+ if !self.config.tab_string.is_empty() {
+ line.map(|s| {
+ if s == "\t" {
+ &self.config.tab_string
+ } else {
+ s
+ }
+ })
+ .collect::<String>()
} else {
line.collect::<String>()
}