plumb OSC 7 cwd through to windows pty layer

This allows this prompt setting to work:

```
prompt $E]7;file://localhost/$P$E\$P$G
```

although this one sets it for future prompts:

```
setx prompt $E]7;file://localhost/$P$E\$P$G
```

refs: https://github.com/wez/wezterm/issues/146
This commit is contained in:
Wez Furlong committed 2020-02-09 09:10:26 -08:00
1 parent 1a50075ae6
commit d73a37be24
3 files changed
+35 -3

No files matched your search

+9
View File
@@ -213,6 +213,15 @@ impl CommandBuilder {
exe.to_owned()
}
pub(crate) fn current_directory(&self) -> Option<Vec<u16>> {
self.cwd.as_ref().map(|c| {
let mut wide = vec![];
wide.extend(c.encode_wide());
wide.push(0);
wide
})
}
/// Constructs an environment block for this spawn attempt.
/// Uses the current process environment as the base and then
/// adds/replaces the environment that was specified via the
+14 -2
View File
@@ -99,6 +99,9 @@ impl PsuedoCon {
let (mut exe, mut cmdline) = cmd.cmdline()?;
let cmd_os = OsString::from_wide(&cmdline);
let cwd = cmd.current_directory();
let res = unsafe {
CreateProcessW(
exe.as_mut_slice().as_mut_ptr(),
@@ -108,14 +111,23 @@ impl PsuedoCon {
0,
EXTENDED_STARTUPINFO_PRESENT | CREATE_UNICODE_ENVIRONMENT,
cmd.environment_block().as_mut_slice().as_mut_ptr() as *mut _,
ptr::null_mut(),
cwd.as_ref()
.map(|c| c.as_slice().as_ptr())
.unwrap_or(ptr::null()),
&mut si.StartupInfo,
&mut pi,
)
};
if res == 0 {
let err = IoError::last_os_error();
bail!("CreateProcessW `{:?}` failed: {}", cmd_os, err);
let msg = format!(
"CreateProcessW `{:?}` in cwd `{:?}` failed: {}",
cmd_os,
cwd.as_ref().map(|c| OsString::from_wide(c)),
err
);
log::error!("{}", msg);
bail!("{}", msg);
}
// Make sure we close out the thread handle so we don't leak it;
+12 -1
View File
@@ -1130,9 +1130,20 @@ impl TermWindow {
),
};
let cwd = match cwd {
Some(url) if url.scheme() == "file" => Some(url.path().to_string()),
Some(url) if url.scheme() == "file" => {
let path = url.path().to_string();
// On Windows the file URI can produce a path like:
// `/C:\Users` which is valid in a file URI, but the leading slash
// is not liked by the windows file APIs, so we strip it off here.
if cfg!(windows) && path.starts_with('/') {
Some(path[1..].to_owned())
} else {
Some(path)
}
}
Some(_) | None => None,
};
let tab = domain.spawn(size, None, cwd, mux_window_id).await?;
let tab_id = tab.tab_id();