Commit Graph
658 Commits
Author SHA1 Message Date
zakradandBenoit de Chezelles d6e1859782 fix(term): avoid divide-by-zero crashes in inline image placement (#7872)
assign_image_to_cells contained two unguarded divisions that could panic
with 'attempt to divide by zero' and take down the pane (and, under the mux,
the pane's reader thread):

1. A Kitty graphics escape requesting a zero-sized placement (eg: an explicit
   w=0/h=0, or a source origin outside the image bounds) yields a
   draw_width/draw_height of 0, used as a divisor when sizing the image.
   This is the case reported in #6344.

2. Displaying a cell-sized image (one without explicit c=/r=) on a pane whose
   pty reported no pixel dimensions makes cell_pixel_width/height 0, which is
   then used as a divisor. A zero pixel size is the default PtySize and is what
   tmux/headless domains report, so a perfectly valid image crashes there.

Guard both: refuse the placement when the drawable region or the cell pixel
size is zero.
The error flows into the existing logging handlers for the Kitty, iTerm and
Sixel paths, so no callers change.
Real GUI panes always have a non-zero pixel size, so valid images are
unaffected.

Adds regression tests for both cases (each panics on main, passes with the
fix) and enables kitty graphics in the test terminal config (off by default)
so the path is exercised.

Closes #6344

---------

Co-authored-by: Benoit de Chezelles <benoit.dechezelles@gmail.com>
2026-06-21 22:45:33 +02:00
Jeff QuastandWez Furlong 577474d89e Prevent "screen scraping", disable DECRQCRA (#7701)
* Security fix: prevent screen scraping

Problem
-------

DECRQCRA was added in 6cbb3ba43, for 9702d1cf5 (esctest integration) Sunday, March 17 2019.  Six days later, March 23 2019, although esctest was removed in c93f967bc, DECRQCRA remained enabled by default for all WezTerm releases since.

March 2023, @j4james mentioned WezTerm has this option enabled by default https://github.com/microsoft/terminal/issues/14974, "some people consider it a security risk"

September 2023, https://dgl.cx/2023/09/ansi-terminal-security#cursor-checksum article writes, "using DECRQCRA [..] potential attack here is reading what is displayed on the terminal before a user SSHes to a remote system."

By switching to "alternate screen", it also possible to recover last TUI display, such as contents of the file last opened in an editor.

Example CLI script scrapes screens '0' and '1' of WezTerm, https://github.com/jquast/blessed/blob/master/bin/screen-scrape.py

Solution
--------

Disable https://vt100.net/docs/vt510-rm/DECRQCRA.html by default, may be re-enabled by configuration.

---

Refs: https://github.com/wezterm/wezterm/pull/7701

Co-authored-by: Wez Furlong <wez@wezfurlong.org>
2026-03-31 04:00:28 -07:00
James Holderness 58141ad6f2 term: indicate support for OSC 52 in Primary DA response
This is an extension agreed upon by modern terminals to indicate that
they support copying to the clipboard with XTerm's OSC 52 sequence.

https://github.com/contour-terminal/vt-extensions/blob/master/clipboard-extension.md
2025-06-22 06:44:36 +01:00
Wez Furlong 6c7e3722b1 term: normalize imports to wezterm-xxx rather than termwiz re-exports 2025-05-10 15:08:56 -07:00
HAMANO TsukasaandWez Furlong 8ec1f2451c add cell_widths option #6289
Co-authored-by: Wez Furlong <wez@wezfurlong.org>
2025-05-03 06:56:33 -07:00
Wez Furlong 54e70e51d2 wezterm-term: revise approach to zero-width graphemes
refs: https://github.com/wezterm/wezterm/issues/1422
refs: https://github.com/wezterm/wezterm/issues/6637

When we encounter a zero-width grapheme we need to be
a little bit smarter about how we handle it.

In the original implementation we'd unconditionally
remap these graphemes into a cell, effectively making
them appear as a blank cell with width of one.

Later we discovered that eg: BIDI control characters
should not be forced to display in this way, so the
logic was changed to elide these graphemes from the
model.

Subsequently we've found that the unicode line separator
should be treated as a blank.  The unicode FAQ says
that any character that has the White_Space property
should be treated that way.

This commit applies that logic: if we get a zero-width
grapheme, if it is white space we'll force it to
have a width of 1, otherwise we'll elide it from
the model.

This probably is still not perfect, but hopefully
balances things out to be good enough, at least
until we find an example of where it isn't the right call!
2025-03-09 06:28:06 -07:00
Wez Furlong 15506bf3ef term: moved saved cursor from ScreenOrAlt -> Screen
refs: #6669
2025-03-06 15:23:38 -07:00
Wez Furlong edcdefda3b workspace-ify the deps
There have been a couple of attempts at this in the past, which
had some usability warts in what I recall as an earlier, less
useful set of features overall.

Whether that was collective misunderstanding at the time, or things
have gotten better since then, now is a good time to adopt the workspace
dep syntax, because wezterm has many crates to keep on top of, and
automation like dependabot can't see a lot of them.

This will help to manage the versions of deps in wezterm centrally.

Let's try this out in CI: the Cargo.lock changes here are minimal
(eliminated a second version of base64 from one crate, terminal_size
from another, and removed an explicit dep on serde_derive) so
hopefully this sails through on !linux.

closes: https://github.com/wezterm/wezterm/pull/6668
2025-02-12 09:43:36 -07:00
Wez Furlong 4d3911b5e2 termwiz: prep for making a new release 2025-02-10 08:45:17 -07:00
Wez Furlong 44866cc137 new: ConEmu progress reporting OSC sequence
This commit parses and captures the progress state as set by
ConEmu style progress reporting escape sequences.

Changes to the state will propagage through the mux via the
existing MuxNotification Alert system, and should also transit
across multiplexer connections.  However, there is no separate
multiplexer state transfer for the progress state, so reconnecting
to a mux in the middle of a progress sequence will show as None
for the progress state, until the next update occurs.

Aside from propgating and exposing the state to lua via PaneInformation
and a Pane::get_progress method, wezterm doesn't do anything with
the progress information at this time.

This commit includes an example of how you might customize your
tab title to reflect the progress in the active pane.

refs: https://github.com/wezterm/wezterm/issues/6581
2025-02-09 18:26:23 -07:00
Wez Furlong fb023956cf termwiz: parse ConEmu progress OSC sequence
refs: https://github.com/wezterm/wezterm/issues/6581
2025-02-09 17:19:50 -07:00
Jose Biosca 47b91d8e0e fix mouse button streak requiring pixel precision 2025-02-07 19:11:37 -07:00
Wez Furlong 11c4b11669 s,wez/wezterm,wezterm/wezterm,
I moved the repo to an org of its own. Update various things
to reference the new location.
2025-02-07 13:08:01 -07:00
Wez Furlong 00644d4e1a update for new wezterm.org domain 2025-02-06 21:13:50 -07:00
Sean Estabrooks 659aedffe8 Region scrolling tests and a fix
@tbung fixed a scrolling bug in #6099.  This patch just
adds some tests and takes care of a couple corner cases
that still remained with region scrolling.
2024-11-28 09:01:13 -07:00
Sean Estabrooks b2889fe889 Region scrolling tests 2024-11-28 09:01:13 -07:00
Wez Furlong c0649ad4bb remove cfg_attr(feature = "cargo-clippy" noise
I never liked clippy for dropping turds like this throughout the
code. I'm glad it is no longer required, but now rust is warning
about this syntax being redundant.
2024-09-14 06:49:13 -07:00
Wez Furlong 45ec2464e5 docs and related fix for #6099
We should avoid nudging the scrollback position when there is no
scrollback allowed in this other case as well.

refs: https://github.com/wez/wezterm/pull/6099
2024-09-14 06:42:10 -07:00
Till Bungert f911e48a95 fix: only change stable row offset if screen has scrollback 2024-09-14 06:37:36 -07:00
Wez Furlong 56a27e93a9 cargo update
plus some noise around the image crate api evolving and deprecating
some type aliases.
2024-07-30 08:27:27 -07:00
Thayne McCombs 03407cae99 fix: Use cols not rows for left margin bound
The location of the left margin should depend on the width, not the
height.

Fixes: #5750
2024-07-30 07:40:42 -07:00
Wez Furlong 2a068cacb7 deps: update terminfo 2024-05-13 12:29:19 -07:00
Wez Furlong 0f03117776 deps: update miniz-oxide 2024-05-13 11:55:58 -07:00
Wez Furlong 281b6e2740 deps: update metrics to a more recent version
This isn't the latest version of metrics; it's just a more recent
version that allows us to remove a duplicate ahash dependency from the
build graph.
2024-05-13 09:41:11 -07:00
Wez Furlong 14d426fea8 add cargo deny config, update lru 2024-05-13 08:29:36 -07:00
Wez Furlong 91a16e5224 remove unused local
this should have happened in efbafbc229
2024-05-09 22:30:25 -07:00
Wanchang Ryu efbafbc229 fix wrapped long line copy problem on tmux
wezterm ignores wrapped long line when alt screen is used and tmux uses
alt screen that makes copying wrapped long line into multiple lines.

After testing on sevaral tui apps like tmux, w3m, htop it seems to show
reasonable performance on resizing.

Fixes #5283
2024-05-09 14:35:26 -07:00
Wez Furlong 265b85be1d update image to 0.25
This improves how non-conforming jpegs are decoded and displayed.

refs: https://github.com/wez/wezterm/issues/5365
2024-05-05 16:14:46 -07:00
Pi-Cla ee61e61e4f [PATCH] Fix various cargo audit errors
closes: https://github.com/wez/wezterm/pull/5206
2024-05-04 22:47:57 -07:00
Wez Furlong aa94a98314 fix invalidation on palette change
refs: https://github.com/wez/wezterm/issues/4932
and possibly: https://github.com/wez/wezterm/issues/2635
2024-02-01 15:58:14 -07:00
Wez Furlong 86d9ec69f5 term: downgrade conpty tmux title mangling warning to debug
The user can't do anything about it anyway.
2024-01-31 07:36:30 -07:00
jonboh 820c451b57 add small helper function to better express bool casting 2024-01-28 07:59:13 -07:00
jonboh 500f84617e fix kitty image protocol display parameters 2024-01-28 07:59:13 -07:00
Wez Furlong 7f3a835548 fix excessive calls to format-tab-title
* Removed title update from main render loop
* Add to PaneFocused event
* term: only emit Alert::OutputSinceFocusLost for the first
  seqno bump after losing focus, rather than on every bump.
  That event indirectly causes the title to update

refs: https://github.com/wez/wezterm/issues/4788
2024-01-25 23:14:38 -07:00
Wez Furlong 516add5a4b fixup tests for seqno increment on resize change
refs: https://github.com/wez/wezterm/issues/4828
refs: https://github.com/wez/wezterm/issues/3694
refs: https://github.com/wez/wezterm/issues/2351
2024-01-23 18:31:59 -07:00
Wez Furlong 8f74e1c848 increment seqno when resizing
Without this, we don't invalidate the shape hash eg: when zooming a
pane.  This is potentially also the root cause of some other weirdness
with the multiplexer.

refs: https://github.com/wez/wezterm/issues/4828
refs: https://github.com/wez/wezterm/issues/3694
refs: https://github.com/wez/wezterm/issues/2351
2024-01-23 18:08:46 -07:00
Wez Furlong ba85958a61 deps: update env-logger
Note that we are pinned on 0.10 for env-bootstrap, where we use it
only for its module filter parser.
2024-01-20 16:01:10 -07:00
Wez Furlong 9fc89e621f de-fang paste payloads by removing bracketed paste sequences from them
refs: https://github.com/wez/wezterm/issues/4765
2024-01-08 18:17:22 -07:00
Luis Javier Merino Morán 97e001c93c Clamp cursor position reported by CPR
From esctest:
CHATests.test_CHA_OutOfBoundsLarge
CUPTests.test_CUP_OutOfBoundsParams
HVPTests.test_HVP_OutOfBoundsParams
2023-11-22 14:56:26 -07:00
Luis Javier Merino Morán 769840d2cb DECRQCRA: treat uninitialized cells as spaces
The concept of uninitialized cells in wezterm is not the same as that on
VT520 or that on xterm, so treat them as spaces, at least when asking
for the checksum of a single cell, which is what esctest does.
2023-11-22 14:38:11 -07:00
Luis Javier Merino Morán c4654d8bf4 Make RIS also clear the alternate screen
xterm clears the alternate screen on RIS since #383. VTE and konsole
already did that.

From esctest:
RISTests.test_RIS_ExitAltScreen
2023-11-12 17:09:34 -07:00
Luis Javier Merino Morán f880188ae4 Default G1 to ASCII
As per DEC STD-070 3.6.4

refs: https://github.com/wez/wezterm/issues/3962
2023-11-07 08:22:51 -07:00
Wez Furlong c75f20f21c deps: ordered-float -> 4.1.0
closes: https://github.com/wez/wezterm/pull/4338
2023-09-28 14:39:22 -07:00
Sean Sullivan 5161de59fe expose pen attribute on terminal info 2023-09-22 12:21:15 -07:00
Wez Furlong 33e727b074 Respond to DECRQM 2027 - grapheme clustering
closes: https://github.com/wez/wezterm/issues/4320
2023-09-20 14:48:05 -07:00
Wez Furlong c1b7ba2f35 fix warning in latest rust compiler 2023-08-28 06:39:14 -07:00
Wez Furlong b7771feef6 imgcat: work better with tmux and conpty
Neither of these understand image protocols, and both are
an additional processing layer between the application and
wezterm.

This commit detects and wraps OSC sequences in tmux's passthru
sequence so that the data is passed on to wezterm rather than
elided from the data stream.

For image protocols in both tmux and conpty, work a little
smarter and explicitly move the cursor position to the same
location that wezterm would move it to.  That prevents the
display from being as mangled by tmux/conpty due to a diverging
understanding of the cursor position.

The logic isn't perfect, and can result in the x-coordinate
being incorrect, and this won't work with the new --position
argument either in its current state, without adding a lot
of complexity to deal with scrolling and relative and absolute
positioning handling.

To facilitate that, a new termwiz Terminal trait method has
been added to probe the terminal name, version, cell and pixel
dimensions. It's not pretty.

refs: https://github.com/wez/wezterm/issues/3624
refs: https://github.com/wez/wezterm/issues/3716
2023-07-15 22:13:19 -07:00
Rémi Labeyrie da2c035ad2 feat: handle horizontal mousewheel events 2023-07-10 12:55:13 -07:00
Wez Furlong c54548df7e Fix ClearToEndOfLine in last column when wrap_next=true
Given a sequence like this, where the `ESC [ K` sequence is
emitted at the last column when wrap_next=true:

\u001b[47;30m  17:24:50 \u001b[0m\u001b[K

rather than treating the column as out of bounds, we'd clear the
final cell.

refs: #3548
2023-05-29 16:01:11 -07:00
Wez Furlong e0a4ebd586 implicitly reset palette when setting it to the equivalent of the config
refs: #3685
2023-05-29 14:46:43 -07:00