break dep from mux -> codec

This commit is contained in:
Wez Furlong committed 2020-10-03 11:15:57 -07:00
1 parent b94c4a11f8
commit 6893adbc34
2 files changed
+94 -91

No files matched your search

+93 -1
View File
@@ -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<Rc<dyn Pane>, SplitDirectionAndSize>;
pub type Cursor = bintree::Cursor<Rc<dyn Pane>, 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<PaneNode>,
right: Box<PaneNode>,
node: SplitDirectionAndSize,
},
Leaf(PaneEntry),
}
impl PaneNode {
pub fn into_tree(self) -> bintree::Tree<PaneEntry, SplitDirectionAndSize> {
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<PtySize> {
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<SerdeUrl>,
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<String> for SerdeUrl {
type Error = url::ParseError;
fn try_from(s: String) -> Result<SerdeUrl, url::ParseError> {
let url = Url::parse(&s)?;
Ok(SerdeUrl { url })
}
}
impl From<Url> for SerdeUrl {
fn from(url: Url) -> SerdeUrl {
SerdeUrl { url }
}
}
impl Into<Url> for SerdeUrl {
fn into(self) -> Url {
self.url
}
}
impl Into<String> for SerdeUrl {
fn into(self) -> String {
self.url.as_str().into()
}
}
#[cfg(test)]
mod test {
use super::*;
+1 -90
View File
@@ -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<String> for SerdeUrl {
type Error = url::ParseError;
fn try_from(s: String) -> Result<SerdeUrl, url::ParseError> {
let url = Url::parse(&s)?;
Ok(SerdeUrl { url })
}
}
impl From<Url> for SerdeUrl {
fn from(url: Url) -> SerdeUrl {
SerdeUrl { url }
}
}
impl Into<Url> for SerdeUrl {
fn into(self) -> Url {
self.url
}
}
impl Into<String> for SerdeUrl {
fn into(self) -> String {
self.url.as_str().into()
}
}
#[derive(Deserialize, Serialize, PartialEq, Debug)]
pub enum PaneNode {
Empty,
Split {
left: Box<PaneNode>,
right: Box<PaneNode>,
node: SplitDirectionAndSize,
},
Leaf(PaneEntry),
}
impl PaneNode {
pub fn into_tree(self) -> bintree::Tree<PaneEntry, SplitDirectionAndSize> {
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<PtySize> {
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<SerdeUrl>,
pub is_active_pane: bool,
pub is_zoomed_pane: bool,
}
#[derive(Deserialize, Serialize, PartialEq, Debug)]
pub struct ListPanesResponse {
pub tabs: Vec<PaneNode>,