From a1bdddd8e54983083ffff6cb3743bd851987e0ff Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Thu, 7 Mar 2019 23:39:10 +0000 Subject: [PATCH] move Tab trait to mux module --- src/gliumwindows.rs | 3 ++- src/guicommon/host.rs | 2 +- src/guicommon/tabs.rs | 26 ++------------------------ src/guicommon/window.rs | 3 ++- src/guiloop/glutinloop.rs | 2 +- src/guiloop/mod.rs | 2 +- src/main.rs | 3 ++- src/mux/mod.rs | 4 +++- src/mux/tab.rs | 31 +++++++++++++++++++++++++++++++ 9 files changed, 45 insertions(+), 31 deletions(-) create mode 100644 src/mux/tab.rs diff --git a/src/gliumwindows.rs b/src/gliumwindows.rs index 21d174c60..2e99abc56 100644 --- a/src/gliumwindows.rs +++ b/src/gliumwindows.rs @@ -4,10 +4,11 @@ use crate::config::Config; use crate::failure::Error; use crate::font::FontConfiguration; use crate::guicommon::host::{HostHelper, HostImpl, TabHost}; -use crate::guicommon::tabs::{Tab, TabId, Tabs}; +use crate::guicommon::tabs::Tabs; use crate::guicommon::window::{Dimensions, TerminalWindow}; use crate::guiloop::glutinloop::GuiEventLoop; use crate::guiloop::SessionTerminated; +use crate::mux::tab::{Tab, TabId}; use crate::opengl::render::Renderer; use glium; use glium::glutin::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize}; diff --git a/src/guicommon/host.rs b/src/guicommon/host.rs index 1254dad19..7f60648be 100644 --- a/src/guicommon/host.rs +++ b/src/guicommon/host.rs @@ -1,5 +1,5 @@ use super::window::TerminalWindow; -use crate::guicommon::tabs::Tab; +use crate::mux::tab::Tab; use clipboard::{ClipboardContext, ClipboardProvider}; use failure::Error; use std::ops::{Deref, DerefMut}; diff --git a/src/guicommon/tabs.rs b/src/guicommon/tabs.rs index cda73a9a9..db37bbbaa 100644 --- a/src/guicommon/tabs.rs +++ b/src/guicommon/tabs.rs @@ -1,33 +1,11 @@ use crate::mux::renderable::Renderable; +use crate::mux::tab::{alloc_tab_id, Tab, TabId}; use crate::{Child, MasterPty}; use failure::Error; use std::cell::{RefCell, RefMut}; use std::rc::Rc; use term::{KeyCode, KeyModifiers, MouseEvent, Terminal, TerminalHost}; -static TAB_ID: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::ATOMIC_USIZE_INIT; -pub type TabId = usize; - -pub trait Tab { - fn tab_id(&self) -> TabId; - fn renderer(&self) -> RefMut; - fn get_title(&self) -> String; - fn send_paste(&self, text: &str) -> Result<(), Error>; - fn reader(&self) -> Result, Error>; - fn writer(&self) -> RefMut; - fn resize( - &self, - rows: u16, - cols: u16, - pixel_width: u16, - pixel_height: u16, - ) -> Result<(), Error>; - fn key_down(&self, key: KeyCode, mods: KeyModifiers) -> Result<(), Error>; - fn mouse_event(&self, event: MouseEvent, host: &mut TerminalHost) -> Result<(), Error>; - fn advance_bytes(&self, buf: &[u8], host: &mut TerminalHost); - fn is_dead(&self) -> bool; -} - pub struct LocalTab { tab_id: TabId, terminal: RefCell, @@ -104,7 +82,7 @@ impl Tab for LocalTab { impl LocalTab { pub fn new(terminal: Terminal, process: Child, pty: MasterPty) -> Self { - let tab_id = TAB_ID.fetch_add(1, ::std::sync::atomic::Ordering::Relaxed); + let tab_id = alloc_tab_id(); Self { tab_id, terminal: RefCell::new(terminal), diff --git a/src/guicommon/window.rs b/src/guicommon/window.rs index 19ffcf49a..49c17d40f 100644 --- a/src/guicommon/window.rs +++ b/src/guicommon/window.rs @@ -1,6 +1,7 @@ use crate::config::Config; use crate::font::FontConfiguration; -use crate::guicommon::tabs::{LocalTab, Tab, TabId, Tabs}; +use crate::guicommon::tabs::{LocalTab, Tabs}; +use crate::mux::tab::{Tab, TabId}; use crate::opengl::render::Renderer; use crate::opengl::textureatlas::OutOfTextureSpace; use crate::openpty; diff --git a/src/guiloop/glutinloop.rs b/src/guiloop/glutinloop.rs index cc9d52e94..c59b058e3 100644 --- a/src/guiloop/glutinloop.rs +++ b/src/guiloop/glutinloop.rs @@ -3,9 +3,9 @@ use crate::config::Config; use crate::font::{FontConfiguration, FontSystemSelection}; use crate::gliumwindows; pub use crate::gliumwindows::GliumTerminalWindow; -use crate::guicommon::tabs::Tab; use crate::guicommon::window::TerminalWindow; use crate::guiloop::SessionTerminated; +use crate::mux::tab::Tab; use crate::mux::Mux; use crate::spawn_tab; use failure::Error; diff --git a/src/guiloop/mod.rs b/src/guiloop/mod.rs index 87b1728ad..b80dfd6ad 100644 --- a/src/guiloop/mod.rs +++ b/src/guiloop/mod.rs @@ -1,7 +1,7 @@ use super::ExitStatus; use crate::config::Config; use crate::font::FontConfiguration; -use crate::guicommon::tabs::Tab; +use crate::mux::tab::Tab; use crate::mux::Mux; use failure::Error; use promise::Executor; diff --git a/src/main.rs b/src/main.rs index b002530ec..3039b39c0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,9 +23,10 @@ mod guiloop; mod mux; mod opengl; mod server; -use crate::guicommon::tabs::{LocalTab, Tab}; +use crate::guicommon::tabs::LocalTab; use crate::guiloop::GuiSelection; use crate::guiloop::GuiSystem; +use crate::mux::tab::Tab; use crate::mux::Mux; mod font; diff --git a/src/mux/mod.rs b/src/mux/mod.rs index 0bfa365f3..4c0788b10 100644 --- a/src/mux/mod.rs +++ b/src/mux/mod.rs @@ -1,4 +1,3 @@ -use crate::guicommon::tabs::{Tab, TabId}; use failure::Error; use promise::{Executor, Future}; use std::cell::RefCell; @@ -10,6 +9,9 @@ use term::TerminalHost; use termwiz::hyperlink::Hyperlink; pub mod renderable; +pub mod tab; + +use crate::mux::tab::{Tab, TabId}; #[derive(Default)] pub struct Mux { diff --git a/src/mux/tab.rs b/src/mux/tab.rs new file mode 100644 index 000000000..4b6cfdc9c --- /dev/null +++ b/src/mux/tab.rs @@ -0,0 +1,31 @@ +use crate::mux::renderable::Renderable; +use failure::Error; +use std::cell::RefMut; +use term::{KeyCode, KeyModifiers, MouseEvent, TerminalHost}; + +static TAB_ID: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::ATOMIC_USIZE_INIT; +pub type TabId = usize; + +pub fn alloc_tab_id() -> TabId { + TAB_ID.fetch_add(1, ::std::sync::atomic::Ordering::Relaxed) +} + +pub trait Tab { + fn tab_id(&self) -> TabId; + fn renderer(&self) -> RefMut; + fn get_title(&self) -> String; + fn send_paste(&self, text: &str) -> Result<(), Error>; + fn reader(&self) -> Result, Error>; + fn writer(&self) -> RefMut; + fn resize( + &self, + rows: u16, + cols: u16, + pixel_width: u16, + pixel_height: u16, + ) -> Result<(), Error>; + fn key_down(&self, key: KeyCode, mods: KeyModifiers) -> Result<(), Error>; + fn mouse_event(&self, event: MouseEvent, host: &mut TerminalHost) -> Result<(), Error>; + fn advance_bytes(&self, buf: &[u8], host: &mut TerminalHost); + fn is_dead(&self) -> bool; +}