Go to file
bakkeby a6344d3241 fix unicode glitch in DCS strings, patch by Tim Allen
Reported on the mailinglist:

"
I discovered recently that if an application running inside st tries to
send a DCS string, subsequent Unicode characters get messed up. For
example, consider the following test-case:

    printf '\303\277\033P\033\\\303\277'

...where:

  - \303\277 is the UTF-8 encoding of U+00FF LATIN SMALL LETTER Y WITH
    DIAERESIS (ÿ).
  - \033P is ESC P, the token that begins a DCS string.
  - \033\\ is ESC \, a token that ends a DCS string.
  - \303\277 is the same ÿ character again.

If I run the above command in a VTE-based terminal, or xterm, or
QTerminal, or pterm (PuTTY), I get the output:

    ÿÿ

...which is to say, the empty DCS string is ignored. However, if I run
that command inside st (as of commit 9ba7ecf), I get:

    ÿÿ

...where those last two characters are \303\277 interpreted as ISO8859-1
characters, instead of UTF-8.

I spent some time tracing through the state machines in st.c, and so far
as I can tell, this is how it works currently:

  - ESC P sets the "ESC_DCS" and "ESC_STR" flags, indicating that
    incoming bytes should be collected into the strescseq buffer, rather
    than being interpreted.
  - ESC \ sets the "ESC_STR_END" flag (when ESC is received), and then
    calls strhandle() (when \ is received) to interpret the collected
    bytes.
  - If the collected bytes begin with 'P' (i.e. if this was a DCS
    string) strhandle() sets the "ESC_DCS" flag again, confusing the
    state machine.

If my understanding is correct, fixing the problem should be as easy as
removing the line that sets ESC_DCS from strhandle():

diff --git a/st.c b/st.c
index ef8abd5..b5b805a 100644
--- a/st.c
+++ b/st.c
@@ -1897,7 +1897,6 @@ strhandle(void)
		xsettitle(strescseq.args[0]);
		return;
	case 'P': /* DCS -- Device Control String */
-		term.mode |= ESC_DCS;
	case '_': /* APC -- Application Program Command */
	case '^': /* PM -- Privacy Message */
		return;

I've tried the above patch and it fixes my problem, but I don't know if
it introduces any others.
"
2020-06-25 12:32:00 +02:00
patch auto-sync: draw on idle to avoid flicker/tearing 2020-05-20 14:15:57 +02:00
.gitignore Adding st to .gitignore 2020-03-24 11:35:58 +01:00
arg.h Initial commit, adding alpha and anysize patches 2019-09-16 09:35:57 +02:00
config.def.h config.def.h: add an option allowwindowops, by default off (secure) 2020-06-10 20:53:01 +02:00
config.mk Adding ligatures patch as requested in #4 2020-06-05 13:43:14 +02:00
FAQ FAQ: fix single-buffer patch (249ef9) 2020-06-10 21:02:22 +02:00
hb.c Adding ligatures patch as requested in #4 2020-06-05 13:43:14 +02:00
hb.h Adding ligatures patch as requested in #4 2020-06-05 13:43:14 +02:00
LEGACY Initial commit, adding alpha and anysize patches 2019-09-16 09:35:57 +02:00
LICENSE Initial commit, adding alpha and anysize patches 2019-09-16 09:35:57 +02:00
Makefile Adding ligatures patch as requested in #4 2020-06-05 13:43:14 +02:00
patches.def.h Adding w3m patch 2020-06-14 20:04:27 +02:00
README Initial commit, adding alpha and anysize patches 2019-09-16 09:35:57 +02:00
README.md Adding w3m patch 2020-06-14 20:04:27 +02:00
st.1 Add support for scroll(1) 2020-04-20 10:24:34 +02:00
st.c fix unicode glitch in DCS strings, patch by Tim Allen 2020-06-25 12:32:00 +02:00
st.h config.def.h: add an option allowwindowops, by default off (secure) 2020-06-10 20:53:01 +02:00
st.info Partially add back in "support REP (repeat) escape sequence" (aa0631) 2020-06-10 20:46:50 +02:00
TODO Initial commit, adding alpha and anysize patches 2019-09-16 09:35:57 +02:00
win.h Adding ligatures patch as requested in #4 2020-06-05 13:43:14 +02:00
x.c Adding w3m patch 2020-06-14 20:04:27 +02:00

Similar to dwm-flexipatch this st 0.8.3 (249ef9, 2020-06-01) project has a different take on st patching. It uses preprocessor directives to decide whether or not to include a patch during build time. Essentially this means that this build, for better or worse, contains both the patched and the original code. The aim being that you can select which patches to include and the build will contain that code and nothing more.

For example to include the alpha patch then you would only need to flip this setting from 0 to 1 in patches.h:

#define ALPHA_PATCH 1

Once you have found out what works for you and what doesn't then you should be in a better position to choose patches should you want to start patching from scratch.

Alternatively if you have found the patches you want, but don't want the rest of the flexipatch entanglement on your plate then you may want to have a look at flexipatch-finalizer; a custom pre-processor tool that removes all the unused flexipatch code leaving you with a build that contains the patches you selected.

Refer to https://st.suckless.org/ for details on the st terminal, how to install it and how it works.


Changelog:

2020-06-14 - Added w3m patch

2020-06-10 - Upgrade to 249ef9, 2020-06-01

2020-06-05 - Added the ligatures patch

2020-05-20 - Upgrade to 222876, 2020-05-09, and removed visualbell 1, 2, 3 patches and force redraw after keypress due to incompatibility. Refer to tag 371878 if you want to try these out.

2020-04-20 - Upgrade to c279f5, 2020-04-19, and added the force redraw on pselect after key is pressed patch and the externalpipein patch

2020-03-29 - Added invert and workingdir patches

2020-03-24 - Upgraded to latest (master) of st (commit 51e19ea11d at the time of writing). Custom changes to make the altscreen mouse scollback patch working.

2020-03-21 - Added font2 patch

2020-01-07 - Added st embedder patch

2019-10-16 - Introduced flexipatch-finalizer

2019-09-17 - Added relativeborder, fix-keyboard-input, iso14755, visualbell, right-click-to-plumb, boxdraw and keyboard-select patches

2019-09-16 - Added alpha, anysize, bold-is-not-bright, clipboard, copyurl, disable-fonts, externalpipe, fixime, hidecursor, newterm, open-copied-url, vertcenter, scrollback, spoiler, themed cursor and xresources patches

Patches included:

  • alpha

    • adds transparency for the terminal
  • anysize

    • allows st to reize to any pixel size rather than snapping to character width / height
  • bold-is-not-bright

    • by default bold text is rendered with a bold font in the bright variant of the current color
    • this patch makes bold text rendered simply as bold, leaving the color unaffected
  • boxdraw

    • adds dustom rendering of lines/blocks/braille characters for gapless alignment
  • clipboard

    • by default st only sets PRIMARY on selection
    • this patch makes st set CLIPBOARD on selection
  • copyurl

    • this patch allows you to select and copy the last URL displayed with Mod+l
    • multiple invocations cycle through the available URLs
  • disable-fonts

    • this patch adds the option of disabling bold/italic/roman fonts globally
  • externalpipe

    • this patch allows for eading and writing st's screen through a pipe, e.g. to pass info to dmenu
  • externalpipein

    • this patch prevents the reset of the signal handler set on SIGCHILD, when the forked process that executes the external process exits
    • it adds the externalpipein function to redirect the standard output of the external command to the slave size of the pty, that is, as if the external program had been manually executed on the terminal
    • this can be used to send desired escape sequences to the terminal with a shortcut (e.g. to change colors)
  • ~fixime~

    • adds better Input Method Editor (IME) support
    • (included in the base as per 35f7db)
  • fix-keyboard-input

    • allows cli applications to use all the fancy key combinations that are available to GUI applications
  • font2

    • allows you to add a spare font besides the default
  • ~force-redraw-after-keypress~

    • ~this patch forces the terminal to check for new data on the tty on keypress with the aim of reducing input latency~
  • hidecursor

    • hides the X cursor whenever a key is pressed and show it back when the mouse is moved in the terminal window
  • invert

    • adds a keybinding that lets you invert the current colorscheme of st
    • this provides a simple way to temporarily switch to a light colorscheme if you use a dark colorscheme or visa-versa
  • iso14755

    • pressing the default binding Ctrl+Shift-i will popup dmenu, asking you to enter a unicode codepoint that will be converted to a glyph and then pushed to st
  • keyboard-select

    • allows you to select text on the terminal using keyboard shortcuts
  • ligatures

    • adds support for drawing ligatures using the Harfbuzz library to transform original text of a single line to a list of glyphs with ligatures included
  • newterm

    • allows you to spawn a new st terminal using Ctrl-Shift-Return
    • it will have the same CWD (current working directory) as the original st instance
  • open-copied-url

    • open contents of the clipboard in a user-defined browser
  • relativeborder

    • allows you to specify a border that is relative in size to the width of a cell in the terminal
  • right-click-to-plumb

    • allows you to right-click on some selected text to send it to the plumbing program of choice
  • scrollback

    • allows you scroll back through terminal output using keyboard shortcuts or mousewheel
  • st-embedder

    • this patch allows clients to embed into the st window and can be useful if you tend to start X applications from the terminal
    • the behavior is similar to Plan 9 where applications can take over windows
  • spoiler

    • use inverted defaultbg/fg for selection when bg/fg are the same
  • themed-cursor

    • instead of a default X cursor, use the xterm cursor from your cursor theme
  • vertcenter

    • vertically center lines in the space available if you have set a larger chscale in config.h
  • ~visualbell~

    • ~adds visual indicators for the terminal bell event~
  • w3m

    • adds support for w3m images
  • workingdir

    • allows user to specify the initial path st should use as the working directory
  • xresources

    • adds the ability to configure st via Xresources
    • during startup, st will read and apply the resources named in the resources[] array in config.h