Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional derives for Serialize and Deserialize for public enums #190

Merged
merged 1 commit into from
Aug 10, 2019
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
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