Skip to content
Merged
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
23 changes: 15 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,21 @@ fn run_app() -> std::io::Result<i32> {
OutputType::from_mode(config.paging_mode, config.pager.clone(), &config).unwrap();
let mut writer = output_type.handle().unwrap();

if atty::is(atty::Stream::Stdin) {
let exit_code = subcommands::diff::diff(
config.minus_file.as_ref(),
config.plus_file.as_ref(),
&config,
&mut writer,
);
return Ok(exit_code);
match (config.minus_file.as_ref(), config.plus_file.as_ref()) {
(None, None) => {}
(Some(minus_file), Some(plus_file)) => {
let exit_code = subcommands::diff::diff(minus_file, plus_file, &config, &mut writer);
return Ok(exit_code);
}
_ => {
eprintln!(
"\
The main way to use delta is to configure it as the pager for git: \
see https://github.com/dandavison/delta#configuration. \
You can also use delta to diff two files: `delta file_A file_B`."
);
return Ok(config.error_exit_code);
}
}

if let Err(error) = delta(io::stdin().lock().byte_lines(), &mut writer, &config) {
Expand Down
19 changes: 4 additions & 15 deletions src/subcommands/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,12 @@ use crate::delta;

/// Run `git diff` on the files provided on the command line and display the output.
pub fn diff(
minus_file: Option<&PathBuf>,
plus_file: Option<&PathBuf>,
minus_file: &Path,
plus_file: &Path,
config: &config::Config,
writer: &mut dyn Write,
) -> i32 {
use std::io::BufReader;
if minus_file.is_none() || plus_file.is_none() {
eprintln!(
"\
The main way to use delta is to configure it as the pager for git: \
see https://github.com/dandavison/delta#configuration. \
You can also use delta to diff two files: `delta file_A file_B`."
);
return config.error_exit_code;
}
let minus_file = minus_file.unwrap();
let plus_file = plus_file.unwrap();

// When called as `delta <(echo foo) <(echo bar)`, then git as of version 2.34 just prints the
// diff of the filenames which were created by the process substitution and does not read their
Expand Down Expand Up @@ -126,8 +115,8 @@ mod main_tests {
let config = integration_test_utils::make_config_from_args(&[]);
let mut writer = Cursor::new(vec![]);
let exit_code = diff(
Some(&PathBuf::from(file_a)),
Some(&PathBuf::from(file_b)),
&PathBuf::from(file_a),
&PathBuf::from(file_b),
&config,
&mut writer,
);
Expand Down