From ce00e62a5dcf22623edaf9c5d34a3cf37abd049b Mon Sep 17 00:00:00 2001 From: o2sh Date: Tue, 3 Nov 2020 00:15:26 +0100 Subject: [PATCH] fix clippy warnings and rename iterm2 to iterm --- src/onefetch/cli.rs | 2 +- .../image_backends/{iterm2.rs => iterm.rs} | 10 +++++----- src/onefetch/image_backends/kitty.rs | 2 +- src/onefetch/image_backends/mod.rs | 14 +++++++++----- 4 files changed, 16 insertions(+), 12 deletions(-) rename src/onefetch/image_backends/{iterm2.rs => iterm.rs} (90%) diff --git a/src/onefetch/cli.rs b/src/onefetch/cli.rs index 54c30e3a2..9f3e18144 100644 --- a/src/onefetch/cli.rs +++ b/src/onefetch/cli.rs @@ -36,7 +36,7 @@ impl Cli { /// Build `Options` from command line arguments. pub fn new() -> Result { #[cfg(not(windows))] - let possible_backends = ["kitty", "iterm2", "sixel"]; + let possible_backends = ["kitty", "iterm", "sixel"]; #[cfg(windows)] let possible_backends = []; let color_values = diff --git a/src/onefetch/image_backends/iterm2.rs b/src/onefetch/image_backends/iterm.rs similarity index 90% rename from src/onefetch/image_backends/iterm2.rs rename to src/onefetch/image_backends/iterm.rs index 5fef195bd..c1ee7bd71 100644 --- a/src/onefetch/image_backends/iterm2.rs +++ b/src/onefetch/image_backends/iterm.rs @@ -4,20 +4,20 @@ use { std::env, }; -pub struct ITerm2Backend {} +pub struct ITermBackend {} -impl ITerm2Backend { +impl ITermBackend { pub fn new() -> Self { - Self {} + ITermBackend {} } pub fn supported() -> bool { - let term_program = env::var("TERM_PROGRAM").unwrap_or("".to_string()); + let term_program = env::var("TERM_PROGRAM").unwrap_or_else(|_| "".to_string()); term_program == "iTerm.app" } } -impl super::ImageBackend for ITerm2Backend { +impl super::ImageBackend for ITermBackend { fn add_image(&self, lines: Vec, image: &DynamicImage, _colors: usize) -> String { let tty_size = unsafe { let tty_size: winsize = std::mem::zeroed(); diff --git a/src/onefetch/image_backends/kitty.rs b/src/onefetch/image_backends/kitty.rs index 5961a96ae..96e13837b 100644 --- a/src/onefetch/image_backends/kitty.rs +++ b/src/onefetch/image_backends/kitty.rs @@ -16,7 +16,7 @@ impl KittyBackend { } pub fn supported() -> bool { - if !env::var("KITTY_WINDOW_ID").unwrap_or("".to_string()).is_empty() { + if !env::var("KITTY_WINDOW_ID").unwrap_or_else(|_| "".to_string()).is_empty() { return true; } diff --git a/src/onefetch/image_backends/mod.rs b/src/onefetch/image_backends/mod.rs index dec796fa7..8571342bb 100644 --- a/src/onefetch/image_backends/mod.rs +++ b/src/onefetch/image_backends/mod.rs @@ -2,7 +2,7 @@ use crate::onefetch::error::*; use image::DynamicImage; #[cfg(not(windows))] -pub mod iterm2; +pub mod iterm; #[cfg(not(windows))] pub mod kitty; #[cfg(not(windows))] @@ -16,8 +16,8 @@ pub trait ImageBackend { pub fn get_best_backend() -> Option> { if kitty::KittyBackend::supported() { Some(Box::new(kitty::KittyBackend::new())) - } else if iterm2::ITerm2Backend::supported() { - Some(Box::new(iterm2::ITerm2Backend::new())) + } else if iterm::ITermBackend::supported() { + Some(Box::new(iterm::ITermBackend::new())) } else if sixel::SixelBackend::supported() { Some(Box::new(sixel::SixelBackend::new())) } else { @@ -36,7 +36,11 @@ pub fn check_if_supported(backend_name: &str) -> Result<()> { return Err("Kitty image backend is not supported".into()); } } - "iterm2" => {} + "iterm" => { + if !iterm::ITermBackend::supported() { + return Err("iTerm image backend is not supported".into()); + } + } "sixel" => { if !sixel::SixelBackend::supported() { return Err("Sixel image backend is not supported".into()); @@ -52,7 +56,7 @@ pub fn get_image_backend(backend_name: &str) -> Option> { #[cfg(not(windows))] let backend = Some(match backend_name { "kitty" => Box::new(kitty::KittyBackend::new()) as Box, - "iterm2" => Box::new(iterm2::ITerm2Backend::new()) as Box, + "iterm" => Box::new(iterm::ITermBackend::new()) as Box, "sixel" => Box::new(sixel::SixelBackend::new()) as Box, _ => unreachable!(), });