summaryrefslogtreecommitdiff
path: root/alacritty_terminal/src
diff options
context:
space:
mode:
Diffstat (limited to 'alacritty_terminal/src')
-rw-r--r--alacritty_terminal/src/config/mod.rs26
-rw-r--r--alacritty_terminal/src/selection.rs4
-rw-r--r--alacritty_terminal/src/term/mod.rs32
-rw-r--r--alacritty_terminal/src/term/search.rs2
-rw-r--r--alacritty_terminal/src/tty/mod.rs2
-rw-r--r--alacritty_terminal/src/tty/unix.rs26
-rw-r--r--alacritty_terminal/src/tty/windows/conpty.rs6
-rw-r--r--alacritty_terminal/src/tty/windows/mod.rs12
-rw-r--r--alacritty_terminal/src/vi_mode.rs4
9 files changed, 62 insertions, 52 deletions
diff --git a/alacritty_terminal/src/config/mod.rs b/alacritty_terminal/src/config/mod.rs
index 0b313598..09161e03 100644
--- a/alacritty_terminal/src/config/mod.rs
+++ b/alacritty_terminal/src/config/mod.rs
@@ -15,37 +15,43 @@ pub use crate::config::scrolling::Scrolling;
pub const LOG_TARGET_CONFIG: &str = "alacritty_config_derive";
const MIN_BLINK_INTERVAL: u64 = 10;
-pub type MockConfig = Config<HashMap<String, serde_yaml::Value>>;
-
/// Top-level config type.
#[derive(ConfigDeserialize, Debug, PartialEq, Default)]
-pub struct Config<T> {
+pub struct Config {
/// TERM env variable.
pub env: HashMap<String, String>,
pub selection: Selection,
- /// Path to a shell program to run on startup.
- pub shell: Option<Program>,
-
/// How much scrolling history to keep.
pub scrolling: Scrolling,
/// Cursor configuration.
pub cursor: Cursor,
+ #[config(flatten)]
+ pub pty_config: PtyConfig,
+}
+
+#[derive(ConfigDeserialize, Clone, Debug, PartialEq, Default)]
+pub struct PtyConfig {
+ /// Path to a shell program to run on startup.
+ pub shell: Option<Program>,
+
/// Shell startup directory.
pub working_directory: Option<PathBuf>,
- /// Additional configuration options not directly required by the terminal.
- #[config(flatten)]
- pub ui_config: T,
-
/// Remain open after child process exits.
#[config(skip)]
pub hold: bool,
}
+impl PtyConfig {
+ pub fn new() -> Self {
+ Default::default()
+ }
+}
+
#[derive(ConfigDeserialize, Clone, Debug, PartialEq, Eq)]
pub struct Selection {
pub semantic_escape_chars: String,
diff --git a/alacritty_terminal/src/selection.rs b/alacritty_terminal/src/selection.rs
index 47a49910..f00622d1 100644
--- a/alacritty_terminal/src/selection.rs
+++ b/alacritty_terminal/src/selection.rs
@@ -394,13 +394,13 @@ impl Selection {
mod tests {
use super::*;
- use crate::config::MockConfig;
+ use crate::config::Config;
use crate::index::{Column, Point, Side};
use crate::term::{SizeInfo, Term};
fn term(height: usize, width: usize) -> Term<()> {
let size = SizeInfo::new(width as f32, height as f32, 1.0, 1.0, 0.0, 0.0, false);
- Term::new(&MockConfig::default(), size, ())
+ Term::new(&Config::default(), size, ())
}
/// Test case of single cell selection.
diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs
index 894bd763..9b7a4c35 100644
--- a/alacritty_terminal/src/term/mod.rs
+++ b/alacritty_terminal/src/term/mod.rs
@@ -288,7 +288,7 @@ impl<T> Term<T> {
self.vi_mode_recompute_selection();
}
- pub fn new<C>(config: &Config<C>, size: SizeInfo, event_proxy: T) -> Term<T> {
+ pub fn new(config: &Config, size: SizeInfo, event_proxy: T) -> Term<T> {
let num_cols = size.columns;
let num_lines = size.screen_lines;
@@ -323,7 +323,7 @@ impl<T> Term<T> {
}
}
- pub fn update_config<C>(&mut self, config: &Config<C>)
+ pub fn update_config(&mut self, config: &Config)
where
T: EventListener,
{
@@ -1903,7 +1903,7 @@ pub mod test {
// Create terminal with the appropriate dimensions.
let size = SizeInfo::new(num_cols as f32, lines.len() as f32, 1., 1., 0., 0., false);
- let mut term = Term::new(&Config::<()>::default(), size, ());
+ let mut term = Term::new(&Config::default(), size, ());
// Fill terminal with content.
for (line, text) in lines.iter().enumerate() {
@@ -1938,7 +1938,7 @@ mod tests {
use std::mem;
use crate::ansi::{self, CharsetIndex, Handler, StandardCharset};
- use crate::config::MockConfig;
+ use crate::config::Config;
use crate::grid::{Grid, Scroll};
use crate::index::{Column, Point, Side};
use crate::selection::{Selection, SelectionType};
@@ -1947,7 +1947,7 @@ mod tests {
#[test]
fn scroll_display_page_up() {
let size = SizeInfo::new(5., 10., 1.0, 1.0, 0.0, 0.0, false);
- let mut term = Term::new(&MockConfig::default(), size, ());
+ let mut term = Term::new(&Config::default(), size, ());
// Create 11 lines of scrollback.
for _ in 0..20 {
@@ -1973,7 +1973,7 @@ mod tests {
#[test]
fn scroll_display_page_down() {
let size = SizeInfo::new(5., 10., 1.0, 1.0, 0.0, 0.0, false);
- let mut term = Term::new(&MockConfig::default(), size, ());
+ let mut term = Term::new(&Config::default(), size, ());
// Create 11 lines of scrollback.
for _ in 0..20 {
@@ -2003,7 +2003,7 @@ mod tests {
#[test]
fn semantic_selection_works() {
let size = SizeInfo::new(5., 3., 1.0, 1.0, 0.0, 0.0, false);
- let mut term = Term::new(&MockConfig::default(), size, ());
+ let mut term = Term::new(&Config::default(), size, ());
let mut grid: Grid<Cell> = Grid::new(3, 5, 0);
for i in 0..5 {
for j in 0..2 {
@@ -2051,7 +2051,7 @@ mod tests {
#[test]
fn line_selection_works() {
let size = SizeInfo::new(5., 1., 1.0, 1.0, 0.0, 0.0, false);
- let mut term = Term::new(&MockConfig::default(), size, ());
+ let mut term = Term::new(&Config::default(), size, ());
let mut grid: Grid<Cell> = Grid::new(1, 5, 0);
for i in 0..5 {
grid[Line(0)][Column(i)].c = 'a';
@@ -2072,7 +2072,7 @@ mod tests {
#[test]
fn selecting_empty_line() {
let size = SizeInfo::new(3.0, 3.0, 1.0, 1.0, 0.0, 0.0, false);
- let mut term = Term::new(&MockConfig::default(), size, ());
+ let mut term = Term::new(&Config::default(), size, ());
let mut grid: Grid<Cell> = Grid::new(3, 3, 0);
for l in 0..3 {
if l != 1 {
@@ -2110,7 +2110,7 @@ mod tests {
#[test]
fn input_line_drawing_character() {
let size = SizeInfo::new(21.0, 51.0, 3.0, 3.0, 0.0, 0.0, false);
- let mut term = Term::new(&MockConfig::default(), size, ());
+ let mut term = Term::new(&Config::default(), size, ());
let cursor = Point::new(Line(0), Column(0));
term.configure_charset(CharsetIndex::G0, StandardCharset::SpecialCharacterAndLineDrawing);
term.input('a');
@@ -2121,7 +2121,7 @@ mod tests {
#[test]
fn clear_saved_lines() {
let size = SizeInfo::new(21.0, 51.0, 3.0, 3.0, 0.0, 0.0, false);
- let mut term = Term::new(&MockConfig::default(), size, ());
+ let mut term = Term::new(&Config::default(), size, ());
// Add one line of scrollback.
term.grid.scroll_up(&(Line(0)..Line(1)), 1);
@@ -2143,7 +2143,7 @@ mod tests {
#[test]
fn grow_lines_updates_active_cursor_pos() {
let mut size = SizeInfo::new(100.0, 10.0, 1.0, 1.0, 0.0, 0.0, false);
- let mut term = Term::new(&MockConfig::default(), size, ());
+ let mut term = Term::new(&Config::default(), size, ());
// Create 10 lines of scrollback.
for _ in 0..19 {
@@ -2163,7 +2163,7 @@ mod tests {
#[test]
fn grow_lines_updates_inactive_cursor_pos() {
let mut size = SizeInfo::new(100.0, 10.0, 1.0, 1.0, 0.0, 0.0, false);
- let mut term = Term::new(&MockConfig::default(), size, ());
+ let mut term = Term::new(&Config::default(), size, ());
// Create 10 lines of scrollback.
for _ in 0..19 {
@@ -2189,7 +2189,7 @@ mod tests {
#[test]
fn shrink_lines_updates_active_cursor_pos() {
let mut size = SizeInfo::new(100.0, 10.0, 1.0, 1.0, 0.0, 0.0, false);
- let mut term = Term::new(&MockConfig::default(), size, ());
+ let mut term = Term::new(&Config::default(), size, ());
// Create 10 lines of scrollback.
for _ in 0..19 {
@@ -2209,7 +2209,7 @@ mod tests {
#[test]
fn shrink_lines_updates_inactive_cursor_pos() {
let mut size = SizeInfo::new(100.0, 10.0, 1.0, 1.0, 0.0, 0.0, false);
- let mut term = Term::new(&MockConfig::default(), size, ());
+ let mut term = Term::new(&Config::default(), size, ());
// Create 10 lines of scrollback.
for _ in 0..19 {
@@ -2235,7 +2235,7 @@ mod tests {
#[test]
fn window_title() {
let size = SizeInfo::new(21.0, 51.0, 3.0, 3.0, 0.0, 0.0, false);
- let mut term = Term::new(&MockConfig::default(), size, ());
+ let mut term = Term::new(&Config::default(), size, ());
// Title None by default.
assert_eq!(term.title, None);
diff --git a/alacritty_terminal/src/term/search.rs b/alacritty_terminal/src/term/search.rs
index 08de602f..07403b67 100644
--- a/alacritty_terminal/src/term/search.rs
+++ b/alacritty_terminal/src/term/search.rs
@@ -785,7 +785,7 @@ mod tests {
#[test]
fn wide_without_spacer() {
let size = SizeInfo::new(2., 2., 1., 1., 0., 0., false);
- let mut term = Term::new(&Config::<()>::default(), size, ());
+ let mut term = Term::new(&Config::default(), size, ());
term.grid[Line(0)][Column(0)].c = 'x';
term.grid[Line(0)][Column(1)].c = '字';
term.grid[Line(0)][Column(1)].flags = Flags::WIDE_CHAR;
diff --git a/alacritty_terminal/src/tty/mod.rs b/alacritty_terminal/src/tty/mod.rs
index a1c8c0c1..cae6a4b9 100644
--- a/alacritty_terminal/src/tty/mod.rs
+++ b/alacritty_terminal/src/tty/mod.rs
@@ -60,7 +60,7 @@ pub trait EventedPty: EventedReadWrite {
}
/// Setup environment variables.
-pub fn setup_env<C>(config: &Config<C>) {
+pub fn setup_env(config: &Config) {
// Default to 'alacritty' terminfo if it is available, otherwise
// default to 'xterm-256color'. May be overridden by user's config
// below.
diff --git a/alacritty_terminal/src/tty/unix.rs b/alacritty_terminal/src/tty/unix.rs
index 697cb2d7..0d123b8c 100644
--- a/alacritty_terminal/src/tty/unix.rs
+++ b/alacritty_terminal/src/tty/unix.rs
@@ -5,12 +5,13 @@ use std::borrow::Cow;
use std::env;
use std::ffi::CStr;
use std::fs::File;
+use std::io::{Error, ErrorKind, Result};
use std::mem::MaybeUninit;
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
use std::os::unix::process::CommandExt;
use std::process::{Child, Command, Stdio};
+use std::ptr;
use std::sync::atomic::{AtomicI32, AtomicUsize, Ordering};
-use std::{io, ptr};
use libc::{self, c_int, pid_t, winsize, TIOCSCTTY};
use log::error;
@@ -21,7 +22,7 @@ use nix::sys::termios::{self, InputFlags, SetArg};
use signal_hook::consts as sigconsts;
use signal_hook_mio::v0_6::Signals;
-use crate::config::{Config, Program};
+use crate::config::{Program, PtyConfig};
use crate::event::OnResize;
use crate::grid::Dimensions;
use crate::term::SizeInfo;
@@ -73,7 +74,7 @@ fn set_controlling_terminal(fd: c_int) {
};
if res < 0 {
- die!("ioctl TIOCSCTTY failed: {}", io::Error::last_os_error());
+ die!("ioctl TIOCSCTTY failed: {}", Error::last_os_error());
}
}
@@ -143,7 +144,7 @@ fn default_shell(pw: &Passwd<'_>) -> Program {
}
/// Create a new TTY and return a handle to interact with it.
-pub fn new<C>(config: &Config<C>, size: &SizeInfo, window_id: Option<usize>) -> Pty {
+pub fn new(config: &PtyConfig, size: &SizeInfo, window_id: Option<usize>) -> Result<Pty> {
let (master, slave) = make_pty(size.to_winsize());
#[cfg(any(target_os = "linux", target_os = "macos"))]
@@ -192,7 +193,7 @@ pub fn new<C>(config: &Config<C>, size: &SizeInfo, window_id: Option<usize>) ->
// Create a new process group.
let err = libc::setsid();
if err == -1 {
- die!("Failed to set session id: {}", io::Error::last_os_error());
+ return Err(Error::new(ErrorKind::Other, "Failed to set session id"));
}
set_controlling_terminal(slave);
@@ -240,9 +241,12 @@ pub fn new<C>(config: &Config<C>, size: &SizeInfo, window_id: Option<usize>) ->
signals_token: mio::Token::from(0),
};
pty.on_resize(size);
- pty
+ Ok(pty)
},
- Err(err) => die!("Failed to spawn command '{}': {}", shell.program(), err),
+ Err(err) => Err(Error::new(
+ ErrorKind::NotFound,
+ format!("Failed to spawn command '{}': {}", shell.program(), err),
+ )),
}
}
@@ -267,7 +271,7 @@ impl EventedReadWrite for Pty {
token: &mut dyn Iterator<Item = mio::Token>,
interest: mio::Ready,
poll_opts: mio::PollOpt,
- ) -> io::Result<()> {
+ ) -> Result<()> {
self.token = token.next().unwrap();
poll.register(&EventedFd(&self.fd.as_raw_fd()), self.token, interest, poll_opts)?;
@@ -286,7 +290,7 @@ impl EventedReadWrite for Pty {
poll: &mio::Poll,
interest: mio::Ready,
poll_opts: mio::PollOpt,
- ) -> io::Result<()> {
+ ) -> Result<()> {
poll.reregister(&EventedFd(&self.fd.as_raw_fd()), self.token, interest, poll_opts)?;
poll.reregister(
@@ -298,7 +302,7 @@ impl EventedReadWrite for Pty {
}
#[inline]
- fn deregister(&mut self, poll: &mio::Poll) -> io::Result<()> {
+ fn deregister(&mut self, poll: &mio::Poll) -> Result<()> {
poll.deregister(&EventedFd(&self.fd.as_raw_fd()))?;
poll.deregister(&self.signals)
}
@@ -360,7 +364,7 @@ impl OnResize for Pty {
let res = unsafe { libc::ioctl(self.fd.as_raw_fd(), libc::TIOCSWINSZ, &win as *const _) };
if res < 0 {
- die!("ioctl TIOCSWINSZ failed: {}", io::Error::last_os_error());
+ die!("ioctl TIOCSWINSZ failed: {}", Error::last_os_error());
}
}
}
diff --git a/alacritty_terminal/src/tty/windows/conpty.rs b/alacritty_terminal/src/tty/windows/conpty.rs
index 002022ea..9556be8b 100644
--- a/alacritty_terminal/src/tty/windows/conpty.rs
+++ b/alacritty_terminal/src/tty/windows/conpty.rs
@@ -15,7 +15,7 @@ use winapi::um::processthreadsapi::{
use winapi::um::winbase::{EXTENDED_STARTUPINFO_PRESENT, STARTF_USESTDHANDLES, STARTUPINFOEXW};
use winapi::um::wincontypes::{COORD, HPCON};
-use crate::config::Config;
+use crate::config::PtyConfig;
use crate::event::OnResize;
use crate::grid::Dimensions;
use crate::term::SizeInfo;
@@ -40,7 +40,7 @@ impl Drop for Conpty {
// The ConPTY handle can be sent between threads.
unsafe impl Send for Conpty {}
-pub fn new<C>(config: &Config<C>, size: &SizeInfo) -> Option<Pty> {
+pub fn new(config: &PtyConfig, size: &SizeInfo) -> Option<Pty> {
let mut pty_handle = 0 as HPCON;
// Passing 0 as the size parameter allows the "system default" buffer
@@ -136,7 +136,7 @@ pub fn new<C>(config: &Config<C>, size: &SizeInfo) -> Option<Pty> {
}
}
- let cmdline = win32_string(&cmdline(&config));
+ let cmdline = win32_string(&cmdline(config));
let cwd = config.working_directory.as_ref().map(win32_string);
let mut proc_info: PROCESS_INFORMATION = Default::default();
diff --git a/alacritty_terminal/src/tty/windows/mod.rs b/alacritty_terminal/src/tty/windows/mod.rs
index 644253f4..0cc6a8bc 100644
--- a/alacritty_terminal/src/tty/windows/mod.rs
+++ b/alacritty_terminal/src/tty/windows/mod.rs
@@ -1,10 +1,10 @@
use std::ffi::OsStr;
-use std::io;
+use std::io::{self, Error, ErrorKind, Result};
use std::iter::once;
use std::os::windows::ffi::OsStrExt;
use std::sync::mpsc::TryRecvError;
-use crate::config::{Config, Program};
+use crate::config::{Program, PtyConfig};
use crate::event::OnResize;
use crate::term::SizeInfo;
use crate::tty::windows::child::ChildExitWatcher;
@@ -28,8 +28,8 @@ pub struct Pty {
child_watcher: ChildExitWatcher,
}
-pub fn new<C>(config: &Config<C>, size: &SizeInfo, _window_id: Option<usize>) -> Pty {
- conpty::new(config, size).expect("Failed to create ConPTY backend")
+pub fn new(config: &PtyConfig, size: &SizeInfo, _window_id: Option<usize>) -> Result<Pty> {
+ conpty::new(config, size).ok_or_else(|| Error::new(ErrorKind::Other, "failed to spawn conpty"))
}
impl Pty {
@@ -165,11 +165,11 @@ impl OnResize for Pty {
}
}
-fn cmdline<C>(config: &Config<C>) -> String {
+fn cmdline(config: &PtyConfig) -> String {
let default_shell = Program::Just("powershell".to_owned());
let shell = config.shell.as_ref().unwrap_or(&default_shell);
- once(shell.program().as_ref())
+ once(shell.program())
.chain(shell.args().iter().map(|a| a.as_ref()))
.collect::<Vec<_>>()
.join(" ")
diff --git a/alacritty_terminal/src/vi_mode.rs b/alacritty_terminal/src/vi_mode.rs
index 5bf5eaed..de5c61b5 100644
--- a/alacritty_terminal/src/vi_mode.rs
+++ b/alacritty_terminal/src/vi_mode.rs
@@ -379,13 +379,13 @@ mod tests {
use super::*;
use crate::ansi::Handler;
- use crate::config::MockConfig;
+ use crate::config::Config;
use crate::index::{Column, Line};
use crate::term::{SizeInfo, Term};
fn term() -> Term<()> {
let size = SizeInfo::new(20., 20., 1.0, 1.0, 0.0, 0.0, false);
- Term::new(&MockConfig::default(), size, ())
+ Term::new(&Config::default(), size, ())
}
#[test]