1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-10 06:34:17 +03:00

mux: remove ProgDomain; just pass down default prog/cwd as appropriate

This allows making these values configurable per-domain in the
future.

refs: #1456
This commit is contained in:
Wez Furlong 2021-12-24 07:51:10 -07:00
parent a38757ef3b
commit 6c1710f87d
4 changed files with 28 additions and 28 deletions

View File

@ -148,12 +148,6 @@ pub fn designate_this_as_the_main_thread() {
}); });
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ProgDomain {
Local,
Remote,
}
#[must_use = "Cancels the subscription when dropped"] #[must_use = "Cancels the subscription when dropped"]
pub struct ConfigSubscription(usize); pub struct ConfigSubscription(usize);
@ -1817,17 +1811,18 @@ impl Config {
pub fn build_prog( pub fn build_prog(
&self, &self,
prog: Option<Vec<&OsStr>>, prog: Option<Vec<&OsStr>>,
prog_domain: ProgDomain, default_prog: Option<&Vec<String>>,
default_cwd: Option<&PathBuf>,
) -> Result<CommandBuilder, Error> { ) -> Result<CommandBuilder, Error> {
let mut cmd = match (prog, prog_domain) { let mut cmd = match prog {
(Some(args), _) => { Some(args) => {
let mut args = args.iter(); let mut args = args.iter();
let mut cmd = CommandBuilder::new(args.next().expect("executable name")); let mut cmd = CommandBuilder::new(args.next().expect("executable name"));
cmd.args(args); cmd.args(args);
cmd cmd
} }
(None, ProgDomain::Local) => { None => {
if let Some(prog) = self.default_prog.as_ref() { if let Some(prog) = default_prog {
let mut args = prog.iter(); let mut args = prog.iter();
let mut cmd = CommandBuilder::new(args.next().expect("executable name")); let mut cmd = CommandBuilder::new(args.next().expect("executable name"));
cmd.args(args); cmd.args(args);
@ -1836,22 +1831,19 @@ impl Config {
CommandBuilder::new_default_prog() CommandBuilder::new_default_prog()
} }
} }
(None, ProgDomain::Remote) => CommandBuilder::new_default_prog(),
}; };
self.apply_cmd_defaults(&mut cmd, prog_domain); self.apply_cmd_defaults(&mut cmd, default_cwd);
Ok(cmd) Ok(cmd)
} }
pub fn apply_cmd_defaults(&self, cmd: &mut CommandBuilder, prog_domain: ProgDomain) { pub fn apply_cmd_defaults(&self, cmd: &mut CommandBuilder, default_cwd: Option<&PathBuf>) {
// Apply `default_cwd` only if `cwd` is not already set, allows `--cwd` // Apply `default_cwd` only if `cwd` is not already set, allows `--cwd`
// option to take precedence // option to take precedence
if prog_domain == ProgDomain::Local { if let (None, Some(cwd)) = (cmd.get_cwd(), default_cwd) {
if let (None, Some(cwd)) = (cmd.get_cwd(), &self.default_cwd) {
cmd.cwd(cwd); cmd.cwd(cwd);
} }
}
// Augment WSLENV so that TERM related environment propagates // Augment WSLENV so that TERM related environment propagates
// across the win32/wsl boundary // across the win32/wsl boundary

View File

@ -12,7 +12,7 @@ use crate::window::WindowId;
use crate::Mux; use crate::Mux;
use anyhow::{bail, Error}; use anyhow::{bail, Error};
use async_trait::async_trait; use async_trait::async_trait;
use config::{configuration, ProgDomain}; use config::configuration;
use downcast_rs::{impl_downcast, Downcast}; use downcast_rs::{impl_downcast, Downcast};
use portable_pty::{native_pty_system, CommandBuilder, PtySize, PtySystem}; use portable_pty::{native_pty_system, CommandBuilder, PtySize, PtySystem};
use std::rc::Rc; use std::rc::Rc;
@ -120,10 +120,14 @@ impl Domain for LocalDomain {
let config = configuration(); let config = configuration();
let mut cmd = match command { let mut cmd = match command {
Some(mut cmd) => { Some(mut cmd) => {
config.apply_cmd_defaults(&mut cmd, ProgDomain::Local); config.apply_cmd_defaults(&mut cmd, config.default_cwd.as_ref());
cmd cmd
} }
None => config.build_prog(None, ProgDomain::Local)?, None => config.build_prog(
None,
config.default_prog.as_ref(),
config.default_cwd.as_ref(),
)?,
}; };
if let Some(dir) = command_dir { if let Some(dir) = command_dir {
// I'm not normally a fan of existence checking, but not checking here // I'm not normally a fan of existence checking, but not checking here
@ -200,10 +204,14 @@ impl Domain for LocalDomain {
let config = configuration(); let config = configuration();
let mut cmd = match command { let mut cmd = match command {
Some(mut cmd) => { Some(mut cmd) => {
config.apply_cmd_defaults(&mut cmd, ProgDomain::Local); config.apply_cmd_defaults(&mut cmd, config.default_cwd.as_ref());
cmd cmd
} }
None => config.build_prog(None, ProgDomain::Local)?, None => config.build_prog(
None,
config.default_prog.as_ref(),
config.default_cwd.as_ref(),
)?,
}; };
if let Some(dir) = command_dir { if let Some(dir) = command_dir {
// I'm not normally a fan of existence checking, but not checking here // I'm not normally a fan of existence checking, but not checking here

View File

@ -7,7 +7,6 @@ use crate::window::WindowId;
use crate::Mux; use crate::Mux;
use anyhow::{anyhow, bail, Context, Error}; use anyhow::{anyhow, bail, Context, Error};
use async_trait::async_trait; use async_trait::async_trait;
use config::ProgDomain;
use filedescriptor::{poll, pollfd, socketpair, AsRawSocketDescriptor, FileDescriptor, POLLIN}; use filedescriptor::{poll, pollfd, socketpair, AsRawSocketDescriptor, FileDescriptor, POLLIN};
use portable_pty::cmdbuilder::CommandBuilder; use portable_pty::cmdbuilder::CommandBuilder;
use portable_pty::{ChildKiller, ExitStatus, MasterPty, PtySize}; use portable_pty::{ChildKiller, ExitStatus, MasterPty, PtySize};
@ -610,10 +609,10 @@ impl Domain for RemoteSshDomain {
let config = config::configuration(); let config = config::configuration();
let cmd = match command { let cmd = match command {
Some(mut cmd) => { Some(mut cmd) => {
config.apply_cmd_defaults(&mut cmd, ProgDomain::Remote); config.apply_cmd_defaults(&mut cmd, None);
cmd cmd
} }
None => config.build_prog(None, ProgDomain::Remote)?, None => config.build_prog(None, None, None)?,
}; };
let pane_id = alloc_pane_id(); let pane_id = alloc_pane_id();

View File

@ -4,7 +4,7 @@
use crate::frontend::front_end; use crate::frontend::front_end;
use ::window::*; use ::window::*;
use anyhow::{anyhow, Context}; use anyhow::{anyhow, Context};
use config::{ConfigHandle, ProgDomain, SshBackend}; use config::{ConfigHandle, SshBackend};
use mux::activity::Activity; use mux::activity::Activity;
use mux::domain::{Domain, LocalDomain}; use mux::domain::{Domain, LocalDomain};
use mux::Mux; use mux::Mux;
@ -364,7 +364,8 @@ fn run_terminal_gui(opts: StartCommand) -> anyhow::Result<()> {
let prog = opts.prog.iter().map(|s| s.as_os_str()).collect::<Vec<_>>(); let prog = opts.prog.iter().map(|s| s.as_os_str()).collect::<Vec<_>>();
let mut builder = config.build_prog( let mut builder = config.build_prog(
if prog.is_empty() { None } else { Some(prog) }, if prog.is_empty() { None } else { Some(prog) },
ProgDomain::Local, config.default_prog.as_ref(),
config.default_cwd.as_ref(),
)?; )?;
if let Some(cwd) = opts.cwd { if let Some(cwd) = opts.cwd {
builder.cwd(cwd); builder.cwd(cwd);