use ayun_core::{Callback, Result};
use clap::{
builder::{
styling::{AnsiColor, Effects},
IntoResettable, Str, StyledStr, Styles,
},
ArgMatches, Command,
};
use std::collections::{BTreeMap, HashMap};
pub mod command;
pub mod commands;
mod service;
pub mod traits;
#[derive(Clone)]
pub struct Console {
inner: Command,
commands: BTreeMap<String, Command>,
closures: HashMap<String, Callback<ArgMatches, Result<()>>>,
}
pub const STYLES: Styles = Styles::styled()
.header(AnsiColor::Yellow.on_default().effects(Effects::BOLD))
.usage(AnsiColor::Yellow.on_default().effects(Effects::BOLD))
.literal(AnsiColor::Green.on_default())
.placeholder(AnsiColor::Cyan.on_default())
.error(AnsiColor::Red.on_default().effects(Effects::BOLD))
.valid(AnsiColor::Cyan.on_default().effects(Effects::BOLD))
.invalid(AnsiColor::Yellow.on_default().effects(Effects::BOLD));
impl Console {
pub fn name(mut self, name: impl Into<Str>) -> Self {
self.inner = self.inner.name(name);
self
}
pub fn version(mut self, ver: impl IntoResettable<Str>) -> Self {
self.inner = self.inner.version(ver);
self
}
pub fn about(mut self, about: impl IntoResettable<StyledStr>) -> Self {
self.inner = self.inner.about(about);
self
}
}
const LOGO: &str = r"
░░ ░░░ ░░░░ ░░ ░░░░ ░░ ░░░ ░
▒ ▒▒▒▒ ▒▒▒ ▒▒ ▒▒▒ ▒▒▒▒ ▒▒ ▒▒ ▒
▓ ▓▓▓▓ ▓▓▓▓ ▓▓▓▓ ▓▓▓▓ ▓▓ ▓ ▓ ▓
█ █████ █████ ████ ██ ██ █
█ ████ █████ ██████ ███ ███ █
";
impl Default for Console {
fn default() -> Self {
let command = Command::default()
.styles(STYLES)
.name("ayun")
.version(env!("CARGO_PKG_VERSION"))
.about(format!("\n {} \n {}", LOGO, env!("CARGO_PKG_DESCRIPTION")));
Self {
inner: command,
commands: BTreeMap::new(),
closures: HashMap::new(),
}
}
}