summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cli.rs6
-rw-r--r--src/config.rs2
-rw-r--r--src/delta.rs5
-rw-r--r--src/options/set.rs1
-rwxr-xr-xtests/test_raw_output_matches_git_on_full_repo_history2
5 files changed, 15 insertions, 1 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 0729ad3b..72ca762b 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -443,6 +443,12 @@ pub struct Opt {
/// Text to display in front of a renamed file path.
pub file_renamed_label: String,
+ #[structopt(long = "max-line-length", default_value = "512")]
+ /// Truncate lines longer than this. To prevent any truncation, set to zero. Note that
+ /// syntax-highlighting very long lines (e.g. minified .js) will be very slow if they are not
+ /// truncated.
+ pub max_line_length: usize,
+
/// The width of underline/overline decorations. Use --width=variable to extend decorations and
/// background colors to the end of the text only. Otherwise background colors extend to the
/// full terminal width.
diff --git a/src/config.rs b/src/config.rs
index b22c2ae0..91887d3b 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -44,6 +44,7 @@ pub struct Config {
pub max_buffered_lines: usize,
pub max_line_distance: f64,
pub max_line_distance_for_naively_paired_lines: f64,
+ pub max_line_length: usize,
pub minus_emph_style: Style,
pub minus_empty_line_marker_style: Style,
pub minus_file: Option<PathBuf>,
@@ -170,6 +171,7 @@ impl From<cli::Opt> for Config {
max_buffered_lines: 32,
max_line_distance: opt.max_line_distance,
max_line_distance_for_naively_paired_lines,
+ max_line_length: opt.max_line_length,
minus_emph_style,
minus_empty_line_marker_style,
minus_file: opt.minus_file.map(|s| s.clone()),
diff --git a/src/delta.rs b/src/delta.rs
index dee3afef..33c205cf 100644
--- a/src/delta.rs
+++ b/src/delta.rs
@@ -78,6 +78,11 @@ where
while let Some(Ok(raw_line_bytes)) = lines.next() {
let raw_line = String::from_utf8_lossy(&raw_line_bytes);
+ let raw_line = if config.max_line_length > 0 && raw_line.len() > config.max_line_length {
+ ansi::truncate_str(&raw_line, config.max_line_length, &config.truncation_symbol)
+ } else {
+ raw_line
+ };
let line = ansi::strip_ansi_codes(&raw_line).to_string();
if source == Source::Unknown {
source = detect_source(&line);
diff --git a/src/options/set.rs b/src/options/set.rs
index 9f6f0b31..cca385ad 100644
--- a/src/options/set.rs
+++ b/src/options/set.rs
@@ -140,6 +140,7 @@ pub fn set_options(
inspect_raw_lines,
keep_plus_minus_markers,
max_line_distance,
+ max_line_length,
// Hack: minus-style must come before minus-*emph-style because the latter default
// dynamically to the value of the former.
minus_style,
diff --git a/tests/test_raw_output_matches_git_on_full_repo_history b/tests/test_raw_output_matches_git_on_full_repo_history
index 74148706..f212d2f4 100755
--- a/tests/test_raw_output_matches_git_on_full_repo_history
+++ b/tests/test_raw_output_matches_git_on_full_repo_history
@@ -1,5 +1,5 @@
#!/bin/bash
-DELTA="./target/release/delta --no-gitconfig --raw"
+DELTA="./target/release/delta --no-gitconfig --raw --max-line-length 0"
ANSIFILTER="./etc/bin/ansifilter"
GIT_ARGS="log --patch --stat --numstat"
diff -u <(git $GIT_ARGS | $ANSIFILTER) <(git $GIT_ARGS | $DELTA | $ANSIFILTER)