1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-20 19:27:22 +03:00
Commit Graph

144 Commits

Author SHA1 Message Date
Wez Furlong
526df72544 textwrap -> 0.13 2020-12-09 14:07:35 -08:00
Wez Furlong
8eb0dac92c Update lru -> 0.6 2020-12-09 14:04:56 -08:00
Wez Furlong
6db583388f cargo update
(this will probably annoy dependabot)
2020-12-09 13:58:44 -08:00
Wez Furlong
22b4e99c82 tidy up default_dpi vs DEFAULT_DPI
This commit breaks the dependency from config -> window,
which in turn breaks the dependency from mux-server -> x11 libs
on linux.
2020-12-09 13:48:23 -08:00
Wez Furlong
c6334a45dd extract window::input to wezterm-input-types 2020-12-09 13:48:23 -08:00
Wez Furlong
dfde0c8809 term: revise color cube in the default palette
This commit adjusts the default color palette to use the same color
cube calculation as xterm; it isn't the ideal color cube calculation
and results in slightly brighter colors.

This commit also memoizes the default palette calculation so that
it isn't recomputed each time a palette is created.

refs: https://github.com/wez/wezterm/issues/348
2020-12-09 00:52:24 -08:00
Wez Furlong
61c52af491 wezterm: add raw_code concept to input layer
This commit is a bit noisy because it also meant flipping the key map
code from using the termwiz input types to the window input types, which
I thought I'd done some time ago, but clearly didn't.

This commit allows defining key assignments in terms of the underlying
operating system raw codes, if provided by the relevant layer in the
window crate (currently, only X11/Wayland).

The raw codes are inherently OS/Machine/Hardware dependent; they are the
rawest value that we have available and there is no meaningful
understanding that we can perform in code to understand what that key
is.

One useful property of the raw code is that, because it hasn't gone
through any OS level keymapping processing, its value reflects its
physical position on the keyboard, allowing you to map keys by position
rather than by value.  That's useful if you use software to implement
eg: DVORAK or COLEMAK but want your muscle memory to kick in for some of
your key bindings.

New config option:

`debug_key_events = true` will cause wezterm to log an "error" to stderr
each time you press a key and show the details in the key event:

```
2020-12-06T21:23:10.313Z ERROR wezterm_gui::gui::termwindow > key_event KeyEvent { key: Char('@'), modifiers: SHIFT | CTRL, raw_key: None, raw_modifiers: SHIFT | CTRL, raw_code: Some(11), repeat_count: 1, key_is_down: true }
```

This is useful if you want to figure out the `raw_code` for a key in your
setup.

In your config, you can use this information to setup new key bindings.
The motivating example for me is that because `raw_key` (the unmodified
equivalent of `key`) is `None`, the built-in `CTRL-SHIFT-1` key
assignment doesn't function for me on Linux, but I can now "fix" this in
my local configuration, taking care to make it linux specific:

```lua
local wezterm = require 'wezterm';
local keys = {}

if wezterm.target_triple == "x86_64-unknown-linux-gnu" then
  local tab_no = 0
  -- raw codes 10 through 19 correspond to the number key 1-9 positions
  -- on my keyboard on my linux system.  They may be different on
  -- your system!
  for i = 10, 20 do
    table.insert(keys, {
      key="raw:"..tostring(i),
      mods="CTRL|SHIFT",
      action=wezterm.action{ActivateTab=tab_no},
    })
    tab_no = tab_no + 1
  end
end

return {
  keys = keys,
}
```

Notice that the key assignment accepts encoding a raw key code using
a value like `key="raw:11"` to indicate that you want a `raw_code` of
`11` to match your key assignment.  The `raw_modifiers` portion of
the `KeyEvent` is used together with the `raw_code` when deciding
the key assignment.

cc: @bew
2020-12-06 13:41:29 -08:00
Wez Furlong
e86d949dae cargo update
We need a newer version of ring in order to compile on M1

refs: #343
2020-12-05 10:35:00 -08:00
Wez Furlong
b0bee3b036 wezterm-font: introduce FontDatabase
This tidies up the font-dir and built-in font management a little
bit and paves the way for codepoint -> font resolution for fonts
discovered in font-dirs.
2020-11-25 19:15:08 -08:00
Wez Furlong
ba44548d46 wezterm-font: teach gdi locator how to search for fallback fonts
This commit uses a bit of DirectWrite to discover which font(s)
can be used to render a set of codepoints.

While hooking this up, I found that the method we were using
to extract the font data didn't handle TTC data so this commit
improves some parser diagnostics and handling for that.

refs: https://github.com/wez/wezterm/issues/299
2020-11-25 16:19:56 -08:00
Wez Furlong
5fbb6a4400 wezterm-font: cache metrics lookup in harfbuzz shaper
98f289f511 causes more metrics retrieval
than in earlier versions; each unchached glyph render would trigger
a metrics recompute for the relevant font.

Add a simple cache for this.

refs: #353
2020-11-24 18:19:49 -08:00
Wez Furlong
a063d20cf0 wezterm: improve shaping of emoji
This is one of those massive time sinks that I almost regret...
As part of recent changes to dust-off the allsorts shaper, I noticed
that the harfbuzz shaper wasn't shaping as well as the allsorts one.

This commit:

* Adds emoji-test.txt, a text file you can `cat` to see how well
  the emoji are shaped and rendered.

* Fixes (or at least, improves) the column width calculation for
  combining sequences such as "deaf man" which was previously calculated
  at 3 cells in width when it should have just been 2 cells wide, which
  resulted in a weird "prismatic" effect during rendering where the
  glyph would be rendered with an extra RHS portion of the glyph across
  3 cells.

* Improved/simplified the clustering logic used to compute fallbacks.
  Previously we could end up with some wonky/disjoint sequence of
  undefined glyphs which wouldn't be successfully resolved from a
  fallback font.  We now make a better effort to consolidate runs of
  undefined glyphs for fallback.

* For sequences such as "woman with veil: dark skin tone" that occupy a
  single cell, the shaper may return 3 clusters with 3 glyphs in the
  case that the font doesn't fully support this grapheme.  At render
  time we'd just take the last glyph from that sequence and render it,
  resulting in eg: a female symbol in this particular case.  It is
  generally a bit more useful to show the first glyph in the sequence
  (eg: person with veil) rather than the gender or skin tone, so the
  renderer now checks for this kind of overlapping sequence and renders
  only the first glyph from the sequence.
2020-11-23 13:45:38 -08:00
Wez Furlong
30cc10d4cf wezterm-font: remove font-loader dependency
This commit replaces it with the underlying core text calls
on macos.

refs: #337
2020-11-22 11:19:44 -08:00
Wez Furlong
ddc4c1b624 wezterm: fixup some allsorts shaping cases
* Fixes `keycap 0` by plucking out the prior character for an
  EnclosingMark
* Fixes lookahead for VariationSelector

refs: #66
2020-11-20 18:44:28 -08:00
Wez Furlong
a2a64e80a7 wezterm: update allsorts shaper
The current master of allsorts supports color fonts in both bitmap and
svg varieties.  I'm interested to see if I can teach wezterm to render
the svg based variety in a subsequent diff.

First though, it's times to dust off our allsorts shaper logic.

This commit updates to point to the current master of allsorts at the
time of writing; there's a little bit of API fanout that makes it a bit
easier to manage font fallback.

The fallback logic has been improved so that we can now successfully
fall back to the emoji font.

The shaping logic has been improved so that we turn on the options that
enable ZWJ for combining sequences of emoji, such as "man health
worker".

Running with the allsorts shaper enabled produces generally superior
emoji/ligature substitution results compared to harfbuzz with Noto Color
Emoji; the "man health worker" and the flags (eg: `flag: England`) from
the subdivsion-flag section don't get substituted at all with harfbuzz,
but do produce appropriate glyphs with allsorts.

refs: https://github.com/wez/wezterm/issues/66
2020-11-20 16:56:07 -08:00
Wez Furlong
fba2159839 deps: remove unused deps
Not all of these are needed in these crates (copypasta resulting
from splitting out modules)
2020-11-20 12:37:38 -08:00
Wez Furlong
aaf63285d2 tmux: attach control mode parser to terminal
This causes `tmux -CC attach` to enter control mode and patch
into the terminal, printing out parsed event messages.

refs: https://github.com/wez/wezterm/issues/336
2020-11-20 09:24:50 -08:00
Wez Furlong
ec55a23398 tmux: add tmux-cc crate
This crate knows how to parse data returned from the `tmux -CC` protocol.

refs: https://github.com/wez/wezterm/issues/336
2020-11-20 09:24:28 -08:00
Wez Furlong
44654f4752 wezterm: add wezterm set-working-directory
This command formats an OSC 7 escape sequence to inform the terminal
of the working directory.

It has two optional arguments:

* The hostname - if unspecified the hostname of the system will be used
* The working directory - if unspecified the working directory of the
  process will be used

This command formats the hostname and working directory into a `file://`
URL and emits an OSC 7 escape sequence.

The intent of this is to make it a bit easier to produce shell
integration scripts for various shell environments without trying
to implement URL encoding in eg: bash.
2020-11-13 09:27:14 -08:00
Wez Furlong
37a3f7db5f wezterm: add ScrollToPrompt key assignment
Adds some supporting methods for computing the `SemanticZone`s
in the display and a key assignment that allows scrolling the
viewport to jump to the next/prev Prompt zone.
2020-11-08 09:58:02 -08:00
Wez Furlong
dab2dd5025 term: cache recently decoded images
This commit introduces a small, bounded, LRU cache for recently
decoded images.

This allows the same image ID to be used in the cache that the
same image bits are repeatedly sent to the terminal.

This is advantageous because it reduces the amount of texture
space required by the gui layer.
2020-10-25 11:59:44 -07:00
Wez Furlong
f8c35f191b wezterm: add env bootstrap to mux server, too 2020-10-24 23:33:31 -07:00
Wez Furlong
21dbeb6f83 wezterm: fixup APPIMAGE environment consistently
Need to apply the same logic in wezterm-gui as we do
in the wezterm-cli.
2020-10-24 23:21:03 -07:00
Wez Furlong
ea0d8d6f11 wezterm-font: remove font-kit dep
This wasn't used by anything and the version was getting pretty stale.
Upgrading is awkward because newer versions pull in an incompatible
freetype library version.
2020-10-24 22:01:00 -07:00
Wez Furlong
7d843c6b24 wezterm: fixup win32 build for wezterm-gui changes
refs: #301
2020-10-24 17:00:07 -07:00
Wez Furlong
7e8c5a06bb split gui into wezterm-gui executable
This commit moves a bunch of stuff around such that `wezterm` is now a
lighter-weight executable that knows how to spawn the gui, talk to
the mux or emit some escape sequences for imgcat.

The gui portion has been moved into `wezterm-gui`, a separate executable
that doesn't know about the CLI or imgcat functionality.

Importantly, `wezterm.exe` is no longer a window subsystem executable
on windows, which makes interactions such as `wezterm -h` feel more
natural when spawned from `cmd`, and should allow
`type foo.png | wezterm imgcat` to work as expected.

That said, I've only tested this on linux so far, and there's a good
chance that something mac or windows specific is broken by this
change and will need fixing up.

refs: #301
2020-10-24 16:40:15 -07:00
Wez Furlong
f4066747d2 wezterm: improve texture atlas allocation
This commit uses the guillotine algorithm to assign rectangles,
which is superior to the dumb algorithm previously in use.

In addition, in the first pass of painting, if we get a texture
space error, we clear the atlas and try again without increasing
it size, which should serve as the ultimate defrag.

Subsequent passes will cause the texture to grow if needed.

refs: #306
2020-10-23 13:57:58 -07:00
Wez Furlong
cac02b3bbb Windows: fix enabling dark mode
This got broken by a recentish windows update.
2020-10-17 19:48:43 -07:00
Wez Furlong
5257e34e2c window: update to latest glium version 2020-10-11 17:07:47 -07:00
Wez Furlong
2a87c1dec7 Change cell api to avoid direct access to hyperlink/image
This allows potentially changing the struct layout
to reduce the struct size.
2020-10-11 13:12:46 -07:00
Wez Furlong
96c4750a30 termwiz: reduce Cell memory consumption by 24 bytes
Replaces SmallVec with an internal TeenyString that only
occupies a single machine word and avoids heap allocation
in the common case on most architectures.  This takes the
textual portion of Cell from 32 bytes to 8 bytes.
2020-10-11 13:08:57 -07:00
Wez Furlong
9d9f3c3c1a lua: add GuiWin and PaneObject proxies for use in script
This commit adds very basic first passes at representing the Pane
and GuiWindow types in lua script.

The `open-uri` event from 9397f2a2db
has been redefined to receive `(window, pane, uri)` parameters
instead of its prior very basic `uri` parameter.

A new key assignment `wezterm.action{EmitEvent="event-name"}` is
now available that allows a key binding assignment to emit an arbitrary
event, which in turn allows for triggering an arbitrary lua callback
in response to a key or mouse click.

`EmitEvent` passes the `(window, pane)` from the triggering window and
pane as parameters.

Here's a brief example:

```lua
local wezterm = require 'wezterm';

wezterm.on("my-thingy", function(window, pane)
  local dims = pane:get_dimensions();
  wezterm.log_error("did my thingy with window " .. window:window_id() ..
    " pane " .. pane:pane_id() .. " " .. dims.cols .. "x" .. dims.viewport_rows);
  window:perform_action("IncreaseFontSize", pane);
end)

return {
  keys = {
     {key="E", mods="CTRL", action=wezterm.action{EmitEvent="my-thingy"}},
  }
}
```

refs: #223
refs: #225
2020-10-09 13:55:36 -07:00
Wez Furlong
5fb1414b69 fix clipboard on x11
This was broken by the changes in
aad493ab2a.  The issue was that the
channel send didn't wakeup the receiver.  I'm not sure why, and I tried
a couple of different async channel implementation.

Doing the simplistic solution here works reliably.
2020-10-09 11:07:18 -07:00
Wez Furlong
9397f2a2db wezterm: allow overriding the default open-uri event
This builds on the new lua event handler plumbing added
in ccea650a93 to co-opt
the default URI opening action:

```lua
wezterm.on("open-uri", function(uri)
  if uri:find("jira") then
    wezterm.log_error("do something with jira")
    wezterm.run_child_process({
      "wezterm",
      "start",
      "--",
      "jira",
      "view",
      extract_task_from_uri(uri)
    })
    -- prevent the default action from opening in a browser
    return false
  else
    -- log but allow the uri to be opened in the browser
    wezterm.log_error("clicken " .. uri)
  end
end)
```

This doesn't allow exactly the sketched out option from
issue #223 to be implemented, but may be close enough
to be useful.

refs: #223
refs: #225
2020-10-07 18:26:16 -07:00
Wez Furlong
ccea650a93 add wezterm.on(), wezterm.emit()
* `wezterm.on("event-name", func)`
* `wezterm.emit("event-name", "arg1", "arg2")`

`on` allows registering multiple functions.
`emit` will call each of the registered functions in turn, passing
a copy of the arguments.  If a handler returns false, no additional
handlers are called and `emit` will return false.  Otherwise,
once all the handlers have been called, `emit` will return true.

`emit` is capable of being called by async code.

These functions are available to the config layer, but nothing in
wezterm uses them at this time.

refs: #225
2020-10-07 08:42:06 -07:00
Wez Furlong
4acf1e3935 Upgrade mlua to 0.4, lua to 5.4 2020-10-06 18:34:29 -07:00
Wez Furlong
8d1af908bf fixup starting mux on windows
* Taught wezterm-mux-server how to `--daemonize` on windows
* Removed pty based command spawn used to spawn unix domain servers.
  This was present because it was the only way to successfully spawn
  wsl in the past.  What I'm finding today is that it doesn't work
  at all for me, generating an `0xc0000142` Application failed to
  initialize error.  A plain command builder spawn seems to work,
  so that's what we're going with.
* Ensure that we put `.exe` on executable name on windows, otherwise
  the spawn may fail.
* `Path::exists()` always returns false for unix domain sockets on
  Windows, so unconditionally try to remove the socket before binding,
  otherwise the bind will falsely fail, claiming that another process
  is already bound.

The docs for mux will need to be updated to show how to revise them
for the new mux server invocation:

```lua
  unix_domains = {
    {
      name = "wsl",
      serve_command = {"wsl", "wezterm-mux-server", "--daemonize"}
    },
  }
```
2020-10-05 20:29:47 -07:00
Wez Furlong
a9a220f43c Fix build on freebsd CI
refs: https://github.com/stjepang/futures-lite/issues/28
2020-10-05 17:19:17 -07:00
Wez Furlong
0a546d7c12 and another speculative diff to fixup windows build 2020-10-05 13:56:11 -07:00
Wez Furlong
a0b3932e6d fixup build for macos 2020-10-05 09:11:17 -07:00
Wez Furlong
aad493ab2a simplify promise crate
Implement Future and Promise in terms of a bounded channel of size 1.
2020-10-05 08:50:29 -07:00
Wez Furlong
5eb4d32004 upgrade misc deps, notably, async-task 2020-10-05 00:06:01 -07:00
Wez Furlong
3e2b86e15e fully remove daemonize crate 2020-10-04 23:08:50 -07:00
Wez Furlong
3de4851aed fixup tls mux sessions
This adopts smol more broadly, but not yet completely.
2020-10-04 21:47:12 -07:00
Wez Furlong
19cea53e35 mux: upgrade rcgen
This version no longer generates invalid CA certificates and
allows TLS connections using the internal PKI to advance
further.  Still need to debug an early disconnect.
2020-10-04 10:05:31 -07:00
Wez Furlong
e8be716cb3 clean up mux server startup
kindof a lot going on in this commit, unintentionally:

* Need the lua context set to be moved into the config crate
  otherwise configs cannot be parsed by the server and we end
  up with the default configs
* Make the server use smol for async io
* Drop the use of the daemonize crate, which I had forked anyway.
  Just inline our own tighter daemonize module
* Improve daemon spawning synchronization, however, it still needs
  work for windows to avoid blocking forever where we don't do
  daemonizing.
2020-10-04 09:39:28 -07:00
Wez Furlong
a4731fd5ab Use smol/async for the mux server unix sockets 2020-10-03 11:15:57 -07:00
Wez Furlong
b996fede7f codec: add async read/write methods 2020-10-03 11:15:57 -07:00
Wez Furlong
75dca6e972 move strip-ansi-escapes into its own crate 2020-10-03 11:15:57 -07:00
Wez Furlong
faba4d9074 move gui into wezterm crate/binary 2020-10-03 11:15:57 -07:00