From 2f3a508e990348e4227ad4be84db99ae7ab1bf52 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 13 Jun 2020 10:00:09 -0700 Subject: [PATCH] term: make serde optional --- Cargo.toml | 2 +- term/Cargo.toml | 4 +++- term/src/input.rs | 12 ++++++++---- term/src/lib.rs | 6 ++++-- term/src/selection.rs | 9 ++++++--- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5d470e3b7..2c49c69d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,7 +68,7 @@ ssh2 = "0.8" structopt = "0.3" strsim = "0.10" tabout = { path = "tabout" } -wezterm-term = { path = "term" } +wezterm-term = { path = "term", features=["use_serde"] } terminfo = "0.7" termwiz = { path = "termwiz" } textwrap = "0.11" diff --git a/term/Cargo.toml b/term/Cargo.toml index 22316d7e9..1eeb0a5fb 100644 --- a/term/Cargo.toml +++ b/term/Cargo.toml @@ -10,6 +10,9 @@ documentation = "https://docs.rs/wezterm-term" keywords = ["terminal", "emulator", "vte"] readme = "README.md" +[features] +use_serde = ["termwiz/use_serde"] + [dependencies] bitflags = "1.0" anyhow = "1.0" @@ -29,4 +32,3 @@ pretty_assertions = "0.6" [dependencies.termwiz] version = "0.10" path = "../termwiz" -features = ["use_serde"] diff --git a/term/src/input.rs b/term/src/input.rs index a289e638d..debdc6a2a 100644 --- a/term/src/input.rs +++ b/term/src/input.rs @@ -2,13 +2,15 @@ #![cfg_attr(feature = "cargo-clippy", allow(clippy::suspicious_arithmetic_impl, clippy::redundant_field_names))] use super::VisibleRowIndex; -use serde::*; +#[cfg(feature = "use_serde")] +use serde::{Deserialize, Serialize}; use std::time::{Duration, Instant}; pub use termwiz::input::KeyCode; pub use termwiz::input::Modifiers as KeyModifiers; -#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize, Hash)] +#[cfg_attr(feature = "use_serde", derive(Deserialize, Serialize))] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum MouseButton { Left, Middle, @@ -18,14 +20,16 @@ pub enum MouseButton { None, } -#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)] +#[cfg_attr(feature = "use_serde", derive(Deserialize, Serialize))] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum MouseEventKind { Press, Release, Move, } -#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)] +#[cfg_attr(feature = "use_serde", derive(Deserialize, Serialize))] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct MouseEvent { pub kind: MouseEventKind, pub x: usize, diff --git a/term/src/lib.rs b/term/src/lib.rs index 3fed0157e..8fcfadc61 100644 --- a/term/src/lib.rs +++ b/term/src/lib.rs @@ -16,7 +16,8 @@ //! The entrypoint to the crate is the [Terminal](terminal/struct.Terminal.html) //! struct. use anyhow::Error; -use serde::*; +#[cfg(feature = "use_serde")] +use serde::{Deserialize, Serialize}; use std::ops::{Deref, DerefMut, Range}; use std::str; @@ -104,7 +105,8 @@ pub enum Position { /// Describes the location of the cursor in the visible portion /// of the screen. -#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Deserialize, Serialize)] +#[cfg_attr(feature = "use_serde", derive(Deserialize, Serialize))] +#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)] pub struct CursorPosition { pub x: usize, pub y: VisibleRowIndex, diff --git a/term/src/selection.rs b/term/src/selection.rs index 6abdb3c26..459feaad9 100644 --- a/term/src/selection.rs +++ b/term/src/selection.rs @@ -2,11 +2,13 @@ // and inclusive range #![cfg_attr(feature = "cargo-clippy", allow(clippy::range_plus_one))] use super::{ScrollbackOrVisibleRowIndex, VisibleRowIndex}; -use serde::*; +#[cfg(feature = "use_serde")] +use serde::{Deserialize, Serialize}; use std::ops::Range; /// The x,y coordinates of either the start or end of a selection region -#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)] +#[cfg_attr(feature = "use_serde", derive(Deserialize, Serialize))] +#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)] pub struct SelectionCoordinate { pub x: usize, pub y: ScrollbackOrVisibleRowIndex, @@ -14,7 +16,8 @@ pub struct SelectionCoordinate { /// Represents the selected text range. /// The end coordinates are inclusive. -#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)] +#[cfg_attr(feature = "use_serde", derive(Deserialize, Serialize))] +#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)] pub struct SelectionRange { pub start: SelectionCoordinate, pub end: SelectionCoordinate,