1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-28 01:06:37 +03:00

Add Mux::default_domain and use it

This tidies up the various spawning call sites and
reduces some code duplication too!
This commit is contained in:
Wez Furlong 2019-03-26 08:33:12 -07:00
parent f642bd56d6
commit d4bc053493
5 changed files with 20 additions and 22 deletions

View File

@ -5,11 +5,11 @@ use crate::frontend::guicommon::window::TerminalWindow;
use crate::frontend::FrontEnd;
use crate::mux::tab::Tab;
use crate::mux::{Mux, SessionTerminated};
use crate::spawn_tab;
use failure::{bail, Error};
use glium;
use glium::glutin::EventsLoopProxy;
use glium::glutin::WindowId;
use portable_pty::PtySize;
use promise::{Executor, Future, SpawnFunc};
use std::cell::RefCell;
use std::collections::HashMap;
@ -215,7 +215,7 @@ impl GuiEventLoop {
config: &Arc<Config>,
fonts: &Rc<FontConfiguration>,
) -> Result<(), Error> {
let tab = spawn_tab(&config)?; // FIXME: Domain
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)?;

View File

@ -1,6 +1,5 @@
use crate::config::Config;
use crate::font::FontConfiguration;
use crate::mux::domain::{Domain, LocalDomain};
use crate::mux::tab::{Tab, TabId};
use crate::mux::window::WindowId;
use crate::mux::Mux;
@ -156,9 +155,6 @@ pub trait TerminalWindow {
}
fn spawn_tab(&mut self) -> Result<TabId, Error> {
let config = self.config();
let domain = LocalDomain::new(config)?; // FIXME: Domain
let dims = self.get_dimensions();
let rows = (dims.height as usize + 1) / dims.cell_height;
@ -171,9 +167,9 @@ pub trait TerminalWindow {
pixel_height: dims.height,
};
let tab = domain.spawn(size, None)?;
let tab_id = tab.tab_id();
let mux = Mux::get().unwrap();
let tab = mux.default_domain().spawn(size, None)?;
let tab_id = tab.tab_id();
let len = {
let mut window = mux

View File

@ -7,9 +7,11 @@ use crate::frontend::FrontEnd;
use crate::mux::tab::Tab;
use crate::mux::Mux;
use crate::spawn_tab;
use failure::Error;
use failure::{bail, Error};
use mio::{Events, Poll, PollOpt, Ready, Token};
use mio_extras::channel::{channel, Receiver as GuiReceiver, Sender as GuiSender};
use portable_pty::PtySize;
use promise::{Executor, Future, SpawnFunc};
use std::cell::RefCell;
use std::collections::HashMap;
@ -213,7 +215,7 @@ impl GuiEventLoop {
config: &Arc<Config>,
fonts: &Rc<FontConfiguration>,
) -> Result<(), Error> {
let tab = spawn_tab(&config)?; // FIXME: Domain
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)?;

View File

@ -17,7 +17,6 @@ mod opengl;
mod server;
use crate::frontend::{FrontEnd, FrontEndSelection};
use crate::mux::domain::{Domain, LocalDomain};
use crate::mux::tab::Tab;
use crate::mux::Mux;
use portable_pty::cmdbuilder::CommandBuilder;
@ -127,15 +126,15 @@ fn run_terminal_gui(config: Arc<config::Config>, opts: &StartCommand) -> Result<
None
};
let mux = Rc::new(mux::Mux::new(&config));
let domain: Arc<Domain> = Arc::new(LocalDomain::new(&config)?);
let mux = Rc::new(mux::Mux::new(&config, &domain));
Mux::set_mux(&mux);
let front_end = opts.front_end.unwrap_or(config.front_end);
let gui = front_end.try_new(&mux)?;
let domain = LocalDomain::new(&config)?;
spawn_window(&mux, &domain, &*gui, cmd, &fontconfig)?;
spawn_window(&mux, &*gui, cmd, &fontconfig)?;
gui.run_forever()
}
@ -191,19 +190,13 @@ fn main() -> Result<(), Error> {
}
}
fn spawn_tab(config: &Arc<config::Config>) -> Result<Rc<Tab>, Error> {
let domain = LocalDomain::new(config)?;
domain.spawn(PtySize::default(), None)
}
fn spawn_window(
mux: &Rc<Mux>,
domain: &Domain,
gui: &FrontEnd,
cmd: Option<CommandBuilder>,
fontconfig: &Rc<FontConfiguration>,
) -> Result<(), Error> {
let tab = domain.spawn(PtySize::default(), cmd)?;
let tab = mux.default_domain().spawn(PtySize::default(), cmd)?;
mux.add_tab(gui.gui_executor(), &tab)?;
gui.spawn_new_window(mux.config(), &fontconfig, &tab)

View File

@ -19,11 +19,13 @@ pub mod window;
use crate::mux::tab::{Tab, TabId};
use crate::mux::window::{Window, WindowId};
use domain::Domain;
pub struct Mux {
tabs: RefCell<HashMap<TabId, Rc<Tab>>>,
windows: RefCell<HashMap<WindowId, Window>>,
config: Arc<Config>,
default_domain: Arc<Domain>,
}
fn read_from_tab_pty(executor: Box<Executor>, tab_id: TabId, mut reader: Box<std::io::Read>) {
@ -100,14 +102,19 @@ thread_local! {
}
impl Mux {
pub fn new(config: &Arc<Config>) -> Self {
pub fn new(config: &Arc<Config>, default_domain: &Arc<Domain>) -> Self {
Self {
tabs: RefCell::new(HashMap::new()),
windows: RefCell::new(HashMap::new()),
config: Arc::clone(config),
default_domain: Arc::clone(default_domain),
}
}
pub fn default_domain(&self) -> &Arc<Domain> {
&self.default_domain
}
pub fn config(&self) -> &Arc<Config> {
&self.config
}