summaryrefslogtreecommitdiffstats
path: root/alacritty_terminal/src/tty/windows
diff options
context:
space:
mode:
author张小白 <364772080@qq.com>2024-08-17 01:37:34 +0800
committerGitHub <noreply@github.com>2024-08-16 17:37:34 +0000
commit91d034ff8b53867143c005acfaa14609147c9a2c (patch)
tree9c362291f1de3ead97adf6a760fcb7c30c70f7b8 /alacritty_terminal/src/tty/windows
parent102b89a8d9ee6543f15f248c15383da7a4684c42 (diff)
Make `ConPty` creation fallible
Diffstat (limited to 'alacritty_terminal/src/tty/windows')
-rw-r--r--alacritty_terminal/src/tty/windows/conpty.rs25
-rw-r--r--alacritty_terminal/src/tty/windows/mod.rs3
2 files changed, 11 insertions, 17 deletions
diff --git a/alacritty_terminal/src/tty/windows/conpty.rs b/alacritty_terminal/src/tty/windows/conpty.rs
index 244681e7..28289f90 100644
--- a/alacritty_terminal/src/tty/windows/conpty.rs
+++ b/alacritty_terminal/src/tty/windows/conpty.rs
@@ -1,7 +1,7 @@
use log::{info, warn};
use std::collections::{HashMap, HashSet};
use std::ffi::OsStr;
-use std::io::Error;
+use std::io::{Error, Result};
use std::os::windows::ffi::OsStrExt;
use std::os::windows::io::IntoRawHandle;
use std::{mem, ptr};
@@ -107,7 +107,7 @@ impl Drop for Conpty {
// The ConPTY handle can be sent between threads.
unsafe impl Send for Conpty {}
-pub fn new(config: &Options, window_size: WindowSize) -> Option<Pty> {
+pub fn new(config: &Options, window_size: WindowSize) -> Result<Pty> {
let api = ConptyApi::new();
let mut pty_handle: HPCON = 0;
@@ -115,8 +115,8 @@ pub fn new(config: &Options, window_size: WindowSize) -> Option<Pty> {
// size to be used. There may be small performance and memory advantages
// to be gained by tuning this in the future, but it's likely a reasonable
// start point.
- let (conout, conout_pty_handle) = miow::pipe::anonymous(0).unwrap();
- let (conin_pty_handle, conin) = miow::pipe::anonymous(0).unwrap();
+ let (conout, conout_pty_handle) = miow::pipe::anonymous(0)?;
+ let (conin_pty_handle, conin) = miow::pipe::anonymous(0)?;
// Create the Pseudo Console, using the pipes.
let result = unsafe {
@@ -154,7 +154,7 @@ pub fn new(config: &Options, window_size: WindowSize) -> Option<Pty> {
// This call was expected to return false.
if failure {
- panic_shell_spawn();
+ return Err(Error::last_os_error());
}
}
@@ -180,7 +180,7 @@ pub fn new(config: &Options, window_size: WindowSize) -> Option<Pty> {
) > 0;
if !success {
- panic_shell_spawn();
+ return Err(Error::last_os_error());
}
}
@@ -197,7 +197,7 @@ pub fn new(config: &Options, window_size: WindowSize) -> Option<Pty> {
) > 0;
if !success {
- panic_shell_spawn();
+ return Err(Error::last_os_error());
}
}
@@ -230,17 +230,17 @@ pub fn new(config: &Options, window_size: WindowSize) -> Option<Pty> {
) > 0;
if !success {
- panic_shell_spawn();
+ return Err(Error::last_os_error());
}
}
let conin = UnblockedWriter::new(conin, PIPE_CAPACITY);
let conout = UnblockedReader::new(conout, PIPE_CAPACITY);
- let child_watcher = ChildExitWatcher::new(proc_info.hProcess).unwrap();
+ let child_watcher = ChildExitWatcher::new(proc_info.hProcess)?;
let conpty = Conpty { handle: pty_handle as HPCON, api };
- Some(Pty::new(conpty, conout, conin, child_watcher))
+ Ok(Pty::new(conpty, conout, conin, child_watcher))
}
// Windows environment variables are case-insensitive, and the caller is responsible for
@@ -300,11 +300,6 @@ fn add_windows_env_key_value_to_block(block: &mut Vec<u16>, key: &OsStr, value:
block.push(0);
}
-// Panic with the last os error as message.
-fn panic_shell_spawn() {
- panic!("Unable to spawn shell: {}", Error::last_os_error());
-}
-
impl OnResize for Conpty {
fn on_resize(&mut self, window_size: WindowSize) {
let result = unsafe { (self.api.resize)(self.handle, window_size.into()) };
diff --git a/alacritty_terminal/src/tty/windows/mod.rs b/alacritty_terminal/src/tty/windows/mod.rs
index 6af162c8..32e24677 100644
--- a/alacritty_terminal/src/tty/windows/mod.rs
+++ b/alacritty_terminal/src/tty/windows/mod.rs
@@ -1,5 +1,5 @@
use std::ffi::OsStr;
-use std::io::{self, Error, ErrorKind, Result};
+use std::io::{self, Result};
use std::iter::once;
use std::os::windows::ffi::OsStrExt;
use std::sync::mpsc::TryRecvError;
@@ -35,7 +35,6 @@ pub struct Pty {
pub fn new(config: &Options, window_size: WindowSize, _window_id: u64) -> Result<Pty> {
conpty::new(config, window_size)
- .ok_or_else(|| Error::new(ErrorKind::Other, "failed to spawn conpty"))
}
impl Pty {