summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWayne Davison <wayne@opencoder.net>2021-11-16 19:06:56 -0800
committerDan Davison <dandavison7@gmail.com>2021-11-17 13:42:20 -0500
commit90fd9c60493cc6f653e76277d67e1fce611bbb1d (patch)
treedef0ffeec54e134e14490a893cc91bcb9a255cf9
parentd4e3c288ae8bdfe2bf93c9c23c88860a3987973c (diff)
Add the --right-arrow option.
This allows the file1 -> file2 arrow to be configured to whatever characters the user desires. The default is the same unicode arrow as before with 2 spaces after it, since this allows someone to remove the extra spaces that are in the current output.
-rw-r--r--README.md3
-rw-r--r--src/cli.rs4
-rw-r--r--src/config.rs3
-rw-r--r--src/handlers/file_meta.rs11
-rw-r--r--src/options/set.rs3
-rw-r--r--src/subcommands/show_config.rs4
6 files changed, 24 insertions, 4 deletions
diff --git a/README.md b/README.md
index 5a03cc10..8cc6b0a0 100644
--- a/README.md
+++ b/README.md
@@ -863,6 +863,9 @@ OPTIONS:
--file-renamed-label <file-renamed-label>
Text to display in front of a renamed file path [default: renamed:]
+ --right-arrow <right-arrow>
+ Text to display with a changed value such as a diff heading, a rename, or a chmod [default: ⟶ ]
+
--hunk-label <hunk-label>
Text to display in front of a hunk header [default: ]
diff --git a/src/cli.rs b/src/cli.rs
index f7a4ec90..aa40ce1e 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -550,6 +550,10 @@ pub struct Opt {
/// Text to display in front of a renamed file path.
pub file_renamed_label: String,
+ #[structopt(long = "right-arrow", default_value = "⟶ ")]
+ /// Text to display with a changed value such as a diff heading, a rename, or a chmod.
+ pub right_arrow: String,
+
#[structopt(long = "hunk-label", default_value = "")]
/// Text to display in front of a hunk header.
pub hunk_label: String,
diff --git a/src/config.rs b/src/config.rs
index 81424211..4ed7f27a 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -73,6 +73,7 @@ pub struct Config {
pub file_modified_label: String,
pub file_removed_label: String,
pub file_renamed_label: String,
+ pub right_arrow: String,
pub file_style: Style,
pub git_config_entries: HashMap<String, GitConfigEntry>,
pub git_config: Option<GitConfig>,
@@ -223,6 +224,7 @@ impl From<cli::Opt> for Config {
let file_modified_label = opt.file_modified_label;
let file_removed_label = opt.file_removed_label;
let file_renamed_label = opt.file_renamed_label;
+ let right_arrow = opt.right_arrow;
let hunk_label = opt.hunk_label;
let line_fill_method = match opt.line_fill_method.as_deref() {
@@ -278,6 +280,7 @@ impl From<cli::Opt> for Config {
file_modified_label,
file_removed_label,
file_renamed_label,
+ right_arrow,
hunk_label,
file_style,
git_config: opt.git_config,
diff --git a/src/handlers/file_meta.rs b/src/handlers/file_meta.rs
index d58eb9dd..8a1ea0d3 100644
--- a/src/handlers/file_meta.rs
+++ b/src/handlers/file_meta.rs
@@ -313,9 +313,10 @@ pub fn get_file_change_description_from_file_paths(
};
if comparing {
format!(
- "{}{} ⟶ {}",
+ "{}{} {} {}",
format_label(&config.file_modified_label),
minus_file,
+ config.right_arrow,
plus_file
)
} else {
@@ -337,7 +338,10 @@ pub fn get_file_change_description_from_file_paths(
// https://medium.com/@tahteche/how-git-treats-changes-in-file-permissions-f71874ca239d
("100644", "100755") => format!("{}: mode +x", plus_file),
("100755", "100644") => format!("{}: mode -x", plus_file),
- _ => format!("{}: {} ⟶ {}", plus_file, old_mode, new_mode),
+ _ => format!(
+ "{}: {} {} {}",
+ plus_file, old_mode, config.right_arrow, new_mode
+ ),
},
(minus_file, plus_file, _, _) if minus_file == plus_file => format!(
"{}{}",
@@ -357,13 +361,14 @@ pub fn get_file_change_description_from_file_paths(
// minus_file_event == plus_file_event, except in the ModeChange
// case above.
(minus_file, plus_file, file_event, _) => format!(
- "{}{} ⟶ {}",
+ "{}{} {} {}",
format_label(match file_event {
FileEvent::Rename => &config.file_renamed_label,
FileEvent::Copy => &config.file_copied_label,
_ => &config.file_modified_label,
}),
format_file(minus_file),
+ config.right_arrow,
format_file(plus_file)
),
}
diff --git a/src/options/set.rs b/src/options/set.rs
index 27a03105..125d4500 100644
--- a/src/options/set.rs
+++ b/src/options/set.rs
@@ -137,6 +137,7 @@ pub fn set_options(
file_modified_label,
file_removed_label,
file_renamed_label,
+ right_arrow,
hunk_label,
file_style,
hunk_header_decoration_style,
@@ -667,6 +668,7 @@ pub mod tests {
file-modified-label = xxxyyyzzz
file-removed-label = xxxyyyzzz
file-renamed-label = xxxyyyzzz
+ right-arrow = xxxyyyzzz
file-style = black black
hunk-header-decoration-style = black black
hunk-header-style = black black
@@ -726,6 +728,7 @@ pub mod tests {
assert_eq!(opt.file_modified_label, "xxxyyyzzz");
assert_eq!(opt.file_removed_label, "xxxyyyzzz");
assert_eq!(opt.file_renamed_label, "xxxyyyzzz");
+ assert_eq!(opt.right_arrow, "xxxyyyzzz");
assert_eq!(opt.file_style, "black black");
assert_eq!(opt.hunk_header_decoration_style, "black black");
assert_eq!(opt.hunk_header_style, "black black");
diff --git a/src/subcommands/show_config.rs b/src/subcommands/show_config.rs
index a36ee4a2..ae45e877 100644
--- a/src/subcommands/show_config.rs
+++ b/src/subcommands/show_config.rs
@@ -54,12 +54,14 @@ pub fn show_config(config: &config::Config, writer: &mut dyn Write) -> std::io::
file-added-label = {file_added_label}
file-modified-label = {file_modified_label}
file-removed-label = {file_removed_label}
- file-renamed-label = {file_renamed_label}",
+ file-renamed-label = {file_renamed_label}
+ right-arrow = {right_arrow}",
true_color = config.true_color,
file_added_label = format_option_value(&config.file_added_label),
file_modified_label = format_option_value(&config.file_modified_label),
file_removed_label = format_option_value(&config.file_removed_label),
file_renamed_label = format_option_value(&config.file_renamed_label),
+ right_arrow = format_option_value(&config.right_arrow),
)?;
writeln!(
writer,