1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-23 15:04:36 +03:00
Commit Graph

116 Commits

Author SHA1 Message Date
Wez Furlong
7250237b9a pty: actually fix win32 build 2021-12-11 10:03:43 -07:00
Wez Furlong
7926c31209 pty: introduce ChildKiller trait
In the mux layer, we have some code that takes a `Child` and then
does a bit of naughty reaching through the abstraction to get at
the pid/handle of the child so that we can send it signals even
if the child is itself mutably (and thus exclusively) borrowed
for the purposes of waiting.

That worked fine for local processes spawned in the mux, but we also
use LocalPane to wrap around arbitrary `Child`ren, such as Ssh,
that are not local and that don't have a local process id, which
meant that this hack wouldn't work for them.

To make things a bit worse, those ssh ptys were used to ssh2 days
where we didn't have a way to signal the remote process and just
did nothing, leading to confusing situations such as
https://github.com/wez/wezterm/issues/1197

This commit graduates the hack mentioned in the first paragraph
to its own ChildKiller trait.  This makes the concept of waiting
for the Child distinct from signalling it and explicitly allows
getting a separate object that can be used for signalling.

With that in place, we're forced to implement something appropriate
for the ssh pty implementations; one in the pty crate itself,
one in wezterm-ssh and the wrapper that we use in the mux crate.

The upshot of this is that the `CloseCurrentPane` action now operates
correctly on panes that were the result of split operations.
2021-12-11 08:40:26 -07:00
Wez Furlong
f905ec8100 fix some unused/unread field warnings 2021-12-10 08:18:36 -07:00
Wez Furlong
348ddcb122 quickselect: de-dup labels
refs: #1271
2021-12-09 09:50:32 -07:00
Wez Furlong
225e7a1243 introduce unicode_version config
This is a fairly far-reaching commit. The idea is:

* Introduce a unicode_version config that specifies the default level
  of unicode conformance for each newly created Terminal (each Pane)
* The unicode_version is passed down to the `grapheme_column_width`
  function which interprets the width based on the version
* `Cell` records the width so that later calculations don't need to
  know the unicode version

In a subsequent diff, I will introduce an escape sequence that allows
setting/pushing/popping the unicode version so that it can be overridden
via eg: a shell alias prior to launching an application that uses a
different version of unicode from the default.

This approach allows output from multiple applications with differing
understanding of unicode to coexist on the same screen a little more
sanely.

Note that the default `unicode_version` is set to 9, which means that
emoji presentation selectors are now by-default ignored.  This was
selected to better match the level of support in widely deployed
applications.

I expect to raise that default version in the future.

Also worth noting: there are a number of callers of
`unicode_column_width` in things like overlays and lua helper functions
that pass `None` for the unicode version: these will assume the latest
known-to-wezterm/termwiz version of unicode to be desired. If those
overlays do things with emoji presentation selectors, then there may be
some alignment artifacts. That can be tackled in a follow up commit.

refs: #1231
refs: #997
2021-11-25 09:00:45 -07:00
Waleed Khan
cda28fa0ad pty: add CommandBuilder::env_clear, CommandBuilder::env_remove functions 2021-11-23 05:16:55 -07:00
Jonathan
e9ed2b4d3e
Unzoom when switching panes (#1301)
* mux: unzoom when switching panes

Add `unzoom_on_switch_pane` config option:

When switching to another pane with ActivatePaneDirection, if the
current pane is zoomed, unzoom and then switch instead of doing nothing.

* Apply suggestions from code review

Co-authored-by: Wez Furlong <wez@wezfurlong.org>
2021-11-13 11:43:15 -08:00
Wez Furlong
e7fc5f0e9e fix: whole tab terminated when only zoomed pane exited
closes: https://github.com/wez/wezterm/issues/1235
2021-10-17 08:34:35 -07:00
Wez Furlong
6f78ee4f14 deps: update unicode-segmentation to 1.8 2021-08-11 23:06:17 -07:00
Wez Furlong
eae327efcc model: replace LineBits::DIRTY with a sequence number
Terminal now maintains a sequence number that increments
for each Action that is applied to it.

Changes to lines are tagged with the current sequence number.

This makes it a bit easier to reason about when an individual
line has changed relative to some point in "time"; the consumer
of the terminal can sample the current sequence number and then
can later determine which lines have changed since that point
in time.

refs: https://github.com/wez/wezterm/issues/867
2021-08-08 12:45:08 -07:00
Wez Furlong
2590e490cd add newline after process completed line
There are some cases where we can print that status before we've
fully drained the output; it's slightly nicer to ensure that
we have an "atomic" line of its own for that, to minimize
the crappiness of the resulting output.
2021-08-03 09:24:35 -07:00
Wez Furlong
159abe5e28 mux: make action parser buffer size configurable and smaller
Previously, we'd use a 1MB buffer both to read the output from the
associated pty (blocking), and the same size buffer again to do the
non-blocking read on top of that.

For pathological cases (eg: cat 100MB+ files), we could build a
resulting `Vec<Action>` with over 1mm entries and it could take as much
as 100ms to apply those actions to the terminal model.

This meant that the output could stutter/lag and appear to be processed
more slowly.

This commit introduces a configuration value for the buffer size for the
second stage, and makes it 10KB in size.  This helps to constrain the
size of the Action vec and keeps the incremental processing costs down,
while still managing the same throughput.
2021-07-31 08:57:13 -07:00
Autumn Lamonte
d100dded23 #133 cleanup + terminalstate-level reverse video mode 2021-07-24 23:36:49 -07:00
Wez Furlong
365a68dfb8 Wrap up synchronized output handling, parser changes
This commit hooks up DECRQM so that we can report that we implement
synchronized updates, and then refines the code that manages sending
data to the terminal model; the first cut at synchronized updates
was a bit simplistic, and now we make a point of "flushing" pending
actions when we start a sync point, and again as soon as we release
the sync point.

This smooths out the jaggies around the orca that I mentioned in
dcbbda7702

and while testing this, I realized that recent parser changes had
mangled processing bundled dec private mode sequences where multiple
modes were specified in the same overall escape sequence.  I've
added the missing unit test case for this and made that work again.

refs: https://github.com/wez/wezterm/issues/955
refs: https://github.com/wez/wezterm/issues/882
2021-07-24 17:01:21 -07:00
Wez Furlong
c6dc677e50 preliminary support for synchronized output
This implementation doesn't include a timeout, but should be
recoverable via a SoftReset.

There's no query response either: I think I'm missing DECRQM
entirely at the moment.

refs: https://github.com/wez/wezterm/issues/882
2021-07-24 08:34:36 -07:00
Wez Furlong
a2e882a7cb deps: cargo update, and a couple of dependabot suggestions 2021-07-18 19:10:46 -07:00
Wez Furlong
1f5b900f3d plumb appearance change event -> reload on macos
This commit causes a window-config-reloaded event to trigger
when the appearance (dark/light mode) is changed on macos.

It also arranges to propagate the window level config to newly
spawned panes and tabs, created both via the gui and via the
CLI/mux interface.

refs: https://github.com/wez/wezterm/issues/894
refs: https://github.com/wez/wezterm/issues/806
2021-07-18 00:01:53 -07:00
Wez Furlong
75eaaab6a1 Allow window config overrides to apply per-pane
This allows window-level config overrides to apply
to panes contained within the window.

For instance, this allows setting a window-level
color scheme.
2021-07-17 23:02:41 -07:00
Wez Furlong
f6a7df9678 ssh: avoid looping forever if the connection drops
I saw this in the stderr logs when the connection was offline:

```
 2021-07-17T01:54:28.036Z ERROR wezterm_ssh::session           > Failed to write data to channel: Failure while draining incoming flow. Now
what?
 2021-07-17T01:54:28.036Z ERROR wezterm_ssh::session           > Failed to write data to channel: Failure while draining incoming flow. Now
what?
 2021-07-17T01:54:28.142Z ERROR wezterm_ssh::session           > Failed to write data to channel: Failure while draining incoming flow. Now
what?
```

This commit propagates the error rather than logging and ignoring it.

In addition, remove a couple of sources of blocking or panicking
that are now unmasked by this.

Possibly the root cause of https://github.com/wez/wezterm/issues/857
2021-07-16 19:31:37 -07:00
Wez Furlong
b4c4c85683 changing the active pane now passes the focus event to the terminal
Test scenario is:

* Create a split
* in each pane run: `printf "\e[?1004h" ; od -c`
* Focus the panes, focus another window, and focus the window again
* The I and O events appear in the panes when changing their focus.
* Previously, only the active pane would get focus events when the
  window focus changed.

refs: https://github.com/wez/wezterm/issues/941
2021-07-13 08:58:18 -07:00
Wez Furlong
1bb2f50eb7 fixup windows build 2021-07-11 09:50:50 -07:00
Wez Furlong
edee1335c1 mux: remove parsing bottleneck
Test scenario is `cat`ing the public domain wiki text data from
http://cs.fit.edu/~mmahoney/compression/enwik8.zip in the terminal;
that file is 96M in size.

`time cat ~/Downloads/enwik8.wiki`

Prior to this change, depending on the OS, the time to cat the file
could be several minutes.

Digging in, the bottleneck appears to be that there isn't sufficient
parallelism between the reader and the parser, which means that the
rate of reading data is constrained by how long it takes to parse
and render a frame.

This commit switches away from using a synchronized vecdeque to
effectively create a non-blocking pipe, to "simply" using a socketpair
with a larger buffer size.

We now do blocking pty read -> write to socketpair in the reader
thread, and then read socketpair -> parse in the other.

The key difference between before and after being that the pty read
can continue to read and accumulate data (with an upper bound, so
that CTRL-C is still responsive) while we're parsing and rendering
a frame.

This increases the throughput for this scenario, bringing it down
from ~3:30 to ~17 seconds on this Ryzen 2700X system.

refs: https://github.com/wez/wezterm/issues/927
2021-07-11 08:26:35 -07:00
Wez Furlong
566243ade5 mux: add some metrics around reading from ptys 2021-07-10 21:06:54 -07:00
Wez Furlong
d57bc9b3dc CloseCurrentPane on last pane in a tab results in window closing
The issue is that the pane was only removed from the tab when explicitly
closed, leaving it to be later detected and flushed.

However, in the meantime, when performing eg: cursor blink maintenance,
if the set of panes in the tab is empty then the window would close.

The resolution is to ask the mux (rather than the tab) to kill the pane,
so that the cascading closure of the tab causes the window's active
tab to reference the correct remaining tab.

refs: #890
2021-06-19 11:06:14 -07:00
Wez Furlong
3ea030794b memoize the renderer used for termwiztermtab and custom tab bars
Create only one, then just clone as needed.

refs: #817
2021-06-13 09:06:29 -07:00
Wez Furlong
4feefdd04a cargo update 2021-06-07 08:32:05 -07:00
Wez Furlong
20c4dcdc36 fixup windows build
refs: https://github.com/wez/wezterm/issues/839
2021-05-31 22:39:26 -07:00
Wez Furlong
ab2918d568 restructure async waiting
Expand on the changes in 3f6ff534d3,
this makes them more general and so that they can be used on unix
systems.

That in turn helps to tackle https://github.com/wez/wezterm/issues/839,
wherein `sleep 300 & disown ; exit` would linger until EOF is detected,
rather than triggering as soon as the child process terminated.

For whatever reason, that would only manifest on linux (and not macos).
2021-05-31 22:28:14 -07:00
Wez Furlong
1a44255529 mux client: connect all mux panes in window to clipboard when attaching
refs: https://github.com/wez/wezterm/issues/836
2021-05-31 08:40:19 -07:00
Wez Furlong
5359f39dcf mux: fix an issue where auth window would linger before closing
Same vein as 8931afba5cee07ab12990f06c2ff34d6f8426b19; the auth
window could sometimes get stuck until an input event was sent
to it.

Wire up a mux event so that the window can close itself.
2021-05-31 00:11:47 -07:00
Wez Furlong
87cb593554 mux: client would prune out the empty window when connecting via ssh/tls domain
When the client connected to an empty remote mux, it would allocate an
empty window and then spawn a new tab into it.

Meanwhile, the authentication window would close and trigger a prune of
all empty windows, causing the in-flight spawn to fail because its
destination window was removed.

This commit defers window pruning while Activity is in progress;
the MuxWindowBuilder has an associated Activity count.
2021-05-30 23:50:13 -07:00
Wez Furlong
529b709277 windows: ssh: detect resizes during authentication
refs: https://github.com/wez/wezterm/issues/696
2021-05-29 15:15:42 -07:00
Wez Furlong
eaa0d2f4d3 ssh: fix lost character after keyboard auth on windows
closes: https://github.com/wez/wezterm/issues/771
2021-05-29 10:05:55 -07:00
Wez Furlong
257d323062 fixup laggy mux connections for recent idle changes
in the same vein as d657721163
this commit introduces more assertive signalling from the remote
mux when a pane is closed so that the client can update.
2021-05-29 00:16:27 -07:00
Wez Furlong
d657721163 fix lingering ssh connections
Similar to 3f6ff534d3, we need to
tickle the mux to detect when the session terminates.

In this case we can relatively simply schedule an async wait without
spawning an additional thread.
2021-05-28 22:16:31 -07:00
Wez Furlong
0b1b30c73a fix a build warning 2021-05-28 17:51:03 -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
f78190ec9c filedescriptor: remove anyhow from public interface
Use thiserror instead
2021-05-23 14:24:01 -07:00
Wez Furlong
78424036f9 mux: reduce kill/wait period for fish
This kill/wait was added to workaround fish being weird on macos.
This is accidentally exponential as the pty layer already loops,
so we don't need to also loop here.

refs: https://github.com/wez/wezterm/issues/774
2021-05-21 23:33:51 -07:00
Wez Furlong
db45238769 improve exit_behavior messaging
The status information now explains the exit status and the
exit_behavior, as well as links to the docs on exit_behavior.

refs: https://github.com/wez/wezterm/issues/795
2021-05-15 08:32:29 -07:00
Wez Furlong
ed6987298a mux: remove window invalidation polling
Add a mux event for this insteead.

refs: https://github.com/wez/wezterm/issues/770
2021-05-08 11:25:03 -07:00
Wez Furlong
1cbaf55640 change mux empty poll to mux empty event
As part of reducing the amount of regularly scheduled stuff wezterm
does in the background, this commit restructures how an empty mux
is detected; now when the mux prunes dead windows it will emit
an Empty event.

The Activity type will now schedule a prune when it is dropped,
which will clean up and trigger the Empty event.

refs: https://github.com/wez/wezterm/issues/770
2021-05-08 10:25:49 -07:00
Wez Furlong
09f0421b48 add lua repl to the debug overlay
`wezterm` is pre-imported.
The repl prints the result of the expressions to the overlay.

refs: https://github.com/wez/wezterm/issues/641
2021-05-03 09:19:44 -07:00
Wez Furlong
7a86f1b2b8 fixup word selection on long lines
This got a bit broken by the fix for https://github.com/wez/wezterm/issues/714

since we can be handed a range of logical line fragments, we should
test each of them to find our matching result.

Also, improve the logic for constraining the length when looking
backwards.
2021-05-02 12:40:16 -07:00
Wez Furlong
94c98aa826 quickselect: fixup edge case with wrapped lines
the binary search would falsely extend the end of the match
to the start of the subsequent match for the wrapped line case.

The resolution is to emit a coordinate for the newline that we
add to the haystack between the wrapped lines.

closes: https://github.com/wez/wezterm/issues/732
2021-04-29 17:15:49 -07:00
Wez Furlong
8ce376753f round out quick select mode
* Make alphabet and patterns configurable
* add docs
* Enhance scrollback search to support regex captures so that
  searching for eg: `fo(o)` will select the last `o` in `foo`.

refs: https://github.com/wez/wezterm/issues/732
2021-04-25 16:27:39 -07:00
Wez Furlong
87677a73bf Add support for iTerm2's SetUserVar escape
This doesn't propagate across wezterm's mux protocol
at this time.

refs: https://github.com/wez/wezterm/issues/647

https://iterm2.com/documentation-scripting-fundamentals.html#setting-user-defined-variables
2021-04-25 14:30:06 -07:00
Wez Furlong
053cb11e9f improve ssh domain support for ssh_config
This tidies up how we pass the ssh config to the connection ui
logic, by moving the ssh_config setup to the two callers.

A couple of notable adjustments:

* SshDomain::username is now optional; it will default to the
  values computed by the ssh config file loader
* no_agent_auth value wasn't hooked up to anything, but now it is

refs: https://github.com/wez/wezterm/issues/730
2021-04-24 21:56:32 -07:00
Wez Furlong
52b57ca512 fix splitting panes while a pane is zoomed
closes: https://github.com/wez/wezterm/issues/723
2021-04-23 22:32:47 -07:00
Wez Furlong
d6cfa9c610 fix a possible panic when word-selecting off the top of viewport
refs: https://github.com/wez/wezterm/issues/713
2021-04-23 19:10:26 -07:00