mirror of
https://github.com/dandavison/delta.git
synced 2024-11-09 12:39:09 +03:00
parent
d13c41c3fe
commit
55287a827e
23
src/main.rs
23
src/main.rs
@ -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) {
|
||||
|
@ -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
|
||||
@ -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,
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user