Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion crates/anstyle/examples/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ impl Args {
})?;
}
Long("effect") => {
const EFFECTS: [(&str, anstyle::Effects); 8] = [
const EFFECTS: [(&str, anstyle::Effects); 12] = [
("bold", anstyle::Effects::BOLD),
("dimmed", anstyle::Effects::DIMMED),
("italic", anstyle::Effects::ITALIC),
("underline", anstyle::Effects::UNDERLINE),
("double_underline", anstyle::Effects::UNDERLINE),
("curly_underline", anstyle::Effects::CURLY_UNDERLINE),
("dotted_underline", anstyle::Effects::DOTTED_UNDERLINE),
("dashed_underline", anstyle::Effects::DASHED_UNDERLINE),
("blink", anstyle::Effects::BLINK),
("invert", anstyle::Effects::INVERT),
("hidden", anstyle::Effects::HIDDEN),
Expand Down
40 changes: 20 additions & 20 deletions crates/anstyle/src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ impl From<(u8, u8, u8)> for Color {
/// # Examples
///
/// ```rust
/// let black = anstyle::Color::from((0, 0, 0));
/// let white = anstyle::Color::from((0xff, 0xff, 0xff));
/// let style = black | white;
/// let fg = anstyle::Color::from((0, 0, 0));
/// let bg = anstyle::Color::from((0xff, 0xff, 0xff));
/// let style = fg | bg;
/// ```
impl<C: Into<Color>> core::ops::BitOr<C> for Color {
type Output = crate::Style;
Expand All @@ -97,8 +97,8 @@ impl<C: Into<Color>> core::ops::BitOr<C> for Color {
/// # Examples
///
/// ```rust
/// let color = anstyle::Color::from((0, 0, 0));
/// let style = color | anstyle::Effects::BOLD | anstyle::Effects::UNDERLINE;
/// let fg = anstyle::Color::from((0, 0, 0));
/// let style = fg | anstyle::Effects::BOLD | anstyle::Effects::UNDERLINE;
/// ```
impl core::ops::BitOr<crate::Effects> for Color {
type Output = crate::Style;
Expand Down Expand Up @@ -239,9 +239,9 @@ impl AnsiColorFmt for AnsiColor {
/// # Examples
///
/// ```rust
/// let black = anstyle::AnsiColor::Black;
/// let white = anstyle::AnsiColor::White;
/// let style = black | white;
/// let fg = anstyle::AnsiColor::Black;
/// let bg = anstyle::AnsiColor::White;
/// let style = fg | bg;
/// ```
impl<C: Into<Color>> core::ops::BitOr<C> for AnsiColor {
type Output = crate::Style;
Expand All @@ -259,8 +259,8 @@ impl<C: Into<Color>> core::ops::BitOr<C> for AnsiColor {
/// # Examples
///
/// ```rust
/// let color = anstyle::AnsiColor::Black;
/// let style = color | anstyle::Effects::BOLD | anstyle::Effects::UNDERLINE;
/// let fg = anstyle::AnsiColor::Black;
/// let style = fg | anstyle::Effects::BOLD | anstyle::Effects::UNDERLINE;
/// ```
impl core::ops::BitOr<crate::Effects> for AnsiColor {
type Output = crate::Style;
Expand Down Expand Up @@ -375,9 +375,9 @@ impl From<AnsiColor> for XTermColor {
/// # Examples
///
/// ```rust
/// let black = anstyle::XTermColor(16);
/// let white = anstyle::XTermColor(231);
/// let style = black | white;
/// let fg = anstyle::XTermColor(16);
/// let bg = anstyle::XTermColor(231);
/// let style = fg | bg;
/// ```
impl<C: Into<Color>> core::ops::BitOr<C> for XTermColor {
type Output = crate::Style;
Expand All @@ -395,8 +395,8 @@ impl<C: Into<Color>> core::ops::BitOr<C> for XTermColor {
/// # Examples
///
/// ```rust
/// let color = anstyle::XTermColor(0);
/// let style = color | anstyle::Effects::BOLD | anstyle::Effects::UNDERLINE;
/// let fg = anstyle::XTermColor(0);
/// let style = fg | anstyle::Effects::BOLD | anstyle::Effects::UNDERLINE;
/// ```
impl core::ops::BitOr<crate::Effects> for XTermColor {
type Output = crate::Style;
Expand Down Expand Up @@ -470,9 +470,9 @@ impl From<(u8, u8, u8)> for RgbColor {
/// # Examples
///
/// ```rust
/// let black = anstyle::RgbColor(0, 0, 0);
/// let white = anstyle::RgbColor(0xff, 0xff, 0xff);
/// let style = black | white;
/// let fg = anstyle::RgbColor(0, 0, 0);
/// let bg = anstyle::RgbColor(0xff, 0xff, 0xff);
/// let style = fg | bg;
/// ```
impl<C: Into<Color>> core::ops::BitOr<C> for RgbColor {
type Output = crate::Style;
Expand All @@ -490,8 +490,8 @@ impl<C: Into<Color>> core::ops::BitOr<C> for RgbColor {
/// # Examples
///
/// ```rust
/// let color = anstyle::RgbColor(0, 0, 0);
/// let style = color | anstyle::Effects::BOLD | anstyle::Effects::UNDERLINE;
/// let fg = anstyle::RgbColor(0, 0, 0);
/// let style = fg | anstyle::Effects::BOLD | anstyle::Effects::UNDERLINE;
/// ```
impl core::ops::BitOr<crate::Effects> for RgbColor {
type Output = crate::Style;
Expand Down
70 changes: 53 additions & 17 deletions crates/anstyle/src/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/// let effects = anstyle::Effects::BOLD | anstyle::Effects::UNDERLINE;
/// ```
#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Effects(u8);
pub struct Effects(u16);

impl Effects {
const PLAIN: Self = Effects(0);
Expand All @@ -15,14 +15,18 @@ impl Effects {
pub const DIMMED: Self = Effects(1 << 1);
/// Not widely supported. Sometimes treated as inverse or blink
pub const ITALIC: Self = Effects(1 << 2);
/// Style extensions exist for Kitty, VTE, mintty and iTerm2.[
/// Style extensions exist for Kitty, VTE, mintty and iTerm2.
pub const UNDERLINE: Self = Effects(1 << 3);
pub const BLINK: Self = Effects(1 << 4);
pub const DOUBLE_UNDERLINE: Self = Effects(1 << 4);
pub const CURLY_UNDERLINE: Self = Effects(1 << 5);
pub const DOTTED_UNDERLINE: Self = Effects(1 << 6);
pub const DASHED_UNDERLINE: Self = Effects(1 << 7);
pub const BLINK: Self = Effects(1 << 8);
/// Swap foreground and background colors; inconsistent emulation
pub const INVERT: Self = Effects(1 << 5);
pub const HIDDEN: Self = Effects(1 << 6);
pub const INVERT: Self = Effects(1 << 9);
pub const HIDDEN: Self = Effects(1 << 10);
/// Characters legible but marked as if for deletion. Not supported in Terminal.app
pub const STRIKETHROUGH: Self = Effects(1 << 7);
pub const STRIKETHROUGH: Self = Effects(1 << 11);

/// No effects enabled
///
Expand Down Expand Up @@ -235,41 +239,70 @@ impl core::ops::SubAssign for Effects {

pub(crate) struct Metadata {
pub(crate) name: &'static str,
pub(crate) code: usize,
pub(crate) primary: usize,
pub(crate) secondary: Option<usize>,
}

pub(crate) const METADATA: [Metadata; 8] = [
pub(crate) const METADATA: [Metadata; 12] = [
Metadata {
name: "BOLD",
code: 1,
primary: 1,
secondary: None,
},
Metadata {
name: "DIMMED",
code: 2,
primary: 2,
secondary: None,
},
Metadata {
name: "ITALIC",
code: 3,
primary: 3,
secondary: None,
},
Metadata {
name: "UNDERLINE",
code: 4,
primary: 4,
secondary: None,
},
Metadata {
name: "DOUBLE_UNDERLINE",
primary: 4,
secondary: Some(2),
},
Metadata {
name: "CURLY_UNDERLINE",
primary: 4,
secondary: Some(3),
},
Metadata {
name: "DOTTED_UNDERLINE",
primary: 4,
secondary: Some(4),
},
Metadata {
name: "DASHED_UNDERLINE",
primary: 4,
secondary: Some(5),
},
Metadata {
name: "BLINK",
code: 5,
primary: 5,
secondary: None,
},
Metadata {
name: "INVERT",
code: 7,
primary: 7,
secondary: None,
},
Metadata {
name: "HIDDEN",
code: 8,
primary: 8,
secondary: None,
},
Metadata {
name: "STRIKETHROUGH",
code: 9,
primary: 9,
secondary: None,
},
];

Expand All @@ -286,7 +319,10 @@ impl core::fmt::Display for EffectsDisplay {
if i != 0 {
write!(f, ";")?;
}
write!(f, "{}", METADATA[index].code)?;
write!(f, "{}", METADATA[index].primary)?;
if let Some(secondary) = METADATA[index].secondary {
write!(f, ":{}", secondary)?;
}
}
write!(f, "m")?;
Ok(())
Expand Down
5 changes: 4 additions & 1 deletion crates/anstyle/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,10 @@ impl core::fmt::Display for StyleDisplay {

for index in self.0.effects.index_iter() {
separator(f, &mut first)?;
write!(f, "{}", crate::effect::METADATA[index].code)?;
write!(f, "{}", crate::effect::METADATA[index].primary)?;
if let Some(secondary) = crate::effect::METADATA[index].secondary {
write!(f, ":{}", secondary)?;
}
}

if let Some(fg) = self.0.fg {
Expand Down