diff --git a/src/cli.rs b/src/cli.rs index a88915792..462f43776 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -442,6 +442,18 @@ pub struct Opt { /// for details. pub hyperlinks_file_link_format: String, + #[arg( + long = "hyperlinks-line-numbers", + default_value = "true", + value_name = "true|false", + value_parser = ["true", "false"], + )] + /// Whether to render line numbers as hyperlinks (requires --hyperlinks). + /// + /// Set this to "false" to keep hyperlinks on commit hashes and file paths while leaving the + /// line-number column as plain text. + pub hyperlinks_line_numbers: String, + #[arg( long = "inline-hint-style", default_value = "blue", @@ -1180,6 +1192,7 @@ pub struct ComputedValues { pub stdout_is_term: bool, pub background_color_extends_to_terminal_width: bool, pub decorations_width: Width, + pub hyperlinks_line_numbers: bool, pub inspect_raw_lines: InspectRawLines, pub color_mode: ColorMode, pub paging_mode: PagingMode, diff --git a/src/config.rs b/src/config.rs index 1c01530a6..515d8f09e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -89,6 +89,7 @@ pub struct Config { pub hyperlinks_commit_link_format: Option, pub hyperlinks_file_link_format: String, pub hyperlinks: bool, + pub hyperlinks_line_numbers: bool, pub inline_hint_style: Style, pub inspect_raw_lines: cli::InspectRawLines, pub keep_plus_minus_markers: bool, @@ -362,6 +363,7 @@ impl From for Config { hyperlinks: opt.hyperlinks, hyperlinks_commit_link_format: opt.hyperlinks_commit_link_format, hyperlinks_file_link_format: opt.hyperlinks_file_link_format, + hyperlinks_line_numbers: opt.computed.hyperlinks_line_numbers, inspect_raw_lines: opt.computed.inspect_raw_lines, inline_hint_style: styles["inline-hint-style"], keep_plus_minus_markers: opt.keep_plus_minus_markers, diff --git a/src/features/line_numbers.rs b/src/features/line_numbers.rs index 3b2fcff08..c845270c3 100644 --- a/src/features/line_numbers.rs +++ b/src/features/line_numbers.rs @@ -306,7 +306,11 @@ fn format_line_number( config: &config::Config, ) -> String { let pad = |n| format::pad(n, width, alignment, precision); - match (line_number, config.hyperlinks, plus_file) { + match ( + line_number, + config.hyperlinks && config.hyperlinks_line_numbers, + plus_file, + ) { (None, _, _) => " ".repeat(width), (Some(n), true, Some(file)) => match utils::path::absolute_path(file, config) { Some(absolute_path) => { @@ -749,6 +753,36 @@ pub mod tests { assert_eq!(lines.next().unwrap(), " ⋮10000│bb = 2"); } + #[test] + fn test_hyperlinks_in_line_number_column() { + let config = make_config_from_args(&["--line-numbers", "--hyperlinks"]); + let output = run_delta(ONE_MINUS_ONE_PLUS_LINE_DIFF, &config); + // Gutter rows wrap the line number in an OSC8 file hyperlink + let gutter = output + .lines() + .find(|l| l.contains('⋮') && l.contains("\x1b]8;;file://")) + .unwrap(); + assert!(gutter.contains("\x1b]8;;file://")); + } + + #[test] + fn test_hyperlinks_line_numbers_disabled_leaves_gutter_plain() { + let config = make_config_from_args(&[ + "--line-numbers", + "--hyperlinks", + "--hyperlinks-line-numbers", + "false", + ]); + let output = run_delta(ONE_MINUS_ONE_PLUS_LINE_DIFF, &config); + // The gutter rows keep plain line numbers; only the hunk header + // (file:line) and file line still carry hyperlinks. + for line in output.lines() { + if line.contains('⋮') { + assert!(!line.contains("\x1b]8;;file://")); + } + } + } + #[test] fn test_color_only() { let config = make_config_from_args(&["--line-numbers", "--color-only"]); diff --git a/src/options/set.rs b/src/options/set.rs index f737bedc1..7c22d372b 100644 --- a/src/options/set.rs +++ b/src/options/set.rs @@ -168,6 +168,7 @@ pub fn set_options( hyperlinks, hyperlinks_commit_link_format, hyperlinks_file_link_format, + hyperlinks_line_numbers, inline_hint_style, inspect_raw_lines, keep_plus_minus_markers, @@ -237,6 +238,7 @@ pub fn set_options( // Setting ComputedValues set_widths_and_isatty(opt); set_true_color(opt); + opt.computed.hyperlinks_line_numbers = opt.hyperlinks_line_numbers == "true"; theme::set__color_mode__syntax_theme__syntax_set(opt, assets); opt.computed.inspect_raw_lines = cli::InspectRawLines::from_str(&opt.inspect_raw_lines).unwrap(); diff --git a/src/subcommands/show_config.rs b/src/subcommands/show_config.rs index 5920eee42..935590aa3 100644 --- a/src/subcommands/show_config.rs +++ b/src/subcommands/show_config.rs @@ -366,6 +366,14 @@ fn write_additional_values(config: &config::Config, writer: &mut dyn Write) -> s .as_deref() .unwrap_or(""), ), + ( + "hyperlinks-line-numbers", + if config.hyperlinks_line_numbers { + "true" + } else { + "false" + }, + ), ( "merge-conflict-begin-symbol", config.merge_conflict_begin_symbol.as_str(),