mirror of
https://github.com/sharkdp/bat.git
synced 2025-08-12 17:27:19 +02:00
Add cycle detection with clircle, now v0.2
This commit is contained in:
committed by
David Peter
parent
8381945cb5
commit
21ae26cb17
@ -1,3 +1,4 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::io::{self, Write};
|
||||
|
||||
use crate::assets::HighlightingAssets;
|
||||
@ -66,6 +67,14 @@ 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 writer = output_type.handle()?;
|
||||
let mut no_errors: bool = true;
|
||||
|
||||
@ -78,6 +87,11 @@ 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()) {
|
||||
Err(error) => {
|
||||
|
Reference in New Issue
Block a user