Skip to content

Commit

Permalink
fix clippy warnings and rename iterm2 to iterm
Browse files Browse the repository at this point in the history
  • Loading branch information
o2sh committed Nov 2, 2020
1 parent 71230ce commit ce00e62
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/onefetch/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Cli {
/// Build `Options` from command line arguments.
pub fn new() -> Result<Self> {
#[cfg(not(windows))]
let possible_backends = ["kitty", "iterm2", "sixel"];
let possible_backends = ["kitty", "iterm", "sixel"];
#[cfg(windows)]
let possible_backends = [];
let color_values =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>, image: &DynamicImage, _colors: usize) -> String {
let tty_size = unsafe {
let tty_size: winsize = std::mem::zeroed();
Expand Down
2 changes: 1 addition & 1 deletion src/onefetch/image_backends/kitty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
14 changes: 9 additions & 5 deletions src/onefetch/image_backends/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand All @@ -16,8 +16,8 @@ pub trait ImageBackend {
pub fn get_best_backend() -> Option<Box<dyn ImageBackend>> {
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 {
Expand All @@ -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());
Expand All @@ -52,7 +56,7 @@ pub fn get_image_backend(backend_name: &str) -> Option<Box<dyn ImageBackend>> {
#[cfg(not(windows))]
let backend = Some(match backend_name {
"kitty" => Box::new(kitty::KittyBackend::new()) as Box<dyn ImageBackend>,
"iterm2" => Box::new(iterm2::ITerm2Backend::new()) as Box<dyn ImageBackend>,
"iterm" => Box::new(iterm::ITermBackend::new()) as Box<dyn ImageBackend>,
"sixel" => Box::new(sixel::SixelBackend::new()) as Box<dyn ImageBackend>,
_ => unreachable!(),
});
Expand Down

0 comments on commit ce00e62

Please sign in to comment.