mirror of
https://github.com/wez/wezterm.git
synced 2024-09-20 03:09:06 +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:
parent
a38757ef3b
commit
6c1710f87d
@ -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"]
|
||||
pub struct ConfigSubscription(usize);
|
||||
|
||||
@ -1817,17 +1811,18 @@ impl Config {
|
||||
pub fn build_prog(
|
||||
&self,
|
||||
prog: Option<Vec<&OsStr>>,
|
||||
prog_domain: ProgDomain,
|
||||
default_prog: Option<&Vec<String>>,
|
||||
default_cwd: Option<&PathBuf>,
|
||||
) -> Result<CommandBuilder, Error> {
|
||||
let mut cmd = match (prog, prog_domain) {
|
||||
(Some(args), _) => {
|
||||
let mut cmd = match prog {
|
||||
Some(args) => {
|
||||
let mut args = args.iter();
|
||||
let mut cmd = CommandBuilder::new(args.next().expect("executable name"));
|
||||
cmd.args(args);
|
||||
cmd
|
||||
}
|
||||
(None, ProgDomain::Local) => {
|
||||
if let Some(prog) = self.default_prog.as_ref() {
|
||||
None => {
|
||||
if let Some(prog) = default_prog {
|
||||
let mut args = prog.iter();
|
||||
let mut cmd = CommandBuilder::new(args.next().expect("executable name"));
|
||||
cmd.args(args);
|
||||
@ -1836,22 +1831,19 @@ impl Config {
|
||||
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)
|
||||
}
|
||||
|
||||
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`
|
||||
// option to take precedence
|
||||
if prog_domain == ProgDomain::Local {
|
||||
if let (None, Some(cwd)) = (cmd.get_cwd(), &self.default_cwd) {
|
||||
if let (None, Some(cwd)) = (cmd.get_cwd(), default_cwd) {
|
||||
cmd.cwd(cwd);
|
||||
}
|
||||
}
|
||||
|
||||
// Augment WSLENV so that TERM related environment propagates
|
||||
// across the win32/wsl boundary
|
||||
|
@ -12,7 +12,7 @@ use crate::window::WindowId;
|
||||
use crate::Mux;
|
||||
use anyhow::{bail, Error};
|
||||
use async_trait::async_trait;
|
||||
use config::{configuration, ProgDomain};
|
||||
use config::configuration;
|
||||
use downcast_rs::{impl_downcast, Downcast};
|
||||
use portable_pty::{native_pty_system, CommandBuilder, PtySize, PtySystem};
|
||||
use std::rc::Rc;
|
||||
@ -120,10 +120,14 @@ impl Domain for LocalDomain {
|
||||
let config = configuration();
|
||||
let mut cmd = match command {
|
||||
Some(mut cmd) => {
|
||||
config.apply_cmd_defaults(&mut cmd, ProgDomain::Local);
|
||||
config.apply_cmd_defaults(&mut cmd, config.default_cwd.as_ref());
|
||||
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 {
|
||||
// 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 mut cmd = match command {
|
||||
Some(mut cmd) => {
|
||||
config.apply_cmd_defaults(&mut cmd, ProgDomain::Local);
|
||||
config.apply_cmd_defaults(&mut cmd, config.default_cwd.as_ref());
|
||||
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 {
|
||||
// I'm not normally a fan of existence checking, but not checking here
|
||||
|
@ -7,7 +7,6 @@ use crate::window::WindowId;
|
||||
use crate::Mux;
|
||||
use anyhow::{anyhow, bail, Context, Error};
|
||||
use async_trait::async_trait;
|
||||
use config::ProgDomain;
|
||||
use filedescriptor::{poll, pollfd, socketpair, AsRawSocketDescriptor, FileDescriptor, POLLIN};
|
||||
use portable_pty::cmdbuilder::CommandBuilder;
|
||||
use portable_pty::{ChildKiller, ExitStatus, MasterPty, PtySize};
|
||||
@ -610,10 +609,10 @@ impl Domain for RemoteSshDomain {
|
||||
let config = config::configuration();
|
||||
let cmd = match command {
|
||||
Some(mut cmd) => {
|
||||
config.apply_cmd_defaults(&mut cmd, ProgDomain::Remote);
|
||||
config.apply_cmd_defaults(&mut cmd, None);
|
||||
cmd
|
||||
}
|
||||
None => config.build_prog(None, ProgDomain::Remote)?,
|
||||
None => config.build_prog(None, None, None)?,
|
||||
};
|
||||
let pane_id = alloc_pane_id();
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
use crate::frontend::front_end;
|
||||
use ::window::*;
|
||||
use anyhow::{anyhow, Context};
|
||||
use config::{ConfigHandle, ProgDomain, SshBackend};
|
||||
use config::{ConfigHandle, SshBackend};
|
||||
use mux::activity::Activity;
|
||||
use mux::domain::{Domain, LocalDomain};
|
||||
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 mut builder = config.build_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 {
|
||||
builder.cwd(cwd);
|
||||
|
Loading…
Reference in New Issue
Block a user