summaryrefslogtreecommitdiff
path: root/alacritty_terminal/src/tty
diff options
context:
space:
mode:
authorKirill Chibisov <contact@kchibisov.com>2023-11-10 18:16:22 +0400
committerGitHub <noreply@github.com>2023-11-10 18:16:22 +0400
commit5060f8eeb864e8c304fbad9588bdd882db942356 (patch)
treeb615ded19e6ac545b495f716e2a22ecd903332af /alacritty_terminal/src/tty
parent3ffd6c8f26f9788466b9ba95659b8de970a10f08 (diff)
downloadalacritty-5060f8eeb864e8c304fbad9588bdd882db942356.tar.gz
alacritty-5060f8eeb864e8c304fbad9588bdd882db942356.zip
Remove `alacritty_config` from alacritty_terminal
There's no need to force alacritty's user configuration on other users of the crate, thus provide the options actually used by alacritty_terminal itself.
Diffstat (limited to 'alacritty_terminal/src/tty')
-rw-r--r--alacritty_terminal/src/tty/mod.rs41
-rw-r--r--alacritty_terminal/src/tty/unix.rs9
-rw-r--r--alacritty_terminal/src/tty/windows/conpty.rs4
-rw-r--r--alacritty_terminal/src/tty/windows/mod.rs13
4 files changed, 44 insertions, 23 deletions
diff --git a/alacritty_terminal/src/tty/mod.rs b/alacritty_terminal/src/tty/mod.rs
index 315f008c..d1bb023c 100644
--- a/alacritty_terminal/src/tty/mod.rs
+++ b/alacritty_terminal/src/tty/mod.rs
@@ -4,8 +4,6 @@ use std::path::PathBuf;
use std::sync::Arc;
use std::{env, io};
-use crate::config::Config;
-
use polling::{Event, PollMode, Poller};
#[cfg(not(windows))]
@@ -18,8 +16,38 @@ pub mod windows;
#[cfg(windows)]
pub use self::windows::*;
+/// Configuration for the `Pty` interface.
+#[derive(Clone, Debug, PartialEq, Eq, Default)]
+pub struct Options {
+ /// Shell options.
+ ///
+ /// [`None`] will use the default shell.
+ pub shell: Option<Shell>,
+
+ /// Shell startup directory.
+ pub working_directory: Option<PathBuf>,
+
+ /// Remain open after child process exits.
+ pub hold: bool,
+}
+
+/// Shell options.
+#[derive(Clone, Debug, PartialEq, Eq, Default)]
+pub struct Shell {
+ /// Path to a shell program to run on startup.
+ pub(crate) program: String,
+ /// Arguments passed to shell.
+ pub(crate) args: Vec<String>,
+}
+
+impl Shell {
+ pub fn new(program: String, args: Vec<String>) -> Self {
+ Self { program, args }
+ }
+}
+
/// This trait defines the behaviour needed to read and/or write to a stream.
-/// It defines an abstraction over mio's interface in order to allow either one
+/// It defines an abstraction over polling's interface in order to allow either one
/// read/write object or a separate read and write object.
pub trait EventedReadWrite {
type Reader: io::Read;
@@ -56,7 +84,7 @@ pub trait EventedPty: EventedReadWrite {
}
/// Setup environment variables.
-pub fn setup_env(config: &Config) {
+pub fn setup_env() {
// Default to 'alacritty' terminfo if it is available, otherwise
// default to 'xterm-256color'. May be overridden by user's config
// below.
@@ -69,11 +97,6 @@ pub fn setup_env(config: &Config) {
// Prevent child processes from inheriting startup notification env.
env::remove_var("DESKTOP_STARTUP_ID");
env::remove_var("XDG_ACTIVATION_TOKEN");
-
- // Set env vars from config.
- for (key, value) in config.env.iter() {
- env::set_var(key, value);
- }
}
/// Check if a terminfo entry exists on the system.
diff --git a/alacritty_terminal/src/tty/unix.rs b/alacritty_terminal/src/tty/unix.rs
index 6b543437..2b4f8e54 100644
--- a/alacritty_terminal/src/tty/unix.rs
+++ b/alacritty_terminal/src/tty/unix.rs
@@ -22,9 +22,8 @@ use rustix_openpty::rustix::termios::{self, InputModes, OptionalActions};
use signal_hook::consts as sigconsts;
use signal_hook::low_level::pipe as signal_pipe;
-use crate::config::PtyConfig;
use crate::event::{OnResize, WindowSize};
-use crate::tty::{ChildEvent, EventedPty, EventedReadWrite};
+use crate::tty::{ChildEvent, EventedPty, EventedReadWrite, Options};
// Interest in PTY read/writes.
pub(crate) const PTY_READ_WRITE_TOKEN: usize = 0;
@@ -194,7 +193,7 @@ fn default_shell_command(shell: &str, user: &str) -> Command {
}
/// Create a new TTY and return a handle to interact with it.
-pub fn new(config: &PtyConfig, window_size: WindowSize, window_id: u64) -> Result<Pty> {
+pub fn new(config: &Options, window_size: WindowSize, window_id: u64) -> Result<Pty> {
let (master, slave) = make_pty(window_size.to_winsize())?;
let master_fd = master.as_raw_fd();
let slave_fd = slave.as_raw_fd();
@@ -209,8 +208,8 @@ pub fn new(config: &PtyConfig, window_size: WindowSize, window_id: u64) -> Resul
let user = ShellUser::from_env()?;
let mut builder = if let Some(shell) = config.shell.as_ref() {
- let mut cmd = Command::new(shell.program());
- cmd.args(shell.args());
+ let mut cmd = Command::new(&shell.program);
+ cmd.args(shell.args.as_slice());
cmd
} else {
default_shell_command(&user.shell, &user.user)
diff --git a/alacritty_terminal/src/tty/windows/conpty.rs b/alacritty_terminal/src/tty/windows/conpty.rs
index 12189371..9731b4f0 100644
--- a/alacritty_terminal/src/tty/windows/conpty.rs
+++ b/alacritty_terminal/src/tty/windows/conpty.rs
@@ -17,11 +17,11 @@ use windows_sys::Win32::System::Threading::{
STARTF_USESTDHANDLES, STARTUPINFOEXW, STARTUPINFOW,
};
-use crate::config::PtyConfig;
use crate::event::{OnResize, WindowSize};
use crate::tty::windows::blocking::{UnblockedReader, UnblockedWriter};
use crate::tty::windows::child::ChildExitWatcher;
use crate::tty::windows::{cmdline, win32_string, Pty};
+use crate::tty::Options;
const PIPE_CAPACITY: usize = crate::event_loop::READ_BUFFER_SIZE;
@@ -104,7 +104,7 @@ impl Drop for Conpty {
// The ConPTY handle can be sent between threads.
unsafe impl Send for Conpty {}
-pub fn new(config: &PtyConfig, window_size: WindowSize) -> Option<Pty> {
+pub fn new(config: &Options, window_size: WindowSize) -> Option<Pty> {
let api = ConptyApi::new();
let mut pty_handle: HPCON = 0;
diff --git a/alacritty_terminal/src/tty/windows/mod.rs b/alacritty_terminal/src/tty/windows/mod.rs
index 080f6e83..cbd803f1 100644
--- a/alacritty_terminal/src/tty/windows/mod.rs
+++ b/alacritty_terminal/src/tty/windows/mod.rs
@@ -5,10 +5,9 @@ use std::os::windows::ffi::OsStrExt;
use std::sync::mpsc::TryRecvError;
use std::sync::Arc;
-use crate::config::{Program, PtyConfig};
use crate::event::{OnResize, WindowSize};
use crate::tty::windows::child::ChildExitWatcher;
-use crate::tty::{ChildEvent, EventedPty, EventedReadWrite};
+use crate::tty::{ChildEvent, EventedPty, EventedReadWrite, Options, Shell};
mod blocking;
mod child;
@@ -34,7 +33,7 @@ pub struct Pty {
child_watcher: ChildExitWatcher,
}
-pub fn new(config: &PtyConfig, window_size: WindowSize, _window_id: u64) -> Result<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"))
}
@@ -123,12 +122,12 @@ impl OnResize for Pty {
}
}
-fn cmdline(config: &PtyConfig) -> String {
- let default_shell = Program::Just("powershell".to_owned());
+fn cmdline(config: &Options) -> String {
+ let default_shell = Shell::new("powershell".to_owned(), Vec::new());
let shell = config.shell.as_ref().unwrap_or(&default_shell);
- once(shell.program())
- .chain(shell.args().iter().map(|a| a.as_ref()))
+ once(shell.program.as_str())
+ .chain(shell.args.iter().map(|s| s.as_str()))
.collect::<Vec<_>>()
.join(" ")
}