mirror of
https://github.com/sharkdp/bat.git
synced 2025-08-13 09:47:27 +02:00
Change circle detection to use new more conservative method and run in main loop instead of before the loop
This commit is contained in:
committed by
David Peter
parent
a98811b6d7
commit
694b31909a
@ -1,4 +1,3 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::io::{self, Write};
|
||||
|
||||
use crate::assets::HighlightingAssets;
|
||||
@ -15,6 +14,8 @@ use crate::output::OutputType;
|
||||
use crate::paging::PagingMode;
|
||||
use crate::printer::{InteractivePrinter, Printer, SimplePrinter};
|
||||
|
||||
use clircle::Clircle;
|
||||
|
||||
pub struct Controller<'a> {
|
||||
config: &'a Config<'a>,
|
||||
assets: &'a HighlightingAssets,
|
||||
@ -67,12 +68,10 @@ impl<'b> Controller<'b> {
|
||||
}
|
||||
|
||||
let attached_to_pager = output_type.is_pager();
|
||||
let rw_cycle_detected = !attached_to_pager && {
|
||||
let identifiers: Vec<_> = inputs
|
||||
.iter()
|
||||
.flat_map(clircle::Identifier::try_from)
|
||||
.collect();
|
||||
clircle::stdout_among_inputs(&identifiers)
|
||||
let stdout_identifier = if cfg!(windows) || attached_to_pager {
|
||||
None
|
||||
} else {
|
||||
clircle::Identifier::stdout()
|
||||
};
|
||||
|
||||
let writer = output_type.handle()?;
|
||||
@ -87,13 +86,8 @@ impl<'b> Controller<'b> {
|
||||
}
|
||||
};
|
||||
|
||||
if rw_cycle_detected {
|
||||
print_error(&"The output file is also an input!".into(), writer);
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
for (index, input) in inputs.into_iter().enumerate() {
|
||||
match input.open(io::stdin().lock()) {
|
||||
match input.open(io::stdin().lock(), stdout_identifier.as_ref()) {
|
||||
Err(error) => {
|
||||
print_error(&error, writer);
|
||||
no_errors = false;
|
||||
|
Reference in New Issue
Block a user