1
0
mirror of https://github.com/sharkdp/bat synced 2026-07-28 17:51:44 +00:00

Replace Input::stdin_as_file with bat-application functions

This commit is contained in:
Ethan P
2020-05-27 16:25:13 -07:00
committed by David Peter
parent a3357547ea
commit 9d08c0102e
4 changed files with 27 additions and 15 deletions
+20
View File
@@ -0,0 +1,20 @@
use bat::input::Input;
use std::ffi::OsStr;
pub fn new_file_input<'a>(file: &'a OsStr, name: Option<&'a OsStr>) -> Input<'a> {
named(Input::ordinary_file(file), name.or_else(|| Some(file)))
}
pub fn new_stdin_input(name: Option<&OsStr>) -> Input {
named(Input::stdin(), name)
}
fn named<'a>(input: Input<'a>, name: Option<&OsStr>) -> Input<'a> {
if let Some(provided_name) = name {
let mut input = input.with_name(Some(provided_name));
input.description_mut().set_kind(Some("File".to_owned()));
input
} else {
input
}
}