From 4fdee2baf00b9ba1d64b0ed5b51ea2e08104931e Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 14 Dec 2019 22:27:37 -0800 Subject: [PATCH] maybe fix the windows build for anyhow changes --- pty/src/win/conpty.rs | 10 +++++----- pty/src/win/winpty/mod.rs | 12 ++++++------ pty/src/win/winpty/safe.rs | 4 ++-- termwiz/src/render/windows.rs | 3 +-- termwiz/src/terminal/windows.rs | 6 +++--- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/pty/src/win/conpty.rs b/pty/src/win/conpty.rs index 83e239beb..089c4bd87 100644 --- a/pty/src/win/conpty.rs +++ b/pty/src/win/conpty.rs @@ -1,7 +1,7 @@ use super::WinChild; use crate::cmdbuilder::CommandBuilder; use crate::{Child, MasterPty, PtyPair, PtySize, PtySystem, SlavePty}; -use failure::{bail, ensure, Error, Fallible}; +use anyhow::{bail, ensure, Error}; use filedescriptor::{FileDescriptor, OwnedHandle, Pipe}; use lazy_static::lazy_static; use shared_library::shared_library; @@ -26,7 +26,7 @@ const PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE: usize = 0x00020016; pub struct ConPtySystem {} impl PtySystem for ConPtySystem { - fn openpty(&self, size: PtySize) -> Fallible { + fn openpty(&self, size: PtySize) -> anyhow::Result { let stdin = Pipe::new()?; let stdout = Pipe::new()?; @@ -224,7 +224,7 @@ pub struct ConPtySlavePty { } impl MasterPty for ConPtyMasterPty { - fn resize(&self, size: PtySize) -> Fallible<()> { + fn resize(&self, size: PtySize) -> anyhow::Result<()> { let mut inner = self.inner.lock().unwrap(); inner.resize(size.rows, size.cols, size.pixel_width, size.pixel_height) } @@ -234,7 +234,7 @@ impl MasterPty for ConPtyMasterPty { Ok(inner.size.clone()) } - fn try_clone_reader(&self) -> Fallible> { + fn try_clone_reader(&self) -> anyhow::Result> { Ok(Box::new(self.inner.lock().unwrap().readable.try_clone()?)) } } @@ -249,7 +249,7 @@ impl io::Write for ConPtyMasterPty { } impl SlavePty for ConPtySlavePty { - fn spawn_command(&self, cmd: CommandBuilder) -> Fallible> { + fn spawn_command(&self, cmd: CommandBuilder) -> anyhow::Result> { let inner = self.inner.lock().unwrap(); let mut si: STARTUPINFOEXW = unsafe { mem::zeroed() }; diff --git a/pty/src/win/winpty/mod.rs b/pty/src/win/winpty/mod.rs index c97bf11dd..2b95cf2e5 100644 --- a/pty/src/win/winpty/mod.rs +++ b/pty/src/win/winpty/mod.rs @@ -4,7 +4,7 @@ use crate::win::winpty::safe::{ AgentFlags, MouseMode, SpawnConfig, SpawnFlags, Timeout, WinPty, WinPtyConfig, }; use crate::{Child, MasterPty, PtyPair, PtySize, PtySystem, SlavePty}; -use failure::{bail, Fallible}; +use anyhow::bail; use filedescriptor::FileDescriptor; use log::debug; use std::ffi::OsString; @@ -32,7 +32,7 @@ pub struct WinPtySlavePty { } impl MasterPty for WinPtyMasterPty { - fn resize(&self, size: PtySize) -> Fallible<()> { + fn resize(&self, size: PtySize) -> anyhow::Result<()> { let mut inner = self.inner.lock().unwrap(); if inner.pty.set_size(size.cols as i32, size.rows as i32)? { inner.size = size; @@ -42,11 +42,11 @@ impl MasterPty for WinPtyMasterPty { } } - fn get_size(&self) -> Fallible { + fn get_size(&self) -> anyhow::Result { Ok(self.inner.lock().unwrap().size) } - fn try_clone_reader(&self) -> Fallible> { + fn try_clone_reader(&self) -> anyhow::Result> { Ok(Box::new(self.inner.lock().unwrap().reader.try_clone()?)) } } @@ -61,7 +61,7 @@ impl std::io::Write for WinPtyMasterPty { } impl SlavePty for WinPtySlavePty { - fn spawn_command(&self, cmd: CommandBuilder) -> Fallible> { + fn spawn_command(&self, cmd: CommandBuilder) -> anyhow::Result> { let (exe, cmdline) = cmd.cmdline()?; let cmd_os = OsString::from_wide(&cmdline); debug!( @@ -91,7 +91,7 @@ impl SlavePty for WinPtySlavePty { pub struct WinPtySystem {} impl PtySystem for WinPtySystem { - fn openpty(&self, size: PtySize) -> Fallible { + fn openpty(&self, size: PtySize) -> anyhow::Result { let mut config = WinPtyConfig::new(AgentFlags::empty())?; config.set_initial_size(size.cols as i32, size.rows as i32); diff --git a/pty/src/win/winpty/safe.rs b/pty/src/win/winpty/safe.rs index 14ffe6a38..2b885d9a4 100644 --- a/pty/src/win/winpty/safe.rs +++ b/pty/src/win/winpty/safe.rs @@ -3,8 +3,8 @@ //! https://github.com/rprichard/winpty/blob/master/src/include/winpty.h #![allow(dead_code)] use super::sys::*; +use anyhow::{bail, ensure, Error}; use bitflags::bitflags; -use failure::{bail, ensure, format_err, Error}; use filedescriptor::{FileDescriptor, OwnedHandle}; use std::ffi::{OsStr, OsString}; use std::os::windows::ffi::{OsStrExt, OsStringExt}; @@ -58,7 +58,7 @@ fn wstr_to_osstr(wstr: LPCWSTR) -> Result { fn wstr_to_string(wstr: LPCWSTR) -> Result { ensure!(!wstr.is_null(), "LPCWSTR is null"); let slice = unsafe { std::slice::from_raw_parts(wstr, libc::wcslen(wstr)) }; - String::from_utf16(slice).map_err(|e| format_err!("String::from_utf16: {}", e)) + String::from_utf16(slice).map_err(|e| anyhow!("String::from_utf16: {}", e)) } fn check_err(err: winpty_error_ptr_t, value: T) -> Result { diff --git a/termwiz/src/render/windows.rs b/termwiz/src/render/windows.rs index eab43b7d4..2c084f9c3 100644 --- a/termwiz/src/render/windows.rs +++ b/termwiz/src/render/windows.rs @@ -5,7 +5,6 @@ use crate::cell::{AttributeChange, CellAttributes, Underline}; use crate::color::{AnsiColor, ColorAttribute}; use crate::surface::{Change, Position}; use crate::terminal::windows::{ConsoleInputHandle, ConsoleOutputHandle}; -use failure; use num; use std::io::{Read, Write}; use winapi::um::wincon::{ @@ -117,7 +116,7 @@ impl WindowsConsoleRenderer { changes: &[Change], _read: &mut A, out: &mut B, - ) -> Result<(), failure::Error> { + ) -> anyhow::Result<()> { for change in changes { match change { Change::ClearScreen(color) => { diff --git a/termwiz/src/terminal/windows.rs b/termwiz/src/terminal/windows.rs index 1fb8b80ad..34387f152 100644 --- a/termwiz/src/terminal/windows.rs +++ b/termwiz/src/terminal/windows.rs @@ -1,5 +1,5 @@ use crate::istty::IsTty; -use failure::{bail, format_err, Error, Fallible}; +use anyhow::{anyhow, bail, Error}; use filedescriptor::{FileDescriptor, OwnedHandle}; use std::cmp::{max, min}; use std::collections::VecDeque; @@ -460,7 +460,7 @@ impl Terminal for WindowsTerminal { ) } - fn set_cooked_mode(&mut self) -> Fallible<()> { + fn set_cooked_mode(&mut self) -> anyhow::Result<()> { let mode = self.input_handle.get_input_mode()?; self.input_handle.set_input_mode( @@ -526,7 +526,7 @@ impl Terminal for WindowsTerminal { fn flush(&mut self) -> Result<(), Error> { self.output_handle .flush() - .map_err(|e| format_err!("flush failed: {}", e)) + .map_err(|e| anyhow!("flush failed: {}", e)) } fn poll_input(&mut self, wait: Option) -> Result, Error> {