mirror of
https://github.com/wez/wezterm.git
synced 2024-12-25 22:33:52 +03:00
move spawn_tab to guicommon
This commit is contained in:
parent
d639ad0ffe
commit
8fdf85b4d6
@ -4,12 +4,11 @@ use crate::config::Config;
|
||||
use crate::failure::Error;
|
||||
use crate::font::FontConfiguration;
|
||||
use crate::guicommon::tabs::{Tab, TabId, Tabs};
|
||||
use crate::guicommon::window::TerminalWindow;
|
||||
use crate::guicommon::window::{Dimensions, TerminalWindow};
|
||||
use crate::guiloop::glutinloop::GuiEventLoop;
|
||||
use crate::guiloop::SessionTerminated;
|
||||
use crate::opengl::render::Renderer;
|
||||
use crate::opengl::textureatlas::OutOfTextureSpace;
|
||||
use crate::{openpty, spawn_window_impl, Child, MasterPty};
|
||||
use crate::{spawn_window_impl, Child, MasterPty};
|
||||
use clipboard::{ClipboardContext, ClipboardProvider};
|
||||
use glium;
|
||||
use glium::glutin::dpi::{LogicalPosition, LogicalSize, PhysicalPosition};
|
||||
@ -145,7 +144,7 @@ impl<'a> term::TerminalHost for TabHost<'a> {
|
||||
GuiEventLoop::with_window(
|
||||
&self.host.event_loop,
|
||||
self.host.display.gl_window().id(),
|
||||
|win| win.spawn_tab(),
|
||||
|win| win.spawn_tab().map(|_| ()),
|
||||
);
|
||||
}
|
||||
|
||||
@ -219,6 +218,12 @@ impl TerminalWindow for GliumTerminalWindow {
|
||||
fn get_tabs_mut(&mut self) -> &mut Tabs {
|
||||
&mut self.tabs
|
||||
}
|
||||
fn config(&self) -> &Rc<Config> {
|
||||
&self.config
|
||||
}
|
||||
fn fonts(&self) -> &Rc<FontConfiguration> {
|
||||
&self.fonts
|
||||
}
|
||||
|
||||
fn set_window_title(&mut self, title: &str) -> Result<(), Error> {
|
||||
self.host.display.gl_window().set_title(title);
|
||||
@ -241,6 +246,23 @@ impl TerminalWindow for GliumTerminalWindow {
|
||||
self.tabs.get_active().unwrap().terminal(),
|
||||
)
|
||||
}
|
||||
fn tab_was_created(&mut self, tab_id: TabId) -> Result<(), Error> {
|
||||
match self.tabs.get_by_id(tab_id) {
|
||||
Ok(tab) => {
|
||||
self.event_loop
|
||||
.schedule_read_pty(tab.pty().try_clone()?, self.window_id(), tab_id)
|
||||
}
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
fn get_dimensions(&self) -> Dimensions {
|
||||
Dimensions {
|
||||
width: self.width,
|
||||
height: self.height,
|
||||
cell_height: self.cell_height,
|
||||
cell_width: self.cell_width,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GliumTerminalWindow {
|
||||
@ -324,36 +346,6 @@ impl GliumTerminalWindow {
|
||||
.tab_id()
|
||||
}
|
||||
|
||||
pub fn spawn_tab(&mut self) -> Result<(), Error> {
|
||||
let rows = (self.height as usize + 1) / self.cell_height;
|
||||
let cols = (self.width as usize + 1) / self.cell_width;
|
||||
|
||||
let (pty, slave) = openpty(rows as u16, cols as u16, self.width, self.height)?;
|
||||
let cmd = self.config.build_prog(None)?;
|
||||
|
||||
let process = slave.spawn_command(cmd)?;
|
||||
eprintln!("spawned: {:?}", process);
|
||||
|
||||
let terminal = term::Terminal::new(
|
||||
rows,
|
||||
cols,
|
||||
self.config.scrollback_lines.unwrap_or(3500),
|
||||
self.config.hyperlink_rules.clone(),
|
||||
);
|
||||
|
||||
let cloned_pty = pty.try_clone()?;
|
||||
let tab = Tab::new(terminal, process, pty);
|
||||
|
||||
self.event_loop
|
||||
.schedule_read_pty(cloned_pty, self.window_id(), tab.tab_id())?;
|
||||
|
||||
self.tabs.push(tab);
|
||||
let len = self.tabs.len();
|
||||
self.activate_tab(len - 1)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn window_id(&self) -> glutin::WindowId {
|
||||
self.host.display.gl_window().id()
|
||||
}
|
||||
|
@ -1,10 +1,20 @@
|
||||
use crate::guicommon::tabs::Tabs;
|
||||
use crate::config::Config;
|
||||
use crate::font::FontConfiguration;
|
||||
use crate::guicommon::tabs::{Tab, TabId, Tabs};
|
||||
use crate::opengl::render::Renderer;
|
||||
use crate::opengl::textureatlas::OutOfTextureSpace;
|
||||
use crate::pty::unix::openpty;
|
||||
use failure::Error;
|
||||
use glium;
|
||||
use glium::backend::Facade;
|
||||
use std::cell::RefMut;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Dimensions {
|
||||
pub width: u16,
|
||||
pub height: u16,
|
||||
pub cell_height: usize,
|
||||
pub cell_width: usize,
|
||||
}
|
||||
|
||||
pub trait TerminalWindow {
|
||||
fn get_tabs_mut(&mut self) -> &mut Tabs;
|
||||
@ -14,6 +24,10 @@ pub trait TerminalWindow {
|
||||
fn renderer(&mut self) -> &mut Renderer;
|
||||
fn renderer_and_terminal(&mut self) -> (&mut Renderer, RefMut<term::Terminal>);
|
||||
fn recreate_texture_atlas(&mut self, size: u32) -> Result<(), Error>;
|
||||
fn tab_was_created(&mut self, tab_id: TabId) -> Result<(), Error>;
|
||||
fn config(&self) -> &Rc<Config>;
|
||||
fn fonts(&self) -> &Rc<FontConfiguration>;
|
||||
fn get_dimensions(&self) -> Dimensions;
|
||||
|
||||
fn activate_tab(&mut self, tab_idx: usize) -> Result<(), Error> {
|
||||
let max = self.get_tabs().len();
|
||||
@ -99,4 +113,37 @@ pub trait TerminalWindow {
|
||||
Ok(_) => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
fn spawn_tab(&mut self) -> Result<TabId, Error> {
|
||||
let config = self.config();
|
||||
|
||||
let dims = self.get_dimensions();
|
||||
|
||||
let rows = (dims.height as usize + 1) / dims.cell_height;
|
||||
let cols = (dims.width as usize + 1) / dims.cell_width;
|
||||
|
||||
let (pty, slave) = openpty(rows as u16, cols as u16, dims.width, dims.height)?;
|
||||
let cmd = config.build_prog(None)?;
|
||||
|
||||
let process = slave.spawn_command(cmd)?;
|
||||
eprintln!("spawned: {:?}", process);
|
||||
|
||||
let terminal = term::Terminal::new(
|
||||
rows,
|
||||
cols,
|
||||
config.scrollback_lines.unwrap_or(3500),
|
||||
config.hyperlink_rules.clone(),
|
||||
);
|
||||
|
||||
let tab = Tab::new(terminal, process, pty);
|
||||
let tab_id = tab.tab_id();
|
||||
|
||||
self.get_tabs_mut().push(tab);
|
||||
let len = self.get_tabs().len();
|
||||
self.activate_tab(len - 1)?;
|
||||
|
||||
self.tab_was_created(tab_id)?;
|
||||
|
||||
Ok(tab_id)
|
||||
}
|
||||
}
|
||||
|
@ -5,11 +5,10 @@ use super::{Connection, Window};
|
||||
use crate::config::Config;
|
||||
use crate::font::FontConfiguration;
|
||||
use crate::guicommon::tabs::{Tab, TabId, Tabs};
|
||||
use crate::guicommon::window::TerminalWindow;
|
||||
use crate::guicommon::window::{Dimensions, TerminalWindow};
|
||||
use crate::guiloop::x11::{GuiEventLoop, WindowId};
|
||||
use crate::guiloop::SessionTerminated;
|
||||
use crate::opengl::textureatlas::OutOfTextureSpace;
|
||||
use crate::{openpty, MasterPty};
|
||||
use crate::MasterPty;
|
||||
use clipboard::{ClipboardContext, ClipboardProvider};
|
||||
use failure::Error;
|
||||
use futures;
|
||||
@ -169,6 +168,12 @@ impl TerminalWindow for X11TerminalWindow {
|
||||
fn get_tabs_mut(&mut self) -> &mut Tabs {
|
||||
&mut self.tabs
|
||||
}
|
||||
fn config(&self) -> &Rc<Config> {
|
||||
&self.host.config
|
||||
}
|
||||
fn fonts(&self) -> &Rc<FontConfiguration> {
|
||||
&self.host.fonts
|
||||
}
|
||||
|
||||
fn set_window_title(&mut self, title: &str) -> Result<(), Error> {
|
||||
self.host.window.set_title(title);
|
||||
@ -190,6 +195,17 @@ impl TerminalWindow for X11TerminalWindow {
|
||||
self.tabs.get_active().unwrap().terminal(),
|
||||
)
|
||||
}
|
||||
fn tab_was_created(&mut self, _tab_id: TabId) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
fn get_dimensions(&self) -> Dimensions {
|
||||
Dimensions {
|
||||
width: self.width,
|
||||
height: self.height,
|
||||
cell_height: self.cell_height,
|
||||
cell_width: self.cell_width,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl X11TerminalWindow {
|
||||
@ -486,31 +502,4 @@ impl X11TerminalWindow {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn spawn_tab(&mut self) -> Result<TabId, Error> {
|
||||
let rows = (self.height as usize + 1) / self.cell_height;
|
||||
let cols = (self.width as usize + 1) / self.cell_width;
|
||||
|
||||
let (pty, slave) = openpty(rows as u16, cols as u16, self.width, self.height)?;
|
||||
let cmd = self.host.config.build_prog(None)?;
|
||||
|
||||
let process = slave.spawn_command(cmd)?;
|
||||
eprintln!("spawned: {:?}", process);
|
||||
|
||||
let terminal = term::Terminal::new(
|
||||
rows,
|
||||
cols,
|
||||
self.host.config.scrollback_lines.unwrap_or(3500),
|
||||
self.host.config.hyperlink_rules.clone(),
|
||||
);
|
||||
|
||||
let tab = Tab::new(terminal, process, pty);
|
||||
let tab_id = tab.tab_id();
|
||||
|
||||
self.tabs.push(tab);
|
||||
let len = self.tabs.len();
|
||||
self.activate_tab(len - 1)?;
|
||||
|
||||
Ok(tab_id)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user