1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-22 22:42:48 +03:00

register mux as a gui thread local variable

This commit is contained in:
Wez Furlong 2019-03-04 20:44:52 +00:00
parent aa6cfb00dd
commit 12e93fce57
2 changed files with 21 additions and 0 deletions

View File

@ -125,6 +125,7 @@ fn main() -> Result<(), Error> {
};
let mux = Rc::new(mux::Mux::default());
Mux::set_mux(&mux);
let gui_system = opts.gui_system.unwrap_or(config.gui_system);
let gui = gui_system.try_new(&mux)?;

View File

@ -101,11 +101,31 @@ impl<'a> TerminalHost for Host<'a> {
fn set_title(&mut self, _title: &str) {}
}
thread_local! {
static MUX: RefCell<Option<Rc<Mux>>> = RefCell::new(None);
}
impl Mux {
pub fn set_spawner(&self, spawner: Spawner) {
*self.spawner.borrow_mut() = Some(spawner);
}
pub fn set_mux(mux: &Rc<Mux>) {
MUX.with(|m| {
*m.borrow_mut() = Some(Rc::clone(mux));
});
}
pub fn get() -> Option<Rc<Mux>> {
let mut res = None;
MUX.with(|m| {
if let Some(mux) = &*m.borrow() {
res = Some(Rc::clone(mux));
}
});
res
}
pub fn get_tab(&self, tab_id: TabId) -> Option<Rc<Tab>> {
self.tabs.borrow().get(&tab_id).map(Rc::clone)
}