From 1625d0b6036e86707ef4aa409b15a1299427f521 Mon Sep 17 00:00:00 2001 From: cstef Date: Tue, 27 Feb 2024 14:34:54 +0100 Subject: [PATCH 1/6] Add serde feature --- Cargo.toml | 2 ++ src/cursor.rs | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index fe9766f..a159a92 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,6 +37,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 } @@ -48,6 +49,7 @@ termion = { version = "2.0", optional = true } termwiz = { version = "0.20.0", optional = true } tui = { version = "0.19", default-features = false, optional = true } unicode-width = "0.1.11" +serde = { version = "1", optional = true } [[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. /// ``` From 4cc1ecaed975a797ccc24d7f74fcf40958d3806e Mon Sep 17 00:00:00 2001 From: cstef Date: Tue, 27 Feb 2024 14:46:08 +0100 Subject: [PATCH 2/6] Make Scrolling serializable --- src/scroll.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 From 38df8592fbd54c1d3b61f8021730503542fd9bcd Mon Sep 17 00:00:00 2001 From: cstef Date: Tue, 27 Feb 2024 15:56:42 +0100 Subject: [PATCH 3/6] Make Input serializable --- src/input/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/input/mod.rs b/src/input/mod.rs index 2ead41b..e4769cd 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -7,6 +7,8 @@ mod termwiz; #[cfg(feature = "arbitrary")] use arbitrary::Arbitrary; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; /// Backend-agnostic key input kind. /// @@ -14,6 +16,7 @@ use arbitrary::Arbitrary; #[non_exhaustive] #[derive(Clone, Copy, Debug, PartialEq, Hash)] #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum Key { /// Normal letter key input Char(char), @@ -102,6 +105,7 @@ impl Default for Key { /// ``` #[derive(Debug, Clone, Default, PartialEq, Hash)] #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Input { /// Typed key. pub key: Key, From f354c48c114bdb2f63c341338d7a72867a167428 Mon Sep 17 00:00:00 2001 From: cstef Date: Tue, 27 Feb 2024 15:57:56 +0100 Subject: [PATCH 4/6] Add Eq derive for Input --- src/input/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/input/mod.rs b/src/input/mod.rs index e4769cd..ab4e1fb 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize}; /// /// 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 { @@ -103,7 +103,7 @@ 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 { From afb9e691b84447d6afced91aef631b233a530cec Mon Sep 17 00:00:00 2001 From: cstef Date: Mon, 8 Jul 2024 18:13:12 +0200 Subject: [PATCH 5/6] Add derive feature to serde --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a159a92..3ea5772 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,7 +49,7 @@ termion = { version = "2.0", optional = true } termwiz = { version = "0.20.0", optional = true } tui = { version = "0.19", default-features = false, optional = true } unicode-width = "0.1.11" -serde = { version = "1", optional = true } +serde = { version = "1", optional = true , features = ["derive"] } [[example]] name = "minimal" From dff26940103fd827f03285f43feb48b31e7d7acf Mon Sep 17 00:00:00 2001 From: cstef Date: Mon, 8 Jul 2024 18:16:00 +0200 Subject: [PATCH 6/6] Add clippy check for serde feature in CI --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) 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