>From fa65a3cc8ab13abb61ede180fd26ab3594d036c3 Mon Sep 17 00:00:00 2001
From: "Roberto E. Vargas Caballero" <[email protected]>
Date: Wed, 7 Nov 2012 18:05:58 +0100
Subject: Save cursor position in terminal reset

After terminal reset saved terminal position is reset to 0, allowing know
where cursor will go in next restore cursor operation.
---
 st.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/st.c b/st.c
index faaca74..f1b2d74 100644
--- a/st.c
+++ b/st.c
@@ -1074,6 +1074,8 @@ treset(void) {
 	term.mode = MODE_WRAP;
 
 	tclearregion(0, 0, term.col-1, term.row-1);
+	tmoveto(0, 0);
+	tcursor(CURSOR_SAVE);
 }
 
 void
-- 
1.7.10.4

>From 89e3a23178c2073415b496a402e3cd869aed7752 Mon Sep 17 00:00:00 2001
From: "Roberto E. Vargas Caballero" <[email protected]>
Date: Wed, 7 Nov 2012 18:12:45 +0100
Subject: Add DECOM sequence

DECOM sequence allows to the user defines a new home position. The home
position is used as base for all the movement commands except HVP and
VPA. It is important notice than DECSLM moves cursor to absolute position
0,0.
---
 st.c |   33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/st.c b/st.c
index f1b2d74..19aa224 100644
--- a/st.c
+++ b/st.c
@@ -115,7 +115,8 @@ enum term_mode {
 	MODE_MOUSEMOTION = 64,
 	MODE_MOUSE       = 32|64,
 	MODE_REVERSE     = 128,
-	MODE_KBDLOCK     = 256
+	MODE_KBDLOCK     = 256,
+	MODE_ORIGIN	 = 512
 };
 
 enum escape_state {
@@ -300,6 +301,7 @@ static void tdeleteline(int);
 static void tinsertblank(int);
 static void tinsertblankline(int);
 static void tmoveto(int, int);
+static void tmoveato(int x, int y);
 static void tnew(int, int);
 static void tnewline(int);
 static void tputtab(bool);
@@ -1209,10 +1211,25 @@ csiparse(void) {
 	}
 }
 
+/* for absolute user moves, when decom is set */
+void
+tmoveato(int x, int y) {
+	tmoveto(x, y + ((IS_SET(MODE_ORIGIN)) ? term.top: 0));
+}
+
 void
 tmoveto(int x, int y) {
+	int miny, maxy;
+
+	if(IS_SET(MODE_ORIGIN)) {
+		miny = term.top;
+		maxy = term.bot;
+	} else {
+		miny = 0;
+		maxy = term.row - 1;
+	}
 	LIMIT(x, 0, term.col-1);
-	LIMIT(y, 0, term.row-1);
+	LIMIT(y, miny, maxy);
 	term.c.state &= ~CURSOR_WRAPNEXT;
 	term.c.x = x;
 	term.c.y = y;
@@ -1454,7 +1471,9 @@ tsetmode(bool priv, bool set, int *args, int narg) {
 				if(mode != term.mode)
 					redraw();
 				break;
-			case 6: /* XXX: DECOM -- Origin */
+			case 6: /* DECOM -- Origin */
+				MODBIT(term.mode, set, MODE_ORIGIN);
+				tmoveato(0, 0);
 				break;
 			case 7: /* DECAWM -- Auto wrap */
 				MODBIT(term.mode, set, MODE_WRAP);
@@ -1591,7 +1610,7 @@ csihandle(void) {
 	case 'f': /* HVP */
 		DEFAULT(csiescseq.arg[0], 1);
 		DEFAULT(csiescseq.arg[1], 1);
-		tmoveto(csiescseq.arg[1]-1, csiescseq.arg[0]-1);
+		tmoveato(csiescseq.arg[1]-1, csiescseq.arg[0]-1);
 		break;
 	case 'I': /* CHT -- Cursor Forward Tabulation <n> tab stops */
 		DEFAULT(csiescseq.arg[0], 1);
@@ -1665,7 +1684,7 @@ csihandle(void) {
 		break;
 	case 'd': /* VPA -- Move to <row> */
 		DEFAULT(csiescseq.arg[0], 1);
-		tmoveto(term.c.x, csiescseq.arg[0]-1);
+		tmoveato(term.c.x, csiescseq.arg[0]-1);
 		break;
 	case 'h': /* SM -- Set terminal mode */
 		tsetmode(csiescseq.priv, 1, csiescseq.arg, csiescseq.narg);
@@ -1680,7 +1699,7 @@ csihandle(void) {
 			DEFAULT(csiescseq.arg[0], 1);
 			DEFAULT(csiescseq.arg[1], term.row);
 			tsetscroll(csiescseq.arg[0]-1, csiescseq.arg[1]-1);
-			tmoveto(0, 0);
+			tmoveato(0, 0);
 		}
 		break;
 	case 's': /* DECSC -- Save cursor position (ANSI.SYS) */
@@ -2117,9 +2136,9 @@ tresize(int col, int row) {
 	term.col = col;
 	term.row = row;
 	/* make use of the LIMIT in tmoveto */
-	tmoveto(term.c.x, term.c.y);
 	/* reset scrolling region */
 	tsetscroll(0, row-1);
+	tmoveto(term.c.x, term.c.y);
 
 	return (slide > 0);
 }
-- 
1.7.10.4

>From 7697e4c6f375f3a2b916e16bd134e8eb9ecfb477 Mon Sep 17 00:00:00 2001
From: "Roberto E. Vargas Caballero" <[email protected]>
Date: Wed, 7 Nov 2012 18:29:42 +0100
Subject: Fix VPR sequence

VPR stands for Move cursor down a number of rows, and the code was moving
the cursor up instead of moving it down.
---
 st.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/st.c b/st.c
index 19aa224..9d4a328 100644
--- a/st.c
+++ b/st.c
@@ -1560,11 +1560,11 @@ csihandle(void) {
 		tinsertblank(csiescseq.arg[0]);
 		break;
 	case 'A': /* CUU -- Cursor <n> Up */
-	case 'e':
 		DEFAULT(csiescseq.arg[0], 1);
 		tmoveto(term.c.x, term.c.y-csiescseq.arg[0]);
 		break;
 	case 'B': /* CUD -- Cursor <n> Down */
+	case 'e': /* VPR --Cursor <n> Down */
 		DEFAULT(csiescseq.arg[0], 1);
 		tmoveto(term.c.x, term.c.y+csiescseq.arg[0]);
 		break;
@@ -1573,7 +1573,7 @@ csihandle(void) {
 			ttywrite(VT102ID, sizeof(VT102ID) - 1);
 		break;
 	case 'C': /* CUF -- Cursor <n> Forward */
-	case 'a':
+	case 'a': /* HPR -- Cursor <n> Forward */
 		DEFAULT(csiescseq.arg[0], 1);
 		tmoveto(term.c.x+csiescseq.arg[0], term.c.y);
 		break;
-- 
1.7.10.4

Reply via email to