mirror of
https://github.com/wez/wezterm.git
synced 2024-11-24 07:46:59 +03:00
centralize calling Mux::add_tab to Domain::spawn
This commit is contained in:
parent
95d2479ea6
commit
0c8cba99af
@ -206,17 +206,12 @@ impl GuiEventLoop {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn register_tab(&self, tab: &Rc<Tab>) -> Result<(), Error> {
|
||||
self.mux.add_tab(self.gui_executor(), tab)
|
||||
}
|
||||
|
||||
fn do_spawn_new_window(
|
||||
&self,
|
||||
config: &Arc<Config>,
|
||||
fonts: &Rc<FontConfiguration>,
|
||||
) -> Result<(), Error> {
|
||||
let tab = self.mux.default_domain().spawn(PtySize::default(), None)?;
|
||||
self.mux.add_tab(self.gui_executor(), &tab)?;
|
||||
let events = Self::get().expect("to be called on gui thread");
|
||||
let window = GliumTerminalWindow::new(&events, &fonts, &config, &tab)?;
|
||||
|
||||
|
@ -5,7 +5,7 @@ use crate::font::FontConfiguration;
|
||||
use crate::frontend::glium::glutinloop::GuiEventLoop;
|
||||
use crate::frontend::guicommon::host::{HostHelper, HostImpl, TabHost};
|
||||
use crate::frontend::guicommon::window::{Dimensions, TerminalWindow};
|
||||
use crate::mux::tab::{Tab, TabId};
|
||||
use crate::mux::tab::Tab;
|
||||
use crate::mux::window::WindowId;
|
||||
use crate::mux::{Mux, SessionTerminated};
|
||||
use crate::opengl::render::Renderer;
|
||||
@ -114,13 +114,6 @@ impl TerminalWindow for GliumTerminalWindow {
|
||||
self.renderer.recreate_atlas(&self.host.display, size)
|
||||
}
|
||||
|
||||
fn tab_was_created(&mut self, tab: &Rc<Tab>) -> Result<(), Error> {
|
||||
self.event_loop.register_tab(tab)
|
||||
}
|
||||
fn deregister_tab(&mut self, _tab_id: TabId) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_dimensions(&self) -> Dimensions {
|
||||
Dimensions {
|
||||
width: self.width,
|
||||
|
@ -37,8 +37,6 @@ pub trait TerminalWindow {
|
||||
cell_height: usize,
|
||||
) -> Result<(), Error>;
|
||||
fn advise_renderer_of_resize(&mut self, width: u16, height: u16) -> Result<(), Error>;
|
||||
fn tab_was_created(&mut self, tab: &Rc<Tab>) -> Result<(), Error>;
|
||||
fn deregister_tab(&mut self, tab_id: TabId) -> Result<(), Error>;
|
||||
fn config(&self) -> &Arc<Config>;
|
||||
fn fonts(&self) -> &Rc<FontConfiguration>;
|
||||
fn get_dimensions(&self) -> Dimensions;
|
||||
@ -179,9 +177,6 @@ pub trait TerminalWindow {
|
||||
window.len()
|
||||
};
|
||||
self.activate_tab(len - 1)?;
|
||||
|
||||
self.tab_was_created(&tab)?;
|
||||
|
||||
Ok(tab_id)
|
||||
}
|
||||
|
||||
@ -273,7 +268,6 @@ pub trait TerminalWindow {
|
||||
}
|
||||
drop(window);
|
||||
self.update_title();
|
||||
self.deregister_tab(tab_id).ok();
|
||||
}
|
||||
|
||||
// let_and_return is needed here to satisfy the borrow checker
|
||||
|
@ -135,10 +135,6 @@ impl GuiEventLoop {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn register_tab(&self, tab: &Rc<Tab>) -> Result<(), Error> {
|
||||
self.mux.add_tab(self.gui_executor(), tab)
|
||||
}
|
||||
|
||||
fn run(&self) -> Result<(), Error> {
|
||||
let mut events = Events::with_capacity(8);
|
||||
|
||||
@ -216,7 +212,6 @@ impl GuiEventLoop {
|
||||
fonts: &Rc<FontConfiguration>,
|
||||
) -> Result<(), Error> {
|
||||
let tab = self.mux.default_domain().spawn(PtySize::default(), None)?;
|
||||
self.mux.add_tab(self.gui_executor(), &tab)?;
|
||||
let events = Self::get().expect("to be called on gui thread");
|
||||
let window = X11TerminalWindow::new(&events, &fonts, &config, &tab)?;
|
||||
events.add_window(window)
|
||||
|
@ -72,12 +72,6 @@ impl TerminalWindow for X11TerminalWindow {
|
||||
fn recreate_texture_atlas(&mut self, size: u32) -> Result<(), Error> {
|
||||
self.renderer.recreate_atlas(&self.host.window, size)
|
||||
}
|
||||
fn tab_was_created(&mut self, tab: &Rc<Tab>) -> Result<(), Error> {
|
||||
self.host.event_loop.register_tab(tab)
|
||||
}
|
||||
fn deregister_tab(&mut self, _tab_id: TabId) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
fn get_dimensions(&self) -> Dimensions {
|
||||
Dimensions {
|
||||
width: self.width,
|
||||
|
@ -197,7 +197,5 @@ fn spawn_window(
|
||||
fontconfig: &Rc<FontConfiguration>,
|
||||
) -> Result<(), Error> {
|
||||
let tab = mux.default_domain().spawn(PtySize::default(), cmd)?;
|
||||
mux.add_tab(gui.gui_executor(), &tab)?;
|
||||
|
||||
gui.spawn_new_window(mux.config(), &fontconfig, &tab)
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
use crate::config::Config;
|
||||
use crate::frontend::guicommon::localtab::LocalTab;
|
||||
use crate::mux::tab::Tab;
|
||||
use crate::mux::Mux;
|
||||
use failure::Error;
|
||||
use portable_pty::cmdbuilder::CommandBuilder;
|
||||
use portable_pty::{PtySize, PtySystem};
|
||||
@ -49,6 +50,10 @@ impl Domain for LocalDomain {
|
||||
self.config.hyperlink_rules.clone(),
|
||||
);
|
||||
|
||||
Ok(Rc::new(LocalTab::new(terminal, child, master)))
|
||||
let tab: Rc<Tab> = Rc::new(LocalTab::new(terminal, child, master));
|
||||
|
||||
Mux::get().unwrap().add_tab(&tab)?;
|
||||
|
||||
Ok(tab)
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
use crate::config::Config;
|
||||
use crate::frontend::gui_executor;
|
||||
use failure::Error;
|
||||
use failure_derive::*;
|
||||
use portable_pty::ExitStatus;
|
||||
@ -28,7 +29,8 @@ pub struct Mux {
|
||||
default_domain: Arc<Domain>,
|
||||
}
|
||||
|
||||
fn read_from_tab_pty(executor: Box<Executor>, tab_id: TabId, mut reader: Box<std::io::Read>) {
|
||||
fn read_from_tab_pty(tab_id: TabId, mut reader: Box<std::io::Read>) {
|
||||
let executor = gui_executor().expect("gui_executor was not registered yet!?");
|
||||
const BUFSIZE: usize = 32 * 1024;
|
||||
let mut buf = [0; BUFSIZE];
|
||||
loop {
|
||||
@ -139,12 +141,12 @@ impl Mux {
|
||||
self.tabs.borrow().get(&tab_id).map(Rc::clone)
|
||||
}
|
||||
|
||||
pub fn add_tab(&self, executor: Box<Executor>, tab: &Rc<Tab>) -> Result<(), Error> {
|
||||
pub fn add_tab(&self, tab: &Rc<Tab>) -> Result<(), Error> {
|
||||
self.tabs.borrow_mut().insert(tab.tab_id(), Rc::clone(tab));
|
||||
|
||||
let reader = tab.reader()?;
|
||||
let tab_id = tab.tab_id();
|
||||
thread::spawn(move || read_from_tab_pty(executor, tab_id, reader));
|
||||
thread::spawn(move || read_from_tab_pty(tab_id, reader));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user