diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6396f1c..4cd17e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,7 @@ jobs: - run: cargo fmt -- --check - run: cargo clippy --examples --tests -- -D warnings - run: cargo clippy --examples --tests --features search -- -D warnings + - run: cargo clippy --examples --tests --features serde -- -D warnings - run: cargo clippy --examples --tests --no-default-features --features termion -- -D warnings - run: cargo clippy --examples --tests --no-default-features --features termion,search -- -D warnings - run: cargo clippy --examples --tests --no-default-features --features termwiz -- -D warnings diff --git a/Cargo.toml b/Cargo.toml index efd23ec..e946b00 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,7 @@ tuirs-termion = ["tuirs", "dep:termion", "tui/termion"] tuirs-no-backend = ["tuirs"] # Other optional features search = ["dep:regex"] +serde = ["dep:serde"] [dependencies] arbitrary = { version = "1", features = ["derive"], optional = true } @@ -42,6 +43,7 @@ termion = { version = "4.0", optional = true } termwiz = { version = "0.22.0", optional = true } tui = { version = "0.19", default-features = false, optional = true } unicode-width = "0.1.11" +serde = { version = "1", optional = true , features = ["derive"] } [[example]] name = "minimal" diff --git a/src/cursor.rs b/src/cursor.rs index ed521e7..e9b084b 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -2,14 +2,17 @@ use crate::widget::Viewport; use crate::word::{find_word_start_backward, find_word_start_forward}; #[cfg(feature = "arbitrary")] use arbitrary::Arbitrary; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; use std::cmp; /// Specify how to move the cursor. /// /// This type is marked as `#[non_exhaustive]` since more variations may be supported in the future. #[non_exhaustive] -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum CursorMove { /// Move cursor forward by one character. When the cursor is at the end of line, it moves to the head of next line. /// ``` diff --git a/src/input/mod.rs b/src/input/mod.rs index 025d7b5..6e107df 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -7,13 +7,16 @@ mod termwiz; #[cfg(feature = "arbitrary")] use arbitrary::Arbitrary; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; /// Backend-agnostic key input kind. /// /// This type is marked as `#[non_exhaustive]` since more keys may be supported in the future. #[non_exhaustive] -#[derive(Clone, Copy, Debug, PartialEq, Hash)] +#[derive(Clone, Copy, Debug, PartialEq, Hash, Eq)] #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum Key { /// Normal letter key input Char(char), @@ -100,8 +103,9 @@ impl Default for Key { /// shift: false, /// }); /// ``` -#[derive(Debug, Clone, Default, PartialEq, Hash)] +#[derive(Debug, Clone, Default, PartialEq, Hash, Eq)] #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Input { /// Typed key. pub key: Key, diff --git a/src/scroll.rs b/src/scroll.rs index 524feb8..875f906 100644 --- a/src/scroll.rs +++ b/src/scroll.rs @@ -1,5 +1,6 @@ use crate::widget::Viewport; - +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; /// Specify how to scroll the textarea. /// /// This type is marked as `#[non_exhaustive]` since more variations may be supported in the future. Note that the cursor will @@ -7,6 +8,8 @@ use crate::widget::Viewport; /// /// [`TextArea::scroll`]: https://docs.rs/tui-textarea/latest/tui_textarea/struct.TextArea.html#method.scroll #[non_exhaustive] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum Scrolling { /// Scroll the textarea by rows (vertically) and columns (horizontally). Passing positive scroll amounts to `rows` and `cols` /// scolls it to down and right. Negative integers means the opposite directions. `(i16, i16)` pair can be converted into