1
1
mirror of https://github.com/wez/wezterm.git synced 2024-10-26 15:52:29 +03:00

dyn everywhere

This commit is contained in:
Wez Furlong 2019-06-08 21:28:11 -07:00
parent f41c62c07b
commit 5ebad9e63a
23 changed files with 113 additions and 125 deletions

View File

@ -63,14 +63,14 @@ const DECTAB: [u8; 256] = [
/// maintains up to 2 bytes of pending data; the Drop impl will implicitly flush on
/// your behalf, but will mask any error that may occur during the flush.
pub struct Base91Encoder<'a> {
writer: &'a mut Write,
writer: &'a mut dyn Write,
accumulator: u64,
bits: u32,
}
impl<'a> Base91Encoder<'a> {
/// Construct a Base91Encoder that writes encoded data to the supplied writer
pub fn new(writer: &'a mut Write) -> Self {
pub fn new(writer: &'a mut dyn Write) -> Self {
Self {
writer,
accumulator: 0,
@ -149,14 +149,14 @@ pub fn encode(buf: &[u8]) -> Vec<u8> {
/// maintains up to 1 byte of pending data; the Drop impl will implicitly flush on
/// your behalf, but will mask any error that may occur during the flush.
pub struct Base91Decoder<'a> {
writer: &'a mut Write,
writer: &'a mut dyn Write,
accumulator: u64,
bits: u32,
value: Option<u8>,
}
impl<'a> Base91Decoder<'a> {
pub fn new(writer: &'a mut Write) -> Self {
pub fn new(writer: &'a mut dyn Write) -> Self {
Self {
writer,
accumulator: 0,

View File

@ -6,14 +6,14 @@ pub type SpawnFunc = Box<dyn FnOnce() + Send>;
pub trait Executor: Send {
fn execute(&self, f: SpawnFunc);
fn clone_executor(&self) -> Box<Executor>;
fn clone_executor(&self) -> Box<dyn Executor>;
}
impl Executor for Box<Executor> {
impl Executor for Box<dyn Executor> {
fn execute(&self, f: SpawnFunc) {
Executor::execute(&**self, f)
}
fn clone_executor(&self) -> Box<Executor> {
fn clone_executor(&self) -> Box<dyn Executor> {
Executor::clone_executor(&**self)
}
}
@ -33,7 +33,7 @@ impl Executor for RayonExecutor {
fn execute(&self, f: SpawnFunc) {
rayon::spawn(f);
}
fn clone_executor(&self) -> Box<Executor> {
fn clone_executor(&self) -> Box<dyn Executor> {
Box::new(RayonExecutor::new())
}
}

View File

@ -85,7 +85,7 @@ pub trait MasterPty: std::io::Write {
fn get_size(&self) -> Result<PtySize, Error>;
/// Obtain a readable handle; output from the slave(s) is readable
/// via this stream.
fn try_clone_reader(&self) -> Result<Box<std::io::Read + Send>, Error>;
fn try_clone_reader(&self) -> Result<Box<dyn std::io::Read + Send>, Error>;
}
/// Represents a child process spawned into the pty.
@ -107,7 +107,7 @@ pub trait Child: std::fmt::Debug {
/// Can be used to spawn processes into the pty.
pub trait SlavePty {
/// Spawns the command specified by the provided CommandBuilder
fn spawn_command(&self, cmd: CommandBuilder) -> Result<Box<Child>, Error>;
fn spawn_command(&self, cmd: CommandBuilder) -> Result<Box<dyn Child>, Error>;
}
/// Represents the exit status of a child process.
@ -146,7 +146,7 @@ pub trait PtySystem {
/// Create a new Pty instance with the window size set to the specified
/// dimensions. Returns a (master, slave) Pty pair. The master side
/// is used to drive the slave side.
fn openpty(&self, size: PtySize) -> Result<(Box<MasterPty>, Box<SlavePty>), Error>;
fn openpty(&self, size: PtySize) -> Result<(Box<dyn MasterPty>, Box<dyn SlavePty>), Error>;
}
impl Child for std::process::Child {
@ -188,7 +188,7 @@ impl PtySystemSelection {
/// Construct an instance of PtySystem described by the enum value.
/// Windows specific enum variants result in an error.
#[cfg(unix)]
pub fn get(&self) -> Result<Box<PtySystem>, Error> {
pub fn get(&self) -> Result<Box<dyn PtySystem>, Error> {
match self {
PtySystemSelection::Unix => Ok(Box::new(unix::UnixPtySystem {})),
_ => bail!("{:?} not available on unix", self),

View File

@ -13,7 +13,7 @@ use std::ptr;
pub struct UnixPtySystem {}
impl PtySystem for UnixPtySystem {
fn openpty(&self, size: PtySize) -> Result<(Box<MasterPty>, Box<SlavePty>), Error> {
fn openpty(&self, size: PtySize) -> Result<(Box<dyn MasterPty>, Box<dyn SlavePty>), Error> {
let mut master: RawFd = -1;
let mut slave: RawFd = -1;
@ -128,15 +128,15 @@ fn set_nonblocking(fd: RawFd) -> Result<(), Error> {
}
impl SlavePty for UnixSlavePty {
fn spawn_command(&self, builder: CommandBuilder) -> Result<Box<Child>, Error> {
fn spawn_command(&self, builder: CommandBuilder) -> Result<Box<dyn Child>, Error> {
let mut cmd = builder.as_command();
cmd.stdin(self.as_stdio()?)
.stdout(self.as_stdio()?)
.stderr(self.as_stdio()?)
.before_exec(move || {
// Clean up a few things before we exec the program
unsafe {
unsafe {
cmd.stdin(self.as_stdio()?)
.stdout(self.as_stdio()?)
.stderr(self.as_stdio()?)
.pre_exec(move || {
// Clean up a few things before we exec the program
// Clear out any potentially problematic signal
// dispositions that we might have inherited
for signo in &[
@ -170,8 +170,8 @@ impl SlavePty for UnixSlavePty {
}
}
Ok(())
}
});
})
};
let mut child = cmd.spawn()?;
@ -232,7 +232,7 @@ impl MasterPty for UnixMasterPty {
})
}
fn try_clone_reader(&self) -> Result<Box<std::io::Read + Send>, Error> {
fn try_clone_reader(&self) -> Result<Box<dyn std::io::Read + Send>, Error> {
let fd = self.fd.try_clone()?;
Ok(Box::new(fd))
}

View File

@ -24,7 +24,7 @@ impl FontSystem for FontConfigAndFreeType {
config: &Config,
style: &TextStyle,
font_scale: f64,
) -> Result<Box<NamedFont>, Error> {
) -> Result<Box<dyn NamedFont>, Error> {
let fonts = style.font_with_fallback();
let mut pattern = if !fonts.is_empty() {
let mut pattern = FontPattern::new()?;
@ -72,7 +72,7 @@ impl Drop for NamedFontImpl {
}
impl NamedFont for NamedFontImpl {
fn get_fallback(&mut self, idx: FallbackIdx) -> Result<&Font, Error> {
fn get_fallback(&mut self, idx: FallbackIdx) -> Result<&dyn Font, Error> {
Ok(self.get_font(idx)?)
}
fn shape(&mut self, s: &str) -> Result<Vec<GlyphInfo>, Error> {

View File

@ -31,13 +31,13 @@ pub mod fontloader_and_freetype;
use super::config::{Config, TextStyle};
use term::CellAttributes;
type FontPtr = Rc<RefCell<Box<NamedFont>>>;
type FontPtr = Rc<RefCell<Box<dyn NamedFont>>>;
/// Matches and loads fonts for a given input style
pub struct FontConfiguration {
config: Arc<Config>,
fonts: RefCell<HashMap<TextStyle, FontPtr>>,
system: Rc<FontSystem>,
system: Rc<dyn FontSystem>,
metrics: RefCell<Option<FontMetrics>>,
dpi_scale: RefCell<f64>,
font_scale: RefCell<f64>,
@ -69,7 +69,7 @@ thread_local! {
}
impl FontSystemSelection {
fn new_font_system(self) -> Rc<FontSystem> {
fn new_font_system(self) -> Rc<dyn FontSystem> {
match self {
FontSystemSelection::FontConfigAndFreeType => {
#[cfg(all(unix, any(feature = "fontconfig", not(target_os = "macos"))))]
@ -142,7 +142,7 @@ impl FontConfiguration {
/// Given a text style, load (with caching) the font that best
/// matches according to the fontconfig pattern.
pub fn cached_font(&self, style: &TextStyle) -> Result<Rc<RefCell<Box<NamedFont>>>, Error> {
pub fn cached_font(&self, style: &TextStyle) -> Result<Rc<RefCell<Box<dyn NamedFont>>>, Error> {
let mut fonts = self.fonts.borrow_mut();
if let Some(entry) = fonts.get(style) {
@ -167,7 +167,7 @@ impl FontConfiguration {
}
/// Returns the baseline font specified in the configuration
pub fn default_font(&self) -> Result<Rc<RefCell<Box<NamedFont>>>, Error> {
pub fn default_font(&self) -> Result<Rc<RefCell<Box<dyn NamedFont>>>, Error> {
self.cached_font(&self.config.font)
}
@ -234,7 +234,7 @@ impl FontConfiguration {
#[allow(dead_code)]
pub fn shape_with_harfbuzz(
font: &mut NamedFont,
font: &mut dyn NamedFont,
font_idx: system::FallbackIdx,
s: &str,
) -> Result<Vec<GlyphInfo>, Error> {

View File

@ -73,7 +73,7 @@ pub type FallbackIdx = usize;
/// zero as the best/most preferred font.
pub trait NamedFont {
/// Get a reference to a numbered fallback Font instance
fn get_fallback(&mut self, idx: FallbackIdx) -> Result<&Font, Error>;
fn get_fallback(&mut self, idx: FallbackIdx) -> Result<&dyn Font, Error>;
/// Shape text and return a vector of GlyphInfo
fn shape(&mut self, text: &str) -> Result<Vec<GlyphInfo>, Error>;
@ -88,7 +88,7 @@ pub trait FontSystem {
config: &Config,
style: &TextStyle,
font_scale: f64,
) -> Result<Box<NamedFont>, Error>;
) -> Result<Box<dyn NamedFont>, Error>;
}
/// Describes the key font metrics that we use in rendering

View File

@ -71,7 +71,7 @@ impl Executor for GlutinGuiExecutor {
fn execute(&self, f: SpawnFunc) {
self.tx.send(f).expect("GlutinExecutor execute failed");
}
fn clone_executor(&self) -> Box<Executor> {
fn clone_executor(&self) -> Box<dyn Executor> {
Box::new(GlutinGuiExecutor {
tx: Arc::clone(&self.tx),
})
@ -109,7 +109,7 @@ thread_local! {
}
impl GlutinFrontEnd {
pub fn try_new(mux: &Rc<Mux>) -> Result<Rc<FrontEnd>, Error> {
pub fn try_new(mux: &Rc<Mux>) -> Result<Rc<dyn FrontEnd>, Error> {
let event_loop = Rc::new(GuiEventLoop::new(mux)?);
GLUTIN_EVENT_LOOP.with(|f| *f.borrow_mut() = Some(Rc::clone(&event_loop)));
Ok(Rc::new(Self { event_loop }))
@ -117,7 +117,7 @@ impl GlutinFrontEnd {
}
impl FrontEnd for GlutinFrontEnd {
fn gui_executor(&self) -> Box<Executor> {
fn gui_executor(&self) -> Box<dyn Executor> {
self.event_loop.gui_executor()
}
@ -146,7 +146,7 @@ impl FrontEnd for GlutinFrontEnd {
&self,
config: &Arc<Config>,
fontconfig: &Rc<FontConfiguration>,
tab: &Rc<Tab>,
tab: &Rc<dyn Tab>,
) -> Result<(), Error> {
let window = GliumTerminalWindow::new(&self.event_loop, fontconfig, config, tab)?;
@ -198,13 +198,13 @@ impl GuiEventLoop {
self.gui_thread_sends.borrow_mut().push_back(func);
}
fn gui_executor(&self) -> Box<Executor> {
fn gui_executor(&self) -> Box<dyn Executor> {
Box::new(GlutinGuiExecutor {
tx: self.gui_tx.clone(),
})
}
pub fn with_window<F: Send + 'static + Fn(&mut TerminalWindow) -> Result<(), Error>>(
pub fn with_window<F: Send + 'static + Fn(&mut dyn TerminalWindow) -> Result<(), Error>>(
&self,
window_id: WindowId,
func: F,

View File

@ -33,7 +33,7 @@ struct Host {
}
impl HostHelper for Host {
fn with_window<F: Send + 'static + Fn(&mut TerminalWindow) -> Result<(), Error>>(
fn with_window<F: Send + 'static + Fn(&mut dyn TerminalWindow) -> Result<(), Error>>(
&self,
func: F,
) {
@ -194,7 +194,7 @@ impl GliumTerminalWindow {
event_loop: &Rc<GuiEventLoop>,
fonts: &Rc<FontConfiguration>,
config: &Arc<Config>,
tab: &Rc<Tab>,
tab: &Rc<dyn Tab>,
) -> Result<GliumTerminalWindow, Error> {
let (physical_rows, physical_cols) = tab.renderer().physical_dimensions();

View File

@ -36,7 +36,7 @@ pub enum KeyAssignment {
}
pub trait HostHelper {
fn with_window<F: Send + 'static + Fn(&mut TerminalWindow) -> Result<(), Error>>(
fn with_window<F: Send + 'static + Fn(&mut dyn TerminalWindow) -> Result<(), Error>>(
&self,
func: F,
);
@ -214,7 +214,7 @@ impl<H: HostHelper> HostImpl<H> {
pub fn perform_key_assignment(
&mut self,
tab: &Tab,
tab: &dyn Tab,
assignment: &KeyAssignment,
) -> Fallible<()> {
use KeyAssignment::*;
@ -252,7 +252,7 @@ impl<H: HostHelper> HostImpl<H> {
pub fn process_gui_shortcuts(
&mut self,
tab: &Tab,
tab: &dyn Tab,
mods: KeyModifiers,
key: KeyCode,
) -> Result<bool, Error> {
@ -341,18 +341,18 @@ impl<H: HostHelper> DerefMut for HostImpl<H> {
/// `TabHost` instances are short lived and borrow references to
/// other state.
pub struct TabHost<'a, H: HostHelper> {
writer: &'a mut std::io::Write,
writer: &'a mut dyn std::io::Write,
host: &'a mut HostImpl<H>,
}
impl<'a, H: HostHelper> TabHost<'a, H> {
pub fn new(writer: &'a mut std::io::Write, host: &'a mut HostImpl<H>) -> Self {
pub fn new(writer: &'a mut dyn std::io::Write, host: &'a mut HostImpl<H>) -> Self {
Self { writer, host }
}
}
impl<'a, H: HostHelper> term::TerminalHost for TabHost<'a, H> {
fn writer(&mut self) -> &mut std::io::Write {
fn writer(&mut self) -> &mut dyn std::io::Write {
&mut self.writer
}

View File

@ -9,8 +9,8 @@ use term::{KeyCode, KeyModifiers, MouseEvent, Terminal, TerminalHost};
pub struct LocalTab {
tab_id: TabId,
terminal: RefCell<Terminal>,
process: RefCell<Box<Child>>,
pty: RefCell<Box<MasterPty>>,
process: RefCell<Box<dyn Child>>,
pty: RefCell<Box<dyn MasterPty>>,
}
impl Tab for LocalTab {
@ -19,7 +19,7 @@ impl Tab for LocalTab {
self.tab_id
}
fn renderer(&self) -> RefMut<Renderable> {
fn renderer(&self) -> RefMut<dyn Renderable> {
RefMut::map(self.terminal.borrow_mut(), |t| &mut *t)
}
@ -31,11 +31,11 @@ impl Tab for LocalTab {
}
}
fn advance_bytes(&self, buf: &[u8], host: &mut TerminalHost) {
fn advance_bytes(&self, buf: &[u8], host: &mut dyn TerminalHost) {
self.terminal.borrow_mut().advance_bytes(buf, host)
}
fn mouse_event(&self, event: MouseEvent, host: &mut TerminalHost) -> Result<(), Error> {
fn mouse_event(&self, event: MouseEvent, host: &mut dyn TerminalHost) -> Result<(), Error> {
self.terminal.borrow_mut().mouse_event(event, host)
}
@ -64,11 +64,11 @@ impl Tab for LocalTab {
Ok(())
}
fn writer(&self) -> RefMut<std::io::Write> {
fn writer(&self) -> RefMut<dyn std::io::Write> {
self.pty.borrow_mut()
}
fn reader(&self) -> Result<Box<std::io::Read + Send>, Error> {
fn reader(&self) -> Result<Box<dyn std::io::Read + Send>, Error> {
self.pty.borrow_mut().try_clone_reader()
}
@ -88,7 +88,7 @@ impl Tab for LocalTab {
}
impl LocalTab {
pub fn new(terminal: Terminal, process: Box<Child>, pty: Box<MasterPty>) -> Self {
pub fn new(terminal: Terminal, process: Box<dyn Child>, pty: Box<dyn MasterPty>) -> Self {
let tab_id = alloc_tab_id();
Self {
tab_id,

View File

@ -284,7 +284,7 @@ pub trait TerminalWindow {
Some(window) => window,
None => return true,
};
let dead_tabs: Vec<Rc<Tab>> = window
let dead_tabs: Vec<Rc<dyn Tab>> = window
.iter()
.filter_map(|tab| {
if tab.is_dead() {

View File

@ -37,13 +37,13 @@ impl Default for FrontEndSelection {
}
lazy_static! {
static ref EXECUTOR: Mutex<Option<Box<Executor>>> = Mutex::new(None);
static ref EXECUTOR: Mutex<Option<Box<dyn Executor>>> = Mutex::new(None);
}
thread_local! {
static FRONT_END: RefCell<Option<Rc<FrontEnd>>> = RefCell::new(None);
static FRONT_END: RefCell<Option<Rc<dyn FrontEnd>>> = RefCell::new(None);
}
pub fn gui_executor() -> Option<Box<Executor>> {
pub fn gui_executor() -> Option<Box<dyn Executor>> {
let locked = EXECUTOR.lock().unwrap();
match locked.as_ref() {
Some(exec) => Some(exec.clone_executor()),
@ -51,7 +51,7 @@ pub fn gui_executor() -> Option<Box<Executor>> {
}
}
pub fn front_end() -> Option<Rc<FrontEnd>> {
pub fn front_end() -> Option<Rc<dyn FrontEnd>> {
let mut res = None;
FRONT_END.with(|f| {
if let Some(me) = &*f.borrow() {
@ -62,7 +62,7 @@ pub fn front_end() -> Option<Rc<FrontEnd>> {
}
impl FrontEndSelection {
pub fn try_new(self, mux: &Rc<Mux>) -> Result<Rc<FrontEnd>, Error> {
pub fn try_new(self, mux: &Rc<Mux>) -> Result<Rc<dyn FrontEnd>, Error> {
let front_end = match self {
FrontEndSelection::Glutin => glium::glutinloop::GlutinFrontEnd::try_new(mux),
#[cfg(all(unix, not(target_os = "macos")))]
@ -111,8 +111,8 @@ pub trait FrontEnd {
&self,
config: &Arc<Config>,
fontconfig: &Rc<FontConfiguration>,
tab: &Rc<Tab>,
tab: &Rc<dyn Tab>,
) -> Result<(), Error>;
fn gui_executor(&self) -> Box<Executor>;
fn gui_executor(&self) -> Box<dyn Executor>;
}

View File

@ -22,7 +22,7 @@ impl Executor for MuxExecutor {
fn execute(&self, f: SpawnFunc) {
self.tx.send(f).expect("MuxExecutor execute failed");
}
fn clone_executor(&self) -> Box<Executor> {
fn clone_executor(&self) -> Box<dyn Executor> {
Box::new(MuxExecutor {
tx: self.tx.clone(),
})
@ -36,7 +36,7 @@ pub struct MuxServerFrontEnd {
impl MuxServerFrontEnd {
#[cfg_attr(feature = "cargo-clippy", allow(clippy::new_ret_no_self))]
fn new(mux: &Rc<Mux>, start_listener: bool) -> Result<Rc<FrontEnd>, Error> {
fn new(mux: &Rc<Mux>, start_listener: bool) -> Result<Rc<dyn FrontEnd>, Error> {
let (tx, rx) = mpsc::sync_channel(4);
if start_listener {
@ -45,17 +45,17 @@ impl MuxServerFrontEnd {
Ok(Rc::new(Self { tx, rx }))
}
pub fn try_new(mux: &Rc<Mux>) -> Result<Rc<FrontEnd>, Error> {
pub fn try_new(mux: &Rc<Mux>) -> Result<Rc<dyn FrontEnd>, Error> {
Self::new(mux, true)
}
pub fn new_null(mux: &Rc<Mux>) -> Result<Rc<FrontEnd>, Error> {
pub fn new_null(mux: &Rc<Mux>) -> Result<Rc<dyn FrontEnd>, Error> {
Self::new(mux, false)
}
}
impl FrontEnd for MuxServerFrontEnd {
fn gui_executor(&self) -> Box<Executor> {
fn gui_executor(&self) -> Box<dyn Executor> {
Box::new(MuxExecutor {
tx: self.tx.clone(),
})
@ -79,7 +79,7 @@ impl FrontEnd for MuxServerFrontEnd {
&self,
_config: &Arc<Config>,
_fontconfig: &Rc<FontConfiguration>,
_tab: &Rc<Tab>,
_tab: &Rc<dyn Tab>,
) -> Result<(), Error> {
// The tab was already added to the mux, so we are a NOP
Ok(())

View File

@ -10,7 +10,6 @@ use failure::{bail, Error};
use log::debug;
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;
@ -36,7 +35,7 @@ impl Executor for X11GuiExecutor {
fn execute(&self, f: SpawnFunc) {
self.tx.send(f).expect("X11GuiExecutor execute failed");
}
fn clone_executor(&self) -> Box<Executor> {
fn clone_executor(&self) -> Box<dyn Executor> {
Box::new(X11GuiExecutor {
tx: self.tx.clone(),
})
@ -60,7 +59,7 @@ pub struct X11FrontEnd {
event_loop: Rc<GuiEventLoop>,
}
impl X11FrontEnd {
pub fn try_new(mux: &Rc<Mux>) -> Result<Rc<FrontEnd>, Error> {
pub fn try_new(mux: &Rc<Mux>) -> Result<Rc<dyn FrontEnd>, Error> {
let event_loop = Rc::new(GuiEventLoop::new(mux)?);
X11_EVENT_LOOP.with(|f| *f.borrow_mut() = Some(Rc::clone(&event_loop)));
Ok(Rc::new(Self { event_loop }))
@ -72,7 +71,7 @@ thread_local! {
}
impl FrontEnd for X11FrontEnd {
fn gui_executor(&self) -> Box<Executor> {
fn gui_executor(&self) -> Box<dyn Executor> {
self.event_loop.gui_executor()
}
@ -83,7 +82,7 @@ impl FrontEnd for X11FrontEnd {
&self,
config: &Arc<Config>,
fontconfig: &Rc<FontConfiguration>,
tab: &Rc<Tab>,
tab: &Rc<dyn Tab>,
) -> Result<(), Error> {
let window = X11TerminalWindow::new(&self.event_loop, fontconfig, config, tab)?;
@ -128,7 +127,7 @@ impl GuiEventLoop {
res
}
fn gui_executor(&self) -> Box<Executor> {
fn gui_executor(&self) -> Box<dyn Executor> {
Box::new(X11GuiExecutor {
tx: self.gui_tx.clone(),
})
@ -183,7 +182,7 @@ impl GuiEventLoop {
/// Run a function with access to the mutable version of the window with
/// the specified window id
pub fn with_window<F: Send + 'static + Fn(&mut TerminalWindow) -> Result<(), Error>>(
pub fn with_window<F: Send + 'static + Fn(&mut dyn TerminalWindow) -> Result<(), Error>>(
&self,
window_id: WindowId,
func: F,
@ -205,17 +204,6 @@ impl GuiEventLoop {
Ok(())
}
fn do_spawn_new_window(
&self,
config: &Arc<Config>,
fonts: &Rc<FontConfiguration>,
) -> Result<(), Error> {
let tab = self.mux.default_domain().spawn(PtySize::default(), None)?;
let events = Self::get().expect("to be called on gui thread");
let window = X11TerminalWindow::new(&events, &fonts, &config, &tab)?;
events.add_window(window)
}
pub fn add_window(&self, window: X11TerminalWindow) -> Result<(), Error> {
let window_id = window.window_id();

View File

@ -25,7 +25,7 @@ struct Host {
}
impl HostHelper for Host {
fn with_window<F: Send + 'static + Fn(&mut TerminalWindow) -> Result<(), Error>>(
fn with_window<F: Send + 'static + Fn(&mut dyn TerminalWindow) -> Result<(), Error>>(
&self,
func: F,
) {
@ -115,7 +115,7 @@ impl X11TerminalWindow {
event_loop: &Rc<GuiEventLoop>,
fonts: &Rc<FontConfiguration>,
config: &Arc<Config>,
tab: &Rc<Tab>,
tab: &Rc<dyn Tab>,
) -> Result<X11TerminalWindow, Error> {
let (physical_rows, physical_cols) = tab.renderer().physical_dimensions();

View File

@ -125,7 +125,7 @@ fn run_terminal_gui(config: Arc<config::Config>, opts: &StartCommand) -> Result<
None
};
let domain: Arc<Domain> = Arc::new(LocalDomain::new(&config)?);
let domain: Arc<dyn Domain> = Arc::new(LocalDomain::new(&config)?);
let mux = Rc::new(mux::Mux::new(&config, &domain));
Mux::set_mux(&mux);
@ -192,7 +192,7 @@ fn main() -> Result<(), Error> {
fn spawn_window(
mux: &Rc<Mux>,
gui: &FrontEnd,
gui: &dyn FrontEnd,
cmd: Option<CommandBuilder>,
fontconfig: &Rc<FontConfiguration>,
) -> Result<(), Error> {

View File

@ -18,11 +18,11 @@ use std::sync::Arc;
pub trait Domain {
/// Spawn a new command within this domain
fn spawn(&self, size: PtySize, command: Option<CommandBuilder>) -> Result<Rc<Tab>, Error>;
fn spawn(&self, size: PtySize, command: Option<CommandBuilder>) -> Result<Rc<dyn Tab>, Error>;
}
pub struct LocalDomain {
pty_system: Box<PtySystem>,
pty_system: Box<dyn PtySystem>,
config: Arc<Config>,
}
@ -35,7 +35,7 @@ impl LocalDomain {
}
impl Domain for LocalDomain {
fn spawn(&self, size: PtySize, command: Option<CommandBuilder>) -> Result<Rc<Tab>, Error> {
fn spawn(&self, size: PtySize, command: Option<CommandBuilder>) -> Result<Rc<dyn Tab>, Error> {
let cmd = match command {
Some(c) => c,
None => self.config.build_prog(None)?,
@ -51,7 +51,7 @@ impl Domain for LocalDomain {
self.config.hyperlink_rules.clone(),
);
let tab: Rc<Tab> = Rc::new(LocalTab::new(terminal, child, master));
let tab: Rc<dyn Tab> = Rc::new(LocalTab::new(terminal, child, master));
Mux::get().unwrap().add_tab(&tab)?;

View File

@ -24,13 +24,13 @@ use crate::mux::window::{Window, WindowId};
use domain::Domain;
pub struct Mux {
tabs: RefCell<HashMap<TabId, Rc<Tab>>>,
tabs: RefCell<HashMap<TabId, Rc<dyn Tab>>>,
windows: RefCell<HashMap<WindowId, Window>>,
config: Arc<Config>,
default_domain: Arc<Domain>,
default_domain: Arc<dyn Domain>,
}
fn read_from_tab_pty(tab_id: TabId, mut reader: Box<std::io::Read>) {
fn read_from_tab_pty(tab_id: TabId, mut reader: Box<dyn std::io::Read>) {
let executor = gui_executor().expect("gui_executor was not registered yet!?");
const BUFSIZE: usize = 32 * 1024;
let mut buf = [0; BUFSIZE];
@ -73,11 +73,11 @@ fn read_from_tab_pty(tab_id: TabId, mut reader: Box<std::io::Read>) {
/// As such it only really has Host::writer get called.
/// The GUI driven flows provide their own impl of TerminalHost.
struct Host<'a> {
writer: &'a mut std::io::Write,
writer: &'a mut dyn std::io::Write,
}
impl<'a> TerminalHost for Host<'a> {
fn writer(&mut self) -> &mut std::io::Write {
fn writer(&mut self) -> &mut dyn std::io::Write {
&mut self.writer
}
@ -105,7 +105,7 @@ thread_local! {
}
impl Mux {
pub fn new(config: &Arc<Config>, default_domain: &Arc<Domain>) -> Self {
pub fn new(config: &Arc<Config>, default_domain: &Arc<dyn Domain>) -> Self {
Self {
tabs: RefCell::new(HashMap::new()),
windows: RefCell::new(HashMap::new()),
@ -114,7 +114,7 @@ impl Mux {
}
}
pub fn default_domain(&self) -> &Arc<Domain> {
pub fn default_domain(&self) -> &Arc<dyn Domain> {
&self.default_domain
}
@ -138,11 +138,11 @@ impl Mux {
res
}
pub fn get_tab(&self, tab_id: TabId) -> Option<Rc<Tab>> {
pub fn get_tab(&self, tab_id: TabId) -> Option<Rc<dyn Tab>> {
self.tabs.borrow().get(&tab_id).map(Rc::clone)
}
pub fn add_tab(&self, tab: &Rc<Tab>) -> Result<(), Error> {
pub fn add_tab(&self, tab: &Rc<dyn Tab>) -> Result<(), Error> {
self.tabs.borrow_mut().insert(tab.tab_id(), Rc::clone(tab));
let reader = tab.reader()?;
@ -175,12 +175,12 @@ impl Mux {
}))
}
pub fn get_active_tab_for_window(&self, window_id: WindowId) -> Option<Rc<Tab>> {
pub fn get_active_tab_for_window(&self, window_id: WindowId) -> Option<Rc<dyn Tab>> {
let window = self.get_window(window_id)?;
window.get_active().map(Rc::clone)
}
pub fn add_new_window_with_tab(&self, tab: &Rc<Tab>) -> Result<WindowId, Error> {
pub fn add_new_window_with_tab(&self, tab: &Rc<dyn Tab>) -> Result<WindowId, Error> {
let window = Window::new(tab);
let window_id = window.window_id();
self.windows.borrow_mut().insert(window_id, window);
@ -192,7 +192,7 @@ impl Mux {
self.tabs.borrow().is_empty()
}
pub fn iter_tabs(&self) -> Vec<Rc<Tab>> {
pub fn iter_tabs(&self) -> Vec<Rc<dyn Tab>> {
self.tabs
.borrow()
.iter()

View File

@ -13,11 +13,11 @@ pub fn alloc_tab_id() -> TabId {
pub trait Tab {
fn tab_id(&self) -> TabId;
fn renderer(&self) -> RefMut<Renderable>;
fn renderer(&self) -> RefMut<dyn Renderable>;
fn get_title(&self) -> String;
fn send_paste(&self, text: &str) -> Result<(), Error>;
fn reader(&self) -> Result<Box<std::io::Read + Send>, Error>;
fn writer(&self) -> RefMut<std::io::Write>;
fn reader(&self) -> Result<Box<dyn std::io::Read + Send>, Error>;
fn writer(&self) -> RefMut<dyn std::io::Write>;
fn resize(
&self,
rows: u16,
@ -26,8 +26,8 @@ pub trait Tab {
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 mouse_event(&self, event: MouseEvent, host: &mut dyn TerminalHost) -> Result<(), Error>;
fn advance_bytes(&self, buf: &[u8], host: &mut dyn TerminalHost);
fn is_dead(&self) -> bool;
fn palette(&self) -> ColorPalette;
}

View File

@ -6,12 +6,12 @@ pub type WindowId = usize;
pub struct Window {
id: WindowId,
tabs: Vec<Rc<Tab>>,
tabs: Vec<Rc<dyn Tab>>,
active: usize,
}
impl Window {
pub fn new(tab: &Rc<Tab>) -> Self {
pub fn new(tab: &Rc<dyn Tab>) -> Self {
Self {
id: WIN_ID.fetch_add(1, ::std::sync::atomic::Ordering::Relaxed),
tabs: vec![Rc::clone(tab)],
@ -23,7 +23,7 @@ impl Window {
self.id
}
pub fn push(&mut self, tab: &Rc<Tab>) {
pub fn push(&mut self, tab: &Rc<dyn Tab>) {
self.tabs.push(Rc::clone(tab))
}
@ -35,7 +35,7 @@ impl Window {
self.tabs.len()
}
pub fn get_by_idx(&self, idx: usize) -> Option<&Rc<Tab>> {
pub fn get_by_idx(&self, idx: usize) -> Option<&Rc<dyn Tab>> {
self.tabs.get(idx)
}
@ -58,7 +58,7 @@ impl Window {
}
}
pub fn get_active(&self) -> Option<&Rc<Tab>> {
pub fn get_active(&self) -> Option<&Rc<dyn Tab>> {
self.get_by_idx(self.active)
}
@ -76,7 +76,7 @@ impl Window {
.make_all_lines_dirty();
}
pub fn iter(&self) -> impl Iterator<Item = &Rc<Tab>> {
pub fn iter(&self) -> impl Iterator<Item = &Rc<dyn Tab>> {
self.tabs.iter()
}
}

View File

@ -653,7 +653,7 @@ impl Renderer {
line: &Line,
selection: Range<usize>,
cursor: &CursorPosition,
terminal: &Renderable,
terminal: &dyn Renderable,
palette: &ColorPalette,
) -> Result<(), Error> {
let (_num_rows, num_cols) = terminal.physical_dimensions();
@ -933,7 +933,7 @@ impl Renderer {
pub fn paint(
&mut self,
target: &mut glium::Frame,
term: &mut Renderable,
term: &mut dyn Renderable,
palette: &ColorPalette,
) -> Result<(), Error> {
let background_color = palette.resolve_bg(term::color::ColorAttribute::Default);

View File

@ -17,11 +17,11 @@ use std::thread;
pub struct Listener {
acceptor: UnixListener,
executor: Box<Executor>,
executor: Box<dyn Executor>,
}
impl Listener {
pub fn new(acceptor: UnixListener, executor: Box<Executor>) -> Self {
pub fn new(acceptor: UnixListener, executor: Box<dyn Executor>) -> Self {
Self { acceptor, executor }
}
@ -44,11 +44,11 @@ impl Listener {
pub struct ClientSession {
stream: UnixStream,
executor: Box<Executor>,
executor: Box<dyn Executor>,
}
impl ClientSession {
fn new(stream: UnixStream, executor: Box<Executor>) -> Self {
fn new(stream: UnixStream, executor: Box<dyn Executor>) -> Self {
Self { stream, executor }
}
@ -197,7 +197,7 @@ fn safely_create_sock_path(sock_path: &str) -> Result<UnixListener, Error> {
.map_err(|e| format_err!("Failed to bind to {}: {}", sock_path.display(), e))
}
pub fn spawn_listener(config: &Arc<Config>, executor: Box<Executor>) -> Result<(), Error> {
pub fn spawn_listener(config: &Arc<Config>, executor: Box<dyn Executor>) -> Result<(), Error> {
let sock_path = config
.mux_server_unix_domain_socket_path
.as_ref()