1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-03 20:02:28 +01:00

Merge branch 'master' into read-from-tail

This commit is contained in:
Keith Hall
2025-04-15 20:27:26 +03:00
130 changed files with 3567 additions and 1099 deletions

View File

@@ -9,10 +9,10 @@ use crate::lessopen::LessOpenPreprocessor;
#[cfg(feature = "git")]
use crate::line_range::LineRange;
use crate::line_range::{LineRanges, MaxBufferedLineNumber, RangeCheckResult};
use crate::output::OutputType;
use crate::output::{OutputHandle, OutputType};
#[cfg(feature = "paging")]
use crate::paging::PagingMode;
use crate::printer::{InteractivePrinter, OutputHandle, Printer, SimplePrinter};
use crate::printer::{InteractivePrinter, Printer, SimplePrinter};
use std::collections::VecDeque;
use std::io::{self, BufRead, Write};
use std::mem;
@@ -26,7 +26,7 @@ pub struct Controller<'a> {
preprocessor: Option<LessOpenPreprocessor>,
}
impl<'b> Controller<'b> {
impl Controller<'_> {
pub fn new<'a>(config: &'a Config, assets: &'a HighlightingAssets) -> Controller<'a> {
Controller {
config,
@@ -36,18 +36,14 @@ impl<'b> Controller<'b> {
}
}
pub fn run(
&self,
inputs: Vec<Input>,
output_buffer: Option<&mut dyn std::fmt::Write>,
) -> Result<bool> {
self.run_with_error_handler(inputs, output_buffer, default_error_handler)
pub fn run(&self, inputs: Vec<Input>, output_handle: Option<OutputHandle<'_>>) -> Result<bool> {
self.run_with_error_handler(inputs, output_handle, default_error_handler)
}
pub fn run_with_error_handler(
&self,
inputs: Vec<Input>,
output_buffer: Option<&mut dyn std::fmt::Write>,
output_handle: Option<OutputHandle<'_>>,
mut handle_error: impl FnMut(&Error, &mut dyn Write),
) -> Result<bool> {
let mut output_type;
@@ -89,8 +85,9 @@ impl<'b> Controller<'b> {
clircle::Identifier::stdout()
};
let mut writer = match output_buffer {
Some(buf) => OutputHandle::FmtWrite(buf),
let mut writer = match output_handle {
Some(OutputHandle::FmtWrite(w)) => OutputHandle::FmtWrite(w),
Some(OutputHandle::IoWrite(w)) => OutputHandle::IoWrite(w),
None => OutputHandle::IoWrite(output_type.handle()?),
};
let mut no_errors: bool = true;