1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-16 10:12:26 +01:00

Add *_with_name methods

This commit is contained in:
sharkdp
2020-04-22 22:41:25 +02:00
committed by David Peter
parent 53a973e9dd
commit 261a7ea154
5 changed files with 37 additions and 13 deletions

View File

@@ -79,17 +79,44 @@ impl<'a> PrettyPrinter<'a> {
self
}
/// Use a string as an input
/// Add STDIN as an input (with customized name)
pub fn input_stdin_with_name(&mut self, name: impl AsRef<OsStr>) -> &mut Self {
self.inputs
.push(Input::stdin().with_name(Some(name.as_ref())));
self
}
/// Add a byte string as an input
pub fn input_from_bytes(&mut self, content: &'a [u8]) -> &mut Self {
self.input_from_reader(content)
}
/// Add a byte string as an input (with customized name)
pub fn input_from_bytes_with_name(
&mut self,
content: &'a [u8],
name: impl AsRef<OsStr>,
) -> &mut Self {
self.input_from_reader_with_name(content, name)
}
/// Add a custom reader as an input
pub fn input_from_reader<R: Read + 'a>(&mut self, reader: R) -> &mut Self {
self.inputs.push(Input::from_reader(Box::new(reader)));
self
}
/// Add a custom reader as an input (with customized name)
pub fn input_from_reader_with_name<R: Read + 'a>(
&mut self,
reader: R,
name: impl AsRef<OsStr>,
) -> &mut Self {
self.inputs
.push(Input::from_reader(Box::new(reader)).with_name(Some(name.as_ref())));
self
}
/// Specify the syntax file which should be used (default: auto-detect)
pub fn language(&mut self, language: &'a str) -> &mut Self {
self.config.language = Some(language);