Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,18 @@ pub struct Opt {
/// <https://dandavison.github.io/delta/hyperlinks.html> 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",
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub struct Config {
pub hyperlinks_commit_link_format: Option<String>,
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,
Expand Down Expand Up @@ -362,6 +363,7 @@ impl From<cli::Opt> 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,
Expand Down
36 changes: 35 additions & 1 deletion src/features/line_numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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"]);
Expand Down
2 changes: 2 additions & 0 deletions src/options/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions src/subcommands/show_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down