Hello,

>       * CHT, TBC and HTS support (Thanks Roberto Caballero!)

The name is Roberto Vargas (latin people have 2 surnames, so, short form of
the name uses the first surname ;) ).

I send other patch in this mail for CBT (back tabulation), and also this
patch fixs a bug in the previous.


Sincerely,

Roberto E. Vargas.
>From 75f814852c532f64d7515496d114fec9ef62bd88 Mon Sep 17 00:00:00 2001
From: "Roberto E. Vargas Caballero" <k...@shike2.com>
Date: Thu, 30 Aug 2012 19:30:16 +0200
Subject: [PATCH] Add CBT sequence

This sequence performs "Cursor Backward Tabulation <n> tab stops". This
patch also fixs a bug in tputtab(), where it was possible to call tmoveto()
with x = term.col + 1.
---
 st.c |   29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/st.c b/st.c
index b9bab29..3eb2e7d 100644
--- a/st.c
+++ b/st.c
@@ -249,7 +249,7 @@ static void tinsertblankline(int);
 static void tmoveto(int, int);
 static void tnew(int, int);
 static void tnewline(int);
-static void tputtab(void);
+static void tputtab(bool);
 static void tputc(char*);
 static void treset(void);
 static int tresize(int, int);
@@ -1229,7 +1229,7 @@ csihandle(void) {
 	case 'I': /* CHT -- Cursor Forward Tabulation <n> tab stops */
 		DEFAULT(escseq.arg[0], 1);
 		while (escseq.arg[0]--)
-			tputtab();
+			tputtab(1);
 		break;
 	case 'J': /* ED -- Clear screen */
 		sel.bx = -1;
@@ -1342,7 +1342,11 @@ csihandle(void) {
 		DEFAULT(escseq.arg[0], 1);
 		tdeletechar(escseq.arg[0]);
 		break;
-	/* XXX: (CSI n Z) CBT -- Cursor Backward Tabulation <n> tab stops */
+	case 'Z': /* CBT -- Cursor Backward Tabulation <n> tab stops */
+		DEFAULT(escseq.arg[0], 1);
+                while (escseq.arg[0]--)
+                        tputtab(0);
+                break;
 	case 'd': /* VPA -- Move to <row> */
 		DEFAULT(escseq.arg[0], 1);
 		tmoveto(term.c.x, escseq.arg[0]-1);
@@ -1444,11 +1448,20 @@ csireset(void) {
 }
 
 void
-tputtab(void) {
-	unsigned x;
+tputtab(bool forward) {
+	unsigned x = term.c.x;
 
-	for (x = term.c.x + 1; x < term.col && !term.tabs[x]; ++x)
-		/* nothing */ ;
+	if (forward) {
+		if (x == term.col)
+			return;
+		for (++x; x < term.col && !term.tabs[x]; ++x)
+			/* nothing */ ;
+	} else {
+		if (x == 0)
+			return;
+		for (--x; x > 0 && !term.tabs[x]; --x)
+			/* nothing */ ;
+	}
 	tmoveto(x, term.c.y);
 }
 
@@ -1552,7 +1565,7 @@ tputc(char *c) {
 			sel.bx = -1;
 		switch(ascii) {
 		case '\t':
-			tputtab();
+			tputtab(1);
 			break;
 		case '\b':
 			tmoveto(term.c.x-1, term.c.y);
-- 
1.7.10.4

Reply via email to