From 9ce17c186f4b301b9af26fa2329ad54dda58e557 Mon Sep 17 00:00:00 2001 From: o2sh Date: Sat, 12 Nov 2022 19:37:59 +0100 Subject: [PATCH] move image_backends into its own crate --- Cargo.lock | 12 ++++++++++++ Cargo.toml | 3 ++- image/Cargo.toml | 16 ++++++++++++++++ image/LICENSE.md | 1 + image/README.md | 11 +++++++++++ {src/ui/image_backends => image/src}/iterm.rs | 0 {src/ui/image_backends => image/src}/kitty.rs | 0 src/ui/image_backends/mod.rs => image/src/lib.rs | 0 {src/ui/image_backends => image/src}/sixel.rs | 0 src/cli.rs | 2 +- src/ui/mod.rs | 1 - src/ui/printer.rs | 7 +++---- 12 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 image/Cargo.toml create mode 100644 image/LICENSE.md create mode 100644 image/README.md rename {src/ui/image_backends => image/src}/iterm.rs (100%) rename {src/ui/image_backends => image/src}/kitty.rs (100%) rename src/ui/image_backends/mod.rs => image/src/lib.rs (100%) rename {src/ui/image_backends => image/src}/sixel.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 5d4639fab..f22ef5e46 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2046,6 +2046,7 @@ dependencies = [ "insta", "lazy_static", "libc", + "onefetch-image", "onefetch-manifest", "owo-colors", "pretty_assertions", @@ -2062,6 +2063,17 @@ dependencies = [ "yaml-rust", ] +[[package]] +name = "onefetch-image" +version = "2.13.2" +dependencies = [ + "anyhow", + "base64", + "clap 4.0.22", + "image", + "libc", +] + [[package]] name = "onefetch-manifest" version = "2.13.2" diff --git a/Cargo.toml b/Cargo.toml index 314b12a62..2670b7b53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,10 +13,11 @@ rust-version = "1.60.0" version = "2.13.2" [workspace] -members = ["manifest"] +members = ["manifest", "image"] [dependencies] onefetch-manifest = { path = "manifest", version = "2.13.2" } +onefetch-image = { path = "image", version = "2.13.2" } anyhow = "1.0.66" askalono = "0.4.6" byte-unit = "4.0.14" diff --git a/image/Cargo.toml b/image/Cargo.toml new file mode 100644 index 000000000..3e89e7838 --- /dev/null +++ b/image/Cargo.toml @@ -0,0 +1,16 @@ +[package] +authors = ["o2sh "] +name = "onefetch-image" +version = "2.13.2" +edition = "2021" +license = "MIT" +readme = "README.md" + +[dependencies] +image = "0.24.4" +anyhow = "1.0" +clap = "4.0.22" + +[target.'cfg(not(windows))'.dependencies] +base64 = "0.13.0" +libc = "0.2.134" diff --git a/image/LICENSE.md b/image/LICENSE.md new file mode 100644 index 000000000..a198ac413 --- /dev/null +++ b/image/LICENSE.md @@ -0,0 +1 @@ +../LICENSE.md diff --git a/image/README.md b/image/README.md new file mode 100644 index 000000000..4ce81e31e --- /dev/null +++ b/image/README.md @@ -0,0 +1,11 @@ +# image + +Provides the primary interface to diplay images in the terminal. + +Protocols supported: + +- Sixel +- Kitty +- Iterm + +_This crate is designed as part of the [onefetch](https://github.com/o2sh/onefetch) project._ diff --git a/src/ui/image_backends/iterm.rs b/image/src/iterm.rs similarity index 100% rename from src/ui/image_backends/iterm.rs rename to image/src/iterm.rs diff --git a/src/ui/image_backends/kitty.rs b/image/src/kitty.rs similarity index 100% rename from src/ui/image_backends/kitty.rs rename to image/src/kitty.rs diff --git a/src/ui/image_backends/mod.rs b/image/src/lib.rs similarity index 100% rename from src/ui/image_backends/mod.rs rename to image/src/lib.rs diff --git a/src/ui/image_backends/sixel.rs b/image/src/sixel.rs similarity index 100% rename from src/ui/image_backends/sixel.rs rename to image/src/sixel.rs diff --git a/src/cli.rs b/src/cli.rs index e52ad379a..587cf7d36 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,12 +1,12 @@ use crate::info::info_field::InfoType; use crate::info::langs::language::{Language, LanguageType}; -use crate::ui::image_backends::ImageProtocol; use crate::ui::printer::SerializationFormat; use anyhow::Result; use clap::builder::PossibleValuesParser; use clap::builder::TypedValueParser as _; use clap::{value_parser, Command, Parser, ValueHint}; use clap_complete::{generate, Generator, Shell}; +use onefetch_image::ImageProtocol; use onefetch_manifest::ManifestType; use regex::Regex; use std::env; diff --git a/src/ui/mod.rs b/src/ui/mod.rs index cd92e2c75..645673e42 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -2,7 +2,6 @@ use crate::info::langs::language::Language; use owo_colors::{AnsiColors, DynColors}; pub mod ascii_art; -pub mod image_backends; pub mod printer; pub mod text_colors; diff --git a/src/ui/printer.rs b/src/ui/printer.rs index 2509981c2..5f7d273af 100644 --- a/src/ui/printer.rs +++ b/src/ui/printer.rs @@ -1,11 +1,10 @@ use crate::cli::{Config, When}; use crate::info::Info; use crate::ui::ascii_art::AsciiArt; -use crate::ui::image_backends; -use crate::ui::image_backends::ImageBackend; use crate::ui::Language; use anyhow::{Context, Result}; use image::DynamicImage; +use onefetch_image::ImageBackend; use std::fmt::Write as _; use std::io::Write; use terminal_size::{terminal_size, Width}; @@ -53,8 +52,8 @@ impl Printer { let image_backend = if image.is_some() { config .image_protocol - .map_or_else(image_backends::get_best_backend, |s| { - image_backends::get_image_backend(s) + .map_or_else(onefetch_image::get_best_backend, |s| { + onefetch_image::get_image_backend(s) }) } else { None