1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-01 09:13:10 +03:00
Commit Graph

51 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
190303c7d5 more explicit dyn for windows 2019-09-23 06:46:56 -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
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
7e50c4db68 workaround conpty drop issue 2019-07-17 08:42:41 -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
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
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