1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-27 02:25:28 +03:00

termwiz: make serde an optional dep

closes: https://github.com/wez/wezterm/pull/186
This commit is contained in:
Wez Furlong 2020-06-13 09:51:17 -07:00
parent 070afa65d6
commit 3002b40fd2
15 changed files with 94 additions and 44 deletions

1
Cargo.lock generated
View File

@ -3914,7 +3914,6 @@ dependencies = [
"palette", "palette",
"pretty_assertions", "pretty_assertions",
"serde", "serde",
"serde_derive",
"termwiz", "termwiz",
"unicode-segmentation", "unicode-segmentation",
"unicode-width", "unicode-width",

View File

@ -21,7 +21,6 @@ palette = "0.5"
unicode-segmentation = "1.5" unicode-segmentation = "1.5"
unicode-width = "0.1" unicode-width = "0.1"
serde = {version="1.0", features = ["rc"]} serde = {version="1.0", features = ["rc"]}
serde_derive = "1.0"
url = "2" url = "2"
[dev-dependencies] [dev-dependencies]
@ -30,3 +29,4 @@ pretty_assertions = "0.6"
[dependencies.termwiz] [dependencies.termwiz]
version = "0.10" version = "0.10"
path = "../termwiz" path = "../termwiz"
features = ["use_serde"]

View File

@ -2,7 +2,7 @@
#![cfg_attr(feature = "cargo-clippy", allow(clippy::suspicious_arithmetic_impl, clippy::redundant_field_names))] #![cfg_attr(feature = "cargo-clippy", allow(clippy::suspicious_arithmetic_impl, clippy::redundant_field_names))]
use super::VisibleRowIndex; use super::VisibleRowIndex;
use serde_derive::*; use serde::*;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
pub use termwiz::input::KeyCode; pub use termwiz::input::KeyCode;

View File

@ -15,9 +15,8 @@
//! //!
//! The entrypoint to the crate is the [Terminal](terminal/struct.Terminal.html) //! The entrypoint to the crate is the [Terminal](terminal/struct.Terminal.html)
//! struct. //! struct.
use serde_derive::*;
use anyhow::Error; use anyhow::Error;
use serde::*;
use std::ops::{Deref, DerefMut, Range}; use std::ops::{Deref, DerefMut, Range};
use std::str; use std::str;

View File

@ -2,7 +2,7 @@
// and inclusive range // and inclusive range
#![cfg_attr(feature = "cargo-clippy", allow(clippy::range_plus_one))] #![cfg_attr(feature = "cargo-clippy", allow(clippy::range_plus_one))]
use super::{ScrollbackOrVisibleRowIndex, VisibleRowIndex}; use super::{ScrollbackOrVisibleRowIndex, VisibleRowIndex};
use serde_derive::*; use serde::*;
use std::ops::Range; use std::ops::Range;
/// The x,y coordinates of either the start or end of a selection region /// The x,y coordinates of either the start or end of a selection region

View File

@ -25,7 +25,7 @@ num-traits = "0.2"
ordered-float = "1.0" ordered-float = "1.0"
regex = "1" regex = "1"
semver = "0.9" semver = "0.9"
serde = {version="1.0", features = ["rc", "derive"]} serde = {version="1.0", features = ["rc", "derive"], optional=true}
smallvec = "0.6" smallvec = "0.6"
terminfo = "0.7" terminfo = "0.7"
unicode-segmentation = "1.5" unicode-segmentation = "1.5"
@ -35,6 +35,7 @@ vtparse = { version="0.3", path="../vtparse" }
[features] [features]
widgets = ["cassowary", "fnv"] widgets = ["cassowary", "fnv"]
use_serde = ["serde"]
[dev-dependencies] [dev-dependencies]
varbincode = "0.1" varbincode = "0.1"

View File

@ -2,6 +2,7 @@
use crate::color::ColorAttribute; use crate::color::ColorAttribute;
pub use crate::escape::osc::Hyperlink; pub use crate::escape::osc::Hyperlink;
use crate::image::ImageCell; use crate::image::ImageCell;
#[cfg(feature = "use_serde")]
use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde::{Deserialize, Deserializer, Serialize, Serializer};
use smallvec::SmallVec; use smallvec::SmallVec;
use std; use std;
@ -14,7 +15,8 @@ use unicode_width::UnicodeWidthStr;
/// to reduce per-cell overhead. /// to reduce per-cell overhead.
/// The setter methods return a mutable self reference so that they can /// The setter methods return a mutable self reference so that they can
/// be chained together. /// be chained together.
#[derive(Debug, Default, Clone, Eq, PartialEq, Serialize, Deserialize)] #[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Default, Clone, Eq, PartialEq)]
pub struct CellAttributes { pub struct CellAttributes {
attributes: u16, attributes: u16,
/// The foreground color /// The foreground color
@ -85,7 +87,8 @@ macro_rules! bitfield {
/// implement `Intensity::Bold` by either using a bold font or by simply /// implement `Intensity::Bold` by either using a bold font or by simply
/// using an alternative color. Some terminals implement `Intensity::Half` /// using an alternative color. Some terminals implement `Intensity::Half`
/// as a dimmer color variant. /// as a dimmer color variant.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] #[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u16)] #[repr(u16)]
pub enum Intensity { pub enum Intensity {
Normal = 0, Normal = 0,
@ -100,7 +103,8 @@ impl Default for Intensity {
} }
/// Specify just how underlined you want your `Cell` to be /// Specify just how underlined you want your `Cell` to be
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] #[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u16)] #[repr(u16)]
pub enum Underline { pub enum Underline {
/// The cell is not underlined /// The cell is not underlined
@ -127,7 +131,8 @@ impl Into<bool> for Underline {
} }
/// Specify whether you want to slowly or rapidly annoy your users /// Specify whether you want to slowly or rapidly annoy your users
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] #[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u16)] #[repr(u16)]
pub enum Blink { pub enum Blink {
None = 0, None = 0,
@ -195,6 +200,7 @@ impl CellAttributes {
} }
} }
#[cfg(feature = "use_serde")]
fn deserialize_smallvec<'de, D>(deserializer: D) -> Result<SmallVec<[u8; 4]>, D::Error> fn deserialize_smallvec<'de, D>(deserializer: D) -> Result<SmallVec<[u8; 4]>, D::Error>
where where
D: Deserializer<'de>, D: Deserializer<'de>,
@ -203,6 +209,7 @@ where
Ok(SmallVec::from_slice(text.as_bytes())) Ok(SmallVec::from_slice(text.as_bytes()))
} }
#[cfg(feature = "use_serde")]
fn serialize_smallvec<S>(value: &SmallVec<[u8; 4]>, serializer: S) -> Result<S::Ok, S::Error> fn serialize_smallvec<S>(value: &SmallVec<[u8; 4]>, serializer: S) -> Result<S::Ok, S::Error>
where where
S: Serializer, S: Serializer,
@ -214,11 +221,15 @@ where
} }
/// Models the contents of a cell on the terminal display /// Models the contents of a cell on the terminal display
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)] #[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Cell { pub struct Cell {
#[serde( #[cfg_attr(
deserialize_with = "deserialize_smallvec", feature = "use_serde",
serialize_with = "serialize_smallvec" serde(
deserialize_with = "deserialize_smallvec",
serialize_with = "serialize_smallvec"
)
)] )]
text: SmallVec<[u8; 4]>, text: SmallVec<[u8; 4]>,
attrs: CellAttributes, attrs: CellAttributes,
@ -340,7 +351,8 @@ pub fn grapheme_column_width(s: &str) -> usize {
/// Models a change in the attributes of a cell in a stream of changes. /// Models a change in the attributes of a cell in a stream of changes.
/// Each variant specifies one of the possible attributes; the corresponding /// Each variant specifies one of the possible attributes; the corresponding
/// value holds the new value to be used for that attribute. /// value holds the new value to be used for that attribute.
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] #[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum AttributeChange { pub enum AttributeChange {
Intensity(Intensity), Intensity(Intensity),
Underline(Underline), Underline(Underline),

View File

@ -3,9 +3,9 @@
#![cfg_attr(feature = "cargo-clippy", allow(clippy::useless_attribute))] #![cfg_attr(feature = "cargo-clippy", allow(clippy::useless_attribute))]
use num_derive::*; use num_derive::*;
use serde::{self, Deserialize, Deserializer, Serialize, Serializer}; #[cfg(feature = "use_serde")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::collections::HashMap; use std::collections::HashMap;
use std::result::Result;
#[derive(Debug, Clone, Copy, FromPrimitive)] #[derive(Debug, Clone, Copy, FromPrimitive)]
#[repr(u8)] #[repr(u8)]
@ -212,6 +212,7 @@ impl RgbColor {
/// is that we have to serialize RgbColor as a 7-byte string when we could /// is that we have to serialize RgbColor as a 7-byte string when we could
/// otherwise serialize it as a 3-byte array. There's probably a way /// otherwise serialize it as a 3-byte array. There's probably a way
/// to make this work more efficiently, but for now this will do. /// to make this work more efficiently, but for now this will do.
#[cfg(feature = "use_serde")]
impl Serialize for RgbColor { impl Serialize for RgbColor {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where where
@ -222,6 +223,7 @@ impl Serialize for RgbColor {
} }
} }
#[cfg(feature = "use_serde")]
impl<'de> Deserialize<'de> for RgbColor { impl<'de> Deserialize<'de> for RgbColor {
fn deserialize<D>(deserializer: D) -> Result<RgbColor, D::Error> fn deserialize<D>(deserializer: D) -> Result<RgbColor, D::Error>
where where
@ -271,7 +273,8 @@ impl From<RgbColor> for ColorSpec {
/// type used in the `CellAttributes` struct and can specify an optional /// type used in the `CellAttributes` struct and can specify an optional
/// TrueColor value, allowing a fallback to a more traditional palette /// TrueColor value, allowing a fallback to a more traditional palette
/// index if TrueColor is not available. /// index if TrueColor is not available.
#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)] #[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum ColorAttribute { pub enum ColorAttribute {
/// Use RgbColor when supported, falling back to the specified PaletteIndex. /// Use RgbColor when supported, falling back to the specified PaletteIndex.
TrueColorWithPaletteFallback(RgbColor, PaletteIndex), TrueColorWithPaletteFallback(RgbColor, PaletteIndex),

View File

@ -6,13 +6,15 @@
//! as we recognize linkable input text during print() processing. //! as we recognize linkable input text during print() processing.
use anyhow::{anyhow, ensure, Error}; use anyhow::{anyhow, ensure, Error};
use regex::{Captures, Regex}; use regex::{Captures, Regex};
use serde::{self, Deserialize, Deserializer, Serialize}; #[cfg(feature = "use_serde")]
use serde::{Deserialize, Deserializer, Serialize};
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt::{Display, Error as FmtError, Formatter}; use std::fmt::{Display, Error as FmtError, Formatter};
use std::ops::Range; use std::ops::Range;
use std::sync::Arc; use std::sync::Arc;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Hyperlink { pub struct Hyperlink {
params: HashMap<String, String>, params: HashMap<String, String>,
uri: String, uri: String,
@ -121,12 +123,13 @@ impl Display for Hyperlink {
/// URL to view the details for that issue. /// URL to view the details for that issue.
/// The Rule struct is configuration that is passed to the terminal /// The Rule struct is configuration that is passed to the terminal
/// and is evaluated when processing mouse hover events. /// and is evaluated when processing mouse hover events.
#[derive(Debug, Clone, Deserialize)] #[cfg_attr(feature = "use_serde", derive(Deserialize))]
#[derive(Debug, Clone)]
pub struct Rule { pub struct Rule {
/// The compiled regex for the rule. This is used to match /// The compiled regex for the rule. This is used to match
/// against a line of text from the screen (typically the line /// against a line of text from the screen (typically the line
/// over which the mouse is hovering). /// over which the mouse is hovering).
#[serde(deserialize_with = "deserialize_regex")] #[cfg_attr(feature = "use_serde", serde(deserialize_with = "deserialize_regex"))]
regex: Regex, regex: Regex,
/// The format string that defines how to transform the matched /// The format string that defines how to transform the matched
/// text into a URL. For example, a format string of `$0` expands /// text into a URL. For example, a format string of `$0` expands
@ -141,6 +144,7 @@ pub struct Rule {
format: String, format: String,
} }
#[cfg(feature = "use_serde")]
fn deserialize_regex<'de, D>(deserializer: D) -> Result<Regex, D::Error> fn deserialize_regex<'de, D>(deserializer: D) -> Result<Regex, D::Error>
where where
D: Deserializer<'de>, D: Deserializer<'de>,

View File

@ -12,9 +12,11 @@
// z-order. // z-order.
use ordered_float::NotNan; use ordered_float::NotNan;
#[cfg(feature = "use_serde")]
use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::sync::Arc; use std::sync::Arc;
#[cfg(feature = "use_serde")]
fn deserialize_notnan<'de, D>(deserializer: D) -> Result<NotNan<f32>, D::Error> fn deserialize_notnan<'de, D>(deserializer: D) -> Result<NotNan<f32>, D::Error>
where where
D: Deserializer<'de>, D: Deserializer<'de>,
@ -23,6 +25,7 @@ where
NotNan::new(value).map_err(|e| serde::de::Error::custom(format!("{:?}", e))) NotNan::new(value).map_err(|e| serde::de::Error::custom(format!("{:?}", e)))
} }
#[cfg(feature = "use_serde")]
#[cfg_attr(feature = "cargo-clippy", allow(clippy::trivially_copy_pass_by_ref))] #[cfg_attr(feature = "cargo-clippy", allow(clippy::trivially_copy_pass_by_ref))]
fn serialize_notnan<S>(value: &NotNan<f32>, serializer: S) -> Result<S::Ok, S::Error> fn serialize_notnan<S>(value: &NotNan<f32>, serializer: S) -> Result<S::Ok, S::Error>
where where
@ -31,16 +34,23 @@ where
value.into_inner().serialize(serializer) value.into_inner().serialize(serializer)
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TextureCoordinate { pub struct TextureCoordinate {
#[serde( #[cfg_attr(
deserialize_with = "deserialize_notnan", feature = "use_serde",
serialize_with = "serialize_notnan" serde(
deserialize_with = "deserialize_notnan",
serialize_with = "serialize_notnan"
)
)] )]
pub x: NotNan<f32>, pub x: NotNan<f32>,
#[serde( #[cfg_attr(
deserialize_with = "deserialize_notnan", feature = "use_serde",
serialize_with = "serialize_notnan" serde(
deserialize_with = "deserialize_notnan",
serialize_with = "serialize_notnan"
)
)] )]
pub y: NotNan<f32>, pub y: NotNan<f32>,
} }
@ -62,7 +72,8 @@ impl TextureCoordinate {
/// carve up the image and track each slice of it. Each cell needs to know /// carve up the image and track each slice of it. Each cell needs to know
/// its "texture coordinates" within that image so that we can render the /// its "texture coordinates" within that image so that we can render the
/// right slice. /// right slice.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ImageCell { pub struct ImageCell {
/// Texture coordinate for the top left of this cell. /// Texture coordinate for the top left of this cell.
/// (0,0) is the top left of the ImageData. (1, 1) is /// (0,0) is the top left of the ImageData. (1, 1) is
@ -102,7 +113,8 @@ impl ImageCell {
static IMAGE_ID: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::AtomicUsize::new(0); static IMAGE_ID: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::AtomicUsize::new(0);
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ImageData { pub struct ImageData {
id: usize, id: usize,
/// The image data bytes. Data is the native image file format /// The image data bytes. Data is the native image file format

View File

@ -6,6 +6,7 @@ use crate::escape::{Action, CSI};
use crate::keymap::{Found, KeyMap}; use crate::keymap::{Found, KeyMap};
use crate::readbuf::ReadBuffer; use crate::readbuf::ReadBuffer;
use bitflags::bitflags; use bitflags::bitflags;
#[cfg(feature = "use_serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std; use std;
@ -16,7 +17,8 @@ use winapi::um::wincon::{
}; };
bitflags! { bitflags! {
#[derive(Default, Serialize, Deserialize)] #[cfg_attr(feature="use_serde", derive(Serialize, Deserialize))]
#[derive(Default)]
pub struct Modifiers: u8 { pub struct Modifiers: u8 {
const NONE = 0; const NONE = 0;
const SHIFT = 1<<1; const SHIFT = 1<<1;
@ -26,7 +28,8 @@ bitflags! {
} }
} }
bitflags! { bitflags! {
#[derive(Default, Serialize, Deserialize)] #[cfg_attr(feature="use_serde", derive(Serialize, Deserialize))]
#[derive(Default)]
pub struct MouseButtons: u8 { pub struct MouseButtons: u8 {
const NONE = 0; const NONE = 0;
const LEFT = 1<<1; const LEFT = 1<<1;
@ -56,7 +59,8 @@ pub enum InputEvent {
Wake, Wake,
} }
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MouseEvent { pub struct MouseEvent {
pub x: u16, pub x: u16,
pub y: u16, pub y: u16,
@ -64,7 +68,8 @@ pub struct MouseEvent {
pub modifiers: Modifiers, pub modifiers: Modifiers,
} }
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct KeyEvent { pub struct KeyEvent {
/// Which key was pressed /// Which key was pressed
pub key: KeyCode, pub key: KeyCode,
@ -76,7 +81,8 @@ pub struct KeyEvent {
/// Which key is pressed. Not all of these are probable to appear /// Which key is pressed. Not all of these are probable to appear
/// on most systems. A lot of this list is @wez trawling docs and /// on most systems. A lot of this list is @wez trawling docs and
/// making an entry for things that might be possible in this first pass. /// making an entry for things that might be possible in this first pass.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] #[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum KeyCode { pub enum KeyCode {
/// The decoded unicode character /// The decoded unicode character
Char(char), Char(char),

View File

@ -34,6 +34,11 @@
//! level. //! level.
//! * `LineEditor` provides line editing facilities similar to those //! * `LineEditor` provides line editing facilities similar to those
//! in the unix shell. //! in the unix shell.
//!
//! ## Features
//!
//! * `widgets` - enables the widget layout and related traits
//! * `use_serde` - makes a number of structs serde serializable
pub mod caps; pub mod caps;
pub mod cell; pub mod cell;

View File

@ -2,6 +2,7 @@ use crate::cell::{unicode_column_width, AttributeChange, CellAttributes};
use crate::color::ColorAttribute; use crate::color::ColorAttribute;
pub use crate::image::{ImageData, TextureCoordinate}; pub use crate::image::{ImageData, TextureCoordinate};
use crate::surface::{CursorShape, CursorVisibility, Position}; use crate::surface::{CursorShape, CursorVisibility, Position};
#[cfg(feature = "use_serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::sync::Arc; use std::sync::Arc;
use unicode_segmentation::UnicodeSegmentation; use unicode_segmentation::UnicodeSegmentation;
@ -9,7 +10,8 @@ use unicode_segmentation::UnicodeSegmentation;
/// `Change` describes an update operation to be applied to a `Surface`. /// `Change` describes an update operation to be applied to a `Surface`.
/// Changes to the active attributes (color, style), moving the cursor /// Changes to the active attributes (color, style), moving the cursor
/// and outputting text are examples of some of the values. /// and outputting text are examples of some of the values.
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] #[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Change { pub enum Change {
/// Change a single attribute /// Change a single attribute
Attribute(AttributeChange), Attribute(AttributeChange),
@ -261,7 +263,8 @@ impl ChangeSequence {
/// A 4x3 cell image would set `width=3`, `height=3`, `top_left=(0,0)`, `bottom_right=(1,1)`. /// A 4x3 cell image would set `width=3`, `height=3`, `top_left=(0,0)`, `bottom_right=(1,1)`.
/// The top left cell from that image, if it were to be included in a diff, /// The top left cell from that image, if it were to be included in a diff,
/// would be recorded as `width=1`, `height=1`, `top_left=(0,0)`, `bottom_right=(1/4,1/3)`. /// would be recorded as `width=1`, `height=1`, `top_left=(0,0)`, `bottom_right=(1/4,1/3)`.
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] #[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Image { pub struct Image {
/// measured in cells /// measured in cells
pub width: usize, pub width: usize,

View File

@ -3,13 +3,14 @@ use crate::cellcluster::CellCluster;
use crate::hyperlink::Rule; use crate::hyperlink::Rule;
use crate::surface::Change; use crate::surface::Change;
use bitflags::bitflags; use bitflags::bitflags;
#[cfg(feature = "use_serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::ops::Range; use std::ops::Range;
use std::sync::Arc; use std::sync::Arc;
use unicode_segmentation::UnicodeSegmentation; use unicode_segmentation::UnicodeSegmentation;
bitflags! { bitflags! {
#[derive(Serialize, Deserialize)] #[cfg_attr(feature="use_serde", derive(Serialize, Deserialize))]
struct LineBits : u8 { struct LineBits : u8 {
const NONE = 0; const NONE = 0;
/// The contents of the Line have changed and cached or /// The contents of the Line have changed and cached or
@ -24,7 +25,8 @@ bitflags! {
} }
} }
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] #[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq)]
pub struct Line { pub struct Line {
bits: LineBits, bits: LineBits,
cells: Vec<Cell>, cells: Vec<Cell>,

View File

@ -2,6 +2,7 @@ use crate::cell::{AttributeChange, Cell, CellAttributes};
use crate::color::ColorAttribute; use crate::color::ColorAttribute;
use crate::image::ImageCell; use crate::image::ImageCell;
use ordered_float::NotNan; use ordered_float::NotNan;
#[cfg(feature = "use_serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::borrow::Cow; use std::borrow::Cow;
use std::cmp::min; use std::cmp::min;
@ -18,7 +19,8 @@ pub use self::line::Line;
/// Relative(0) is the current position in the line or /// Relative(0) is the current position in the line or
/// column and EndRelative(0) is the end position in the /// column and EndRelative(0) is the end position in the
/// line or column. /// line or column.
#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)] #[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum Position { pub enum Position {
/// Negative values move up, positive values down, 0 means no change /// Negative values move up, positive values down, 0 means no change
Relative(isize), Relative(isize),
@ -28,7 +30,8 @@ pub enum Position {
EndRelative(usize), EndRelative(usize),
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CursorVisibility { pub enum CursorVisibility {
Hidden, Hidden,
Visible, Visible,
@ -40,7 +43,8 @@ impl Default for CursorVisibility {
} }
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CursorShape { pub enum CursorShape {
Default, Default,
BlinkingBlock, BlinkingBlock,