summaryrefslogtreecommitdiff
path: root/alacritty_terminal/src/tty
diff options
context:
space:
mode:
authorChristian Duerr <chrisduerr@users.noreply.github.com>2019-05-10 11:36:16 +0000
committerGitHub <noreply@github.com>2019-05-10 11:36:16 +0000
commit5d173f6df3b20308eb318cef4b58147b2197d5f9 (patch)
tree05638837bef25d65a818253814331a4f429f57ac /alacritty_terminal/src/tty
parent7738c52ed4eb177ead9f43d14207ecb129cfe617 (diff)
downloadalacritty-5d173f6df3b20308eb318cef4b58147b2197d5f9.tar.gz
alacritty-5d173f6df3b20308eb318cef4b58147b2197d5f9.zip
Refactor config parsing files
This is a large refactor of the config parsing structure, attempting to reduce the size of the file a bit by splitting it up into different modules with more specific purposes. This also fixes #2279.
Diffstat (limited to 'alacritty_terminal/src/tty')
-rw-r--r--alacritty_terminal/src/tty/mod.rs2
-rw-r--r--alacritty_terminal/src/tty/unix.rs19
-rw-r--r--alacritty_terminal/src/tty/windows/conpty.rs22
-rw-r--r--alacritty_terminal/src/tty/windows/mod.rs13
-rw-r--r--alacritty_terminal/src/tty/windows/winpty.rs18
5 files changed, 25 insertions, 49 deletions
diff --git a/alacritty_terminal/src/tty/mod.rs b/alacritty_terminal/src/tty/mod.rs
index 2a6410d8..c0ac7a31 100644
--- a/alacritty_terminal/src/tty/mod.rs
+++ b/alacritty_terminal/src/tty/mod.rs
@@ -90,7 +90,7 @@ pub fn setup_env(config: &Config) {
env::set_var("COLORTERM", "truecolor");
// Set env vars from config
- for (key, value) in config.env().iter() {
+ for (key, value) in config.env.iter() {
env::set_var(key, value);
}
}
diff --git a/alacritty_terminal/src/tty/unix.rs b/alacritty_terminal/src/tty/unix.rs
index 668fe7bd..0cf1a821 100644
--- a/alacritty_terminal/src/tty/unix.rs
+++ b/alacritty_terminal/src/tty/unix.rs
@@ -15,7 +15,7 @@
//! tty related functionality
//!
-use crate::config::{Config, Options, Shell};
+use crate::config::{Config, Shell};
use crate::display::OnResize;
use crate::term::SizeInfo;
use crate::tty::{ChildEvent, EventedPty, EventedReadWrite};
@@ -154,12 +154,7 @@ impl Pty {
}
/// Create a new tty and return a handle to interact with it.
-pub fn new<T: ToWinsize>(
- config: &Config,
- options: &Options,
- size: &T,
- window_id: Option<usize>,
-) -> Pty {
+pub fn new<T: ToWinsize>(config: &Config, size: &T, window_id: Option<usize>) -> Pty {
let win_size = size.to_winsize();
let mut buf = [0; 1024];
let pw = get_pw_entry(&mut buf);
@@ -174,12 +169,10 @@ pub fn new<T: ToWinsize>(
} else {
Shell::new(pw.shell)
};
- let shell = config.shell().unwrap_or(&default_shell);
+ let shell = config.shell.as_ref().unwrap_or(&default_shell);
- let initial_command = options.command().unwrap_or(shell);
-
- let mut builder = Command::new(initial_command.program());
- for arg in initial_command.args() {
+ let mut builder = Command::new(&*shell.program);
+ for arg in &shell.args {
builder.arg(arg);
}
@@ -230,7 +223,7 @@ pub fn new<T: ToWinsize>(
});
// Handle set working directory option
- if let Some(ref dir) = options.working_dir {
+ if let Some(ref dir) = config.working_directory() {
builder.current_dir(dir.as_path());
}
diff --git a/alacritty_terminal/src/tty/windows/conpty.rs b/alacritty_terminal/src/tty/windows/conpty.rs
index 0789dd96..bd602c35 100644
--- a/alacritty_terminal/src/tty/windows/conpty.rs
+++ b/alacritty_terminal/src/tty/windows/conpty.rs
@@ -37,7 +37,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, Options, Shell};
+use crate::config::{Config, Shell};
use crate::display::OnResize;
use crate::term::SizeInfo;
@@ -98,13 +98,8 @@ impl Drop for Conpty {
unsafe impl Send for Conpty {}
unsafe impl Sync for Conpty {}
-pub fn new<'a>(
- config: &Config,
- options: &Options,
- size: &SizeInfo,
- _window_id: Option<usize>,
-) -> Option<Pty<'a>> {
- if !config.enable_experimental_conpty_backend() {
+pub fn new<'a>(config: &Config, size: &SizeInfo, _window_id: Option<usize>) -> Option<Pty<'a>> {
+ if !config.enable_experimental_conpty_backend {
return None;
}
@@ -143,7 +138,7 @@ pub fn new<'a>(
let mut startup_info_ex: STARTUPINFOEXW = Default::default();
- let title = options.title.as_ref().map(String::as_str).unwrap_or("Alacritty");
+ let title = config.window.title.as_ref().map(String::as_str).unwrap_or("Alacritty");
let title = U16CString::from_str(title).unwrap();
startup_info_ex.StartupInfo.lpTitle = title.as_ptr() as LPWSTR;
@@ -209,13 +204,12 @@ pub fn new<'a>(
// Get process commandline
let default_shell = &Shell::new("powershell");
- let shell = config.shell().unwrap_or(default_shell);
- let initial_command = options.command().unwrap_or(shell);
- let mut cmdline = initial_command.args().to_vec();
- cmdline.insert(0, initial_command.program().into());
+ let shell = config.shell.as_ref().unwrap_or(default_shell);
+ let mut cmdline = shell.args.clone();
+ cmdline.insert(0, shell.program.to_string());
// Warning, here be borrow hell
- let cwd = options.working_dir.as_ref().map(|dir| canonicalize(dir).unwrap());
+ let cwd = config.working_directory().as_ref().map(|dir| canonicalize(dir).unwrap());
let cwd = cwd.as_ref().map(|dir| dir.to_str().unwrap());
// Create the client application, using startup info containing ConPTY info
diff --git a/alacritty_terminal/src/tty/windows/mod.rs b/alacritty_terminal/src/tty/windows/mod.rs
index a3d3faec..7537d331 100644
--- a/alacritty_terminal/src/tty/windows/mod.rs
+++ b/alacritty_terminal/src/tty/windows/mod.rs
@@ -24,7 +24,7 @@ use winapi::shared::winerror::WAIT_TIMEOUT;
use winapi::um::synchapi::WaitForSingleObject;
use winapi::um::winbase::WAIT_OBJECT_0;
-use crate::config::{Config, Options};
+use crate::config::Config;
use crate::display::OnResize;
use crate::term::SizeInfo;
use crate::tty::{EventedPty, EventedReadWrite};
@@ -83,19 +83,14 @@ impl<'a> Pty<'a> {
}
}
-pub fn new<'a>(
- config: &Config,
- options: &Options,
- size: &SizeInfo,
- window_id: Option<usize>,
-) -> Pty<'a> {
- if let Some(pty) = conpty::new(config, options, size, window_id) {
+pub fn new<'a>(config: &Config, size: &SizeInfo, window_id: Option<usize>) -> Pty<'a> {
+ if let Some(pty) = conpty::new(config, size, window_id) {
info!("Using Conpty agent");
IS_CONPTY.store(true, Ordering::Relaxed);
pty
} else {
info!("Using Winpty agent");
- winpty::new(config, options, size, window_id)
+ winpty::new(config, size, window_id)
}
}
diff --git a/alacritty_terminal/src/tty/windows/winpty.rs b/alacritty_terminal/src/tty/windows/winpty.rs
index 7aa976ee..8795ca6d 100644
--- a/alacritty_terminal/src/tty/windows/winpty.rs
+++ b/alacritty_terminal/src/tty/windows/winpty.rs
@@ -27,7 +27,7 @@ use winapi::um::winbase::FILE_FLAG_OVERLAPPED;
use winpty::Config as WinptyConfig;
use winpty::{ConfigFlags, MouseMode, SpawnConfig, SpawnFlags, Winpty};
-use crate::config::{Config, Options, Shell};
+use crate::config::{Config, Shell};
use crate::display::OnResize;
use crate::term::SizeInfo;
@@ -75,12 +75,7 @@ impl<'a> Drop for Agent<'a> {
/// This is a placeholder value until we see how often long responses happen
const AGENT_TIMEOUT: u32 = 10000;
-pub fn new<'a>(
- config: &Config,
- options: &Options,
- size: &SizeInfo,
- _window_id: Option<usize>,
-) -> Pty<'a> {
+pub fn new<'a>(config: &Config, size: &SizeInfo, _window_id: Option<usize>) -> Pty<'a> {
// Create config
let mut wconfig = WinptyConfig::new(ConfigFlags::empty()).unwrap();
@@ -94,13 +89,12 @@ pub fn new<'a>(
// Get process commandline
let default_shell = &Shell::new("powershell");
- let shell = config.shell().unwrap_or(default_shell);
- let initial_command = options.command().unwrap_or(shell);
- let mut cmdline = initial_command.args().to_vec();
- cmdline.insert(0, initial_command.program().into());
+ let shell = config.shell.as_ref().unwrap_or(default_shell);
+ let mut cmdline = shell.args.clone();
+ cmdline.insert(0, shell.program.to_string());
// Warning, here be borrow hell
- let cwd = options.working_dir.as_ref().map(|dir| canonicalize(dir).unwrap());
+ let cwd = config.working_directory().as_ref().map(|dir| canonicalize(dir).unwrap());
let cwd = cwd.as_ref().map(|dir| dir.to_str().unwrap());
// Spawn process