Skip to content

Commit

Permalink
Add optional derives for Serialize and Deserialize for public enums (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
arnej authored and TimonPost committed Aug 10, 2019
1 parent 6148a8f commit ac9c9af
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions crossterm_input/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ libc = "0.2.51"
[dependencies]
crossterm_utils = { path="../crossterm_utils", version = "0.2.4"}
crossterm_screen = {path="../crossterm_screen", version = "0.2.4"}
serde = { version = "1.0", features = ["derive"], optional = true }
7 changes: 7 additions & 0 deletions crossterm_input/src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub use self::windows_input::SyncReader;
#[cfg(windows)]
use self::windows_input::WindowsInput;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

pub use self::input::{input, TerminalInput};
use crossterm_utils::Result;
use std::io;
Expand Down Expand Up @@ -52,6 +55,7 @@ trait ITerminalInput {
}

/// Enum to specify which input event has occurred.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialOrd, PartialEq, Hash, Clone)]
pub enum InputEvent {
/// A single key or a combination is pressed.
Expand All @@ -65,6 +69,7 @@ pub enum InputEvent {
}

/// Enum to specify which mouse event has occurred.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialOrd, PartialEq, Hash, Clone, Copy)]
pub enum MouseEvent {
/// A mouse press has occurred, this contains the pressed button and the position of the press.
Expand All @@ -78,6 +83,7 @@ pub enum MouseEvent {
}

/// Enum to define mouse buttons.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialOrd, PartialEq, Hash, Clone, Copy)]
pub enum MouseButton {
/// Left mouse button
Expand All @@ -94,6 +100,7 @@ pub enum MouseButton {

/// Enum with different key or key combinations.
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum KeyEvent {
Backspace,
Left,
Expand Down
1 change: 1 addition & 0 deletions crossterm_style/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ crossterm_winapi = { path="../crossterm_winapi", version = "0.1.5"}

[dependencies]
crossterm_utils = { path="../crossterm_utils", version = "0.2.4"}
serde = { version = "1.0.0", features = ["derive"], optional = true }
4 changes: 4 additions & 0 deletions crossterm_style/src/enums/attribute.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use std::fmt::Display;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// Enum with the different attributes to style your test.
///
/// There are few things to note:
Expand Down Expand Up @@ -28,6 +31,7 @@ use std::fmt::Display;
/// println!("{}", style("Underlined text").underlined());
/// println!("{}", style("Negative text").negative());
/// ```
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
pub enum Attribute {
/// All attributes off
Expand Down
4 changes: 4 additions & 0 deletions crossterm_style/src/enums/color.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use std::convert::AsRef;
use std::str::FromStr;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// Enum with the different colors to color your test and terminal.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
pub enum Color {
// This resets the color.
Expand Down
4 changes: 4 additions & 0 deletions crossterm_style/src/enums/colored.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use crate::color::color;
use crate::enums::Color;
use std::fmt::Display;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// Could be used to color the foreground or background color.
///
/// `Colored::Fg` represents the foreground color.
Expand All @@ -22,6 +25,7 @@ use std::fmt::Display;
/// let styled_text = "Red forground color on blue background.".red().on_blue();
/// println!("{}", styled_text);
/// ```
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
pub enum Colored {
Fg(Color),
Expand Down
1 change: 1 addition & 0 deletions crossterm_terminal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ libc = "0.2.51"
[dependencies]
crossterm_utils = { path="../crossterm_utils", version = "0.2.4"}
crossterm_cursor = {path="../crossterm_cursor", version = "0.2.5"}
serde = { version = "1.0.0", features = ["derive"], optional = true }
4 changes: 4 additions & 0 deletions crossterm_terminal/src/terminal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ pub use self::terminal::{terminal, Clear, ScrollDown, ScrollUp, SetSize, Termina

use crossterm_utils::Result;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// Enum with the different values to clear the terminal.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
pub enum ClearType {
/// clear all cells in terminal.
Expand Down

0 comments on commit ac9c9af

Please sign in to comment.