Commit graph

130 commits

Author SHA1 Message Date
Bakkeby
e77d5e1b3b sync patch: add DECRQM 80 and 8452 for sixel patch ref. #179 2025-10-26 00:22:53 +02:00
Bakkeby
d12d2ad1c2 sync patch: remove redundant inner #if for DECRQM -- DEC Request Mode case statement ref. #179 2025-10-25 14:04:52 +02:00
Bakkeby
bdb21ddb8b bump version to 0.9.3
https://git.suckless.org/st/commit/5a4666c19e3956069147aee43a06b326d998366e.html

add a few comments

https://git.suckless.org/st/commit/5a4666c19e3956069147aee43a06b326d998366e.html

Support OSC 110, 111, and 112 for resetting colors

This adds support for OSC 110, 111, and 112 escape sequences to reset
the foreground, background, and cursor colors in the terminal. The
changes include handling these sequences in the `strhandle` function of
`st.c`, allowing applications to reset colors to their default values.

The OSC sequences originated from Xterm control sequences and are now
widely used in terminal applications and supported by many terminal
emulators. For applications, this allows them to reset colors to
default values without needing to know the colors beforehand.

https://git.suckless.org/st/commit/d6c431859c6c0201e0668ed24a9f17cebf0a68f5.html
2025-08-10 15:44:48 +02:00
Bakkeby
92e6c003f7 Eat up "CSI 58" sequences
This is used in the wild by systemd systemctl for example and st
misinterpreted it as "blink", because it didn't know "58", then saw "5"
as "blink", and then didn't know "245".

This should print "foo" as normal text:

    printf '\e[58:5:245mfoo\n'
    printf '\e[58:2:50💯200mfoo\n'

Ref.
https://git.suckless.org/st/commit/f114bcedd113017d907aad32031db92c050f4bf3.html
2025-07-27 20:48:20 +02:00
Laurent Cheylus
f17e1dcf31
Do not interpret CSI ? u as DECRC (#181)
The kitty keyboard protocol docs recommend CSI ? u to query support for
that protocol, see https://sw.kovidgoyal.net/kitty/keyboard-protocol/

For better or worse, fish shell uses this query to work around bugs
in other terminals triggered by requesting that protocol via CSI = 5 u.

Unfortunately, st interprets CSI ? u as DECRC (restore cursor
position). reproduce with 'printf "\x1b[?u"; cat'.

fish could work around this by switching to the alternate screen
before running this query; but that might cause tearing on terminals
that don't support Synchronized Output. I'm not sure.

In the meantime, let's correct our parser.

This adds a redundant else-after-return, for consistency with the
surrounding code.

ref. https://git.suckless.org/st/commit/98610fcd37f655d44586323dc86c1d013c2798ce.html

Signed-off-by: Laurent Cheylus <foxy@free.fr>
2025-07-09 09:45:24 +02:00
Bakkeby
7c28c7868a sync: add support for DECRQM queries for synchronization ref. #179 2025-07-08 19:17:57 +02:00
Bakkeby
9edaa4c149 sync: mode 2026 correction ref. #179 2025-07-08 15:11:17 +02:00
Bakkeby
4000b47a10 sync: adding mode 2026 for the sync patch to allow syncing to be controlled by programs ref. #179 2025-07-08 10:42:24 +02:00
Bakkeby
c4af76a9cc reflow: addressing selection clearing bug when selection includes the prompt ref. #166 2025-02-26 21:23:09 +01:00
Bakkeby
b77fb11b76 Clear screen: Fix edge case
With sequence \e[1J, if cursor is on second line, clear the first line.

ref.
https://git.suckless.org/st/commit/6009e6e25bdff9548f085e9ae562b1ca305d3a0b.html
2024-12-06 23:06:38 +01:00
Stein Gunnar Bakkeby
4dec55eead
Refactoring sigchld ref. #156 (#159) 2024-11-25 20:48:52 +01:00
Utkarsh Verma
c4c5113fbd
osc7: initial patch implementation (#154)
* osc7: initial patch implementation

Closes #153

* osc7: avoid redundant use of realpath()

* osc7: fix styling

* Changing position of the OSC7_PATCH toggle in patches.def.h

---------

Co-authored-by: Bakkeby <bakkeby@gmail.com>
2024-10-15 09:54:45 +02:00
Bakkeby
3f1a5ed034 Revert "undercurl: support semicolons in SGR character attributes ref. #148"
This reverts commit 398aeb1cd6.
2024-10-01 23:17:07 +02:00
Bakkeby
398aeb1cd6 undercurl: support semicolons in SGR character attributes ref. #148
Back in May 2024 support for colons in SGR character attributes was
added to allow both colons and semicolons to be used to separate the
subparameters in SGR escape codes.

The undercurl patch only read colons to separate parameters. This
commit allows for semicolons to be used as well when using escape
codes for undercurl.

https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
https://git.suckless.org/st/commit/5dbcca49263be094fc38159c297458ae323ef647.html
https://st.suckless.org/patches/undercurl/
2024-10-01 21:35:46 +02:00
Utkarsh Verma
fe065cc366
osc133: initial patch implementation (#127)
* osc133: initial patch implementation

* Specify dependency on reflow or scrollback patch
2024-10-01 21:35:30 +02:00
veltza
aaaa59eb77
sixel: fix image deletion issue (#150)
This fixes the current implementation, which does not delete an image if
an application first erases the image and then spawns a new transparent
image in its place. The reason it didn't work before was because the two
operations were handled at different stages in the rendering pipeline.
2024-09-20 09:21:30 +02:00
veltza
714fcffaa8
Fix issue with columns and reflow that breaks sixels (#146)
Fixes #145
2024-08-09 09:12:51 +02:00
veltza
7a581fe4e1
sixel: improve the renderer (#143)
In the current implementation, when text is written over an image, we
have to cut the entire text line out of the image, regardless of how
long the text is. It doesn't look good, but it was a design choice for
the following reasons:
1) To keep the sixel engine as fast as possible
2) Most applications do not write text on the images anyway

To bring the st terminal in line with other terminals that support
sixels, I have now improved the sixel renderer so that the images can
now have gaps, which allows the text to be printed inside the images.
The changes should not affect performance in normal cases. Only when the
renderer has to deal with the text there might be some performance hits
depending on how many gaps there are in the images.
2024-07-07 21:18:09 +02:00
veltza
48c85cdcf5
sixel: refactor the sixel display mode (#142)
This does not change the current behavior of SDM.
2024-07-05 11:30:55 +02:00
Bakkeby
aa5957495d support colons in SGR character attributes
Patch by Mikhail Kot <to@myrrc.dev>
With some modifications to behave more like xterm (see note below).

Example:

	printf '\033[48;2;255:0:0mtest\n'

https://invisible-island.net/xterm/ctlseqs/ctlseqs.html

Some notes:

"CSI Pm m  Character Attributes (SGR).
[...]
o   xterm allows either colons (standard) or semicolons
(legacy) to separate the subparameters (but after the
first colon, colons must be used).
2024-05-02 09:28:20 +02:00
veltza
118e965d0c
sixel: add support for fully transparent bg (P2=1) (#132)
P2 selects how the terminal draws the background color.

P2                  Meaning
0 or 2 (default)    Pixel positions specified as 0 are set to the
                    current background color.
1                   Pixel positions specified as 0 remain at their
                    current color.

Both modes are now supported.

Ref. https://www.vt100.net/docs/vt3xx-gp/chapter14.html
2024-04-17 18:04:27 +02:00
Bakkeby
4997f1b1ae reflow: fix for scrollback buffer content getting lost following ctrl+l ref. #123 2024-03-14 16:58:22 +01:00
Stein Gunnar Bakkeby
3b87b07404
Adding reflow patch (#120) 2024-03-13 10:33:51 +01:00
Bakkeby
a28f3e0d39 Adding back lines that were removed by mistake, fixes mouse double click to select 2024-03-11 22:49:20 +01:00
Bakkeby
3564593563 Revert "Fix cursor move with wide glyphs" ref. #118
This reverts commit 400aa4492f.
2024-03-08 19:52:11 +01:00
Bakkeby
cd37481bde sixel: moving osc_table out of sixel patch due to global dependency ref. #118 2024-03-08 19:52:00 +01:00
Bakkeby
b43957b061 Optimise utf8decode() 2024-03-07 23:26:34 +01:00
Bakkeby
d78d582eaa Streamline validation in utf8decode()
https://lists.suckless.org/hackers/2207/18407.html
2024-03-07 23:22:02 +01:00
Bakkeby
6d5c2b3ddb code-golfing: cleanup osc color related code
* adds missing function prototype
* move xgetcolor() prototype to win.h (that's where all the other x.c
  func prototype seems to be declared at)
* check for snprintf error/truncation
* reduces code duplication for osc 10/11/12
* unify osc_color_response() and osc4_color_response() into a single function

the latter two was suggested by Quentin Rameau in his patch review on
the hackers list.

ref.
https://git.suckless.org/st/commit/8629d9a1da72cc18568a8f146307b0e939b77ebf.html
2024-03-07 23:16:00 +01:00
Bakkeby
e88f2bf20c Removing the VIM browse patch.
The general reasoning is that the vim browse patch is very invasive,
has a high level of complexity, and is incompatible with a significant
number of other patches and it complicates further maintenance.

Additionally the patch has its own scrollback mechanism which seemingly
did not work properly - and nobody seems to have complained about this
since the patch was added back in May 2021.

If you want to try out the vim browse patch then I would recommend having
a play around with the patch author's own build that has this patch
integrated:
   - https://github.com/juliusHuelsmann/st-history-vim
   - https://github.com/juliusHuelsmann/st

Alternatively a tag has been added to this repository that refers to the
last commit that still has the vim browse patch:
   - https://github.com/bakkeby/st-flexipatch/tree/VIM_BROWSE_PATCH
2024-03-07 22:35:11 +01:00
Bakkeby
b7add20215 Set upper limit for REP escape sequence argument
Previously, printf 'L\033[2147483647b' would call tputc('L') 2^31 times,
making st unresponsive. This commit allows repeating the last character
at most 65535 times in order to prevent freezing and DoS attacks.

ref.
https://git.suckless.org/st/commit/95f22c53059ccd60ee701ccf2659dacd95e4e89a.html
2024-03-07 21:44:39 +01:00
Bakkeby
400aa4492f Fix cursor move with wide glyphs
st would always move back 1 column,
even with wide glyhps (using more than a single column).

The glyph rune is set on its first column,
and the other ones are to 0,
so loop until we detect the start of the previous glyph.

ref.
https://git.suckless.org/st/commit/7473a8d1a57e5f9aba41b953f4e498c35e1c9dc5.html
2024-03-07 21:43:24 +01:00
Stein Gunnar Bakkeby
677c2da0be
Reworking sixel implementation based on veltza's implementation (#117)
* sixel: remove black bars from sixel images

When the images don't fully cover the text cells, black bars are added
to them. This fix removes those bars, but if you need the old behavior,
you can restore it by setting 'sixelremovebars' to zero in config.h

* sixel: fix a potential memory leak

* sixel: improve behavior with text reflow

* sixel: prevent animated gifs from choking the terminal

Animated gifs constantly spawn new images that eventually choke the
terminal because the old animation frames are kept in the image buffer.
This fix removes overlapping images from the image buffer and prevents
them from piling up.

* sixel: add zooming and clipping

* sixel: copying bulk of changes

* sixel: move sixel_parser_parse() and add missing sequences and blocks (#113)

- Move sixel_parser_parse() from tputc() to twrite()
- Add missing 8452, DECSDM, XTSMGRAPHICS and XTWINOPS sequences
- Add more conditional blocks for the scrollback and sync patches
- Remove unused reflow_y from ImageList. It is only used for the
  scrollback-reflow patch in st-sx.

* sixel: update vtiden to VT200 family

* sixel: fix scrolling issues inside tmux (#114)

tmux is using the scrolling region and sequence to clear the screen
below the shell prompt. This peculiar behavior caused the tscrollup()
function to be called, which always scrolled the images regardless of
whether they were inside the region or not. So the images moved out of
place whenever the bottom of the screen was cleared. This fix checks
that the images are inside the region before scrolling them.

* sixel: prevent images from being deleted when resizing (#115)

This fixes resizing issues outside of tmux not inside.

* Rewriting tresize logic based on veltza's proposed implementation in PR #115

* tresize: correction for tscrollup call when scrollback patch is used

---------

Co-authored-by: veltza <106755522+veltza@users.noreply.github.com>
2024-03-07 09:22:44 +01:00
Bakkeby
74f19eafe9 csi: check for private marker in 'S' case
The handler for 'S' final character does not check for a private
marker. This can cause a conflict with a sequence called 'XTSMGRAPHICS'
which also has an 'S' final character, but uses the private marker '?'.
Without checking for a private marker, st will perform a scroll up
operation when XTSMGRAPHICS is seen, which can cause unexpected display
artifacts.

ref.
https://git.suckless.org/st/commit/a3f7420310be0fd778ef9fe2abf20edc2d8dc81a.html
2024-02-19 09:09:08 +01:00
veltza
76cb5801f6
sixel: fix resizing issues (#109)
Fixes #108
2023-12-12 21:29:26 +01:00
Bakkeby
1df649dfbd Unhide cursor on RIS (\033c)
It is unclear if it's "required" to do this on RIS, but it's useful when
calling reset(1) after interactive programs have crashed and garbled up
the screen.

FWIW, other terminals do it as well (tested with XTerm, VTE, Kitty,
Alacritty, Linux VT).

ref.
https://git.suckless.org/st/commit/559fdc278681c98470749adb59f01cd071720458.html
2023-10-08 20:22:22 +02:00
Bakkeby
3cbaecfa31 Fix wide glyphs breaking "nowrap" mode
Consider the following example:

    printf '\e[?7l';\
    for i in $(seq $(($(tput cols) - 1))); do printf a; done;\
    printf '🙈\n';\
    printf '\e[?7h'

Even though MODE_WRAP has been disabled, the emoji appeared on the next
line. This patch keeps wide glyphs on the same line and moves them to
the right-most possible position.

ref.
https://git.suckless.org/st/commit/8abe4bcb41aa7fda0ae00823f6a20271124150db.html
2023-10-08 20:21:13 +02:00
Bakkeby
6ade70c726 Don't scroll selection on the other screen
Fixes garbage selections when switching to/from the alternate screen.

How to reproduce:

-   Be in primary screen.
-   Select something.
-   Run this (switches to alternate screen, positions the cursor at the
    bottom, triggers selscroll(), and then goes back to primary screen):

        tput smcup; tput cup $(tput lines) 0; echo foo; tput rmcup

-   Notice how the (visual) selection now covers a different line.

The reason is that selscroll() calls selnormalize() and that cannot find
the original range anymore. It's all empty lines now, so it snaps to
"select the whole line".

ref.
https://git.suckless.org/st/commit/2fc7e532b23e2f820c6b73d352ec7c41fefa45b5.html
2023-10-08 20:19:56 +02:00
Bakkeby
1c03f10db9 sixel: only clear sixel images on RM (Reset Mode) if we are in alt screen ref. #102 2023-09-12 16:11:08 +02:00
Bakkeby
c1ef3ce0d8 scrollback: clear history on reset ref. #102 2023-09-12 16:02:19 +02:00
Bakkeby
41e6f9dce6 sixel: remove images on escape code 'l' - Reset Mode (RM) ref. #102 2023-09-12 00:16:10 +02:00
Bakkeby
b82057eb85 Fix for wide character being incorrectly cleared on MODE_INSERT
Under insert mode, when inserting a normal character in front of
a wide character, the affected region is shifted to the right by
one cell. However, the empty cell is reset as if being a part of a
wide character, causing the following cell being mishandled as a
dummy cell.
To reproduce the bug:
	printf '\033[4h' # set MODE_INSERT
	printf 妳好
	printf '\033[4D'
	printf 'x'
	printf '\033[4l\n'

Ref.
https://git.suckless.org/st/commit/3a6d6d740110e6ee1b092d05ad746244eedabe4b.html
2023-06-25 14:19:27 +02:00
veltza
677f854c05
Fix sixel issues and add a clearing sequence (#99)
This patch fixes the following sixel issues:

- The current sixel implementation cleared all cells from the left side
  of the image when the image was drawn. The fix only clears the cells
  where the image will be drawn.
- The deletion routine didn't work correctly. In certain situations,
  it left the image or images undrawn. For example, if the first image
  was marked for deletion, it didn't draw the second one.
- The drawing routine caused a high cpu usage, because XCopyArea()
  triggered the X server to send the NoExpose event, which caused sixels
  to be redrawn and the X server to send another NoExpose event and so
  on. This loop caused constant redraw of sixels and high cpu usage.
  The fix prevents the X server from sending GraphicsExpose and NoExpose
  events.

The patch also adds a control sequence for removing sixels:

Because the sixels are implemented as overlay images, they cannot be
removed by clearing the underlaying cells. Therefore, we need a control
sequence to remove them. I opted to choose ESC[6J as the control
sequence because it is not used and the number refers to sixels. So when
the lf file manager supports sixels [1], you can use the following
minimal scripts to preview images in lf:

previewer:
  #!/bin/sh
  case "$(readlink -f "$1")" in
      *.bmp|*.gif|*.jpg|*.jpeg|*.png|*.webp|*.six|*.svg|*.xpm)
          chafa -s "$(($2-3))x$3" -f sixels "$1"
          exit 1 ;;
      *)
          bat "$1" ;;
  esac

cleaner:
  #!/bin/sh
  printf "\033[6J" >/dev/tty

[1] https://github.com/gokcehan/lf/pull/1211
2023-06-12 16:02:19 +02:00
Bakkeby
1343b29ee5 Bump to 211964d.
ignore C1 control characters in UTF-8 mode

Ignore processing and printing C1 control characters in UTF-8 mode.
These are in the range: 0x80 - 0x9f.

By default in st the mode is set to UTF-8.

This matches more the behaviour of xterm with the options -u8 or +u8 also.
Also see the xterm resource "allowC1Printable".

Let me know if this breaks something, in most cases I don't think so.

As usual a very good reference is:
https://invisible-island.net/xterm/ctlseqs/ctlseqs.html

Ref.
https://git.suckless.org/st/commit/211964d56ee00a7d46e251cbc150afb79138ae37.html
2023-04-07 14:31:41 +02:00
Bakkeby
18e7dc5545 Bump to f17abd2.
Add support for DSR response "OK" escape sequence

"VT100 defines an escape sequence [1] called Device Status Report (DSR). When
the DSR sequence received is `csi 5n`, an "OK" response `csi 0n` is returned.
This patch adds that "OK" response.

I encountered this missing sequence when I noticed that fzf [2] would clobber
my prompt whenever completing a find.

To test that ST doesn't currently respond to `csi 5n`, use fzf's shell
extension in ST's repo to complete the path for a file.

    my-fancy-prompt $ vim **<tab>
    <select a file>
    st.c

Select a file with <enter>, and notice that fzf clobbers some or all of your
prompt.

After applying this patch, do the same test as above and notice that fzf has no
longer clobbered your prompt by placing the file name in the correct position
in your command.

    my-fancy-prompt $ vim **<tab>
    <select a file>
    my-fancy prompt $ vim st.c

Thank you for considering my first patch submission.

[1] https://www.xfree86.org/current/ctlseqs.html#VT100%20Mode
[2] https://github.com/junegunn/fzf
"

Patch slightly adapted with input from the mailinglist,

Ref.
https://git.suckless.org/st/commit/f17abd25b376c292f783062ecf821453eaa9cc4c.html
2023-04-07 14:28:19 +02:00
Bakkeby
da9835bdf0 Bump to 7e8050c.
Fixed OSC color reset without parameter->resets all colors

Adapted from (garbled) patch by wim <wim@thinkerwim.org>

Additional notes: it should reset all the colors using xloadcols().
To reproduce: set a different (theme) color using some escape code, then reset
it:

	printf '\x1b]104\x07'

Ref.
https://git.suckless.org/st/commit/7e8050cc621f27002eaf1be8114dee2497beff91.html
2023-04-07 14:25:12 +02:00
Bakkeby
4dfb6683cd Adding the COLORTERM environment variable 2022-10-24 11:26:36 +02:00
Bakkeby
34cd955f14 Adding key and mouse binding option to control whether they apply to primary screen, alt screen or both ref. #81 2022-09-01 22:01:20 +02:00
Bakkeby
cd1aa57a06 Bump to 72fd327.
st: use `void' to indicate an empty parameter list

Ref.
https://git.suckless.org/st/commit/72fd32736a612edec43596c14148322122a5544d.html
2022-08-18 17:30:18 +02:00
step
427895a7c2
Fix externalpipein patch (#78)
* fix externalpipein patch

don't close the slave fd, according to the original patch in
https://lists.suckless.org/hackers/2004/17218.html

* externalpipein patch: add example command

press S-C-M to set the terminal background green dynamically.

Replace `printf ...` with `dynamic-colors cycle` command mentioned in
https://lists.suckless.org/hackers/2004/17218.html to cycle though the
available dynamic color themes.
2022-08-16 16:49:10 +02:00