1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-23 21:32:13 +03:00

cargo fix dyn

This commit is contained in:
Wez Furlong 2019-09-28 20:29:48 -07:00
parent ed25cc81e6
commit 950a7d2b22
8 changed files with 39 additions and 31 deletions

View File

@ -15,10 +15,10 @@ pub trait Clipboard {
pub trait TerminalHost { pub trait TerminalHost {
/// Returns an object that can be used to send data to the /// Returns an object that can be used to send data to the
/// slave end of the associated pty. /// slave end of the associated pty.
fn writer(&mut self) -> &mut std::io::Write; fn writer(&mut self) -> &mut dyn std::io::Write;
/// Returns the clipboard manager /// Returns the clipboard manager
fn get_clipboard(&mut self) -> Fallible<Arc<Clipboard>>; fn get_clipboard(&mut self) -> Fallible<Arc<dyn Clipboard>>;
/// Change the title of the window /// Change the title of the window
fn set_title(&mut self, title: &str); fn set_title(&mut self, title: &str);
@ -85,7 +85,7 @@ impl Terminal {
} }
/// Feed the terminal parser a slice of bytes of input. /// Feed the terminal parser a slice of bytes of input.
pub fn advance_bytes<B: AsRef<[u8]>>(&mut self, bytes: B, host: &mut TerminalHost) { pub fn advance_bytes<B: AsRef<[u8]>>(&mut self, bytes: B, host: &mut dyn TerminalHost) {
let bytes = bytes.as_ref(); let bytes = bytes.as_ref();
let mut performer = Performer::new(&mut self.state, host); let mut performer = Performer::new(&mut self.state, host);

View File

@ -419,7 +419,7 @@ impl TerminalState {
fn mouse_single_click_left( fn mouse_single_click_left(
&mut self, &mut self,
event: MouseEvent, event: MouseEvent,
host: &mut TerminalHost, host: &mut dyn TerminalHost,
) -> Result<(), Error> { ) -> Result<(), Error> {
// Prepare to start a new selection. // Prepare to start a new selection.
// We don't form the selection until the mouse drags. // We don't form the selection until the mouse drags.
@ -436,7 +436,7 @@ impl TerminalState {
fn mouse_double_click_left( fn mouse_double_click_left(
&mut self, &mut self,
event: MouseEvent, event: MouseEvent,
host: &mut TerminalHost, host: &mut dyn TerminalHost,
) -> Result<(), Error> { ) -> Result<(), Error> {
let y = event.y as ScrollbackOrVisibleRowIndex let y = event.y as ScrollbackOrVisibleRowIndex
- self.viewport_offset as ScrollbackOrVisibleRowIndex; - self.viewport_offset as ScrollbackOrVisibleRowIndex;
@ -513,7 +513,7 @@ impl TerminalState {
fn mouse_triple_click_left( fn mouse_triple_click_left(
&mut self, &mut self,
event: MouseEvent, event: MouseEvent,
host: &mut TerminalHost, host: &mut dyn TerminalHost,
) -> Result<(), Error> { ) -> Result<(), Error> {
let y = event.y as ScrollbackOrVisibleRowIndex let y = event.y as ScrollbackOrVisibleRowIndex
- self.viewport_offset as ScrollbackOrVisibleRowIndex; - self.viewport_offset as ScrollbackOrVisibleRowIndex;
@ -537,7 +537,7 @@ impl TerminalState {
fn mouse_press_left( fn mouse_press_left(
&mut self, &mut self,
event: MouseEvent, event: MouseEvent,
host: &mut TerminalHost, host: &mut dyn TerminalHost,
) -> Result<(), Error> { ) -> Result<(), Error> {
self.current_mouse_button = MouseButton::Left; self.current_mouse_button = MouseButton::Left;
self.dirty_selection_lines(); self.dirty_selection_lines();
@ -565,7 +565,7 @@ impl TerminalState {
fn mouse_release_left( fn mouse_release_left(
&mut self, &mut self,
event: MouseEvent, event: MouseEvent,
host: &mut TerminalHost, host: &mut dyn TerminalHost,
) -> Result<(), Error> { ) -> Result<(), Error> {
// Finish selecting a region, update clipboard // Finish selecting a region, update clipboard
self.current_mouse_button = MouseButton::None; self.current_mouse_button = MouseButton::None;
@ -613,7 +613,11 @@ impl TerminalState {
Ok(()) Ok(())
} }
fn mouse_wheel(&mut self, event: MouseEvent, writer: &mut std::io::Write) -> Result<(), Error> { fn mouse_wheel(
&mut self,
event: MouseEvent,
writer: &mut dyn std::io::Write,
) -> Result<(), Error> {
let (report_button, scroll_delta, key) = match event.button { let (report_button, scroll_delta, key) = match event.button {
MouseButton::WheelUp(amount) => (64, -(amount as i64), KeyCode::UpArrow), MouseButton::WheelUp(amount) => (64, -(amount as i64), KeyCode::UpArrow),
MouseButton::WheelDown(amount) => (65, amount as i64, KeyCode::DownArrow), MouseButton::WheelDown(amount) => (65, amount as i64, KeyCode::DownArrow),
@ -636,7 +640,7 @@ impl TerminalState {
fn mouse_button_press( fn mouse_button_press(
&mut self, &mut self,
event: MouseEvent, event: MouseEvent,
host: &mut TerminalHost, host: &mut dyn TerminalHost,
) -> Result<(), Error> { ) -> Result<(), Error> {
self.current_mouse_button = event.button; self.current_mouse_button = event.button;
if let Some(button) = match event.button { if let Some(button) = match event.button {
@ -661,7 +665,7 @@ impl TerminalState {
fn mouse_button_release( fn mouse_button_release(
&mut self, &mut self,
event: MouseEvent, event: MouseEvent,
writer: &mut std::io::Write, writer: &mut dyn std::io::Write,
) -> Result<(), Error> { ) -> Result<(), Error> {
if self.current_mouse_button != MouseButton::None { if self.current_mouse_button != MouseButton::None {
self.current_mouse_button = MouseButton::None; self.current_mouse_button = MouseButton::None;
@ -673,7 +677,11 @@ impl TerminalState {
Ok(()) Ok(())
} }
fn mouse_move(&mut self, event: MouseEvent, writer: &mut std::io::Write) -> Result<(), Error> { fn mouse_move(
&mut self,
event: MouseEvent,
writer: &mut dyn std::io::Write,
) -> Result<(), Error> {
if let Some(button) = match (self.current_mouse_button, self.button_event_mouse) { if let Some(button) = match (self.current_mouse_button, self.button_event_mouse) {
(MouseButton::Left, true) => Some(32), (MouseButton::Left, true) => Some(32),
(MouseButton::Middle, true) => Some(33), (MouseButton::Middle, true) => Some(33),
@ -690,7 +698,7 @@ impl TerminalState {
pub fn mouse_event( pub fn mouse_event(
&mut self, &mut self,
mut event: MouseEvent, mut event: MouseEvent,
host: &mut TerminalHost, host: &mut dyn TerminalHost,
) -> Result<(), Error> { ) -> Result<(), Error> {
// Clamp the mouse coordinates to the size of the model. // Clamp the mouse coordinates to the size of the model.
// This situation can trigger for example when the // This situation can trigger for example when the
@ -793,7 +801,7 @@ impl TerminalState {
/// Send text to the terminal that is the result of pasting. /// Send text to the terminal that is the result of pasting.
/// If bracketed paste mode is enabled, the paste is enclosed /// If bracketed paste mode is enabled, the paste is enclosed
/// in the bracketing, otherwise it is fed to the pty as-is. /// in the bracketing, otherwise it is fed to the pty as-is.
pub fn send_paste(&mut self, text: &str, writer: &mut std::io::Write) -> Result<(), Error> { pub fn send_paste(&mut self, text: &str, writer: &mut dyn std::io::Write) -> Result<(), Error> {
if self.bracketed_paste { if self.bracketed_paste {
let buf = format!("\x1b[200~{}\x1b[201~", text); let buf = format!("\x1b[200~{}\x1b[201~", text);
writer.write_all(buf.as_bytes())?; writer.write_all(buf.as_bytes())?;
@ -811,7 +819,7 @@ impl TerminalState {
&mut self, &mut self,
key: KeyCode, key: KeyCode,
mods: KeyModifiers, mods: KeyModifiers,
writer: &mut std::io::Write, writer: &mut dyn std::io::Write,
) -> Result<(), Error> { ) -> Result<(), Error> {
const CTRL: KeyModifiers = KeyModifiers::CTRL; const CTRL: KeyModifiers = KeyModifiers::CTRL;
const SHIFT: KeyModifiers = KeyModifiers::SHIFT; const SHIFT: KeyModifiers = KeyModifiers::SHIFT;
@ -1358,7 +1366,7 @@ impl TerminalState {
*/ */
} }
fn perform_device(&mut self, dev: Device, host: &mut TerminalHost) { fn perform_device(&mut self, dev: Device, host: &mut dyn TerminalHost) {
match dev { match dev {
Device::DeviceAttributes(a) => error!("unhandled: {:?}", a), Device::DeviceAttributes(a) => error!("unhandled: {:?}", a),
Device::SoftReset => { Device::SoftReset => {
@ -1533,7 +1541,7 @@ impl TerminalState {
checksum checksum
} }
fn perform_csi_window(&mut self, window: Window, host: &mut TerminalHost) { fn perform_csi_window(&mut self, window: Window, host: &mut dyn TerminalHost) {
match window { match window {
Window::ReportTextAreaSizeCells => { Window::ReportTextAreaSizeCells => {
let screen = self.screen(); let screen = self.screen();
@ -1701,7 +1709,7 @@ impl TerminalState {
} }
} }
fn perform_csi_cursor(&mut self, cursor: Cursor, host: &mut TerminalHost) { fn perform_csi_cursor(&mut self, cursor: Cursor, host: &mut dyn TerminalHost) {
match cursor { match cursor {
Cursor::SetTopAndBottomMargins { top, bottom } => { Cursor::SetTopAndBottomMargins { top, bottom } => {
let rows = self.screen().physical_rows; let rows = self.screen().physical_rows;
@ -1863,7 +1871,7 @@ impl TerminalState {
/// the terminal state and the embedding/host terminal interface /// the terminal state and the embedding/host terminal interface
pub(crate) struct Performer<'a> { pub(crate) struct Performer<'a> {
pub state: &'a mut TerminalState, pub state: &'a mut TerminalState,
pub host: &'a mut TerminalHost, pub host: &'a mut dyn TerminalHost,
print: Option<String>, print: Option<String>,
} }
@ -1888,7 +1896,7 @@ impl<'a> Drop for Performer<'a> {
} }
impl<'a> Performer<'a> { impl<'a> Performer<'a> {
pub fn new(state: &'a mut TerminalState, host: &'a mut TerminalHost) -> Self { pub fn new(state: &'a mut TerminalState, host: &'a mut dyn TerminalHost) -> Self {
Self { Self {
state, state,
host, host,

View File

@ -16,7 +16,7 @@ use termwiz::escape::{OneBased, OperatingSystemCommand, CSI};
struct TestHost { struct TestHost {
title: String, title: String,
clip: Arc<Clipboard>, clip: Arc<dyn Clipboard>,
} }
impl TestHost { impl TestHost {
@ -70,11 +70,11 @@ impl TerminalHost for TestHost {
self.title = title.into(); self.title = title.into();
} }
fn get_clipboard(&mut self) -> Fallible<Arc<Clipboard>> { fn get_clipboard(&mut self) -> Fallible<Arc<dyn Clipboard>> {
Ok(Arc::clone(&self.clip)) Ok(Arc::clone(&self.clip))
} }
fn writer(&mut self) -> &mut std::io::Write { fn writer(&mut self) -> &mut dyn std::io::Write {
self self
} }

View File

@ -24,7 +24,7 @@ impl LineEditorHost for Host {
] ]
} }
fn history(&mut self) -> &mut History { fn history(&mut self) -> &mut dyn History {
&mut self.history &mut self.history
} }

View File

@ -62,7 +62,7 @@ pub trait LineEditorHost {
} }
/// Returns the history implementation /// Returns the history implementation
fn history(&mut self) -> &mut History; fn history(&mut self) -> &mut dyn History;
/// Tab completion support. /// Tab completion support.
/// The line and current cursor position are provided and it is up to the /// The line and current cursor position are provided and it is up to the
@ -91,7 +91,7 @@ pub struct NopLineEditorHost {
history: BasicHistory, history: BasicHistory,
} }
impl LineEditorHost for NopLineEditorHost { impl LineEditorHost for NopLineEditorHost {
fn history(&mut self) -> &mut History { fn history(&mut self) -> &mut dyn History {
&mut self.history &mut self.history
} }
} }

View File

@ -144,7 +144,7 @@ impl<T: Terminal> LineEditor<T> {
} }
} }
fn render(&mut self, host: &mut LineEditorHost) -> Fallible<()> { fn render(&mut self, host: &mut dyn LineEditorHost) -> Fallible<()> {
let mut changes = vec![ let mut changes = vec![
Change::CursorPosition { Change::CursorPosition {
x: Position::Absolute(0), x: Position::Absolute(0),
@ -192,7 +192,7 @@ impl<T: Terminal> LineEditor<T> {
/// Control is not returned to the caller until a line has been /// Control is not returned to the caller until a line has been
/// accepted, or until an error is detected. /// accepted, or until an error is detected.
/// Returns Ok(None) if the editor was cancelled eg: via CTRL-C. /// Returns Ok(None) if the editor was cancelled eg: via CTRL-C.
pub fn read_line(&mut self, host: &mut LineEditorHost) -> Fallible<Option<String>> { pub fn read_line(&mut self, host: &mut dyn LineEditorHost) -> Fallible<Option<String>> {
self.terminal.set_raw_mode()?; self.terminal.set_raw_mode()?;
let res = self.read_line_impl(host); let res = self.read_line_impl(host);
self.terminal.set_cooked_mode()?; self.terminal.set_cooked_mode()?;
@ -450,7 +450,7 @@ impl<T: Terminal> LineEditor<T> {
self.completion = None; self.completion = None;
} }
fn read_line_impl(&mut self, host: &mut LineEditorHost) -> Fallible<Option<String>> { fn read_line_impl(&mut self, host: &mut dyn LineEditorHost) -> Fallible<Option<String>> {
self.line.clear(); self.line.clear();
self.cursor = 0; self.cursor = 0;
self.history_pos = None; self.history_pos = None;

View File

@ -140,7 +140,7 @@ struct RenderData<'widget> {
surface: Surface, surface: Surface,
cursor: CursorShapeAndPosition, cursor: CursorShapeAndPosition,
coordinates: ParentRelativeCoords, coordinates: ParentRelativeCoords,
widget: Box<Widget + 'widget>, widget: Box<dyn Widget + 'widget>,
} }
#[derive(Default)] #[derive(Default)]

View File

@ -96,7 +96,7 @@ fn spawn_window() -> Fallible<()> {
)?; )?;
win.show(); win.show();
win.apply(|myself, win| { win.apply(|myself, _win| {
if let Some(myself) = myself.downcast_ref::<MyWindow>() { if let Some(myself) = myself.downcast_ref::<MyWindow>() {
eprintln!( eprintln!(
"got myself; allow_close={}, cursor_pos:{:?}", "got myself; allow_close={}, cursor_pos:{:?}",