summaryrefslogtreecommitdiffstats
path: root/src/bin/bat/input.rs
blob: 8e65d800e63f9b999193d3d09fe4b2f394b7f929 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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(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
    }
}