(De)serialize Reset color (#824)
This commit is contained in:
parent
cd1780c2d8
commit
94fdd586e6
41
CHANGELOG.md
41
CHANGELOG.md
@ -1,3 +1,8 @@
|
|||||||
|
# Version 0.27.1
|
||||||
|
|
||||||
|
## Added ⭐
|
||||||
|
- Add support for (de)serializing `Reset` `Color`
|
||||||
|
|
||||||
# Version 0.27
|
# Version 0.27
|
||||||
|
|
||||||
## Added ⭐
|
## Added ⭐
|
||||||
@ -8,7 +13,7 @@
|
|||||||
- Add `window_size` function to fetch pixel width/height of screen for more sophisticated rendering in terminals.
|
- Add `window_size` function to fetch pixel width/height of screen for more sophisticated rendering in terminals.
|
||||||
- Add support for deserializing hex color strings to `Color` e.g #fffff.
|
- Add support for deserializing hex color strings to `Color` e.g #fffff.
|
||||||
|
|
||||||
## Changes
|
## Changes
|
||||||
|
|
||||||
- Make the events module an optional feature `events` (to make crossterm more lightweight) (#776)
|
- Make the events module an optional feature `events` (to make crossterm more lightweight) (#776)
|
||||||
|
|
||||||
@ -65,7 +70,7 @@ We removed the `Copy` from `Event` because the new `Paste` event, which contains
|
|||||||
|
|
||||||
# Version 0.24.0
|
# Version 0.24.0
|
||||||
- Add DoubleUnderlined, Undercurled, Underdots the text, Underdotted, Underdashes, Underdashed attributes and allow coloring their foreground / background color.
|
- Add DoubleUnderlined, Undercurled, Underdots the text, Underdotted, Underdashes, Underdashed attributes and allow coloring their foreground / background color.
|
||||||
- Fix windows unicode character parsing, this fixed various key combinations and support typing unicode characters.
|
- Fix windows unicode character parsing, this fixed various key combinations and support typing unicode characters.
|
||||||
- Consistency and better documentation on mouse cursor operations (BREAKING CHANGE).
|
- Consistency and better documentation on mouse cursor operations (BREAKING CHANGE).
|
||||||
- MoveTo, MoveToColumn, MoveToRow are 0-based. (left top most cell is 0,0). Moving like this is absolute
|
- MoveTo, MoveToColumn, MoveToRow are 0-based. (left top most cell is 0,0). Moving like this is absolute
|
||||||
- MoveToNextLine, MoveToPreviousLine, MoveUp, MoveDown, MoveRight, MoveLeft are 1-based,. Moving like this is relative. Moving 1 left means moving 1 left. Moving 0 to the left is not possible, wikipedia states that most terminals will just default to 1.
|
- MoveToNextLine, MoveToPreviousLine, MoveUp, MoveDown, MoveRight, MoveLeft are 1-based,. Moving like this is relative. Moving 1 left means moving 1 left. Moving 0 to the left is not possible, wikipedia states that most terminals will just default to 1.
|
||||||
@ -73,7 +78,7 @@ We removed the `Copy` from `Event` because the new `Paste` event, which contains
|
|||||||
- Remove println from serialisation code.
|
- Remove println from serialisation code.
|
||||||
- Fix mouse up for middle and right buttons.
|
- Fix mouse up for middle and right buttons.
|
||||||
- Fix escape codes on Git-Bash + Windows Terminal / Alacritty / WezTerm.
|
- Fix escape codes on Git-Bash + Windows Terminal / Alacritty / WezTerm.
|
||||||
- Add support for cursor keys in application mode.
|
- Add support for cursor keys in application mode.
|
||||||
# Version 0.23.2
|
# Version 0.23.2
|
||||||
- Update signal-hook and mio to version 0.8.
|
- Update signal-hook and mio to version 0.8.
|
||||||
|
|
||||||
@ -98,12 +103,12 @@ We removed the `Copy` from `Event` because the new `Paste` event, which contains
|
|||||||
|
|
||||||
# Version 0.21
|
# Version 0.21
|
||||||
- Expose `is_raw` function.
|
- Expose `is_raw` function.
|
||||||
- Add 'purge' option on unix system, this clears the entire screen buffer.
|
- Add 'purge' option on unix system, this clears the entire screen buffer.
|
||||||
- Improve serialisation for color enum values.
|
- Improve serialisation for color enum values.
|
||||||
|
|
||||||
# Version 0.20
|
# Version 0.20
|
||||||
- Update from signal-hook with 'mio-feature flag' to signal-hook-mio 0.2.1.
|
- Update from signal-hook with 'mio-feature flag' to signal-hook-mio 0.2.1.
|
||||||
- Manually implements Eq, PartialEq and Hash for KeyEvent improving equality checks and hash calculation.
|
- Manually implements Eq, PartialEq and Hash for KeyEvent improving equality checks and hash calculation.
|
||||||
- `crossterm::ErrorKind` to `io::Error`.
|
- `crossterm::ErrorKind` to `io::Error`.
|
||||||
- Added Cursor Shape Support.
|
- Added Cursor Shape Support.
|
||||||
- Add support for function keys F13...F20.
|
- Add support for function keys F13...F20.
|
||||||
@ -112,9 +117,9 @@ We removed the `Copy` from `Event` because the new `Paste` event, which contains
|
|||||||
- Remove extra Clone bounds in the style module.
|
- Remove extra Clone bounds in the style module.
|
||||||
- Add `MoveToRow` command.
|
- Add `MoveToRow` command.
|
||||||
- Remove writer parameter from execute_winapi
|
- Remove writer parameter from execute_winapi
|
||||||
|
|
||||||
# Version 0.19
|
# Version 0.19
|
||||||
- Use single thread for async event reader.
|
- Use single thread for async event reader.
|
||||||
- Patch timeout handling for event polling this was not working correctly.
|
- Patch timeout handling for event polling this was not working correctly.
|
||||||
- Add unix support for more key combinations mainly complex ones with ALT/SHIFT/CTRL.
|
- Add unix support for more key combinations mainly complex ones with ALT/SHIFT/CTRL.
|
||||||
- Derive `PartialEq` and `Eq` for ContentStyle
|
- Derive `PartialEq` and `Eq` for ContentStyle
|
||||||
@ -124,13 +129,13 @@ We removed the `Copy` from `Event` because the new `Paste` event, which contains
|
|||||||
# Version 0.18.2
|
# Version 0.18.2
|
||||||
- Fix panic when only setting bold and redirecting stdout.
|
- Fix panic when only setting bold and redirecting stdout.
|
||||||
- Use `tty_fd` for set/get terminal attributes
|
- Use `tty_fd` for set/get terminal attributes
|
||||||
|
|
||||||
# Version 0.18.1
|
# Version 0.18.1
|
||||||
- Fix enabling ANSI support when stdout is redirected
|
- Fix enabling ANSI support when stdout is redirected
|
||||||
- Update crossterm-winapi to 0.6.2
|
- Update crossterm-winapi to 0.6.2
|
||||||
|
|
||||||
# Version 0.18.0
|
# Version 0.18.0
|
||||||
- Fix get position bug
|
- Fix get position bug
|
||||||
- Fix windows 8 or lower write to user-given stdout instead of stdout.
|
- Fix windows 8 or lower write to user-given stdout instead of stdout.
|
||||||
- Make MoveCursor(Left/Right/Up/Dow) command with input 0 not move.
|
- Make MoveCursor(Left/Right/Up/Dow) command with input 0 not move.
|
||||||
- Switch to futures-core to reduce dependencies.
|
- Switch to futures-core to reduce dependencies.
|
||||||
@ -142,13 +147,13 @@ We removed the `Copy` from `Event` because the new `Paste` event, which contains
|
|||||||
- Fix cursor position retrieval bug linux.
|
- Fix cursor position retrieval bug linux.
|
||||||
|
|
||||||
# Version 0.17.6
|
# Version 0.17.6
|
||||||
- Add functionality to retrieve color based on passed ansi code.
|
- Add functionality to retrieve color based on passed ansi code.
|
||||||
- Switch from 'futures' to 'futures-util' crate to reduce dependency count
|
- Switch from 'futures' to 'futures-util' crate to reduce dependency count
|
||||||
- Mio 0.7 update
|
- Mio 0.7 update
|
||||||
- signal-hook update
|
- signal-hook update
|
||||||
- Make windows raw_mode act on CONIN$
|
- Make windows raw_mode act on CONIN$
|
||||||
- Added From<(u8, u8, u8)> Trait to Color::Rgb Enum
|
- Added From<(u8, u8, u8)> Trait to Color::Rgb Enum
|
||||||
- Implement Color::try_from()
|
- Implement Color::try_from()
|
||||||
- Implement styler traits for `&'a str`
|
- Implement styler traits for `&'a str`
|
||||||
|
|
||||||
# Version 0.17.5
|
# Version 0.17.5
|
||||||
@ -157,14 +162,14 @@ We removed the `Copy` from `Event` because the new `Paste` event, which contains
|
|||||||
- Mio 0.7 update
|
- Mio 0.7 update
|
||||||
|
|
||||||
# Version 0.17.4
|
# Version 0.17.4
|
||||||
- Add macros for `Colorize` and `Styler` impls, add an impl for `String`
|
- Add macros for `Colorize` and `Styler` impls, add an impl for `String`
|
||||||
- Add shift modifier to uppercase char events on unix
|
- Add shift modifier to uppercase char events on unix
|
||||||
|
|
||||||
# Version 0.17.3
|
# Version 0.17.3
|
||||||
- Fix get terminal size mac os, this did not report the correct size.
|
- Fix get terminal size mac os, this did not report the correct size.
|
||||||
|
|
||||||
# Version 0.17.2
|
# Version 0.17.2
|
||||||
- Windows unicode support
|
- Windows unicode support
|
||||||
|
|
||||||
# Version 0.17.1
|
# Version 0.17.1
|
||||||
- Reverted bug in 0.17.0: "Make terminal size function fallback to `STDOUT_FILENO` if `/dev/tty` is missing.".
|
- Reverted bug in 0.17.0: "Make terminal size function fallback to `STDOUT_FILENO` if `/dev/tty` is missing.".
|
||||||
@ -174,18 +179,18 @@ We removed the `Copy` from `Event` because the new `Paste` event, which contains
|
|||||||
- Impl Display for MoveToColumn, MoveToNextLine, MoveToPreviousLine
|
- Impl Display for MoveToColumn, MoveToNextLine, MoveToPreviousLine
|
||||||
- Make unix event reader always use `/dev/tty`.
|
- Make unix event reader always use `/dev/tty`.
|
||||||
- Direct write command ansi_codes into formatter instead of double allocation.
|
- Direct write command ansi_codes into formatter instead of double allocation.
|
||||||
- Add NONE flag to KeyModifiers
|
- Add NONE flag to KeyModifiers
|
||||||
- Add support for converting chars to StylizedContent
|
- Add support for converting chars to StylizedContent
|
||||||
- Make terminal size function fallback to `STDOUT_FILENO` if `/dev/tty` is missing.
|
- Make terminal size function fallback to `STDOUT_FILENO` if `/dev/tty` is missing.
|
||||||
|
|
||||||
# Version 0.16.0
|
# Version 0.16.0
|
||||||
- Change attribute vector in `ContentStyle` to bitmask.
|
- Change attribute vector in `ContentStyle` to bitmask.
|
||||||
- Add `SetAttributes` command.
|
- Add `SetAttributes` command.
|
||||||
- Add `Attributes` type, which is a bitfield of enabled attributes.
|
- Add `Attributes` type, which is a bitfield of enabled attributes.
|
||||||
- Remove `exit()`, was useless.
|
- Remove `exit()`, was useless.
|
||||||
|
|
||||||
# Version 0.15.0
|
# Version 0.15.0
|
||||||
- Fix CTRL + J key combination. This used to return an ENTER event.
|
- Fix CTRL + J key combination. This used to return an ENTER event.
|
||||||
- Add a generic implementation `Command` for `&T: Command`. This allows commands to be queued by reference, as well as by value.
|
- Add a generic implementation `Command` for `&T: Command`. This allows commands to be queued by reference, as well as by value.
|
||||||
- Remove unnecessary `Clone` trait bounds from `StyledContent`.
|
- Remove unnecessary `Clone` trait bounds from `StyledContent`.
|
||||||
- Add `StyledContent::style_mut`.
|
- Add `StyledContent::style_mut`.
|
||||||
|
@ -173,6 +173,7 @@ impl TryFrom<&str> for Color {
|
|||||||
let src = src.to_lowercase();
|
let src = src.to_lowercase();
|
||||||
|
|
||||||
match src.as_ref() {
|
match src.as_ref() {
|
||||||
|
"reset" => Ok(Color::Reset),
|
||||||
"black" => Ok(Color::Black),
|
"black" => Ok(Color::Black),
|
||||||
"dark_grey" => Ok(Color::DarkGrey),
|
"dark_grey" => Ok(Color::DarkGrey),
|
||||||
"red" => Ok(Color::Red),
|
"red" => Ok(Color::Red),
|
||||||
@ -223,6 +224,7 @@ impl serde::ser::Serialize for Color {
|
|||||||
S: serde::ser::Serializer,
|
S: serde::ser::Serializer,
|
||||||
{
|
{
|
||||||
let str = match *self {
|
let str = match *self {
|
||||||
|
Color::Reset => "reset",
|
||||||
Color::Black => "black",
|
Color::Black => "black",
|
||||||
Color::DarkGrey => "dark_grey",
|
Color::DarkGrey => "dark_grey",
|
||||||
Color::Red => "red",
|
Color::Red => "red",
|
||||||
@ -271,7 +273,7 @@ impl<'de> serde::de::Deserialize<'de> for Color {
|
|||||||
type Value = Color;
|
type Value = Color;
|
||||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
formatter.write_str(
|
formatter.write_str(
|
||||||
"`black`, `blue`, `dark_blue`, `cyan`, `dark_cyan`, `green`, `dark_green`, `grey`, `dark_grey`, `magenta`, `dark_magenta`, `red`, `dark_red`, `white`, `yellow`, `dark_yellow`, `ansi_(value)`, or `rgb_(r,g,b)` or `#rgbhex`",
|
"`reset`, `black`, `blue`, `dark_blue`, `cyan`, `dark_cyan`, `green`, `dark_green`, `grey`, `dark_grey`, `magenta`, `dark_magenta`, `red`, `dark_red`, `white`, `yellow`, `dark_yellow`, `ansi_(value)`, or `rgb_(r,g,b)` or `#rgbhex`",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fn visit_str<E>(self, value: &str) -> Result<Color, E>
|
fn visit_str<E>(self, value: &str) -> Result<Color, E>
|
||||||
@ -343,6 +345,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_known_color_conversion() {
|
fn test_known_color_conversion() {
|
||||||
|
assert_eq!("reset".parse(), Ok(Color::Reset));
|
||||||
assert_eq!("grey".parse(), Ok(Color::Grey));
|
assert_eq!("grey".parse(), Ok(Color::Grey));
|
||||||
assert_eq!("dark_grey".parse(), Ok(Color::DarkGrey));
|
assert_eq!("dark_grey".parse(), Ok(Color::DarkGrey));
|
||||||
assert_eq!("red".parse(), Ok(Color::Red));
|
assert_eq!("red".parse(), Ok(Color::Red));
|
||||||
@ -388,6 +391,14 @@ mod serde_tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_deserial_known_color_conversion() {
|
fn test_deserial_known_color_conversion() {
|
||||||
|
assert_eq!(
|
||||||
|
serde_json::from_str::<Color>("\"Reset\"").unwrap(),
|
||||||
|
Color::Reset
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
serde_json::from_str::<Color>("\"reset\"").unwrap(),
|
||||||
|
Color::Reset
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serde_json::from_str::<Color>("\"Red\"").unwrap(),
|
serde_json::from_str::<Color>("\"Red\"").unwrap(),
|
||||||
Color::Red
|
Color::Red
|
||||||
|
Loading…
Reference in New Issue
Block a user