From 6893adbc340fdb47ba1e804ee940e2cadca94d49 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 2 Oct 2020 17:26:56 -0700 Subject: [PATCH] break dep from mux -> codec --- src/mux/tab.rs | 94 ++++++++++++++++++++++++++++++++++++++++++++- src/server/codec.rs | 91 +------------------------------------------ 2 files changed, 94 insertions(+), 91 deletions(-) diff --git a/src/mux/tab.rs b/src/mux/tab.rs index 6727cbbaa..6f3aa34d5 100644 --- a/src/mux/tab.rs +++ b/src/mux/tab.rs @@ -1,7 +1,6 @@ use crate::mux::domain::DomainId; use crate::mux::pane::*; use crate::mux::{Mux, WindowId}; -use crate::server::codec::{PaneEntry, PaneNode}; use bintree::PathBranch; use config::keyassignment::PaneDirection; use portable_pty::PtySize; @@ -10,6 +9,7 @@ use serde::{Deserialize, Serialize}; use std::cell::{RefCell, RefMut}; use std::convert::TryInto; use std::rc::Rc; +use url::Url; pub type Tree = bintree::Tree, SplitDirectionAndSize>; pub type Cursor = bintree::Cursor, SplitDirectionAndSize>; @@ -1363,6 +1363,98 @@ impl Tab { } } +/// This type is used directly by the codec, take care to bump +/// the codec version if you change this +#[derive(Deserialize, Serialize, PartialEq, Debug)] +pub enum PaneNode { + Empty, + Split { + left: Box, + right: Box, + node: SplitDirectionAndSize, + }, + Leaf(PaneEntry), +} + +impl PaneNode { + pub fn into_tree(self) -> bintree::Tree { + match self { + PaneNode::Empty => bintree::Tree::Empty, + PaneNode::Split { left, right, node } => bintree::Tree::Node { + left: Box::new((*left).into_tree()), + right: Box::new((*right).into_tree()), + data: Some(node), + }, + PaneNode::Leaf(e) => bintree::Tree::Leaf(e), + } + } + + pub fn root_size(&self) -> Option { + match self { + PaneNode::Empty => None, + PaneNode::Split { node, .. } => Some(node.size()), + PaneNode::Leaf(entry) => Some(entry.size), + } + } + + pub fn window_and_tab_ids(&self) -> Option<(WindowId, TabId)> { + match self { + PaneNode::Empty => None, + PaneNode::Split { left, right, .. } => match left.window_and_tab_ids() { + Some(res) => Some(res), + None => right.window_and_tab_ids(), + }, + PaneNode::Leaf(entry) => Some((entry.window_id, entry.tab_id)), + } + } +} + +/// This type is used directly by the codec, take care to bump +/// the codec version if you change this +#[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] +pub struct PaneEntry { + pub window_id: WindowId, + pub tab_id: TabId, + pub pane_id: PaneId, + pub title: String, + pub size: PtySize, + pub working_dir: Option, + pub is_active_pane: bool, + pub is_zoomed_pane: bool, +} + +#[derive(Deserialize, Clone, Serialize, PartialEq, Debug)] +#[serde(try_from = "String", into = "String")] +pub struct SerdeUrl { + pub url: Url, +} + +impl std::convert::TryFrom for SerdeUrl { + type Error = url::ParseError; + fn try_from(s: String) -> Result { + let url = Url::parse(&s)?; + Ok(SerdeUrl { url }) + } +} + +impl From for SerdeUrl { + fn from(url: Url) -> SerdeUrl { + SerdeUrl { url } + } +} + +impl Into for SerdeUrl { + fn into(self) -> Url { + self.url + } +} + +impl Into for SerdeUrl { + fn into(self) -> String { + self.url.as_str().into() + } +} + #[cfg(test)] mod test { use super::*; diff --git a/src/server/codec.rs b/src/server/codec.rs index 57496e3d8..eaf1bc451 100644 --- a/src/server/codec.rs +++ b/src/server/codec.rs @@ -14,7 +14,7 @@ use crate::mux::domain::DomainId; use crate::mux::pane::PaneId; use crate::mux::renderable::{RenderableDimensions, StableCursorPosition}; -use crate::mux::tab::{SplitDirection, SplitDirectionAndSize, TabId}; +use crate::mux::tab::{PaneNode, SerdeUrl, SplitDirection, TabId}; use crate::mux::window::WindowId; use anyhow::{bail, Context as _, Error}; use leb128; @@ -28,7 +28,6 @@ use std::ops::Range; use std::sync::Arc; use termwiz::hyperlink::Hyperlink; use termwiz::surface::Line; -use url::Url; use varbincode; use wezterm_term::StableRowIndex; @@ -400,94 +399,6 @@ pub struct GetTlsCredsResponse { #[derive(Deserialize, Serialize, PartialEq, Debug)] pub struct ListPanes {} -#[derive(Deserialize, Clone, Serialize, PartialEq, Debug)] -#[serde(try_from = "String", into = "String")] -pub struct SerdeUrl { - pub url: Url, -} - -impl std::convert::TryFrom for SerdeUrl { - type Error = url::ParseError; - fn try_from(s: String) -> Result { - let url = Url::parse(&s)?; - Ok(SerdeUrl { url }) - } -} - -impl From for SerdeUrl { - fn from(url: Url) -> SerdeUrl { - SerdeUrl { url } - } -} - -impl Into for SerdeUrl { - fn into(self) -> Url { - self.url - } -} - -impl Into for SerdeUrl { - fn into(self) -> String { - self.url.as_str().into() - } -} - -#[derive(Deserialize, Serialize, PartialEq, Debug)] -pub enum PaneNode { - Empty, - Split { - left: Box, - right: Box, - node: SplitDirectionAndSize, - }, - Leaf(PaneEntry), -} - -impl PaneNode { - pub fn into_tree(self) -> bintree::Tree { - match self { - PaneNode::Empty => bintree::Tree::Empty, - PaneNode::Split { left, right, node } => bintree::Tree::Node { - left: Box::new((*left).into_tree()), - right: Box::new((*right).into_tree()), - data: Some(node), - }, - PaneNode::Leaf(e) => bintree::Tree::Leaf(e), - } - } - - pub fn root_size(&self) -> Option { - match self { - PaneNode::Empty => None, - PaneNode::Split { node, .. } => Some(node.size()), - PaneNode::Leaf(entry) => Some(entry.size), - } - } - - pub fn window_and_tab_ids(&self) -> Option<(WindowId, TabId)> { - match self { - PaneNode::Empty => None, - PaneNode::Split { left, right, .. } => match left.window_and_tab_ids() { - Some(res) => Some(res), - None => right.window_and_tab_ids(), - }, - PaneNode::Leaf(entry) => Some((entry.window_id, entry.tab_id)), - } - } -} - -#[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] -pub struct PaneEntry { - pub window_id: WindowId, - pub tab_id: TabId, - pub pane_id: PaneId, - pub title: String, - pub size: PtySize, - pub working_dir: Option, - pub is_active_pane: bool, - pub is_zoomed_pane: bool, -} - #[derive(Deserialize, Serialize, PartialEq, Debug)] pub struct ListPanesResponse { pub tabs: Vec,