pub use anstyle::*;
#[derive(Clone, Debug)]
#[allow(missing_copy_implementations)] pub struct Styles {
header: Style,
error: Style,
usage: Style,
literal: Style,
placeholder: Style,
valid: Style,
invalid: Style,
context: Style,
context_value: Option<Style>,
}
impl Styles {
pub const fn plain() -> Self {
Self {
header: Style::new(),
error: Style::new(),
usage: Style::new(),
literal: Style::new(),
placeholder: Style::new(),
valid: Style::new(),
invalid: Style::new(),
context: Style::new(),
context_value: None,
}
}
pub const fn styled() -> Self {
#[cfg(feature = "color")]
{
Self {
header: Style::new().bold().underline(),
error: Style::new()
.fg_color(Some(Color::Ansi(AnsiColor::Red)))
.bold(),
usage: Style::new().bold().underline(),
literal: Style::new().bold(),
placeholder: Style::new(),
valid: Style::new().fg_color(Some(Color::Ansi(AnsiColor::Green))),
invalid: Style::new().fg_color(Some(Color::Ansi(AnsiColor::Yellow))),
context: Style::new(),
context_value: None,
}
}
#[cfg(not(feature = "color"))]
{
Self::plain()
}
}
#[inline]
pub const fn header(mut self, style: Style) -> Self {
self.header = style;
self
}
#[inline]
pub const fn error(mut self, style: Style) -> Self {
self.error = style;
self
}
#[inline]
pub const fn usage(mut self, style: Style) -> Self {
self.usage = style;
self
}
#[inline]
pub const fn literal(mut self, style: Style) -> Self {
self.literal = style;
self
}
#[inline]
pub const fn placeholder(mut self, style: Style) -> Self {
self.placeholder = style;
self
}
#[inline]
pub const fn valid(mut self, style: Style) -> Self {
self.valid = style;
self
}
#[inline]
pub const fn invalid(mut self, style: Style) -> Self {
self.invalid = style;
self
}
#[inline]
pub const fn context(mut self, style: Style) -> Self {
self.context = style;
self
}
#[inline]
pub const fn context_value(mut self, style: Style) -> Self {
self.context_value = Some(style);
self
}
}
impl Styles {
#[inline(always)]
pub const fn get_header(&self) -> &Style {
&self.header
}
#[inline(always)]
pub const fn get_error(&self) -> &Style {
&self.error
}
#[inline(always)]
pub const fn get_usage(&self) -> &Style {
&self.usage
}
#[inline(always)]
pub const fn get_literal(&self) -> &Style {
&self.literal
}
#[inline(always)]
pub const fn get_placeholder(&self) -> &Style {
&self.placeholder
}
#[inline(always)]
pub const fn get_valid(&self) -> &Style {
&self.valid
}
#[inline(always)]
pub const fn get_invalid(&self) -> &Style {
&self.invalid
}
#[inline(always)]
pub const fn get_context(&self) -> &Style {
&self.context
}
#[inline(always)]
pub const fn get_context_value(&self) -> &Style {
match &self.context_value {
Some(s) => s,
None => &self.context,
}
}
}
impl super::AppExt for Styles {}
impl Default for Styles {
fn default() -> Self {
Self::styled()
}
}
impl Default for &'_ Styles {
fn default() -> Self {
const STYLES: Styles = Styles::styled();
&STYLES
}
}