-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from Nukesor/mirror_crossterm_types
change: Don't re-export crossterm's types by default
- Loading branch information
Showing
10 changed files
with
347 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/// Represents an attribute. | ||
/// | ||
/// # Platform-specific Notes | ||
/// | ||
/// * Only UNIX and Windows 10 terminals do support text attributes. | ||
/// * Keep in mind that not all terminals support all attributes. | ||
/// * Crossterm implements almost all attributes listed in the | ||
/// [SGR parameters](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters). | ||
/// | ||
/// | Attribute | Windows | UNIX | Notes | | ||
/// | :-- | :--: | :--: | :-- | | ||
/// | `Reset` | ✓ | ✓ | | | ||
/// | `Bold` | ✓ | ✓ | | | ||
/// | `Dim` | ✓ | ✓ | | | ||
/// | `Italic` | ? | ? | Not widely supported, sometimes treated as inverse. | | ||
/// | `Underlined` | ✓ | ✓ | | | ||
/// | `SlowBlink` | ? | ? | Not widely supported, sometimes treated as inverse. | | ||
/// | `RapidBlink` | ? | ? | Not widely supported. MS-DOS ANSI.SYS; 150+ per minute. | | ||
/// | `Reverse` | ✓ | ✓ | | | ||
/// | `Hidden` | ✓ | ✓ | Also known as Conceal. | | ||
/// | `Fraktur` | ✗ | ✓ | Legible characters, but marked for deletion. | | ||
/// | `DefaultForegroundColor` | ? | ? | Implementation specific (according to standard). | | ||
/// | `DefaultBackgroundColor` | ? | ? | Implementation specific (according to standard). | | ||
/// | `Framed` | ? | ? | Not widely supported. | | ||
/// | `Encircled` | ? | ? | This should turn on the encircled attribute. | | ||
/// | `OverLined` | ? | ? | This should draw a line at the top of the text. | | ||
/// | ||
/// Usage: | ||
/// | ||
/// Check [crate::Cell::add_attribute] on how to use it. | ||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)] | ||
#[non_exhaustive] | ||
pub enum Attribute { | ||
/// Resets all the attributes. | ||
Reset, | ||
/// Increases the text intensity. | ||
Bold, | ||
/// Decreases the text intensity. | ||
Dim, | ||
/// Emphasises the text. | ||
Italic, | ||
/// Underlines the text. | ||
Underlined, | ||
|
||
// Other types of underlining | ||
/// Double underlines the text. | ||
DoubleUnderlined, | ||
/// Undercurls the text. | ||
Undercurled, | ||
/// Underdots the text. | ||
Underdotted, | ||
/// Underdashes the text. | ||
Underdashed, | ||
|
||
/// Makes the text blinking (< 150 per minute). | ||
SlowBlink, | ||
/// Makes the text blinking (>= 150 per minute). | ||
RapidBlink, | ||
/// Swaps foreground and background colors. | ||
Reverse, | ||
/// Hides the text (also known as Conceal). | ||
Hidden, | ||
/// Crosses the text. | ||
CrossedOut, | ||
/// Sets the [Fraktur](https://en.wikipedia.org/wiki/Fraktur) typeface. | ||
/// | ||
/// Mostly used for [mathematical alphanumeric symbols](https://en.wikipedia.org/wiki/Mathematical_Alphanumeric_Symbols). | ||
Fraktur, | ||
/// Turns off the `Bold` attribute. - Inconsistent - Prefer to use NormalIntensity | ||
NoBold, | ||
/// Switches the text back to normal intensity (no bold, italic). | ||
NormalIntensity, | ||
/// Turns off the `Italic` attribute. | ||
NoItalic, | ||
/// Turns off the `Underlined` attribute. | ||
NoUnderline, | ||
/// Turns off the text blinking (`SlowBlink` or `RapidBlink`). | ||
NoBlink, | ||
/// Turns off the `Reverse` attribute. | ||
NoReverse, | ||
/// Turns off the `Hidden` attribute. | ||
NoHidden, | ||
/// Turns off the `CrossedOut` attribute. | ||
NotCrossedOut, | ||
/// Makes the text framed. | ||
Framed, | ||
/// Makes the text encircled. | ||
Encircled, | ||
/// Draws a line at the top of the text. | ||
OverLined, | ||
/// Turns off the `Frame` and `Encircled` attributes. | ||
NotFramedOrEncircled, | ||
/// Turns off the `OverLined` attribute. | ||
NotOverLined, | ||
} | ||
|
||
/// Map the internal mirrored [Attribute] to the actually used [crossterm::style::Attribute] | ||
pub(crate) fn map_attribute(attribute: Attribute) -> crossterm::style::Attribute { | ||
match attribute { | ||
Attribute::Reset => crossterm::style::Attribute::Reset, | ||
Attribute::Bold => crossterm::style::Attribute::Bold, | ||
Attribute::Dim => crossterm::style::Attribute::Dim, | ||
Attribute::Italic => crossterm::style::Attribute::Italic, | ||
Attribute::Underlined => crossterm::style::Attribute::Underlined, | ||
Attribute::DoubleUnderlined => crossterm::style::Attribute::DoubleUnderlined, | ||
Attribute::Undercurled => crossterm::style::Attribute::Undercurled, | ||
Attribute::Underdotted => crossterm::style::Attribute::Underdotted, | ||
Attribute::Underdashed => crossterm::style::Attribute::Underdashed, | ||
Attribute::SlowBlink => crossterm::style::Attribute::SlowBlink, | ||
Attribute::RapidBlink => crossterm::style::Attribute::RapidBlink, | ||
Attribute::Reverse => crossterm::style::Attribute::Reverse, | ||
Attribute::Hidden => crossterm::style::Attribute::Hidden, | ||
Attribute::CrossedOut => crossterm::style::Attribute::CrossedOut, | ||
Attribute::Fraktur => crossterm::style::Attribute::Fraktur, | ||
Attribute::NoBold => crossterm::style::Attribute::NoBold, | ||
Attribute::NormalIntensity => crossterm::style::Attribute::NormalIntensity, | ||
Attribute::NoItalic => crossterm::style::Attribute::NoItalic, | ||
Attribute::NoUnderline => crossterm::style::Attribute::NoUnderline, | ||
Attribute::NoBlink => crossterm::style::Attribute::NoBlink, | ||
Attribute::NoReverse => crossterm::style::Attribute::NoReverse, | ||
Attribute::NoHidden => crossterm::style::Attribute::NoHidden, | ||
Attribute::NotCrossedOut => crossterm::style::Attribute::NotCrossedOut, | ||
Attribute::Framed => crossterm::style::Attribute::Framed, | ||
Attribute::Encircled => crossterm::style::Attribute::Encircled, | ||
Attribute::OverLined => crossterm::style::Attribute::OverLined, | ||
Attribute::NotFramedOrEncircled => crossterm::style::Attribute::NotFramedOrEncircled, | ||
Attribute::NotOverLined => crossterm::style::Attribute::NotOverLined, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/// Represents a color. | ||
/// | ||
/// This type is a simplified re-implementation of crossterm's Color enum. | ||
/// See [crossterm::style::color](https://docs.rs/crossterm/latest/crossterm/style/enum.Color.html) | ||
/// | ||
/// # Platform-specific Notes | ||
/// | ||
/// The following list of 16 base colors are available for almost all terminals (Windows 7 and 8 included). | ||
/// | ||
/// | Light | Dark | | ||
/// | :--------- | :------------ | | ||
/// | `DarkGrey` | `Black` | | ||
/// | `Red` | `DarkRed` | | ||
/// | `Green` | `DarkGreen` | | ||
/// | `Yellow` | `DarkYellow` | | ||
/// | `Blue` | `DarkBlue` | | ||
/// | `Magenta` | `DarkMagenta` | | ||
/// | `Cyan` | `DarkCyan` | | ||
/// | `White` | `Grey` | | ||
/// | ||
/// Most UNIX terminals and Windows 10 consoles support additional colors. | ||
/// See [Color::Rgb] or [Color::AnsiValue] for more info. | ||
/// | ||
/// Usage: | ||
/// | ||
/// Check [crate::Cell::bg], [crate::Cell::fg] and on how to use it. | ||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)] | ||
pub enum Color { | ||
/// Resets the terminal color. | ||
Reset, | ||
|
||
/// Black color. | ||
Black, | ||
|
||
/// Dark grey color. | ||
DarkGrey, | ||
|
||
/// Light red color. | ||
Red, | ||
|
||
/// Dark red color. | ||
DarkRed, | ||
|
||
/// Light green color. | ||
Green, | ||
|
||
/// Dark green color. | ||
DarkGreen, | ||
|
||
/// Light yellow color. | ||
Yellow, | ||
|
||
/// Dark yellow color. | ||
DarkYellow, | ||
|
||
/// Light blue color. | ||
Blue, | ||
|
||
/// Dark blue color. | ||
DarkBlue, | ||
|
||
/// Light magenta color. | ||
Magenta, | ||
|
||
/// Dark magenta color. | ||
DarkMagenta, | ||
|
||
/// Light cyan color. | ||
Cyan, | ||
|
||
/// Dark cyan color. | ||
DarkCyan, | ||
|
||
/// White color. | ||
White, | ||
|
||
/// Grey color. | ||
Grey, | ||
|
||
/// An RGB color. See [RGB color model](https://en.wikipedia.org/wiki/RGB_color_model) for more info. | ||
/// | ||
/// Most UNIX terminals and Windows 10 supported only. | ||
/// See [Platform-specific notes](enum.Color.html#platform-specific-notes) for more info. | ||
Rgb { r: u8, g: u8, b: u8 }, | ||
|
||
/// An ANSI color. See [256 colors - cheat sheet](https://jonasjacek.github.io/colors/) for more info. | ||
/// | ||
/// Most UNIX terminals and Windows 10 supported only. | ||
/// See [Platform-specific notes](enum.Color.html#platform-specific-notes) for more info. | ||
AnsiValue(u8), | ||
} | ||
|
||
/// Map the internal mirrored [Color] enum to the actually used [crossterm::style::Color]. | ||
pub(crate) fn map_color(color: Color) -> crossterm::style::Color { | ||
match color { | ||
Color::Reset => crossterm::style::Color::Reset, | ||
Color::Black => crossterm::style::Color::Black, | ||
Color::DarkGrey => crossterm::style::Color::DarkGrey, | ||
Color::Red => crossterm::style::Color::Red, | ||
Color::DarkRed => crossterm::style::Color::DarkRed, | ||
Color::Green => crossterm::style::Color::Green, | ||
Color::DarkGreen => crossterm::style::Color::DarkGreen, | ||
Color::Yellow => crossterm::style::Color::Yellow, | ||
Color::DarkYellow => crossterm::style::Color::DarkYellow, | ||
Color::Blue => crossterm::style::Color::Blue, | ||
Color::DarkBlue => crossterm::style::Color::DarkBlue, | ||
Color::Magenta => crossterm::style::Color::Magenta, | ||
Color::DarkMagenta => crossterm::style::Color::DarkMagenta, | ||
Color::Cyan => crossterm::style::Color::Cyan, | ||
Color::DarkCyan => crossterm::style::Color::DarkCyan, | ||
Color::White => crossterm::style::Color::White, | ||
Color::Grey => crossterm::style::Color::Grey, | ||
Color::Rgb { r, g, b } => crossterm::style::Color::Rgb { r, g, b }, | ||
Color::AnsiValue(value) => crossterm::style::Color::AnsiValue(value), | ||
} | ||
} |
Oops, something went wrong.