mirror of
https://github.com/sharkdp/bat.git
synced 2026-10-30 10:06:12 +00:00
PagerKind::from(): Simplify
This commit is contained in:
1 parent
c2c2b0211a
commit
7809008016
1 file changed
+9
-14
+9
-14
@@ -38,23 +38,18 @@ pub(crate) enum PagerKind {
|
|||||||
|
|
||||||
impl PagerKind {
|
impl PagerKind {
|
||||||
fn from_bin(bin: &str) -> PagerKind {
|
fn from_bin(bin: &str) -> PagerKind {
|
||||||
use std::ffi::OsStr;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
let stem = Path::new(bin)
|
match Path::new(bin)
|
||||||
.file_stem()
|
.file_stem()
|
||||||
.unwrap_or_else(|| OsStr::new("unknown"));
|
.map(|s| s.to_string_lossy())
|
||||||
|
.as_deref()
|
||||||
if stem == OsStr::new("bat") {
|
{
|
||||||
PagerKind::Bat
|
Some("bat") => PagerKind::Bat,
|
||||||
} else if stem == OsStr::new("less") {
|
Some("less") => PagerKind::Less,
|
||||||
PagerKind::Less
|
Some("more") => PagerKind::More,
|
||||||
} else if stem == OsStr::new("more") {
|
Some("most") => PagerKind::Most,
|
||||||
PagerKind::More
|
_ => PagerKind::Unknown,
|
||||||
} else if stem == OsStr::new("most") {
|
|
||||||
PagerKind::Most
|
|
||||||
} else {
|
|
||||||
PagerKind::Unknown
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user