Compare commits

..

10 Commits

Author SHA1 Message Date
87bd9f37b1 use M+Fx to change color scheme 2023-08-03 06:21:48 +02:00
d30e68a4c0 colorschemes: 1 tokyonight-storm, 2 tokyonight-day; font: FiraCode 2023-08-03 06:19:18 +02:00
wael
00ad398632 add glyph wide support patch 2023-07-31 16:02:20 +02:00
Timo Röhling
07b35d356c Terminal scrollback with ring buffer
This patch adds a ring buffer for scrollback to the terminal.  The
advantage of using a ring buffer is that the common case, scrolling with
no static screen content, can be achieved very efficiently by
incrementing and decrementing the starting line (modulo buffer size).

The scrollback buffer is limited to HISTSIZE lines in order to bound
memory usage. As the lines are allocated on demand, it is possible to
implement unlimited scrollback with few changes.  If the terminal is
reset, the scroll back buffer is reset, too.

(apply st-scrollback-ringbuffer-0.8.5.diff on top of colorscheme)
2023-07-31 16:02:20 +02:00
Max Schillinger
01b6343666 Add multiple color schemes and key bindings to change them
This commits adds these color schemes:

- the default (dark) st color scheme
- the default (dark) alacritty color scheme
- One Half (dark & light)
- Solarized (dark & light)
- Gruvbox (dark & light)

Select one with Alt+1..8.
Select the next one with Alt+0.
Select the previous one with Ctrl+Alt+0.
2023-07-31 16:02:20 +02:00
Shi Tian
3a6d6d7401 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'
2023-06-25 11:59:06 +02:00
Hiltjo Posthuma
211964d56e 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
2023-02-07 20:00:59 +01:00
Adam Price
f17abd25b3 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,
2023-02-07 19:57:34 +01:00
Hiltjo Posthuma
7e8050cc62 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'
2023-02-05 13:29:35 +01:00
Hiltjo Posthuma
e5e959835b fix buffer overflow when handling long composed input
To reproduce the issue:

"
If you already have the multi-key enabled on your system, then add this line
to your ~/.XCompose file:

[...]
<question> <T> <E> <S> <T> <question> :
"1234567890123456789012345678901234567890123456789012345678901234567890"
"

Reported by and an initial patch by Andy Gozas <andy@gozas.me>, thanks!

Adapted the patch, for now st (like dmenu) handles a fixed amount of composed
characters, or otherwise ignores it. This is done for simplicity sake.
2022-10-25 17:11:11 +02:00
3 changed files with 49 additions and 32 deletions

View File

@ -5,7 +5,7 @@
* *
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
*/ */
static char *font = "Iosevka NFM Light:size=12"; static char *font = "FiraCode Nerd Font Ret:size=10";
static int borderpx = 2; static int borderpx = 2;
/* /*
@ -106,19 +106,19 @@ typedef struct {
* foreground, background, cursor, reverse cursor * foreground, background, cursor, reverse cursor
*/ */
static const ColorScheme schemes[] = { static const ColorScheme schemes[] = {
// onenord (dark) // tokyonight-storm
{{"#3B4252", "#E06C75", "#9EC183", "#EBCB8B", {{"#1d202f", "#f7768e", "#9ece6a", "#e0af68",
"#81A1C1", "#B988B0", "#88C0D0", "#E5E9F0", "#7aa2f7", "#bb9af7", "#7dcfff", "#a9b1d6",
"#4C566A", "#E06C75", "#9EC183", "#EBCB8B", "#414868", "#f7768e", "#9ece6a", "#e0af68",
"#81A1C1", "#B988B0", "#8FBCBB", "#ECEFF4", "#7aa2f7", "#bb9af7", "#7dcfff", "#c0caf5",
[256]="#81A1C1", "#555555", "#E5E9F0", "#2E3440"}, 258, 259, 256, 257}, [256]="#81A1C1", "#555555", "#c0caf5", "#24283b"}, 258, 259, 256, 257},
// onenord (light) // tokyonight-day
{{"#2E3440", "#CB4F53", "#48A53D", "#EE5E25", {{"#e9e9ed", "#f52a65", "#587539", "#8c6c3e",
"#3879C5", "#9F4ACA", "#3EA1AD", "#E5E9F0", "#2e7de9", "#9854f1", "#007197", "#6172b0",
"#646A76", "#D16366", "#5F9E9D", "#BA793E", "#a1a6c5", "#f52a65", "#587539", "#8c6c3e",
"#1B40A6", "#9665AF", "#8FBCBB", "#ECEFF4", "#2e7de9", "#9854f1", "#007197", "#3760bf",
[256]="#3879C5", "#555555", "#2E3440", "#F7F8FA"}, 258, 259, 256, 257}, [256]="#3879C5", "#555555", "#3760bf", "#e1e2e7"}, 258, 259, 256, 257},
// One Half dark // One Half dark
{{"#282c34", "#e06c75", "#98c379", "#e5c07b", {{"#282c34", "#e06c75", "#98c379", "#e5c07b",
@ -249,17 +249,17 @@ static Shortcut shortcuts[] = {
{ TERMMOD, XK_Y, selpaste, {.i = 0} }, { TERMMOD, XK_Y, selpaste, {.i = 0} },
{ ShiftMask, XK_Insert, selpaste, {.i = 0} }, { ShiftMask, XK_Insert, selpaste, {.i = 0} },
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, { TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
{ MODKEY, XK_1, selectscheme, {.i = 0} }, { MODKEY, XK_F1, selectscheme, {.i = 0} },
{ MODKEY, XK_2, selectscheme, {.i = 1} }, { MODKEY, XK_F2, selectscheme, {.i = 1} },
{ MODKEY, XK_3, selectscheme, {.i = 2} }, { MODKEY, XK_F3, selectscheme, {.i = 2} },
{ MODKEY, XK_4, selectscheme, {.i = 3} }, { MODKEY, XK_F4, selectscheme, {.i = 3} },
{ MODKEY, XK_5, selectscheme, {.i = 4} }, { MODKEY, XK_F5, selectscheme, {.i = 4} },
{ MODKEY, XK_6, selectscheme, {.i = 5} }, { MODKEY, XK_F6, selectscheme, {.i = 5} },
{ MODKEY, XK_7, selectscheme, {.i = 6} }, { MODKEY, XK_F7, selectscheme, {.i = 6} },
{ MODKEY, XK_8, selectscheme, {.i = 7} }, { MODKEY, XK_F8, selectscheme, {.i = 7} },
{ MODKEY, XK_9, selectscheme, {.i = 8} }, { MODKEY, XK_F9, selectscheme, {.i = 8} },
{ MODKEY, XK_0, nextscheme, {.i = +1} }, { MODKEY, XK_F10, nextscheme, {.i = +1} },
{ MODKEY|ControlMask, XK_0, nextscheme, {.i = -1} }, { MODKEY|ControlMask, XK_F10, nextscheme, {.i = -1} },
{ ShiftMask, XK_Page_Up, kscrollup, {.i = -1} }, { ShiftMask, XK_Page_Up, kscrollup, {.i = -1} },
{ ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} }, { ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} },
}; };

22
st.c
View File

@ -1862,11 +1862,18 @@ csihandle(void)
case 'm': /* SGR -- Terminal attribute (color) */ case 'm': /* SGR -- Terminal attribute (color) */
tsetattr(csiescseq.arg, csiescseq.narg); tsetattr(csiescseq.arg, csiescseq.narg);
break; break;
case 'n': /* DSR Device Status Report (cursor position) */ case 'n': /* DSR -- Device Status Report */
if (csiescseq.arg[0] == 6) { switch (csiescseq.arg[0]) {
case 5: /* Status Report "OK" `0n` */
ttywrite("\033[0n", sizeof("\033[0n") - 1, 0);
break;
case 6: /* Report Cursor Position (CPR) "<row>;<column>R" */
len = snprintf(buf, sizeof(buf), "\033[%i;%iR", len = snprintf(buf, sizeof(buf), "\033[%i;%iR",
term.c.y+1, term.c.x+1); term.c.y+1, term.c.x+1);
ttywrite(buf, len, 0); ttywrite(buf, len, 0);
break;
default:
goto unknown;
} }
break; break;
case 'r': /* DECSTBM -- Set Scrolling Region */ case 'r': /* DECSTBM -- Set Scrolling Region */
@ -2025,8 +2032,10 @@ strhandle(void)
if (p && !strcmp(p, "?")) { if (p && !strcmp(p, "?")) {
osc_color_response(j, 0, 1); osc_color_response(j, 0, 1);
} else if (xsetcolorname(j, p)) { } else if (xsetcolorname(j, p)) {
if (par == 104 && narg <= 1) if (par == 104 && narg <= 1) {
xloadcols();
return; /* color reset without parameter */ return; /* color reset without parameter */
}
fprintf(stderr, "erresc: invalid color j=%d, p=%s\n", fprintf(stderr, "erresc: invalid color j=%d, p=%s\n",
j, p ? p : "(null)"); j, p ? p : "(null)");
} else { } else {
@ -2528,6 +2537,9 @@ check_control_code:
* they must not cause conflicts with sequences. * they must not cause conflicts with sequences.
*/ */
if (control) { if (control) {
/* in UTF-8 mode ignore handling C1 control characters */
if (IS_SET(MODE_UTF8) && ISCONTROLC1(u))
return;
tcontrolcode(u); tcontrolcode(u);
/* /*
* control codes are not shown ever * control codes are not shown ever
@ -2574,8 +2586,10 @@ check_control_code:
gp = &TLINE(term.c.y)[term.c.x]; gp = &TLINE(term.c.y)[term.c.x];
} }
if (IS_SET(MODE_INSERT) && term.c.x+width < term.col) if (IS_SET(MODE_INSERT) && term.c.x+width < term.col) {
memmove(gp+width, gp, (term.col - term.c.x - width) * sizeof(Glyph)); memmove(gp+width, gp, (term.col - term.c.x - width) * sizeof(Glyph));
gp->mode &= ~ATTR_WIDE;
}
if (term.c.x+width > term.col) { if (term.c.x+width > term.col) {
tnewline(1); tnewline(1);

9
x.c
View File

@ -1838,7 +1838,7 @@ void
kpress(XEvent *ev) kpress(XEvent *ev)
{ {
XKeyEvent *e = &ev->xkey; XKeyEvent *e = &ev->xkey;
KeySym ksym; KeySym ksym = NoSymbol;
char buf[64], *customkey; char buf[64], *customkey;
int len; int len;
Rune c; Rune c;
@ -1848,10 +1848,13 @@ kpress(XEvent *ev)
if (IS_SET(MODE_KBDLOCK)) if (IS_SET(MODE_KBDLOCK))
return; return;
if (xw.ime.xic) if (xw.ime.xic) {
len = XmbLookupString(xw.ime.xic, e, buf, sizeof buf, &ksym, &status); len = XmbLookupString(xw.ime.xic, e, buf, sizeof buf, &ksym, &status);
else if (status == XBufferOverflow)
return;
} else {
len = XLookupString(e, buf, sizeof buf, &ksym, NULL); len = XLookupString(e, buf, sizeof buf, &ksym, NULL);
}
/* 1. shortcuts */ /* 1. shortcuts */
for (bp = shortcuts; bp < shortcuts + LEN(shortcuts); bp++) { for (bp = shortcuts; bp < shortcuts + LEN(shortcuts); bp++) {
if (ksym == bp->keysym && match(bp->mod, e->state)) { if (ksym == bp->keysym && match(bp->mod, e->state)) {