[hackers] [st] Add DECOM sequence || "Roberto E. Vargas Caballero"

From: <hg_AT_suckless.org>
Date: Thu, 8 Nov 2012 17:24:47 +0100 (CET)

changeset: 391:dafe8e46feea
user: "Roberto E. Vargas Caballero" <k0ga_AT_shike2.com>
date: Thu Nov 08 17:21:10 2012 +0100
files: st.c
description:
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 -r d36ee84e4216 -r dafe8e46feea st.c
--- a/st.c	Thu Nov 08 17:20:15 2012 +0100
+++ b/st.c	Thu Nov 08 17:21:10 2012 +0100
_AT_@ -97,6 +97,7 @@
 enum cursor_state {
 	CURSOR_DEFAULT  = 0,
 	CURSOR_WRAPNEXT = 1,
+	CURSOR_ORIGIN	= 2
 };
 
 enum glyph_state {
_AT_@ -300,6 +301,7 @@
 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);
_AT_@ -1211,10 +1213,25 @@
 	}
 }
 
+/* for absolute user moves, when decom is set */
+void
+tmoveato(int x, int y) {
+	tmoveto(x, y + ((term.c.state & CURSOR_ORIGIN) ? term.top: 0));
+}
+
 void
 tmoveto(int x, int y) {
+	int miny, maxy;
+
+	if(term.c.state & CURSOR_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;
_AT_@ -1456,7 +1473,9 @@
 				if(mode != term.mode)
 					redraw();
 				break;
-			case 6: /* XXX: DECOM -- Origin */
+			case 6: /* DECOM -- Origin */
+				MODBIT(term.c.state, set, CURSOR_ORIGIN);
+				tmoveato(0, 0);
 				break;
 			case 7: /* DECAWM -- Auto wrap */
 				MODBIT(term.mode, set, MODE_WRAP);
_AT_@ -1593,7 +1612,7 @@
 	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);
_AT_@ -1667,7 +1686,7 @@
 		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);
_AT_@ -1682,7 +1701,7 @@
 			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) */
_AT_@ -2119,10 +2138,10 @@
 	/* update terminal size */
 	term.col = col;
 	term.row = row;
+	/* reset scrolling region */
+	tsetscroll(0, row-1);
 	/* make use of the LIMIT in tmoveto */
 	tmoveto(term.c.x, term.c.y);
-	/* reset scrolling region */
-	tsetscroll(0, row-1);
 
 	return (slide > 0);
 }
Received on Thu Nov 08 2012 - 17:24:47 CET

This archive was generated by hypermail 2.3.0 : Thu Nov 08 2012 - 17:36:10 CET