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

271 Commits

Author SHA1 Message Date
Wez Furlong
5e993c581a termwiz: remove reverse video attribute from Line
It didn't really belong there; it was added as a bit of a hack
to propagate screen reverse video mode.

Move that to the RenderableDims struct and remove the related
bits from Line
2022-08-24 22:43:47 -07:00
Wez Furlong
f59e1d5fff mux: remove stale portion of comment from Pane::get_lines
we haven't had dirty bits in a long while
2022-08-24 20:19:15 -07:00
Wez Furlong
e05b3581b8 optimize Pane::get_lines_with_hyperlinks_applied for empty rules case
It's ~30x cheaper to just get the underlying lines when there
are no hyperlink rules defined (3us vs 112us)
2022-08-23 17:20:46 -07:00
Wez Furlong
00ddfbf9b8 perf: cache quads by line
Introduces a heap-based quad allocator that we cache on a per-line
basis, so if a line is unchanged we simply need to copy the previously
computed set of quads for it into the gpu quad buffer.

The results are encouraging wrt. constructing those quads; the
`quad_buffer_apply` is the cost of the copy operation, compare with
`render_screen_line_opengl` which is the cost of computing the quads;
it's 300x better at the p50 and >100x better at p95 for a full-screen
updating program:

full 2880x1800 screen top:

```
STAT                                             p50      p75      p95
Key(quad_buffer_apply)                           2.26µs   5.22µs   9.60µs
Key(render_screen_line_opengl)                   610.30µs 905.22µs 1.33ms
Key(gui.paint.opengl)                            35.39ms  37.75ms  45.88ms
```

However, the extra buffering does increase the latency of
`gui.paint.opengl` (the overall cost of painting a frame); contrast the
above with the latency in the same scenario with the current `main`
(rather than this branch):

```
Key(gui.paint.opengl)                            19.14ms  21.10ms  28.18ms
```

Note that for an idle screen this latency is ~1.5ms but that is also true
of `main`.

While the overall latency in the histogram isn't a slam dunk,
running `time cat bigfile` is ~10% faster on my mac.

I'm sure there's something that can be shaved off to get a more
convincing win.
2022-08-23 06:37:12 -07:00
Wez Furlong
7caaf136e4 compensate for flickery TUI programs by going slower(!)
It's not the first time that I've solved a problem by slowing things
down... in this situation, a couple of very inefficient TUI programs had
flickering outputs in wezterm because they were filling a buffer with a
bunch of spaces to erase a screen before sending the main body of their
updates in a subsequent buffer chunk. wezterm would render the
intervening partially blank frame and appear to flicker.

The resolution is to add a small delay (3ms by default) before sending
data to the terminal model. If the output is readable in that time
we'll accumulate it with the pending set of actions so that the
whole batch can be applied "more atomically".

Take care: `time cat bigfile` is sensitive to this, so we want to
keep the latency as small as possible, and we also want to avoid
accumulating actions and only flushing them at the end of the file.

We use the existing buffer size (~1MB) as a threshold: we bump
a count of the number of input bytes that resulted in the current
set of actions, and if that exceeds that buffer size we flush it.

refs: https://github.com/wez/wezterm/issues/2443
2022-08-21 14:40:06 -07:00
Wez Furlong
de89d650a3 cargo update 2022-08-21 08:51:16 -07:00
Wez Furlong
cb75b642f7 Fixup ActivatePaneDirection to respect edge intersection
d2892c6 switched to using recency only, but neglected to verify that
the edges of the candidate panes were actually touching, leading to
some weird results.

This commit uses recency only when the edges intersect, otherwise,
scores 0 for the candidate.

refs: #2374
2022-08-20 07:20:07 -07:00
Wez Furlong
517cdc9c1b fixup build for pty api change 2022-08-12 08:45:02 -07:00
Wez Furlong
e6421d1b72 pty: try_clone_writer -> take_writer
This breaking API change allows us to explicitly generate EOF when the
taken writer is dropped.

The examples have been updated to show how to manage read, write
and waiting without deadlock for both linux and windows.
Need to confirm that this is still good on macOS, but my
confidence is high.

I've also removed ssh2 support from this crate as part of this
change. We haven't used it directly in wezterm in a long while
and removing it from here means that there is slightly less code
to keep compiling over and over.

refs: https://github.com/wez/wezterm/discussions/2392
refs: https://github.com/wez/wezterm/issues/1396
2022-08-12 07:56:46 -07:00
Wez Furlong
d2892c6ff0 ActivatePaneDirection uses recency to resolve ambiguous moves
refs: https://github.com/wez/wezterm/issues/2374
2022-08-08 21:16:01 -07:00
Wez Furlong
ef532fc7e5 mux: adjust window size after attach
Since the initial attach is async, we'd create the window at the
default/initial size and then never reconcile the size of the remote
tabs once they'd attached.

This commit introduces an event that allows the gui window to do that.

The action that it takes is to take the max width and height between
its current size and the size of a newly added tab and resizes to
that new size, if it changed.

refs: https://github.com/wez/wezterm/issues/2133
refs: https://github.com/wez/wezterm/issues/2351
2022-08-05 07:53:44 -07:00
Wez Furlong
9c75292450 flatpak: use /.flatpak-info file to test if we are in flatpak sandbox 2022-08-03 07:04:31 -07:00
Wez Furlong
404d742c14 Teach wezterm how to spawn programs when running in flatpak
This commit allows wezterm to spawn programs into the host rather
than in the container environment.

It feels weird that it is so trivial to "break out" of the container
sandbox, but I'm not complaining.

There are some unfortunate consequences:

* there is no `wezterm` installed on the host, so no ability to `wezterm
  cli` to control it from other apps
* The unix domain socket is scoped inside the sandbox, so there's "no
  way" for `wezterm cli` to reach inside anyway.

But: with this, it is at least usable to start a flatpak and open a
shell.

refs: https://github.com/wez/wezterm/issues/2229
2022-08-03 07:04:31 -07:00
Wez Furlong
0d51a9c444 Add cursor and pane position info to wezterm cli list data
This is included only in the json output mode.

Note that this does not and cannot include positioning information known
only to the GUI, as there may not be a GUI. That means that window
position, tab bar and padding data are not known and not able to be
returned via this interface.

```
; wezterm cli list --format json
[
  {
    "window_id": 0,
    "tab_id": 0,
    "pane_id": 0,
    "workspace": "default",
    "size": {
      "rows": 24,
      "cols": 80,
      "pixel_width": 1040,
      "pixel_height": 672,
      "dpi": 124
    },
    "title": "wezterm cli list --format json -- wez@foo:~",
    "cwd": "file://foo/home/wez/",
    "cursor_x": 0,
    "cursor_y": 2,
    "cursor_shape": "Default",
    "cursor_visibility": "Visible",
    "left_col": 0,
    "top_row": 0
  }
]
```

refs: #2319
2022-07-31 12:01:34 -07:00
Wez Furlong
aed0e3ebf8 populate pixel dims + dpi in PaneEntry
This makes those fields usable in `wezterm cli list --format json`.

This doesn't change the ABI of the mux protocol, but prior to
this commit, those fields were always 0.

refs: #2319
2022-07-31 11:25:39 -07:00
Wez Furlong
1d64071609 tabs: revise active index after killing panes
refs: #2304
2022-07-26 08:25:31 -07:00
Wez Furlong
5e6ce47330 fix "no pane" tab hang when two panes close at once
There was a race condition where we could leave the tab
active index pointing to the wrong pane.

That meant that the tab information computed by the gui
layer would see no panes marked as active, and thus would
end up with no active tab.

This commit fixes that by clamping the active index to
the number of panes.

refs: https://github.com/wez/wezterm/issues/2304
2022-07-25 21:06:24 -07:00
Wez Furlong
39adbb984d Pane::search: expose range, limit. Limit quickselect by default
The recent work on the scrollback made it easier to constrain the
search region, so expose those parameters to the Pane::search
interface and to the mux protocol.

Use those new parameters to constrain quickselect search to
1000 rows above and below the current viewport by default, and
add a new parameter to QuickSelectArgs that allows overriding that
range.

A follow-up commit could make the search/copy overlay issue a series
of searches in chunks so that it avoids blocking the UI when
searching very large scrollback.

refs: https://github.com/wez/wezterm/pull/1317
2022-07-25 18:31:27 -07:00
Wez Furlong
5831bd7c8d search: fix coordinates for matches at EOL
The returned coords didn't include the last cell on the line;
adjust the fallback case to generate an exclusive rather than
inclusive end coordinate.
2022-07-24 16:56:19 -07:00
Wez Furlong
ff954ec196 search: improve coordinates for new search implementation
We weren't using the correct grapheme width. Feed through the original
line so that we have the correct information.
2022-07-24 13:11:14 -07:00
Wez Furlong
565b03b1c5 localpane: revise search method implementation
Avoids allocating strings for the non-wrapped line case,
has bounded memory usage compared to prior implementation.
2022-07-24 11:38:06 -07:00
Wez Furlong
dec5ca0349 term: refactor getting logical lines
This will make it easier to refactor search in a subsequent commit
2022-07-24 10:57:05 -07:00
Wez Furlong
c8b1b92e08 Line::as_str() -> Cow<str>
Previously this would create a new String because it had to, but
with the clustered storage we may be able to simply reference the
existing string as a str reference, so allow for that.
2022-07-23 12:10:13 -07:00
Wez Furlong
614900f85c line: introduce possibility of alternate cell backing
Uses an enum as a way to use an alternative to Vec<Cell>, but
doesn't provide that alternative in this commit.
2022-07-23 08:18:34 -07:00
Wez Furlong
e26d634da1 termwiz: refactor Line::visible_cells()
Don't promise that we iterate Cell directly, but things that smell
like Cell.  That makes it easier to adjust internal storage in
a later commit.
2022-07-23 07:03:34 -07:00
Wez Furlong
355f3d3975 fix reloading the global config when the appearance changes
We didn't actually update the global config, just the per-window
configs, which led to weird stale throwbacks to earlier versions
of the config when spawning windows or new panes.

Fix that up by explicitly reloading the global config when the
window appearance is changed.  That isn't ideal as we will reload
once per window, but it's "OK".

While poking at this, I noticed that the get/set config methods
on the termwiztermtab overlay weren't hooked up, and also made
a point of calling those for any overlays during a window config
reload event, so that per-window overrides are more likely to get
picked up and respected.

refs: https://github.com/wez/wezterm/issues/2295
2022-07-22 20:23:04 -07:00
Wez Furlong
112feb3374 add MuxTab:set_zoomed and SetPaneZoomState keyassignment
refs: #2284
2022-07-19 05:52:38 -07:00
Wez Furlong
80e72fa46e exec domains: pass paneid to fixup method
This way we can ensure that it is set in the environment
in time for the lua callback to see it.

refs: #1776
2022-07-15 06:44:36 -07:00
Wez Furlong
48ebbd7991 exec domains: report errors in label function 2022-07-09 12:44:16 -07:00
Wez Furlong
686daf7bca wsl_domains: soft-bind to the config definition
Allows config file changes to be reflected
2022-07-08 20:47:07 -07:00
Wez Furlong
0899282ea6 exec_domains: soft-bind to the config definition
This allows config file changes to be reflected
2022-07-08 20:40:26 -07:00
Wez Furlong
8f44dc46d9 exec_domains: allow async callbacks. can now also set label for launcher
The fixup callback can now by async, which makes it possible to use
other async functions in the callback.

There is an additional parameter to wezterm.exec_domain that allows
setting the label that is shown in the launcher menu.
It accepts either a string value or an async callback function
that can be used to compute the label dynamically.
2022-07-08 18:46:09 -07:00
Wez Furlong
5c6312c6a5 remove stray debug 2022-07-07 22:44:12 -07:00
Wez Furlong
d78cc6edb8 new: exec_domains
An ExecDomain is a variation on WslDomain with the key difference
being that you can control how to map the command that would be
executed.

The idea is that the user can define eg: a domain for a docker
container, or a domain that chooses to run every command in its
own cgroup.

The example below shows a really crappy implementation as a
demonstration:

```
local wezterm = require 'wezterm'

return {
  exec_domains = {
    -- Commands executed in the woot domain have "WOOT" echoed
    -- first and are then run via bash.
    -- `cmd` is a SpawnCommand
    wezterm.exec_domain("woot", function(cmd)
      if cmd.args then
        cmd.args = {
          "bash",
          "-c",
          "echo WOOT && " .. wezterm.shell_join_args(cmd.args)
        }
      end
      -- you must return the SpawnCommand that will be run
      return cmd
    end),
  },
  default_domain = "woot",
}
```

This commit unfortunately does more than should go into a single
commit, but I'm a bit too lazy to wrangle splitting it up.

* Reverts the nil/null stuff from #2177 and makes the
  `ExtendSelectionToMouseCursor` parameter mandatory to dodge
  a whole load of urgh around nil in table values. That is
  necessary because SpawnCommand uses optional fields and the
  userdata proxy was making that a PITA.
* Adds some shell quoting helper functions
* Adds ExecDomain itself, which is really just a way to
  to run a callback to fixup the command that will be run.
  That command is converted to a SpawnCommand for the callback
  to process in lua and return an adjusted version of it,
  then converted back to a command builder for execution.

refs: https://github.com/wez/wezterm/issues/1776
2022-07-07 16:38:14 -07:00
Wez Furlong
a282d07776 mux: add titles to mux window and tab objects
Previously, the mux layer had no internal understanding of titles other
than the Pane::get_title method to return state from a pane.

Users have asked for ways to explicitly set titles on windows and tabs,
so this commit is a step towards that.

The mux window and tab objects now store a title string.

The terminal layer now emits Alert::WindowTitleChanged when the window
title is changed via eg: OSC 0 or OSC 2.

The mux layer will respond to Alert::WindowTitleChanged by resolving the
window that corresponds to the source pane and amending its title.

The MuxWindow and MuxTab objects now provide accessor methods for the
title.

TabInformation (as used by format-tab-title and format-window-title) now
exposes the underlying window_id as well as tab_title and window_title.

The tab title can be changed via the lua MuxTab type, but there is not
currently an escape sequence associated with this.

The defaults for format-tab-title and format-window-title don't
currently consider these new title strings.

refs: https://github.com/wez/wezterm/issues/1598
2022-06-27 12:01:40 -07:00
Wez Furlong
bb1465508b ssh: allow chdir to fail when spawning via ssh. use login shell.
Similar to 3b9be25161, but relax for
the ssh session when assume_shell="Posix".

Augument how we run the shell in this case as well, so that we make
an effort to run it as a login shell.

refs: #2092
refs: #2076
2022-06-16 09:54:39 -07:00
Wez Furlong
df7c09d760 track dpi in mux and terminal model
refs: https://github.com/wez/wezterm/issues/2085
2022-06-15 18:54:51 -07:00
Wez Furlong
3b9be25161 avoid spawn failures after using sudo -i
The heart of the issue is that `sudo -i` sets the cwd to the homedir
of the root user, and that isn't accessible to the regular unprivileged
user, and cannot be set as the cwd for the newly spawned panes/tabs.

A secondary issue is that it is hard to see what the error is without
improved diagnostics.

So this improves the diagnostics, and then changes the existence
check that we were doing for local domain spawns to try to read the
directory instead.

refs: https://github.com/wez/wezterm/issues/2120
2022-06-15 10:37:57 -07:00
Wez Furlong
d2faa96271 mux: restore same-domain check for cwd when spawning tabs
I think this got lost when this mux function was refactored into
this location from elsewhere.

refs: #2092
2022-06-08 07:56:00 -07:00
Wez Furlong
ead3d4a188 avoid invalidating line seqno when applying hyperlinks
Return the the appropriate seqno from the original line
2022-06-03 08:40:51 -07:00
Wez Furlong
75420c1b8f cli: add move-pane-to-new-tab command
This allows moving a pane to a new tab, which can in turn be
created in a new window.

refs: https://github.com/wez/wezterm/issues/1253
2022-05-28 06:43:22 -07:00
Wez Furlong
c4a248f1a3 mux: split-pane can optionally move an existing pane into the split
This commit allows for the SplitPane internal action to use the
pane id of an existing pane as the source of the pane to be added
in the new split target, rather than spawning a new command.

This can be used to move a pane from one tab to another, and is
analagous to tmux's `join-pane` command.

refs: https://github.com/wez/wezterm/discussions/2043
refs: https://github.com/wez/wezterm/issues/1253
2022-05-27 19:47:12 -07:00
Wez Furlong
17d1170b2a windows: fix divined current working directory
The issue was that we were generating an invalid file URI; fix
that up!

refs: #2036
2022-05-26 05:56:57 -07:00
Wez Furlong
2725559fc0 paneselect: add mode parameter and a mode for swapping panes
Extends the pane selector to allow:

```
wezterm --config 'keys={{key="p", mods="CTRL", action=wezterm.action{PaneSelect={mode="SwapWithActive"}}}}'
```

to swap the active pane with the selected pane.
Similar to https://wezfurlong.org/wezterm/config/lua/keyassignment/RotatePanes.html
except that only the active and the selected panes have their positions
adjusted.

refs: https://github.com/wez/wezterm/issues/1842
refs: https://github.com/wez/wezterm/issues/1975
2022-05-24 22:52:54 -07:00
Wez Furlong
ecd05547d5 Add SplitPane assignment
This, along with the plumbing included here, allows specifying
the destination of the split (now you can specify top/left, whereas
previously it was limited to right/bottom), as well as the size
of the split, and also whether the split targets the node at the
top level of the tab rather than the active pane--that is referred
to as full-width in tmux terminology.

https://github.com/wez/wezterm/issues/578
2022-05-21 21:09:11 -07:00
Wez Furlong
d2d4257f79 Add RotatePanes key assignment 2022-05-21 17:10:04 -07:00
Wez Furlong
107d3d2378 search mode can now default to searching the selection text
To do this, we split `Pattern` into the underlying pattern for the mux
layer (which is part of the codec), and another for the config layer,
so that we can specify this new mode.

At the gui layer, we translate the selection variant into the actual
selection text and map it to the mux Pattern enum.

When taking the selection text, we restrict it to just the first line.

refs: https://github.com/wez/wezterm/issues/1912
2022-05-21 07:24:50 -07:00
Wez Furlong
b312479266 quickselect: allow multiline matches
Turn on multi-line mode by default, and improve the localpane
search function to collapse runs of trailing whitespace into
just a newline.

That allows:

```
./target/debug/wezterm -n --config 'quick_select_patterns={"foo$"}'
```

to match the first line from this, but not the second:

```
printf "foo\nfoobar\n"
```

and this to match both:

```
./target/debug/wezterm -n --config 'quick_select_patterns={"^foo"}'
```

refs: https://github.com/wez/wezterm/issues/2008
2022-05-20 09:47:08 -07:00
Wez Furlong
0e0bac2576 deps: prune some unused deps 2022-05-19 06:48:09 -07:00
Wez Furlong
2f14d640e8 config: split out lua functions into their own crates
This shaves off some build time and allows more parallism in the build.
2022-05-19 06:48:09 -07:00