mirror of
https://github.com/hykilpikonna/hyfetch.git
synced 2026-10-01 12:36:37 -05:00
[PR] Add palette_glyph for macchina backend (#501)
Some checks failed
Shellcheck / check (push) Has been cancelled
Some checks failed
Shellcheck / check (push) Has been cancelled
* add palette_glyph for macchina backend * new palette enum to accomodate different palette types * fixed some errors * whoops * [F] Fix building without cfg macchina * [+] Useful characters * [O] Shorten --------- Co-authored-by: Azalea <noreply@aza.moe>
This commit is contained in:
@@ -8,6 +8,8 @@ use std::iter;
|
|||||||
use std::iter::zip;
|
use std::iter::zip;
|
||||||
use std::num::NonZeroU8;
|
use std::num::NonZeroU8;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
#[cfg(feature = "macchina")]
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use aho_corasick::AhoCorasick;
|
use aho_corasick::AhoCorasick;
|
||||||
use anyhow::{Context as _, Result};
|
use anyhow::{Context as _, Result};
|
||||||
@@ -24,7 +26,9 @@ use hyfetch::color_util::{
|
|||||||
NeofetchAsciiIndexedColor, PresetIndexedColor, Theme as _, ToAnsiString as _,
|
NeofetchAsciiIndexedColor, PresetIndexedColor, Theme as _, ToAnsiString as _,
|
||||||
};
|
};
|
||||||
use hyfetch::distros::Distro;
|
use hyfetch::distros::Distro;
|
||||||
use hyfetch::models::{build_hex_color_profile, Config, PresetValue};
|
#[cfg(feature = "macchina")]
|
||||||
|
use hyfetch::models::Palette;
|
||||||
|
use hyfetch::models::{Config, PresetValue, build_hex_color_profile};
|
||||||
#[cfg(feature = "macchina")]
|
#[cfg(feature = "macchina")]
|
||||||
use hyfetch::neofetch_util::macchina_path;
|
use hyfetch::neofetch_util::macchina_path;
|
||||||
use hyfetch::neofetch_util::{self, add_pkg_path, fastfetch_path, get_distro_ascii, get_distro_name, literal_input, ColorAlignment, NEOFETCH_COLORS_AC, NEOFETCH_COLOR_PATTERNS, TEST_ASCII};
|
use hyfetch::neofetch_util::{self, add_pkg_path, fastfetch_path, get_distro_ascii, get_distro_name, literal_input, ColorAlignment, NEOFETCH_COLORS_AC, NEOFETCH_COLOR_PATTERNS, TEST_ASCII};
|
||||||
@@ -135,6 +139,22 @@ fn main() -> Result<()> {
|
|||||||
|
|
||||||
let backend = options.backend.unwrap_or(config.backend);
|
let backend = options.backend.unwrap_or(config.backend);
|
||||||
let args = options.args.as_ref().or(config.args.as_ref());
|
let args = options.args.as_ref().or(config.args.as_ref());
|
||||||
|
#[cfg(feature = "macchina")]
|
||||||
|
let palette_glyph: Option<&String> = options.palette_glyph.as_ref().or(config.palette_glyph.as_ref());
|
||||||
|
#[cfg(feature = "macchina")]
|
||||||
|
let palette_type: Option<&String> = options.palette_type.as_ref().or(config.palette_type.as_ref());
|
||||||
|
#[cfg(feature = "macchina")]
|
||||||
|
let palette: Option<Palette> = if let Some(glyph) = palette_glyph {
|
||||||
|
if let Some(type_str) = palette_type {
|
||||||
|
if let Ok(mut parsed_type) = Palette::from_str(type_str) {
|
||||||
|
parsed_type.get_glyph_mut().push_str(glyph);
|
||||||
|
Some(parsed_type)
|
||||||
|
} else { Some(Palette::Full(glyph.to_owned())) }
|
||||||
|
} else { Some(Palette::Full(glyph.to_owned())) }
|
||||||
|
} else { None };
|
||||||
|
|
||||||
|
#[cfg(not(feature = "macchina"))]
|
||||||
|
let palette: Option<&String> = None;
|
||||||
|
|
||||||
fn parse_preset_string(preset_string: &str, config: &Config) -> Result<ColorProfile> {
|
fn parse_preset_string(preset_string: &str, config: &Config) -> Result<ColorProfile> {
|
||||||
if preset_string.contains('#') {
|
if preset_string.contains('#') {
|
||||||
@@ -225,7 +245,7 @@ fn main() -> Result<()> {
|
|||||||
let asc = asc
|
let asc = asc
|
||||||
.to_recolored(&color_align, &color_profile, color_mode, theme)
|
.to_recolored(&color_align, &color_profile, color_mode, theme)
|
||||||
.context("failed to recolor ascii")?;
|
.context("failed to recolor ascii")?;
|
||||||
neofetch_util::run(asc, backend, args)?;
|
neofetch_util::run(asc, backend, args, palette)?;
|
||||||
|
|
||||||
if options.ask_exit {
|
if options.ask_exit {
|
||||||
input(Some("Press enter to exit...")).context("failed to read input")?;
|
input(Some("Press enter to exit...")).context("failed to read input")?;
|
||||||
@@ -1231,6 +1251,12 @@ fn create_config(
|
|||||||
backend.as_ref(),
|
backend.as_ref(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//////////////////////////////
|
||||||
|
// 7.5. Prepare macchina advanced options
|
||||||
|
|
||||||
|
#[cfg(feature = "macchina")]
|
||||||
|
let mut palette: Option<Palette> = None;
|
||||||
|
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
// 8. Custom ASCII file
|
// 8. Custom ASCII file
|
||||||
let mut custom_ascii_path: Option<String> = None;
|
let mut custom_ascii_path: Option<String> = None;
|
||||||
@@ -1277,6 +1303,181 @@ fn create_config(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////
|
||||||
|
// 9. Macchina advanced options
|
||||||
|
|
||||||
|
#[cfg(feature = "macchina")]
|
||||||
|
if backend == Backend::Macchina {
|
||||||
|
clear_screen(Some(&title), color_mode, debug_mode).context("failed to clear screen")?;
|
||||||
|
print_title_prompt(option_counter, "Edit advanced options for macchina?");
|
||||||
|
let choice = literal_input("Your choice?", &["y", "n"], "n", true, color_mode)
|
||||||
|
.context("failed to ask for macchina advanced options input")?;
|
||||||
|
|
||||||
|
if choice == "y" {
|
||||||
|
use hyfetch::formatc;
|
||||||
|
|
||||||
|
palette = Some(Palette::Full("".to_owned()));
|
||||||
|
let mut current_title = "Create a glyph for macchina (leave empty for None):";
|
||||||
|
|
||||||
|
clear_screen(Some(&title), color_mode, debug_mode)
|
||||||
|
.context("failed to clear screen")?;
|
||||||
|
print_title_prompt(option_counter, current_title);
|
||||||
|
|
||||||
|
const DARK_COLORS: [&str; 8] = ["&0","&4","&2","&6","&1","&5","&3","&8"];
|
||||||
|
const LIGHT_COLORS: [&str; 8] = ["&8","&c","&a","&e","&9","&d","&b","&f"];
|
||||||
|
|
||||||
|
let to_palette = |glyph: &str, colors: [&str; 8]| -> String {
|
||||||
|
colors
|
||||||
|
.into_iter()
|
||||||
|
.map(|s| s.to_owned() + glyph + "&r" )
|
||||||
|
.collect()
|
||||||
|
};
|
||||||
|
|
||||||
|
let print_palette = |palette: &mut Palette, current_title: &str| -> Result<()> {
|
||||||
|
clear_screen(Some(&title), color_mode, debug_mode)
|
||||||
|
.context("failed to clear screen")?;
|
||||||
|
print_title_prompt(option_counter, current_title);
|
||||||
|
println!("Useful characters: █▓▒░▄‗");
|
||||||
|
|
||||||
|
match palette {
|
||||||
|
Palette::Full(glyph) =>
|
||||||
|
printc!("Preview:\n{}\n{}\n", to_palette(glyph, DARK_COLORS),
|
||||||
|
to_palette(glyph, LIGHT_COLORS)),
|
||||||
|
Palette::Light(glyph) =>
|
||||||
|
printc!("Preview:\n{}\n\n", to_palette(glyph, LIGHT_COLORS)),
|
||||||
|
Palette::Dark(glyph) =>
|
||||||
|
printc!("Preview:\n{}\n\n", to_palette(glyph, DARK_COLORS))
|
||||||
|
}
|
||||||
|
print!("> {}", palette.get_glyph());
|
||||||
|
io::stdout().flush().context("failed to flush preset prompt")?;
|
||||||
|
Ok(())
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut raw_mode = RawModeGuard::new().context("failed to initialize raw input mode")?;
|
||||||
|
loop {
|
||||||
|
raw_mode
|
||||||
|
.disable()
|
||||||
|
.context("failed to disable raw mode for rendering")?;
|
||||||
|
|
||||||
|
print_palette(palette.as_mut().unwrap(), current_title).context("failed to print palette during glyph input")?;
|
||||||
|
|
||||||
|
raw_mode
|
||||||
|
.enable()
|
||||||
|
.context("failed to enable raw mode for key input")?;
|
||||||
|
let event = event::read().context("failed to read keyboard event")?;
|
||||||
|
let Event::Key(key) = event else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
if !matches!(key.kind, KeyEventKind::Press | KeyEventKind::Repeat) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
match key.code {
|
||||||
|
KeyCode::Enter => {
|
||||||
|
break;
|
||||||
|
},
|
||||||
|
KeyCode::Backspace => {
|
||||||
|
palette.as_mut().unwrap().get_glyph_mut().pop();
|
||||||
|
},
|
||||||
|
KeyCode::Esc => {
|
||||||
|
palette.as_mut().unwrap().get_glyph_mut().clear();
|
||||||
|
},
|
||||||
|
KeyCode::Char('c') if key.modifiers.contains(KeyModifiers::CONTROL) => {
|
||||||
|
raw_mode
|
||||||
|
.disable()
|
||||||
|
.context("failed to disable raw mode before interrupting")?;
|
||||||
|
println!();
|
||||||
|
return Err(anyhow::anyhow!("interrupted by user"));
|
||||||
|
},
|
||||||
|
KeyCode::Char(c)
|
||||||
|
if !key.modifiers.contains(KeyModifiers::CONTROL)
|
||||||
|
&& !key.modifiers.contains(KeyModifiers::ALT) =>
|
||||||
|
{
|
||||||
|
palette.as_mut().unwrap().get_glyph_mut().push(c);
|
||||||
|
},
|
||||||
|
_ => {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
raw_mode
|
||||||
|
.disable()
|
||||||
|
.context("failed to disable raw mode after entering glyph")?;
|
||||||
|
drop(raw_mode);
|
||||||
|
|
||||||
|
if palette.as_ref().unwrap().get_glyph().is_empty() {
|
||||||
|
palette = None;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(palette) = palette.as_mut() {
|
||||||
|
current_title = "Pick your palette type!";
|
||||||
|
|
||||||
|
let mut raw_mode = RawModeGuard::new().context("failed to initialize raw input mode")?;
|
||||||
|
let mut select_display: String;
|
||||||
|
loop {
|
||||||
|
raw_mode
|
||||||
|
.disable()
|
||||||
|
.context("failed to disable raw mode for rendering")?;
|
||||||
|
|
||||||
|
print_palette(palette, current_title).context("failed to clear screen during glyph input")?;
|
||||||
|
select_display = match palette {
|
||||||
|
Palette::Full(_) => formatc!("&l&o&nFull&r, Light, Dark"),
|
||||||
|
Palette::Light(_) => formatc!("Full, &l&o&nLight&r, Dark"),
|
||||||
|
Palette::Dark(_) => formatc!("Full, Light, &l&o&nDark")
|
||||||
|
};
|
||||||
|
println!("\n> {}", select_display);
|
||||||
|
|
||||||
|
raw_mode
|
||||||
|
.enable()
|
||||||
|
.context("failed to enable raw mode for key input")?;
|
||||||
|
let event = event::read().context("failed to read keyboard event")?;
|
||||||
|
let Event::Key(key) = event else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
if !matches!(key.kind, KeyEventKind::Press | KeyEventKind::Repeat) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
match key.code {
|
||||||
|
KeyCode::Enter => break,
|
||||||
|
KeyCode::Left => palette.shift_type(false),
|
||||||
|
KeyCode::Right => palette.shift_type(true),
|
||||||
|
KeyCode::Char('c') if key.modifiers.contains(KeyModifiers::CONTROL) => {
|
||||||
|
raw_mode
|
||||||
|
.disable()
|
||||||
|
.context("failed to disable raw mode before interrupting")?;
|
||||||
|
println!();
|
||||||
|
return Err(anyhow::anyhow!("interrupted by user"));
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let preview = match palette.as_ref() {
|
||||||
|
Some(p) => match p {
|
||||||
|
Palette::Full(glyph) =>
|
||||||
|
formatc!("\n{}\n{}", to_palette(glyph, DARK_COLORS),
|
||||||
|
to_palette(glyph, LIGHT_COLORS)),
|
||||||
|
Palette::Light(glyph) =>
|
||||||
|
formatc!("\n{}", to_palette(glyph, LIGHT_COLORS)),
|
||||||
|
Palette::Dark(glyph) =>
|
||||||
|
formatc!("\n{}", to_palette(glyph, DARK_COLORS))
|
||||||
|
},
|
||||||
|
None => "None".to_owned()
|
||||||
|
};
|
||||||
|
|
||||||
|
update_title(
|
||||||
|
&mut title,
|
||||||
|
&mut option_counter,
|
||||||
|
"Customized palette",
|
||||||
|
&preview
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "macchina")]
|
||||||
|
let palette_glyph: Option<String> = palette.as_ref().map(|palette| palette.get_glyph().to_owned());
|
||||||
|
#[cfg(feature = "macchina")]
|
||||||
|
let palette_type: Option<String> = palette.as_ref().map(ToString::to_string);
|
||||||
|
|
||||||
// Create config
|
// Create config
|
||||||
clear_screen(Some(&title), color_mode, debug_mode).context("failed to clear screen")?;
|
clear_screen(Some(&title), color_mode, debug_mode).context("failed to clear screen")?;
|
||||||
let config = Config {
|
let config = Config {
|
||||||
@@ -1292,6 +1493,10 @@ fn create_config(
|
|||||||
pride_month_disable: false,
|
pride_month_disable: false,
|
||||||
custom_ascii_path,
|
custom_ascii_path,
|
||||||
custom_presets: None,
|
custom_presets: None,
|
||||||
|
#[cfg(feature = "macchina")]
|
||||||
|
palette_glyph,
|
||||||
|
#[cfg(feature = "macchina")]
|
||||||
|
palette_type,
|
||||||
};
|
};
|
||||||
debug!(?config, "created config");
|
debug!(?config, "created config");
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ pub struct Options {
|
|||||||
pub test_print: bool,
|
pub test_print: bool,
|
||||||
pub ask_exit: bool,
|
pub ask_exit: bool,
|
||||||
pub auto_detect_light_dark: Option<bool>,
|
pub auto_detect_light_dark: Option<bool>,
|
||||||
|
#[cfg(feature = "macchina")]
|
||||||
|
pub palette_glyph: Option<String>,
|
||||||
|
#[cfg(feature = "macchina")]
|
||||||
|
pub palette_type: Option<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn options() -> OptionParser<Options> {
|
pub fn options() -> OptionParser<Options> {
|
||||||
@@ -153,7 +157,19 @@ BACKEND={{{backends}}}",
|
|||||||
.argument("BOOL")
|
.argument("BOOL")
|
||||||
.optional();
|
.optional();
|
||||||
|
|
||||||
construct!(Options {
|
#[cfg(feature = "macchina")]
|
||||||
|
let palette_glyph = long("palette-glyph")
|
||||||
|
.help("Sets the glyph to be used for the macchina backend")
|
||||||
|
.argument("STR")
|
||||||
|
.optional();
|
||||||
|
#[cfg(feature = "macchina")]
|
||||||
|
let palette_type = long("palette-type")
|
||||||
|
.help("Sets the type of palette to be used for the macchina backend")
|
||||||
|
.argument("full,light,dark")
|
||||||
|
.optional();
|
||||||
|
|
||||||
|
#[cfg(feature = "macchina")]
|
||||||
|
return construct!(Options {
|
||||||
config,
|
config,
|
||||||
config_file,
|
config_file,
|
||||||
preset,
|
preset,
|
||||||
@@ -171,6 +187,8 @@ BACKEND={{{backends}}}",
|
|||||||
test_print,
|
test_print,
|
||||||
ask_exit,
|
ask_exit,
|
||||||
auto_detect_light_dark,
|
auto_detect_light_dark,
|
||||||
|
palette_glyph,
|
||||||
|
palette_type
|
||||||
})
|
})
|
||||||
.to_options()
|
.to_options()
|
||||||
.header(
|
.header(
|
||||||
@@ -180,7 +198,37 @@ BACKEND={{{backends}}}",
|
|||||||
)
|
)
|
||||||
.expect("header should not contain invalid color codes"),
|
.expect("header should not contain invalid color codes"),
|
||||||
)
|
)
|
||||||
.version(env!("CARGO_PKG_VERSION"))
|
.version(env!("CARGO_PKG_VERSION"));
|
||||||
|
|
||||||
|
#[cfg(not(feature = "macchina"))]
|
||||||
|
return construct!(Options {
|
||||||
|
config,
|
||||||
|
config_file,
|
||||||
|
preset,
|
||||||
|
mode,
|
||||||
|
backend,
|
||||||
|
args,
|
||||||
|
scale,
|
||||||
|
lightness,
|
||||||
|
june,
|
||||||
|
debug,
|
||||||
|
distro,
|
||||||
|
ascii_file,
|
||||||
|
print_font_logo,
|
||||||
|
// hidden
|
||||||
|
test_print,
|
||||||
|
ask_exit,
|
||||||
|
auto_detect_light_dark
|
||||||
|
})
|
||||||
|
.to_options()
|
||||||
|
.header(
|
||||||
|
&*color(
|
||||||
|
"&l&bhyfetch&~&L - neofetch with flags <3",
|
||||||
|
AnsiMode::Ansi256,
|
||||||
|
)
|
||||||
|
.expect("header should not contain invalid color codes"),
|
||||||
|
)
|
||||||
|
.version(env!("CARGO_PKG_VERSION"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "autocomplete")]
|
#[cfg(feature = "autocomplete")]
|
||||||
|
|||||||
@@ -410,6 +410,13 @@ macro_rules! printc {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! formatc {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
format!("{}", color(format!("{}&r", format!($($arg)*)), AnsiMode::Rgb).expect("failed to color message"));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// Prints with color.
|
/// Prints with color.
|
||||||
pub fn printc<S>(msg: S, mode: AnsiMode) -> Result<()>
|
pub fn printc<S>(msg: S, mode: AnsiMode) -> Result<()>
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use anyhow::{Context as _, Result};
|
use anyhow::{Context as _, Result};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use strum::{AsRefStr, Display, EnumString};
|
||||||
|
|
||||||
use crate::color_profile::ColorProfile;
|
use crate::color_profile::ColorProfile;
|
||||||
use crate::color_util::Lightness;
|
use crate::color_util::Lightness;
|
||||||
@@ -24,6 +25,10 @@ pub struct Config {
|
|||||||
pub pride_month_disable: bool,
|
pub pride_month_disable: bool,
|
||||||
pub custom_ascii_path: Option<String>,
|
pub custom_ascii_path: Option<String>,
|
||||||
pub custom_presets: Option<HashMap<String, Vec<String>>>,
|
pub custom_presets: Option<HashMap<String, Vec<String>>>,
|
||||||
|
#[cfg(feature = "macchina")]
|
||||||
|
pub palette_glyph: Option<String>,
|
||||||
|
#[cfg(feature = "macchina")]
|
||||||
|
pub palette_type: Option<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
@@ -186,3 +191,52 @@ impl PresetValue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handling macchina palettes
|
||||||
|
#[derive(Clone, Debug, Display, EnumString, Deserialize, Serialize, AsRefStr)]
|
||||||
|
pub enum Palette {
|
||||||
|
#[strum(to_string = "Full", ascii_case_insensitive)]
|
||||||
|
Full(String),
|
||||||
|
#[strum(to_string = "Light", ascii_case_insensitive)]
|
||||||
|
Light(String),
|
||||||
|
#[strum(to_string = "Dark", ascii_case_insensitive)]
|
||||||
|
Dark(String)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Palette {
|
||||||
|
pub fn get_glyph(&self) -> &String {
|
||||||
|
match self {
|
||||||
|
Palette::Full(s) => s,
|
||||||
|
Palette::Light(s) => s,
|
||||||
|
Palette::Dark(s) => s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn get_glyph_mut(&mut self) -> &mut String {
|
||||||
|
match self {
|
||||||
|
Palette::Full(s) => s,
|
||||||
|
Palette::Light(s) => s,
|
||||||
|
Palette::Dark(s) => s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn shift_type(&mut self, go_right: bool) {
|
||||||
|
*self = if go_right {
|
||||||
|
match self {
|
||||||
|
Palette::Full(s) => Palette::Light(s.to_owned()),
|
||||||
|
Palette::Light(s) => Palette::Dark(s.to_owned()),
|
||||||
|
Palette::Dark(s) => Palette::Full(s.to_owned())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
match self {
|
||||||
|
Palette::Full(s) => Palette::Dark(s.to_owned()),
|
||||||
|
Palette::Light(s) => Palette::Full(s.to_owned()),
|
||||||
|
Palette::Dark(s) => Palette::Light(s.to_owned())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test() {
|
||||||
|
println!("{:?}", Palette::Full("".to_owned()))
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
#[cfg(feature = "macchina")]
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{Write as _};
|
use std::io::{Write as _};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@@ -14,6 +13,9 @@ use indexmap::IndexMap;
|
|||||||
use itertools::Itertools as _;
|
use itertools::Itertools as _;
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
|
#[cfg(feature = "macchina")]
|
||||||
|
use crate::models::Palette;
|
||||||
|
#[cfg(feature = "macchina")]
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use crate::utils::find_file;
|
use crate::utils::find_file;
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
@@ -33,7 +35,10 @@ use crate::ascii::{RawAsciiArt, RecoloredAsciiArt};
|
|||||||
use crate::color_util::{printc, NeofetchAsciiIndexedColor, PresetIndexedColor};
|
use crate::color_util::{printc, NeofetchAsciiIndexedColor, PresetIndexedColor};
|
||||||
use crate::distros::Distro;
|
use crate::distros::Distro;
|
||||||
use crate::types::{AnsiMode, Backend};
|
use crate::types::{AnsiMode, Backend};
|
||||||
|
#[cfg(feature = "macchina")]
|
||||||
use crate::utils::{find_in_path, get_cache_path, input, process_command_status};
|
use crate::utils::{find_in_path, get_cache_path, input, process_command_status};
|
||||||
|
#[cfg(not(feature = "macchina"))]
|
||||||
|
use crate::utils::{get_cache_path, input, process_command_status};
|
||||||
|
|
||||||
pub const TEST_ASCII: &str = r####################"
|
pub const TEST_ASCII: &str = r####################"
|
||||||
### |\___/| ###
|
### |\___/| ###
|
||||||
@@ -273,14 +278,28 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "debug", skip(asc), fields(asc.w = asc.w, asc.h = asc.h))]
|
#[tracing::instrument(level = "debug", skip(asc), fields(asc.w = asc.w, asc.h = asc.h))]
|
||||||
pub fn run(asc: RecoloredAsciiArt, backend: Backend, args: Option<&Vec<String>>) -> Result<()> {
|
#[cfg(feature = "macchina")]
|
||||||
|
pub fn run(asc: RecoloredAsciiArt, backend: Backend, args: Option<&Vec<String>>, palette: Option<Palette>) -> Result<()> {
|
||||||
let asc = asc.lines.join("\n");
|
let asc = asc.lines.join("\n");
|
||||||
|
|
||||||
match backend {
|
match backend {
|
||||||
Backend::Neofetch => run_neofetch(asc, args).context("failed to run neofetch")?,
|
Backend::Neofetch => run_neofetch(asc, args).context("failed to run neofetch")?,
|
||||||
Backend::Fastfetch => run_fastfetch(asc, args).context("failed to run fastfetch")?,
|
Backend::Fastfetch => run_fastfetch(asc, args).context("failed to run fastfetch")?,
|
||||||
#[cfg(feature = "macchina")]
|
#[cfg(feature = "macchina")]
|
||||||
Backend::Macchina => run_macchina(asc, args).context("failed to run macchina")?,
|
Backend::Macchina => run_macchina(asc, args, palette).context("failed to run macchina")?,
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(level = "debug", skip(asc), fields(asc.w = asc.w, asc.h = asc.h))]
|
||||||
|
#[cfg(not(feature = "macchina"))]
|
||||||
|
pub fn run(asc: RecoloredAsciiArt, backend: Backend, args: Option<&Vec<String>>, _palette: Option<&String>) -> Result<()> {
|
||||||
|
let asc = asc.lines.join("\n");
|
||||||
|
|
||||||
|
match backend {
|
||||||
|
Backend::Neofetch => run_neofetch(asc, args).context("failed to run neofetch")?,
|
||||||
|
Backend::Fastfetch => run_fastfetch(asc, args).context("failed to run fastfetch")?,
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -664,7 +683,7 @@ fn run_fastfetch(asc: String, args: Option<&Vec<String>>) -> Result<()> {
|
|||||||
/// Runs macchina with custom ascii art.
|
/// Runs macchina with custom ascii art.
|
||||||
#[cfg(feature = "macchina")]
|
#[cfg(feature = "macchina")]
|
||||||
#[tracing::instrument(level = "debug", skip(asc))]
|
#[tracing::instrument(level = "debug", skip(asc))]
|
||||||
fn run_macchina(asc: String, args: Option<&Vec<String>>) -> Result<()> {
|
fn run_macchina(asc: String, args: Option<&Vec<String>>, palette: Option<Palette>) -> Result<()> {
|
||||||
// Write ascii art to temp file
|
// Write ascii art to temp file
|
||||||
let asc_file_path = {
|
let asc_file_path = {
|
||||||
let mut temp_file = tempfile::Builder::new()
|
let mut temp_file = tempfile::Builder::new()
|
||||||
@@ -695,6 +714,13 @@ fn run_macchina(asc: String, args: Option<&Vec<String>>) -> Result<()> {
|
|||||||
"path",
|
"path",
|
||||||
&*asc_file_path.to_string_lossy(),
|
&*asc_file_path.to_string_lossy(),
|
||||||
)]));
|
)]));
|
||||||
|
if let Some(p) = palette {
|
||||||
|
doc["palette"] = Item::Table(Table::from_iter([
|
||||||
|
("type", value(p.to_string())),
|
||||||
|
("glyph", value(p.get_glyph())),
|
||||||
|
("visible", value(true))
|
||||||
|
]))
|
||||||
|
}
|
||||||
doc
|
doc
|
||||||
};
|
};
|
||||||
debug!(%theme_doc, "macchina theme");
|
debug!(%theme_doc, "macchina theme");
|
||||||
|
|||||||
Reference in New Issue
Block a user