Skip to content

Commit

Permalink
split style module into implementation modules and add skeleton of mi…
Browse files Browse the repository at this point in the history
…ssing format classes
  • Loading branch information
apparebit committed Aug 16, 2024
1 parent bded3a2 commit 58afad3
Show file tree
Hide file tree
Showing 6 changed files with 600 additions and 358 deletions.
44 changes: 44 additions & 0 deletions prettypretty/color/style.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,47 @@ class Layer:
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
def __str__(self) -> str: ...


class Format:
"""Stylistic attributes of text other than color."""
def __new__(cls) -> Self: ...
def bold(self) -> Self: ...
def thin(self) -> Self: ...
def italic(self) -> Self: ...
def underlined(self) -> Self: ...
def blinking(self) -> Self: ...
def reversed(self) -> Self: ...
def hidden(self) -> Self: ...
def stricken(self) -> Self: ...
def negate(self) -> Self: ...


class Style_Reset(Style):
def __new__(cls) -> Self: ...


class Style_Format(Style):
def __new__(cls, format: Format) -> Self: ...


class Style_Foreground(Style):
def __new__(cls, foreground: TerminalColor) -> Self: ...


class Style_Background(Style):
def __new__(cls, background: TerminalColor) -> Self: ...


class Style:
"""The enum of all terminal styles."""
Reset = Style_Reset
Format = Style_Format
Foreground = Style_Foreground
Background = Style_Background


class RichText:
def fidelity(self) -> Fidelity: ...
#def styles(self) -> Iterator[Style]: ...
def text(self) -> str: ...
14 changes: 10 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ feature disabled, [on Docs.rs](https://docs.rs/prettypretty/latest/prettypretty/
//! conversion between color spaces, interpolation between colors,
//! calculation of perceptual contrast, as well as gamut testing, clipping,
//! and mapping.
//! * The [`style`] module models **terminal colors**. Notably, the
//! [`TerminalColor`](crate::style::TerminalColor) enum combines, in order
//! from lowest to highest resolution,
//! * The [`style`] module models **terminal colors** and other stylistic text
//! attributes. Notably, the [`TerminalColor`](crate::style::TerminalColor)
//! enum combines, in order from lowest to highest resolution,
//! [`DefaultColor`](crate::style::DefaultColor),
//! [`AnsiColor`](crate::style::AnsiColor),
//! [`EmbeddedRgb`](crate::style::EmbeddedRgb),
Expand All @@ -50,7 +50,10 @@ feature disabled, [on Docs.rs](https://docs.rs/prettypretty/latest/prettypretty/
//! [`TerminalColor`](crate::style::TerminalColor) instances as well as raw
//! 24-bit (`[u8; 3]`), 24-bit color objects
//! ([`TrueColor`](crate::style::TrueColor)), and high-resolution colors
//! ([`Color`]).
//! ([`Color`]). [`Format`](crate::style::Format) captures other stylistic
//! attributes, [`Style`](crate::style::Style) is the enumeration of all
//! style options, and [`RichText`](crate:style::RichText) combines styles
//! with text.
//! * The [`trans`] module implements more **complicated color conversions**.
//! Notably, [`Translation`](crate::trans::Translator) handles conversion
//! between ANSI/8-bit colors and high-resolution colors. It includes
Expand Down Expand Up @@ -229,8 +232,11 @@ pub fn color(m: &Bound<'_, PyModule>) -> PyResult<()> {
modstyle.add_class::<crate::style::DefaultColor>()?;
modstyle.add_class::<crate::style::EmbeddedRgb>()?;
modstyle.add_class::<crate::style::Fidelity>()?;
modstyle.add_class::<crate::style::Format>()?;
modstyle.add_class::<crate::style::GrayGradient>()?;
modstyle.add_class::<crate::style::Layer>()?;
modstyle.add_class::<crate::style::RichText>()?;
modstyle.add_class::<crate::style::Style>()?;
modstyle.add_class::<crate::style::TerminalColor>()?;
modstyle.add_class::<crate::style::TrueColor>()?;
m.add_submodule(&modstyle)?;
Expand Down
Loading

0 comments on commit 58afad3

Please sign in to comment.