1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-23 06:54:45 +03:00
Commit Graph

140 Commits

Author SHA1 Message Date
Wez Furlong
690d1e3f5e pty: resolve relative to configured cwd
Otherwise `wezterm start --cwd foo ./something` will refuse to launch

refs: #1005
2021-08-12 10:11:09 -07:00
Wez Furlong
4d4f780f8b pty: unix: return an error if the executable doesn't exist
Without this check, something, presumably in the guts of rust itself,
generates `fatal runtime error: assertion failed:
output.write(&bytes).is_ok()` on the output stream of the spawned child
when attempting to spawn `wsl.exe` on linux.

refs: #1005
2021-08-08 15:21:41 -07:00
kas
91ae9bcbaf Always provide an absolute path for the working directory to CreateProcessW() 2021-07-19 08:36:08 -07:00
Wez Furlong
7cd3dcaee4 tidy up cwd vs. home dir on Windows
Looking at #900; the unconditional directory change on startup
is "bad" because it only happens on Windows.

This commit removes it and instead puts the logic into the pty
layer to match the unix behavior.

The behavior is:

* If the command specifies the cwd, use that.
* Otherwise, use the home directory
2021-07-18 14:57:33 -07:00
Wez Furlong
3f6ff534d3 windows: fix lingering cmd.exe panes
Since removing the regular periodic background tasks, we're now
prone to not noticing child processes exiting.

This commit explicictly schedules a thread to do that on Windows
so that we can close a tab as soon as it exits.
2021-05-28 15:11:29 -07:00
Wez Furlong
b5bfec6510 update conpty to v1.9.1445.0
refs: https://github.com/microsoft/terminal/issues/376

This also enables as the conpty layer the new win32 mode discussed in
https://github.com/wez/wezterm/issues/318
wezterm itself is not able to use this mode yet.
2021-05-28 15:11:29 -07:00
Wez Furlong
f78190ec9c filedescriptor: remove anyhow from public interface
Use thiserror instead
2021-05-23 14:24:01 -07:00
Wez Furlong
bc0766396d use -$SHELL rather than $SHELL -l to trigger a login shell
Since the original code was written, Rust grew and stabilized
an interface for specifying argv0 for the child process, so
we can remove the fragile `-l` argument passing.

refs: https://github.com/wez/wezterm/issues/753
2021-05-01 07:31:35 -07:00
Wez Furlong
5b9be21165 prep for pty 0.4 release 2021-04-30 10:17:25 -07:00
Wez Furlong
5aef725171 pty: unconditionally export some unix+ssh specific things
These were gated to the ssh feature, but I want to use them
with wezterm-ssh, and externally defined ssh pty implementation.
2021-03-27 07:25:00 -07:00
Wez Furlong
3cf7c9c3c2 refine skip_close_confirmation_for_processes_named to look at proc tree
That means that we won't be fooled by a shell with a backgrounded
editor.

refs: https://github.com/wez/wezterm/issues/562
2021-03-22 21:34:10 -07:00
Wez Furlong
38e6a1bc4c window: fix ToggleFullScreen on Windows
closes: https://github.com/wez/wezterm/issues/177
2021-02-26 19:39:35 -08:00
Benoit de Chezelles
84a45f28e5 Send SIGHUP when terminating the pty child
This commit first delivers SIGHUP, then follows up with a regular
kill after a grace period.  This should allow processes an opportunity
to clean up when eg: the terminal window is closed.

Co-authored-by: Wez Furlong <wez@wezfurlong.org>

closes: #490
2021-02-18 10:00:47 -08:00
Benoit de Chezelles
322fb5ee83 fmt 👀 2021-02-18 09:50:50 -08:00
Benoit de Chezelles
dc9784e0db Add comment 2021-02-18 09:50:50 -08:00
Benoit de Chezelles
18e8d48171 unix: Correctly signal child process on exit 2021-02-18 09:50:50 -08:00
Ives van Hoorne
80d486ef03
Add Sync marker to child process created through pty spawn (#437)
* Add Sync marker to child process created through pty spawn

* Add 'Sync' to Windows build of pty

* Wrap proc in WinChild in a Mutex

* Make sure the Mutex is not locked for long by cloning
2021-01-31 10:09:18 -08:00
Dylan Frankland
3793ff2587
Add config option to specify default current working directory (#438)
* Add config option to specify default current working directory

* Make `cwd` of CLI take precedence over `default_cwd`

* Update docs for `default_cwd` and Launching Programs

Explains the `default_cwd` property more succinctly on the `Config` struct.

Adds documentation on the various ways to set the working directory and the logic used to decide the working directory.
2021-01-26 10:40:22 -08:00
Wez Furlong
713da95a02 fix build on windows
refs: #416
2021-01-07 09:38:45 -08:00
Wez Furlong
db0d54cf44 Take care to restore the original umask
wezterm sets a more restrictive umask (`0o077`) by default so that any files
that it creates (eg: unix domain socket, log files) are more secure
by default.

However, some environments rely on the more general default of (`0o022`)
without checking that it is set.

This matters because programs spawned by wezterm inherit its more
restricted umask.

I hadn't noticed this because I've had `umask 022` in my shell RC files
since sometime in the 1990's.

This commit adds some plumbing to the pty layer to specify an optional
umask for the child process, and some more to our umask saver helper
so that any thread can determine the saved umask without needing a
reference to the saver itself, which may be in a different crate.

The logic in the config crate has been adjusted to connect the saved
value to the default command builder arguments.

The net result of this is that running `wezterm -n start bash -- --norc`
and typing `umask` in the resultant window now prints `0022`.

refs: #416
2021-01-07 09:20:13 -08:00
Wez Furlong
1c0817b2b2 mux: factor out server bits to helper crate 2020-12-29 15:25:15 -08:00
Wez Furlong
7cf68365a5 deps: misc updates 2020-12-29 09:24:34 -08:00
Wez Furlong
e831032c72 wezterm: close random fds when starting wezterm-gui
Let's try to eliminate garbage that the OS gui system leaks into
us when it spawns wezterm.
2020-12-20 11:46:59 -08:00
Wez Furlong
44729a7e89 pty: avoid leaking fds from the parent process on all unices
I noticed that wezterm is picking up garbage from gnome too,
so let's trigger the random fd closing function on all unix
systems.

It turns out that iterating the entries in /dev/fd works on
BSD and Linux which is nice.
2020-12-20 11:37:03 -08:00
Wez Furlong
592dbffa22 pty: avoid leaking random fds to children on macOS Big Sur
I'm assuming this is Big Sur specified, as I hadn't noticed
this until upgrading; there are a bunch of gui related files
inherited by my shell:

```
$ lsof -p $$
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF                NODE NAME
zsh     66016  wez  cwd    DIR   1,16     1760              396092 /Users/wez/wez-personal/wezterm
zsh     66016  wez  txt    REG   1,16  1331248 1152921500312774717 /bin/zsh
zsh     66016  wez  txt    REG   1,16   138640 1152921500312777271 /usr/lib/zsh/5.8/zsh/terminfo.so
zsh     66016  wez  txt    REG   1,16   174352 1152921500312777285 /usr/lib/zsh/5.8/zsh/zutil.so
zsh     66016  wez  txt    REG   1,16   138128 1152921500312777261 /usr/lib/zsh/5.8/zsh/rlimits.so
zsh     66016  wez  txt    REG   1,16   579888 1152921500312777275 /usr/lib/zsh/5.8/zsh/zle.so
zsh     66016  wez  txt    REG   1,16   341904 1152921500312777223 /usr/lib/zsh/5.8/zsh/complete.so
zsh     66016  wez  txt    REG   1,16   174752 1152921500312777257 /usr/lib/zsh/5.8/zsh/parameter.so
zsh     66016  wez  txt    REG   1,16   211584 1152921500312777225 /usr/lib/zsh/5.8/zsh/complist.so
zsh     66016  wez  txt    REG   1,16   208768 1152921500312777227 /usr/lib/zsh/5.8/zsh/computil.so
zsh     66016  wez  txt    REG   1,16  2528384 1152921500312776994 /usr/lib/dyld
zsh     66016  wez    0u   CHR   16,1 0t158834                1019 /dev/ttys001
zsh     66016  wez    1u   CHR   16,1 0t158834                1019 /dev/ttys001
zsh     66016  wez    2u   CHR   16,1 0t158834                1019 /dev/ttys001
zsh     66016  wez    8r   REG   1,16   273022 1152921500312217452 /System/Library/Extensions/AppleMetalGLRenderer.bundle/Contents/Resources/default.metallib
zsh     66016  wez   10u   CHR   16,1  0t20923                1019 /dev/ttys001
zsh     66016  wez   11u   REG   1,16    65536              576611 /private/var/folders/mg/hk5n1_9x7014sm0syzqzzn640000gn/C/com.github.wez.wezterm/com.apple.metal/16777235_322/functions.data
zsh     66016  wez   12u   REG   1,16     1276             2360034 /private/var/folders/mg/hk5n1_9x7014sm0syzqzzn640000gn/C/com.github.wez.wezterm/com.apple.metal/16777235_322/functions.list
zsh     66016  wez   13r   REG   1,16   215992             2354718 /Library/Application Support/CrashReporter/SubmitDiagInfo.domains
zsh     66016  wez   14u   REG   1,16     5232             2360053 /Users/wez/Library/Saved Application State/com.github.wez.wezterm.savedState/window_2.data
zsh     66016  wez   15u   REG   1,16    59040             2360054 /Users/wez/Library/Saved Application State/com.github.wez.wezterm.savedState/data.data
zsh     66016  wez   16w   REG   1,16     4716             2360055 /Users/wez/Library/Saved Application State/com.github.wez.wezterm.savedState/windows.plist
```

This commit iterates the list of open descriptors just prior
to calling exec and closes any that aren't the stdio (0-2) descriptors.
2020-12-19 14:01:39 -08:00
Wez Furlong
18e010f1df deps: normalize the lazy-static version 2020-11-13 08:15:35 -08:00
Wez Furlong
b239801085 wezterm: fixup wezterm ssh host
Needed to re-order a couple of things to match recent changes.

Also: don't hard fail if the ssh server rejects a setenv request,
just log the error instead.
2020-10-31 11:45:30 -07:00
Wez Furlong
233adb5fe9 pty: update async example for more recent smol release 2020-10-03 11:15:57 -07:00
Wez Furlong
2d3f4f9bf9 wezterm: guess at cwd associated with pty on linux
We still prefer to consume the OSC 7 value, but can fall back
to guessing the cwd for a target process.
2020-09-26 11:51:21 -07:00
Wez Furlong
9d8839a6d9 pty: adjust examples for macOS Catalina
Seems that you need to have read everything you want before you
call waitpid, otherwise the pending data seems to be snipped and
prevented from being read.

closes: https://github.com/wez/wezterm/issues/187
2020-09-25 09:20:22 -07:00
Wez Furlong
ec468acb40 panes: adopt zipper based bintree for managing panes
This simplifies the logic in the tab.rs module
2020-09-20 10:20:40 -07:00
Wez Furlong
fb890cbaf0 pty: bump version ready for publishing
refs: https://github.com/wez/wezterm/pull/258
refs: https://github.com/TimeToogo/tunshell/issues/8
2020-09-08 21:27:01 -07:00
Elliot Levin
86d66dae54
portable_pty - fix build on x86_64-unknown-freebsd target (#258)
* portable_pty - support for x86_64-unknown-freebsd target

* Update TIOCGWINSZ type conversion to use cast syntax and apply same logic to TIOCSWINSZ
2020-09-08 08:50:43 -07:00
john01dav
f2327de74d Fixed bug where setting the current directory was impossible on UNIX for non-default terminal commands 2020-07-18 08:40:58 -07:00
Wez Furlong
954a05919d pty: remove dead code 2020-06-05 07:33:23 -07:00
Wez Furlong
1d154a3109 pty: bump for 0.3.0 release
Since the last release we've migrated from failure -> anyhow,
added more functions to the command builder, improved windows
support and have compatibility with the `smol` crate.

refs: https://github.com/wez/wezterm/issues/166
2020-05-17 12:14:55 -07:00
Wez Furlong
2ef985aa18 pty: async example using smol
refs: https://github.com/wez/wezterm/issues/166
2020-05-09 11:24:14 -07:00
Wez Furlong
e2d044bb14 pty: add MasterPty::try_clone_writer 2020-05-09 11:24:14 -07:00
Wez Furlong
c54c64f395 pty: remove experimental awaitable bits 2020-05-09 11:24:14 -07:00
Wez Furlong
61e3545c68 pty: windows: allow loading a newer conpty dll
This commit allows loading the console functions from `conpty.dll`
instead of `kernel32.dll` which means that we can update and
track newer features than have been deployed to Windows.

In practical terms this means that we can now unlock mouse input
reporting in eg: VIM running under WSL.
refs: https://github.com/microsoft/terminal/issues/376

We're jumping the gun on this issue, which is tracking making
a proper supportable way to deploy this sort of update:
refs: https://github.com/microsoft/terminal/issues/1130

For now it seems easier just for us to bundle our own copy of
these bits.

This includes a speculative change to include those in our
Windows downloads also.

The binaries were built from
4f8acb4b9f
2020-04-06 12:48:54 -07:00
Wez Furlong
70e18c74aa serial: fix a bug where baud rate was not applied 2020-03-07 17:09:43 -08:00
Wez Furlong
18294841e9 ssh2: update to 0.8
That version has the ability to use SSH agent forwarding.
This commit doesn't enable that functionality, it's just updating
the version and adjusting for changes in the upstream.
2020-02-22 08:50:13 -08:00
Wez Furlong
65707aba56 allow setting default values for environment variables
This is useful for setting up a reasonable initial environment.
For example, on Windows you might want to set the `prompt` environment
so that some basic shell integration is enabled; this will cause new
tabs to open with the same cwd as the current tab:

```
set_environment_variables = { "prompt"="$E]7;file://localhost/$P$E\\$P$G" }
```

This setting is intended to apply only to the local domain.

refs: https://github.com/wez/wezterm/issues/146
2020-02-09 12:55:04 -08:00
Wez Furlong
d73a37be24 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
2020-02-09 09:10:26 -08:00
Wez Furlong
8f9d654301 ssh: fix coordination of pty readers
At some recent point in history, I effective broke multiple tabs in
`wezterm ssh HOST` by allowing them to contend in weird ways on locks,
leading to a horribly sluggish experience where multiple keypresses
in alternate tabs would appear to be swallowed until IO happened in
another tab.  Yuk!

This commit fixes that up by teaching channels how to wait cooperatively
and to attempt a read in all waiting channels when the fd becomes
readable.
2020-01-31 22:56:25 -08:00
Wez Furlong
38b19cb7ea Spawn login shells by default on unix systems
refs: https://github.com/wez/wezterm/issues/133
2020-01-26 13:47:12 -08:00
Wez Furlong
f3e42c3d2a point to local filedescriptor crate 2020-01-26 09:15:24 -08:00
Wez Furlong
df58a12827 deps: update to ssh2 0.7.0 2020-01-24 17:49:37 -08:00
Wez Furlong
ffa00bef29 pty: the compiler needed these types for macos
I don't know why this only was a problem on macos, but this fixes
the release build for me on my macos.
2020-01-23 10:50:34 -08:00
Wez Furlong
d84e8531a3 pty: implement awaitable conpty for windows
A bit of a PITA, but it appears to be functional
2020-01-20 15:23:56 -08:00
Wez Furlong
ca836ff95b pty: unix: add awaitable interface 2020-01-20 15:23:55 -08:00
Wez Furlong
118b91bdf6 pty: fix windows build 2020-01-20 08:20:38 -08:00
Wez Furlong
82c824f371 pty: remove conpty support
It's too fiddly to setup in practice, and literally no one has
expressed an interest in using it.

Removing it simplifies some upcoming work.

Closes: https://github.com/wez/wezterm/issues/35
2020-01-20 07:55:51 -08:00
Wez Furlong
256b4e6da8 fix pollable_channel to be non-blocking on Windows
Upgrade filedescriptor to 0.7 to use the portable helper for
setting non-blocking mode, and enable non-blocking mode on Windows.
2020-01-15 21:30:14 -08:00
Jeremy Fitzhardinge
d789748c99 Default to starting tab in home dir if current dir doesn't exist. 2020-01-11 18:25:17 -08:00
Jeremy Fitzhardinge
31b5798e95 pty: add cwd to CommandBuilder 2020-01-11 18:25:17 -08:00
Wez Furlong
9c9bf6fb97 add CommandBuilder::from_argv 2020-01-07 07:27:02 -08:00
Wez Furlong
52dfce6c4e more mac + windows build tweaks 2019-12-14 22:38:24 -08:00
Wez Furlong
4fdee2baf0 maybe fix the windows build for anyhow changes 2019-12-14 22:27:37 -08:00
Wez Furlong
9a2c7a1485 failure -> anyhow + thiserror 2019-12-14 21:43:05 -08:00
Wez Furlong
cdfd77902a update ssh2 dep 2019-12-08 10:43:55 -08:00
Wez Furlong
6c2fbd43db update ssh2 dep 2019-11-08 18:49:31 -08:00
Wez Furlong
190303c7d5 more explicit dyn for windows 2019-09-23 06:46:56 -07:00
Wez Furlong
986cfcd41a Bump version for publish with ssh support 2019-09-15 18:16:43 -07:00
Wez Furlong
16a17857f6 update to ssh2 0.4.0 2019-09-15 17:54:37 -07:00
Wez Furlong
e818ad9dd1 pty, wezterm: add support for serial ports
Tested only on windows with a USB serial connector to my NUC running
linux.

This allows opening up wezterm on a serial port connection.
Serial is closer to a tty than a pty, so it is a bit different
to configure and use.

This commit allows running:

```
wezterm serial COM3
```

to open a window that connects to the specified COM port.

You can change the baud rate with:

```
wezterm serial --baud 9600 COM3
```

There are more options that could be set, but I'm a bit lazy and
have only exposed the baud rate to the wezterm cli so far.
2019-08-07 10:59:42 -07:00
Wez Furlong
786a4c8551 pty: add concept of "default prog" to the pty layer
Previously we had the logic for this in wezterm itself; it would know
how to figure out which shell to run, or whether we should run a
different program by default (the `default_prog` setting).

This was OK, but when I added support for ssh we hit a conceptual
issue: the local side of the ssh session doesn't have any information
about the shell that should be invoked on the remote side and instead
needs to ask the remote to figure that out.   The interfaces defined
in the code didn't allow for this.

This commit formalizes the concept of a default program and allows
it to be carried through to the pty layer, including over ssh sessions.

Since we now have enough smarts to figure out the local shell and the
local home dir, I've removed the logic that run `login -pf` on macos
by default; this should make the terminal startup very slightly faster
on macos, but since I'm currently on a windows system, I can only test
linux and windows on this side of this commit.  I'll follow up on macos
later.
2019-08-06 15:03:25 -07:00
Wez Furlong
073615ef39 pty: remove some dead code 2019-08-06 14:24:06 -07:00
Wez Furlong
863cf1768a pty: fixup passing term to ssh pty requests 2019-08-06 14:17:03 -07:00
Wez Furlong
acfd712efc pty: fix passing env to windows child processes 2019-08-06 14:11:49 -07:00
Wez Furlong
ca8227a00f use my fork of ssh2 so that we can run properly on windows 2019-08-05 13:40:43 -07:00
Wez Furlong
127b2a567b add wezterm ssh user@host some command
This is mostly useful for folks on Windows, as you can also run
`wezterm start ssh user@host some command` to run the `ssh` binary in a
local pty and let it manage your ssh session.

On Windows the local pty currently breaks mouse reporting
(see https://github.com/microsoft/terminal/issues/376) so it is
desirable to avoid using a local pty if we're going to talk to a
remote system.

This commit makes it a bit more convenient to establish an ad-hoc ssh
session with a pty on a remote host.  This method uses libssh2 under the
covers and thus doesn't support gssapi, which is potentially frustrating
for kerberized environments, but works ok for the majority of users.

There are two issues that I want to resolve in follow up work:

* The TERM has to be sent very early in the channel establishment,
  before we "know" the TERM in the `portable-pty` interface.  Will need to
  figure out how to specify that earlier in an appropriate way.
* Similarly, if no command is specified, we should request the use
  of the shell subsystem but we don't have a way to capture this
  intend with the cmdbuilder. Will need to solve this too.
2019-08-05 09:05:54 -07:00
Wez Furlong
c8aa11ac81 pty: add ssh support
This commit adds (untested!) support for remote ttys over ssh.
It requires that the embedding application connect and authenticate
the ssh session prior to turning it into a PtySystem implementation.
2019-08-02 10:55:04 -07:00
Wez Furlong
9d46bd889f pty: fixup build when serde_support is not enabled 2019-07-23 13:31:01 -07:00
Wez Furlong
23e174a324 fully bump filedescriptor dep 2019-07-23 09:50:48 -07:00
Wez Furlong
7e50c4db68 workaround conpty drop issue 2019-07-17 08:42:41 -07:00
Wez Furlong
2c7138cc6e use consistent version of filedescriptor crate 2019-06-22 14:31:19 -07:00
Wez Furlong
e98d8acb96 add spawn rpc 2019-06-09 08:15:37 -07:00
Wez Furlong
8055957406 clippy 2019-06-09 07:33:00 -07:00
Wez Furlong
5ebad9e63a dyn everywhere 2019-06-08 21:28:11 -07:00
Wez Furlong
5ccff722ef more log 2019-06-08 15:37:55 -07:00
Wez Furlong
f642bd56d6 introduce mux Domain concept
All locations that were setting up ptys now do so via the
Domain concept.  We still need a way to set up a persistent
global domain.
2019-06-04 08:11:55 -07:00
Wez Furlong
fb1a5b42d2 bump filedescriptor crate 2019-06-01 08:23:23 -07:00
Wez Furlong
3bf551706e improve pty example
Example output on linux:

```
child status: ExitStatus { successful: true }
output: wez\r\n%
```

Example output on windows:

```
child status: ExitStatus { successful: true }
output: \u{1b}[2J\u{1b}[?25l\u{1b}[m\u{1b}[HDOMAIN\\wez\u{8}\u{1b}]0;C:\\windows\\system32\\whoami.EXE\u{0}\u{7}\u{1b}[?25h
```

Refs: https://github.com/wez/wezterm/issues/27
2019-05-21 08:58:42 -07:00
Wez Furlong
015a97e2be add pty example that runs whoami
Refs: https://github.com/wez/wezterm/issues/27
2019-05-20 07:20:47 -07:00
Wez Furlong
257c864403 flesh out the crate level docs 2019-05-19 22:35:35 -07:00
Wez Furlong
1d8b024f2f add some doc comments to the pty crate
Refs: https://github.com/wez/wezterm/issues/27
2019-05-19 20:31:07 -07:00
Wez Furlong
c562f35db8 adopt my filedescriptor crate in the pty crate
Refs: https://github.com/wez/wezterm/issues/27
2019-05-19 19:54:12 -07:00
Wez Furlong
7464965d1e fixup windows build for pty mod -> crate move
Refs: https://github.com/wez/wezterm/issues/27
2019-05-19 18:55:10 -07:00
Wez Furlong
7bf1d99d77 move pty to its own crate in preparation for publishing
Refs: https://github.com/wez/wezterm/issues/27
2019-05-19 18:40:26 -07:00