Colona | 24 Apr 20:35 2014
Picon

[st] [PATCH] On terminal resize, clear the alt screen with its own cursor.

Currently the alternate screen get messed up on resize if it has
different colors or mode.

---
 st.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/st.c b/st.c
index 60243a7..c1f983f 100644
--- a/st.c
+++ b/st.c
 <at>  <at>  -2680,7 +2680,9  <at>  <at>  tresize(int col, int row) {
 		if(0 < col && minrow < row) {
 			tclearregion(0, minrow, col - 1, row - 1);
 		}
+		tcursor(CURSOR_SAVE);
 		tswapscreen();
+		tcursor(CURSOR_LOAD);
 	} while(orig != term.line);

 	return (slide > 0);
-- 
1.9.2

--

-- 
Ivan "Colona" Delalande

noname | 23 Apr 21:12 2014

[st PATCH 4/4] Optimize tputtab.

Before this patch executing
	printf '\e[10000000000I'
or
	printf '\e[10000000000Z'
resulted in long delay.
---
 st.c | 28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/st.c b/st.c
index e61ee68..964a0ae 100644
--- a/st.c
+++ b/st.c
 <at>  <at>  -374,7 +374,7  <at>  <at>  static void tmoveto(int, int);
 static void tmoveato(int, int);
 static void tnew(int, int);
 static void tnewline(int);
-static void tputtab(bool);
+static void tputtab(int);
 static void tputc(char *, int);
 static void treset(void);
 static int tresize(int, int);
 <at>  <at>  -1995,8 +1995,7  <at>  <at>  csihandle(void) {
 		break;
 	case 'I': /* CHT -- Cursor Forward Tabulation <n> tab stops */
 		DEFAULT(csiescseq.arg[0], 1);
-		while(csiescseq.arg[0]--)
-			tputtab(1);
+		tputtab(csiescseq.arg[0]);
 		break;
(Continue reading)

noname | 23 Apr 21:12 2014

[st PATCH 3/4] Use != instead of ^ for logical values.

sel.alt is only changed by
	sel.alt = IS_SET(MODE_ALTSCREEN);
---
 st.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/st.c b/st.c
index 07f408c..e61ee68 100644
--- a/st.c
+++ b/st.c
 <at>  <at>  -3449,7 +3449,7  <at>  <at>  drawregion(int x1, int y1, int x2, int y2) {
 	bool ena_sel = sel.ob.x != -1;
 	long unicodep;

-	if(sel.alt ^ IS_SET(MODE_ALTSCREEN))
+	if(sel.alt != IS_SET(MODE_ALTSCREEN))
 		ena_sel = 0;

 	if(!(xw.state & WIN_VISIBLE))
--

-- 
1.8.4

noname | 23 Apr 21:12 2014

[st PATCH 2/4] Use BETWEEN macro in xsetcolorname and fix style.

---
 st.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/st.c b/st.c
index ede90d5..07f408c 100644
--- a/st.c
+++ b/st.c
 <at>  <at>  -2750,10 +2750,10  <at>  <at>  int
 xsetcolorname(int x, const char *name) {
 	XRenderColor color = { .alpha = 0xffff };
 	Colour colour;
-	if (x < 0 || x > LEN(colorname))
+	if(!BETWEEN(x, 0, LEN(colorname)))
 		return -1;
 	if(!name) {
-		if(16 <= x && x < 16 + 216) {
+		if(BETWEEN(x, 16, 16 + 215)) {
 			int r = (x - 16) / 36, g = ((x - 16) % 36) / 6, b = (x - 16) % 6;
 			color.red = sixd_to_16bit(r);
 			color.green = sixd_to_16bit(g);
 <at>  <at>  -2762,7 +2762,7  <at>  <at>  xsetcolorname(int x, const char *name) {
 				return 0; /* something went wrong */
 			dc.col[x] = colour;
 			return 1;
-		} else if (16 + 216 <= x && x < 256) {
+		} else if(BETWEEN(x, 16 + 216, 255)) {
 			color.red = color.green = color.blue = 0x0808 + 0x0a0a * (x - (16 + 216));
 			if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, &colour))
 				return 0; /* something went wrong */
(Continue reading)

noname | 23 Apr 21:12 2014

[st PATCH 1/4] Simplify tsetscroll.

---
 st.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/st.c b/st.c
index aba034f..ede90d5 100644
--- a/st.c
+++ b/st.c
 <at>  <at>  -1765,17 +1765,11  <at>  <at>  tsetattr(int *attr, int l) {

 void
 tsetscroll(int t, int b) {
-	int temp;
-
 	LIMIT(t, 0, term.row-1);
 	LIMIT(b, 0, term.row-1);
-	if(t > b) {
-		temp = t;
-		t = b;
-		b = temp;
-	}
-	term.top = t;
-	term.bot = b;
+
+	term.top = MIN(t, b);
+	term.bot = MAX(t, b);
 }

 void
--

-- 
(Continue reading)

joshua | 23 Apr 07:26 2014

[sandy][patch] minor typo correction

Minor typo correction.
diff --git a/TODO b/TODO
index 6e01237..535a8e4 100644
--- a/TODO
+++ b/TODO
<at> <at> -13,7 +13,7 <at> <at> In no particular order, at sandy.c:
 At config.def.h:
 - Bindings!
 - Use local/system script path and all
-- Choose color-set for either black of white bg
+- Choose color-set for either black or white bg
 - Define more syntaxes
 - Refine syntax regexes


Attachment (typo.txt): application/octet-stream, 351 bytes
noname | 23 Apr 00:08 2014

[PATCH] Simplify tdeletechar and tinsertblank and fix memory corruption.

Current CSI parsing code uses strtol to parse arguments and allows them
to be negative. Negative argument is not properly handled in tdeletechar
and tinsertblank and results in memory corruption in memmove.

Reproduce with printf '\e[-500 <at> '

Patch also removes special handling for corner case and simplifies
the code.

Removed
	term.dirty[term.c.y] = 1
because tclearregion sets dirty flag.
---
 st.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/st.c b/st.c
index 019f53c..ae76731 100644
--- a/st.c
+++ b/st.c
 <at>  <at>  -1592,16 +1592,13  <at>  <at>  tclearregion(int x1, int y1, int x2, int y2) {

 void
 tdeletechar(int n) {
-	int src = term.c.x + n;
-	int dst = term.c.x;
-	int size = term.col - src;
+	int dst, src, size;

-	term.dirty[term.c.y] = 1;
+	LIMIT(n, 0, term.col - term.c.x);

-	if(src >= term.col) {
-		tclearregion(term.c.x, term.c.y, term.col-1, term.c.y);
-		return;
-	}
+	dst = term.c.x;
+	src = term.c.x + n;
+	size = term.col - src;

 	memmove(&term.line[term.c.y][dst], &term.line[term.c.y][src],
 			size * sizeof(Glyph));
 <at>  <at>  -1610,16 +1607,13  <at>  <at>  tdeletechar(int n) {

 void
 tinsertblank(int n) {
-	int src = term.c.x;
-	int dst = src + n;
-	int size = term.col - dst;
+	int dst, src, size;

-	term.dirty[term.c.y] = 1;
+	LIMIT(n, 0, term.col - term.c.x);

-	if(dst >= term.col) {
-		tclearregion(term.c.x, term.c.y, term.col-1, term.c.y);
-		return;
-	}
+	dst = term.c.x + n;
+	src = term.c.x;
+	size = term.col - dst;

 	memmove(&term.line[term.c.y][dst], &term.line[term.c.y][src],
 			size * sizeof(Glyph));
--

-- 
1.8.4

noname | 22 Apr 22:26 2014

[st] [PATCH] Fix techo handling of control and multibyte characters.

techo compares signed char to '\x20'. Any character with code less then
'\x20' is treated as control character.  This way characters with MSB
set to 1 are considered control characters too.

Also this patch makes techo display DEL character as ^?.

To reprocuce the bug, enable echo mode using printf '\e[12l',
then type DEL character or any non-ASCII character.
---
 st.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/st.c b/st.c
index 019f53c..b6cb01c 100644
--- a/st.c
+++ b/st.c
 <at>  <at>  -2316,9 +2316,9  <at>  <at>  techo(char *buf, int len) {
 	for(; len > 0; buf++, len--) {
 		char c = *buf;

-		if(c < '\x20') { /* control code */
+		if(c < 0x20u || c == 0177) { /* control code */
 			if(c != '\n' && c != '\r' && c != '\t') {
-				c |= '\x40';
+				c ^= '\x40';
 				tputc("^", 1);
 			}
 			tputc(&c, 1);
--

-- 
1.8.4

noname | 22 Apr 20:56 2014

[st] [PATCH] Fix techo handling of control characters.

Internally st represents characters using "char" type.
It is used in CSIEscape.buf, Glyph.c etc.
However, char can be either signed or unsigned depends on the
architecture.

On x86 '\x80' < 0x20 is true, but (uchar)'\x80' < 0x20 is false.

tputc explicitly converts character to ascii code:
	uchar ascii = *c;

In tsetchar there is this code:
	c[0] >= 0x41 && c[0] <= 0x7e
This condition is false for negative chars, so, accidentally, it works
the same way for signed and unsigned chars.

However, techo compares signed char to '\x20' and has a bug.

How to reproduce:
1. Add the following keybinding:
  { XK_F1,            XK_NO_MOD,      "\x80" ,       0,    0,    0},
2. Run st and enable echo mode: printf '\e[12l'
3. Press F1. Character '\x80' is recognized as control and ^ is displayed,
followed by unprintable character.

This patch fixes the bug the same way it is fixed in tputc.

Also techo did not recognize DEL as control character and did not
display ^? for it, this patch fixes this bug too.
---
 st.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/st.c b/st.c
index 019f53c..3bf8eee 100644
--- a/st.c
+++ b/st.c
 <at>  <at>  -2315,10 +2315,12  <at>  <at>  void
 techo(char *buf, int len) {
 	for(; len > 0; buf++, len--) {
 		char c = *buf;
+		uchar ascii = c;
+		bool control = ascii < '\x20' || ascii == 0177;

-		if(c < '\x20') { /* control code */
+		if(control) { /* control code */
 			if(c != '\n' && c != '\r' && c != '\t') {
-				c |= '\x40';
+				c ^= '\x40';
 				tputc("^", 1);
 			}
 			tputc(&c, 1);
--

-- 
1.8.4

noname | 22 Apr 19:59 2014

[st] [PATCH 6/6] Make xrealloc and xstrdup style consistent.

---
 st.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/st.c b/st.c
index bb3e687..aba034f 100644
--- a/st.c
+++ b/st.c
 <at>  <at>  -549,12 +549,10  <at>  <at>  xrealloc(void *p, size_t len) {

 char *
 xstrdup(char *s) {
-	char *p = strdup(s);
-
-	if (!p)
+	if((s = strdup(s)) == NULL)
 		die("Out of memory\n");

-	return p;
+	return s;
 }

 size_t
--

-- 
1.8.4

noname | 22 Apr 19:59 2014

[st] [PATCH 5/6] Use BETWEEN in tsetchar.

---
 st.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/st.c b/st.c
index b8bf84b..bb3e687 100644
--- a/st.c
+++ b/st.c
 <at>  <at>  -1544,8 +1544,7  <at>  <at>  tsetchar(char *c, Glyph *attr, int x, int y) {
 	 * The table is proudly stolen from rxvt.
 	 */
 	if(attr->mode & ATTR_GFX) {
-		if(c[0] >= 0x41 && c[0] <= 0x7e
-				&& vt100_0[c[0] - 0x41]) {
+		if(BETWEEN(c[0], 0x41, 0x7e) && vt100_0[c[0] - 0x41]) {
 			c = vt100_0[c[0] - 0x41];
 		}
 	}
--

-- 
1.8.4


Gmane