Change circle detection to use new more conservative method and run in main loop instead of before the loop

This commit is contained in:
Niklas Mohrin
2021-02-27 15:32:07 +01:00
committed by David Peter
parent a98811b6d7
commit 694b31909a
5 changed files with 55 additions and 42 deletions

View File

@ -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;