Compare commits

...

10 Commits

Author SHA1 Message Date
Sky Hearn 7544d3c13d gruvbox-dark 2024-03-01 23:36:15 -08:00
Quentin Rameau 7473a8d1a5 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.
2024-02-25 11:56:43 +01:00
Tim Culverhouse a3f7420310 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.
2024-02-18 16:14:26 +01:00
Peter Hofmann 9846a56bd7 Add terminfo entries for bracketed paste mode
Helps Vim (and hopefully others) to discover that this feature exists
without further user configuration.
2023-10-07 12:16:59 +02:00
Peter Hofmann 559fdc2786 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).
2023-10-07 12:16:59 +02:00
Peter Hofmann 8abe4bcb41 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.
2023-10-07 12:16:59 +02:00
Peter Hofmann 2fc7e532b2 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".
2023-10-07 12:16:59 +02:00
Peter Hofmann a6bbc0c96b Fix bounds checks of dc.col
dc.collen is the length of dc.col, not the maximum index, hence if x is
equal to dc.collen, then it's an error.

With config.def.h, the last valid index is 259, so this correctly
reports "black":

    $ printf '\033]4;259;?\e\\'

260 is an invalid index and this reports garbage instead of printing an
error:

    $ printf '\033]4;260;?\e\\'
2023-10-07 12:16:59 +02:00
Hiltjo Posthuma eb3b894f40 Makefile: remove the options target
The Makefile used to suppress output (by using @), so this target made sense at
the time.

But the Makefile should be simple and make debugging with less abstractions or
fancy printing.  The Makefile was made verbose and doesn't hide the build
output, so remove this target.

Prompted by a question on the mailing list about the options target.
2023-09-22 15:16:52 +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
7 changed files with 177 additions and 43 deletions

View File

@ -7,13 +7,7 @@ include config.mk
SRC = st.c x.c SRC = st.c x.c
OBJ = $(SRC:.c=.o) OBJ = $(SRC:.c=.o)
all: options st all: st
options:
@echo st build options:
@echo "CFLAGS = $(STCFLAGS)"
@echo "LDFLAGS = $(STLDFLAGS)"
@echo "CC = $(CC)"
config.h: config.h:
cp config.def.h config.h cp config.def.h config.h
@ -54,4 +48,4 @@ uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/st rm -f $(DESTDIR)$(PREFIX)/bin/st
rm -f $(DESTDIR)$(MANPREFIX)/man1/st.1 rm -f $(DESTDIR)$(MANPREFIX)/man1/st.1
.PHONY: all options clean dist install uninstall .PHONY: all clean dist install uninstall

View File

@ -96,32 +96,24 @@ unsigned int tabspaces = 8;
/* Terminal colors (16 first used in escape sequence) */ /* Terminal colors (16 first used in escape sequence) */
static const char *colorname[] = { static const char *colorname[] = {
/* 8 normal colors */ /* 8 normal colors */
"black", [0] = "#282828", /* hard contrast: #1d2021 / soft contrast: #32302f */
"red3", [1] = "#cc241d", /* red */
"green3", [2] = "#98971a", /* green */
"yellow3", [3] = "#d79921", /* yellow */
"blue2", [4] = "#458588", /* blue */
"magenta3", [5] = "#b16286", /* magenta */
"cyan3", [6] = "#689d6a", /* cyan */
"gray90", [7] = "#a89984", /* white */
/* 8 bright colors */ /* 8 bright colors */
"gray50", [8] = "#928374", /* black */
"red", [9] = "#fb4934", /* red */
"green", [10] = "#b8bb26", /* green */
"yellow", [11] = "#fabd2f", /* yellow */
"#5c5cff", [12] = "#83a598", /* blue */
"magenta", [13] = "#d3869b", /* magenta */
"cyan", [14] = "#8ec07c", /* cyan */
"white", [15] = "#ebdbb2", /* white */
[255] = 0,
/* more colors can be added after 255 to use with DefaultXX */
"#cccccc",
"#555555",
"gray90", /* default foreground colour */
"black", /* default background colour */
}; };
@ -129,9 +121,9 @@ static const char *colorname[] = {
* Default colors (colorname index) * Default colors (colorname index)
* foreground, background, cursor, reverse cursor * foreground, background, cursor, reverse cursor
*/ */
unsigned int defaultfg = 258; unsigned int defaultfg = 15;
unsigned int defaultbg = 259; unsigned int defaultbg = 0;
unsigned int defaultcs = 256; unsigned int defaultcs = 15;
static unsigned int defaultrcs = 257; static unsigned int defaultrcs = 257;
/* /*

View File

@ -0,0 +1,66 @@
diff --git a/config.def.h b/config.def.h
index 91ab8ca..a068694 100644
--- a/config.def.h
+++ b/config.def.h
@@ -96,32 +96,24 @@ unsigned int tabspaces = 8;
/* Terminal colors (16 first used in escape sequence) */
static const char *colorname[] = {
/* 8 normal colors */
- "black",
- "red3",
- "green3",
- "yellow3",
- "blue2",
- "magenta3",
- "cyan3",
- "gray90",
+ [0] = "#282828", /* hard contrast: #1d2021 / soft contrast: #32302f */
+ [1] = "#cc241d", /* red */
+ [2] = "#98971a", /* green */
+ [3] = "#d79921", /* yellow */
+ [4] = "#458588", /* blue */
+ [5] = "#b16286", /* magenta */
+ [6] = "#689d6a", /* cyan */
+ [7] = "#a89984", /* white */
/* 8 bright colors */
- "gray50",
- "red",
- "green",
- "yellow",
- "#5c5cff",
- "magenta",
- "cyan",
- "white",
-
- [255] = 0,
-
- /* more colors can be added after 255 to use with DefaultXX */
- "#cccccc",
- "#555555",
- "gray90", /* default foreground colour */
- "black", /* default background colour */
+ [8] = "#928374", /* black */
+ [9] = "#fb4934", /* red */
+ [10] = "#b8bb26", /* green */
+ [11] = "#fabd2f", /* yellow */
+ [12] = "#83a598", /* blue */
+ [13] = "#d3869b", /* magenta */
+ [14] = "#8ec07c", /* cyan */
+ [15] = "#ebdbb2", /* white */
};
@@ -129,9 +121,9 @@ static const char *colorname[] = {
* Default colors (colorname index)
* foreground, background, cursor, reverse cursor
*/
-unsigned int defaultfg = 258;
-unsigned int defaultbg = 259;
-unsigned int defaultcs = 256;
+unsigned int defaultfg = 15;
+unsigned int defaultbg = 0;
+unsigned int defaultcs = 15;
static unsigned int defaultrcs = 257;
/*

View File

@ -0,0 +1,67 @@
diff --git a/config.def.h b/config.def.h
index 91ab8ca..0be90e8 100644
--- a/config.def.h
+++ b/config.def.h
@@ -96,42 +96,34 @@ unsigned int tabspaces = 8;
/* Terminal colors (16 first used in escape sequence) */
static const char *colorname[] = {
/* 8 normal colors */
- "black",
- "red3",
- "green3",
- "yellow3",
- "blue2",
- "magenta3",
- "cyan3",
- "gray90",
+ [0] = "#fbf1c7", /* hard contrast: #f9f5d7 / soft contrast: #f2e5bc */
+ [1] = "#cc241d", /* red */
+ [2] = "#98971a", /* green */
+ [3] = "#d79921", /* yellow */
+ [4] = "#458588", /* blue */
+ [5] = "#b16286", /* magenta */
+ [6] = "#689d6a", /* cyan */
+ [7] = "#7c6f64", /* white */
/* 8 bright colors */
- "gray50",
- "red",
- "green",
- "yellow",
- "#5c5cff",
- "magenta",
- "cyan",
- "white",
-
- [255] = 0,
-
- /* more colors can be added after 255 to use with DefaultXX */
- "#cccccc",
- "#555555",
- "gray90", /* default foreground colour */
- "black", /* default background colour */
+ [8] = "#928374", /* black */
+ [9] = "#9d0006", /* red */
+ [10] = "#79740e", /* green */
+ [11] = "#b57614", /* yellow */
+ [12] = "#076678", /* blue */
+ [13] = "#8f3f71", /* magenta */
+ [14] = "#427b58", /* cyan */
+ [15] = "#3c3836", /* white */
};
/*
* Default colors (colorname index)
- * foreground, background, cursor, reverse cursor
+ * foreground, background, cursor
*/
-unsigned int defaultfg = 258;
-unsigned int defaultbg = 259;
-unsigned int defaultcs = 256;
+unsigned int defaultfg = 15;
+unsigned int defaultbg = 0;
+unsigned int defaultcs = 15;
static unsigned int defaultrcs = 257;
/*

23
st.c
View File

@ -86,8 +86,8 @@ enum escape_state {
typedef struct { typedef struct {
Glyph attr; /* current char attributes */ Glyph attr; /* current char attributes */
int x; int x; /* terminal column */
int y; int y; /* terminal row */
char state; char state;
} TCursor; } TCursor;
@ -1097,7 +1097,7 @@ tscrollup(int orig, int n)
void void
selscroll(int orig, int n) selscroll(int orig, int n)
{ {
if (sel.ob.x == -1) if (sel.ob.x == -1 || sel.alt != IS_SET(MODE_ALTSCREEN))
return; return;
if (BETWEEN(sel.nb.y, orig, term.bot) != BETWEEN(sel.ne.y, orig, term.bot)) { if (BETWEEN(sel.nb.y, orig, term.bot) != BETWEEN(sel.ne.y, orig, term.bot)) {
@ -1728,6 +1728,7 @@ csihandle(void)
} }
break; break;
case 'S': /* SU -- Scroll <n> line up */ case 'S': /* SU -- Scroll <n> line up */
if (csiescseq.priv) break;
DEFAULT(csiescseq.arg[0], 1); DEFAULT(csiescseq.arg[0], 1);
tscrollup(term.top, csiescseq.arg[0]); tscrollup(term.top, csiescseq.arg[0]);
break; break;
@ -2174,12 +2175,16 @@ tstrsequence(uchar c)
void void
tcontrolcode(uchar ascii) tcontrolcode(uchar ascii)
{ {
size_t i;
switch (ascii) { switch (ascii) {
case '\t': /* HT */ case '\t': /* HT */
tputtab(1); tputtab(1);
return; return;
case '\b': /* BS */ case '\b': /* BS */
tmoveto(term.c.x-1, term.c.y); for (i = 1; term.c.x && term.line[term.c.y][term.c.x - i].u == 0; ++i)
;
tmoveto(term.c.x - i, term.c.y);
return; return;
case '\r': /* CR */ case '\r': /* CR */
tmoveto(0, term.c.y); tmoveto(0, term.c.y);
@ -2330,6 +2335,7 @@ eschandle(uchar ascii)
treset(); treset();
resettitle(); resettitle();
xloadcols(); xloadcols();
xsetmode(0, MODE_HIDE);
break; break;
case '=': /* DECPAM -- Application keypad */ case '=': /* DECPAM -- Application keypad */
xsetmode(1, MODE_APPKEYPAD); xsetmode(1, MODE_APPKEYPAD);
@ -2471,11 +2477,16 @@ check_control_code:
gp = &term.line[term.c.y][term.c.x]; gp = &term.line[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); if (IS_SET(MODE_WRAP))
tnewline(1);
else
tmoveto(term.col - width, term.c.y);
gp = &term.line[term.c.y][term.c.x]; gp = &term.line[term.c.y][term.c.x];
} }

View File

@ -184,6 +184,10 @@ st-mono| simpleterm monocolor,
# XTerm extensions # XTerm extensions
rmxx=\E[29m, rmxx=\E[29m,
smxx=\E[9m, smxx=\E[9m,
BE=\E[?2004h,
BD=\E[?2004l,
PS=\E[200~,
PE=\E[201~,
# disabled rep for now: causes some issues with older ncurses versions. # disabled rep for now: causes some issues with older ncurses versions.
# rep=%p1%c\E[%p2%{1}%-%db, # rep=%p1%c\E[%p2%{1}%-%db,
# tmux extensions, see TERMINFO EXTENSIONS in tmux(1) # tmux extensions, see TERMINFO EXTENSIONS in tmux(1)

4
x.c
View File

@ -818,7 +818,7 @@ xloadcols(void)
int int
xgetcolor(int x, unsigned char *r, unsigned char *g, unsigned char *b) xgetcolor(int x, unsigned char *r, unsigned char *g, unsigned char *b)
{ {
if (!BETWEEN(x, 0, dc.collen)) if (!BETWEEN(x, 0, dc.collen - 1))
return 1; return 1;
*r = dc.col[x].color.red >> 8; *r = dc.col[x].color.red >> 8;
@ -833,7 +833,7 @@ xsetcolorname(int x, const char *name)
{ {
Color ncolor; Color ncolor;
if (!BETWEEN(x, 0, dc.collen)) if (!BETWEEN(x, 0, dc.collen - 1))
return 1; return 1;
if (!xloadcolor(x, name, &ncolor)) if (!xloadcolor(x, name, &ncolor))