[dev] [PATCH] Add tab stop escape sequences

2012-08-15 Thread Roberto E. Vargas Caballero

I wrote a path set for stterm which adds handling of TBC and HTS sequences
(and logically of HT character). I also removed the comment:


XXX: (CSI n I) CHT -- Cursor Forward Tabulation n tab stops

because CHT is not a vt10x escape sequence, it is a vt51x sequence, and I
think this could mean adding non necessary stuff (I wrote the patch for this
sequence also, so if you want it, ask me for it). It is not implemented by
linux virtual terminal neither by xterm.

Roberto.
From 057c24bb41e918224c1dc3d841015180ab56a7cb Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Wed, 15 Aug 2012 09:21:14 +0200
Subject: [PATCH 1/3] Add tabs field into Term struct

Tabs stop are simulated in st using a fixed size of 8, always, without be
worried about sequences changing the tab stops. A user can put a tab stop in
each horizontal position of the screen, so we need at least one flag for
each column of the screen. In the same way as dirty flags is used for the
rows, it is used a bool dinamic array.

Signed-off-by: Roberto E. Vargas Caballero k...@shike2.com
---
 st.c |   22 +++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/st.c b/st.c
index 4fc4d3d..d169ddf 100644
--- a/st.c
+++ b/st.c
@@ -164,7 +164,7 @@ typedef struct {
 	int col;	/* nb col */
 	Line* line;	/* screen */
 	Line* alt;	/* alternate screen */
-	bool* dirty; /* dirtyness of lines */
+	bool* dirty;	/* dirtyness of lines */
 	TCursor c;	/* cursor */
 	int top;	/* topscroll limit */
 	int bot;	/* bottom scroll limit */
@@ -172,6 +172,7 @@ typedef struct {
 	int esc;	/* escape state flags */
 	char title[ESC_TITLE_SIZ];
 	int titlelen;
+	bool *tabs;
 } Term;
 
 /* Purely graphic info */
@@ -847,12 +848,16 @@ tcursor(int mode) {
 
 void
 treset(void) {
+	unsigned i;
 	term.c = (TCursor){{
 		.mode = ATTR_NULL,
 		.fg = DefaultFG,
 		.bg = DefaultBG
 	}, .x = 0, .y = 0, .state = CURSOR_DEFAULT};
-	
+
+	memset(term.tabs, 0, term.col * sizeof(*term.tabs));
+	for (i = TAB; i  term.col; i += TAB)
+		term.tabs[i] = 1;
 	term.top = 0, term.bot = term.row - 1;
 	term.mode = MODE_WRAP;
 	tclearregion(0, 0, term.col-1, term.row-1);
@@ -865,12 +870,14 @@ tnew(int col, int row) {
 	term.line = malloc(term.row * sizeof(Line));
 	term.alt  = malloc(term.row * sizeof(Line));
 	term.dirty = malloc(term.row * sizeof(*term.dirty));
+	term.tabs = malloc(term.col * sizeof(*term.tabs));
 
 	for(row = 0; row  term.row; row++) {
 		term.line[row] = malloc(term.col * sizeof(Glyph));
 		term.alt [row] = malloc(term.col * sizeof(Glyph));
 		term.dirty[row] = 0;
 	}
+	memset(term.tabs, 0, term.col * sizeof(*term.tabs));
 	/* setup screen */
 	treset();
 }
@@ -1588,6 +1595,7 @@ tresize(int col, int row) {
 	term.line = realloc(term.line, row * sizeof(Line));
 	term.alt  = realloc(term.alt,  row * sizeof(Line));
 	term.dirty = realloc(term.dirty, row * sizeof(*term.dirty));
+	term.tabs = realloc(term.tabs, col * sizeof(*term.tabs));
 
 	/* resize each row to new width, zero-pad if needed */
 	for(i = 0; i  minrow; i++) {
@@ -1606,7 +1614,15 @@ tresize(int col, int row) {
 		term.line[i] = calloc(col, sizeof(Glyph));
 		term.alt [i] = calloc(col, sizeof(Glyph));
 	}
-	
+	if (col  term.col) {
+		bool *bp = term.tabs + term.col;
+
+		memset(bp, 0, sizeof(*term.tabs) * (col - term.col));
+		while (--bp  term.tabs  !*bp)
+			/* nothing */ ;
+		for (bp += TAB; bp  term.tabs + col; bp += TAB)
+			*bp = 1;
+	}
 	/* update terminal size */
 	term.col = col, term.row = row;
 	/* make use of the LIMIT in tmoveto */
-- 
1.7.10.4

From 1adde6a59379be80c47f6e02afcc2ffe26bec895 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Wed, 15 Aug 2012 10:09:22 +0200
Subject: [PATCH 2/3] Add HTS sequence

This sequence adds a new tab stop in the current horizontal position. This
means that tputtab must be look for the next tab stop in the tabs array
instead of using a hard coded value offset. Also, CHT sequence XXX message
is removed because it is not a vt10x sequence (as far as I know it is a
vt50x sequence), and it is not implemented by linux virtual terminal neither
by xterm.

Signed-off-by: Roberto E. Vargas Caballero k...@shike2.com
---
 st.c |   12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/st.c b/st.c
index d169ddf..4b7e4eb 100644
--- a/st.c
+++ b/st.c
@@ -1214,7 +1214,6 @@ csihandle(void) {
 		DEFAULT(escseq.arg[1], 1);
 		tmoveto(escseq.arg[1]-1, escseq.arg[0]-1);
 		break;
-	/* XXX: (CSI n I) CHT -- Cursor Forward Tabulation n tab stops */
 	case 'J': /* ED -- Clear screen */
 		sel.bx = -1;
 		switch(escseq.arg[0]) {
@@ -1429,8 +1428,11 @@ csireset(void) {
 
 void
 tputtab(void) {
-	int space = TAB - term.c.x % TAB;
-	tmoveto(term.c.x + space, term.c.y);
+	unsigned x;
+
+	for (x = term.c.x + 1; x  term.col  !term.tabs[x]; ++x)
+		/* nothing */ ;
+	tmoveto(x, term.c.y);
 }
 
 void
@@ -1491,6 +1493,10 @@ tputc(char *c) {
 tnewline(1); /* always go to first col

Re: [dev] [st] new features

2012-08-30 Thread Roberto E. Vargas Caballero

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



[dev] RM and SM sequences in st

2012-09-02 Thread Roberto E. Vargas Caballero
Hello,

In this mail I send two patchs, one for enabling vpa capability in
terminfo (st already has the correct sequence for this capability), and
other which enable SM and RM for dealing more of one argument.


Best regards,

Roberto Vargas.
From dc9b65b8ecf95a4d00acdca919b084d038cdca9c Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Thu, 30 Aug 2012 21:37:17 +0200
Subject: [PATCH] Add vpa terminfo capability

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

diff --git a/st.info b/st.info
index 08630d3..902c05a 100644
--- a/st.info
+++ b/st.info
@@ -103,6 +103,8 @@ st| simpleterm,
 	tsl=\E]0;,
 	ul,
 	xenl,
+	vpa=\E[%i%p1%dd,
+
 
 st-256color| simpleterm with 256 colors,
 	use=st,
-- 
1.7.10.4

From a6f356b1d8505e647fb588406fd3a8e293daac99 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Sun, 2 Sep 2012 12:02:30 +0200
Subject: [PATCH] Enable multiple arguments in SM and RM

SM and RM can receive multiple parameters, but the code only was accepting
only one. This patch join the code of set and reset modes (SM and RM) in a
common function and uses a loop which deals with all the arguments of the
sequence. This patch improves xterm and vt100 compability.
---
 st.c |  180 --
 1 file changed, 76 insertions(+), 104 deletions(-)

diff --git a/st.c b/st.c
index 123d29e..f3f7f28 100644
--- a/st.c
+++ b/st.c
@@ -273,6 +273,7 @@ static void tsetchar(char*);
 static void tsetscroll(int, int);
 static void tswapscreen(void);
 static void tsetdirt(int, int);
+static void tsetmode(bool, bool, int *, int);
 static void tfulldirt(void);
 
 static void ttynew(void);
@@ -1178,6 +1179,79 @@ tsetscroll(int t, int b) {
 	term.bot = b;
 }
 
+#define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) = ~(bit)))
+
+void
+tsetmode(bool priv, bool set, int *args, int narg) {
+	int *lim, mode;
+
+	for (lim = args + narg; args  lim; ++args) {
+		if(priv) {
+			switch(*args) {
+			case 1:
+MODBIT(term.mode, set, MODE_APPKEYPAD);
+break;
+			case 5: /* DECSCNM -- Reverve video */
+mode = term.mode;
+MODBIT(term.mode,set, MODE_REVERSE);
+if (mode != term.mode)
+	draw();
+break;
+			case 7:
+MODBIT(term.mode, set, MODE_WRAP);
+break;
+			case 20:
+MODBIT(term.mode, set, MODE_CRLF);
+break;
+			case 12: /* att610 -- Start blinking cursor (IGNORED) */
+break;
+			case 25:
+MODBIT(term.c.state, !set, CURSOR_HIDE);
+break;
+			case 1000: /* 1000,1002: enable xterm mouse report */
+MODBIT(term.mode, set, MODE_MOUSEBTN);
+break;
+			case 1002:
+MODBIT(term.mode, set, MODE_MOUSEMOTION);
+break;
+			case 1049: /* = 1047 and 1048 */
+			case 47:
+			case 1047:
+if(IS_SET(MODE_ALTSCREEN))
+	tclearregion(0, 0, term.col-1, term.row-1);
+if ((set  !IS_SET(MODE_ALTSCREEN)) ||
+(!set  IS_SET(MODE_ALTSCREEN))) {
+	tswapscreen();
+}
+if (*args != 1049)
+	break;
+/* pass through */
+			case 1048:
+tcursor((set) ? CURSOR_SAVE : CURSOR_LOAD);
+break;
+			default:
+fprintf(stderr,
+	erresc: unknown private set/reset mode %d\n,
+	*args);
+break;
+			}
+		} else {
+			switch(*args) {
+			case 4:
+MODBIT(term.mode, set, MODE_INSERT);
+break;
+			default:
+fprintf(stderr,
+	erresc: unknown set/reset mode %d\n,
+	*args);
+break;
+			}
+		}
+	}
+}
+#undef MODBIT
+
+
 void
 csihandle(void) {
 	switch(csiescseq.mode) {
@@ -1291,58 +1365,7 @@ csihandle(void) {
 		tinsertblankline(csiescseq.arg[0]);
 		break;
 	case 'l': /* RM -- Reset Mode */
-		if(csiescseq.priv) {
-			switch(csiescseq.arg[0]) {
-			case 1:
-term.mode = ~MODE_APPKEYPAD;
-break;
-			case 5: /* DECSCNM -- Remove reverse video */
-if(IS_SET(MODE_REVERSE)) {
-	term.mode = ~MODE_REVERSE;
-	draw();
-}
-break;
-			case 7:
-term.mode = ~MODE_WRAP;
-break;
-			case 12: /* att610 -- Stop blinking cursor (IGNORED) */
-break;
-			case 20:
-term.mode = ~MODE_CRLF;
-break;
-			case 25:
-term.c.state |= CURSOR_HIDE;
-break;
-			case 1000: /* disable X11 xterm mouse reporting */
-term.mode = ~MODE_MOUSEBTN;
-break;
-			case 1002:
-term.mode = ~MODE_MOUSEMOTION;
-break;
-			case 1049: /* = 1047 and 1048 */
-			case 47:
-			case 1047:
-if(IS_SET(MODE_ALTSCREEN)) {
-	tclearregion(0, 0, term.col-1, term.row-1);
-	tswapscreen();
-}
-if(csiescseq.arg[0] != 1049)
-	break;
-			case 1048:
-tcursor(CURSOR_LOAD);
-break;
-			default:
-goto unknown;
-			}
-		} else {
-			switch(csiescseq.arg[0]) {
-			case 4:
-term.mode = ~MODE_INSERT;
-break;
-			default:
-goto unknown;
-			}
-		}
+		tsetmode(csiescseq.priv, 0, csiescseq.arg, csiescseq.narg);
 		break;
 	case 'M': /* DL -- Delete n lines */
 		DEFAULT(csiescseq.arg[0], 1);
@@ -1366,58 +1389,7 @@ csihandle(void) {
 		tmoveto(term.c.x, csiescseq.arg[0]-1

[dev] New patches for st

2012-09-03 Thread Roberto E. Vargas Caballero
Hello,

Some new patches for st:

0001-Add-initialization-strings-in-terminfo.patch

Some new terminfo capabilities which help running reset.

0001-Add-write-I-O-to-file.patch

Add a theorical feature listed in st goals.

0001-Force-redisplay-of-all-lines-in-DECSCNM.patch

Add full redraw of the window in DECSCNM (reverse mode).

Best regards,
From 36550dccb6776a67d25b8af3cbfa87407fb5364b Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Mon, 3 Sep 2012 18:50:52 +0200
Subject: [PATCH] Add initialization strings in terminfo

When tput init is executed the list of task performed are (taken from
terminfo(5)):

  run the program
 iprog

  output is1 is2

  set the margins using
 mgc, smgl and smgr

  set tabs using
 tbc and hts

  print the file
 if

  and finally
 output is3.

When reset is executed, a more stronger initialization process is performed,
so the terminal can return from an unknown state. rs1, rs2 and rs3 are used
in this case instead of
using is1, is2 and is3.

This patch makes is2 = rs2, resets insert mode and set normal keypad
mode. For rs1 it performs a full initilization using ^[c.
---
 st.info |3 +++
 1 file changed, 3 insertions(+)

diff --git a/st.info b/st.info
index e883319..20e3f57 100644
--- a/st.info
+++ b/st.info
@@ -46,6 +46,7 @@ st| simpleterm,
 	ind=^J,
 	indn=\E[%p1%dS,
 	invis=\E[8m,
+	is2=\E[4l\E,
 	it#8,
 	kbs=\177,
 	kcub1=\E[D,
@@ -82,6 +83,8 @@ st| simpleterm,
 	op=\E[39;49m,
 	pairs#64,
 	rc=\E8,
+rs1=\Ec,
+rs2=\E[4l\E,
 	rev=\E[7m,
 	ri=\EM,
 	rmacs=\E(B,
-- 
1.7.10.4

From 91dbb5a8892b4b672722c9044316a0611683c777 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Mon, 3 Sep 2012 18:47:54 +0200
Subject: [PATCH] Add write I/O to file

This is a theorical feature listed in http://st.suckless.org/goals. All the
input/output of the terminal will be written to a file, which can be very
useful for debugging, and also allow interconnect st to other process
through named pipes.
---
 st.1 |6 ++
 st.c |   14 +-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/st.1 b/st.1
index b6c119f..931b481 100644
--- a/st.1
+++ b/st.1
@@ -10,6 +10,8 @@ st \- simple terminal
 .RB [ \-w 
 .IR windowid ]
 .RB [ \-v ]
+.RB [ \-f
+.IR file ]
 .RB [ \-e
 .IR command ...]
 .SH DESCRIPTION
@@ -30,6 +32,10 @@ embeds st within the window identified by
 .B \-v
 prints version information to stderr, then exits.
 .TP
+.BI \-f  file
+writes all the I/O to
+.I file
+.TP
 .BI \-e  program  [  arguments  ... ]
 st executes
 .I program
diff --git a/st.c b/st.c
index bd230a3..fde0493 100644
--- a/st.c
+++ b/st.c
@@ -36,7 +36,7 @@
 
 #define USAGE \
 	st  VERSION  (c) 2010-2012 st engineers\n \
-	usage: st [-t title] [-c class] [-w windowid] [-v] [-e command...]\n
+	usage: st [-t title] [-c class] [-w windowid] [-v] [-f file] [-e command...]\n
 
 /* XEMBED messages */
 #define XEMBED_FOCUS_IN  4
@@ -342,7 +342,9 @@ static STREscape strescseq;
 static int cmdfd;
 static pid_t pid;
 static Selection sel;
+static FILE *fileio;
 static char **opt_cmd  = NULL;
+static char *opt_io= NULL;
 static char *opt_title = NULL;
 static char *opt_embed = NULL;
 static char *opt_class = NULL;
@@ -776,6 +778,10 @@ ttynew(void) {
 		close(s);
 		cmdfd = m;
 		signal(SIGCHLD, sigchld);
+		if (opt_io  !(fileio = fopen(opt_io, w))) {
+			fprintf(stderr, Error opening %s:%s,
+opt_io, strerror(errno));
+		}
 	}
 }
 
@@ -1534,6 +1540,9 @@ tputtab(bool forward) {
 void
 tputc(char *c) {
 	char ascii = *c;
+
+	if (fileio)
+		putc(ascii, fileio);
 	if(term.esc  ESC_START) {
 		if(term.esc  ESC_CSI) {
 			csiescseq.buf[csiescseq.len++] = ascii;
@@ -2269,6 +2278,9 @@ main(int argc, char *argv[]) {
 		case 'w':
 			if(++i  argc) opt_embed = argv[i];
 			break;
+		case 'f':
+			if (++i  argc) opt_io = argv[i];
+			break;
 		case 'e':
 			/* eat every remaining arguments */
 			if(++i  argc) opt_cmd = argv[i];
-- 
1.7.10.4

From 7274e538601584d00617236193ad225e7b8e3f8d Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Mon, 3 Sep 2012 19:01:53 +0200
Subject: [PATCH] Force redisplay of all lines in DECSCNM

When it is called DECSCNM all lines become dirty, because it is necessary
redraw all lines for getting the new colors. It is easy see the problem
running 'echo ^[[?5h'.

In order to get a correct flash when running tput flash is necessary wait
after DECSCNM, until the changes are displayed, because in other case the
switch between reverse on/reverse off will be too much fast and nothing will
happen.
---
 st.c |   12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/st.c b/st.c
index fde0493..193db5e 100644
--- a/st.c
+++ b/st.c
@@ -54,6 +54,7 @@
 
 #define SELECT_TIMEOUT (20*1000) /* 20

[dev] [st] New patches

2012-09-04 Thread Roberto E. Vargas Caballero
Hello,

Two new patches for st:

0001-Add-newline-to-stderr-message.patch
- Fix a typo error in previous patches

0001-Check-alternative-screen-before-drawing-box-selectio.patch
- Don't paint selection box in the wrong screen.

Best regards,



Re: [dev] [st] New patches

2012-09-04 Thread Roberto E. Vargas Caballero
Sorry, but I forgot the patches ...


On Tue, Sep 04, 2012 at 07:34:29PM +0200, Roberto E. Vargas Caballero wrote:
 Hello,
 
   Two new patches for st:
 
 0001-Add-newline-to-stderr-message.patch
   - Fix a typo error in previous patches
 
 0001-Check-alternative-screen-before-drawing-box-selectio.patch
   - Don't paint selection box in the wrong screen.
 
 Best regards,
From cb0b3f9fc7692463053b42e50e6874779dbc6bba Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Tue, 4 Sep 2012 19:18:56 +0200
Subject: [PATCH] Add newline to stderr message

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

diff --git a/st.c b/st.c
index e869890..cdf2498 100644
--- a/st.c
+++ b/st.c
@@ -786,7 +786,7 @@ ttynew(void) {
 		cmdfd = m;
 		signal(SIGCHLD, sigchld);
 		if (opt_io  !(fileio = fopen(opt_io, w))) {
-			fprintf(stderr, Error opening %s:%s,
+			fprintf(stderr, Error opening %s:%s\n,
 opt_io, strerror(errno));
 		}
 	}
-- 
1.7.10.4

From 20290a9974d7cc3b95d5ad68f36f3449183f084b Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Tue, 4 Sep 2012 19:09:29 +0200
Subject: [PATCH] Check alternative screen before drawing box selection

Some programs use the alternative screen (vi, less, ...), whose
content is different of the main screen. If you select text in one of
the screen, you don't wait the box selection is painted in the other
screen, so it is necessary check if the selection was done in the same
screen we are going to paint. Before to this commit, you could do
something like:

	$ LESS= ls | less
	(select some code)
	q

and selection box remains drawing in the main screen, but the content
of selection keeps text of the alternate screen.
---
 st.c |7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/st.c b/st.c
index 09b0262..e869890 100644
--- a/st.c
+++ b/st.c
@@ -221,6 +221,7 @@ typedef struct {
 	struct {int x, y;} b, e;
 	char *clip;
 	Atom xtarget;
+	bool alt;
 	struct timeval tclick1;
 	struct timeval tclick2;
 } Selection;
@@ -579,6 +580,7 @@ selcopy(void) {
 		}
 		*ptr = 0;
 	}
+	sel.alt = IS_SET(MODE_ALTSCREEN);
 	xsetsel(str);
 }
 
@@ -2076,7 +2078,10 @@ drawregion(int x1, int y1, int x2, int y2) {
 	int ic, ib, x, y, ox, sl;
 	Glyph base, new;
 	char buf[DRAW_BUF_SIZ];
+	bool ena_sel = sel.bx != -1, alt = IS_SET(MODE_ALTSCREEN);
 
+	if ((sel.alt  !alt) || (!sel.alt  alt))
+		ena_sel = 0;
 	if(!(xw.state  WIN_VISIBLE))
 		return;
 
@@ -2089,7 +2094,7 @@ drawregion(int x1, int y1, int x2, int y2) {
 		ic = ib = ox = 0;
 		for(x = x1; x  x2; x++) {
 			new = term.line[y][x];
-			if(sel.bx != -1  *(new.c)  selected(x, y))
+			if (ena_sel  *(new.c)  selected(x, y))
 new.mode ^= ATTR_REVERSE;
 			if(ib  0  (!(new.state  GLYPH_SET) || ATTRCMP(base, new) ||
 		  ib = DRAW_BUF_SIZ-UTF_SIZ)) {
-- 
1.7.10.4



[dev] [st] Removing highlight when selection is owner by another process

2012-09-05 Thread Roberto E. Vargas Caballero
Hello,

When the selection is woner by another window we sholud remove the
highlight, because in other case it creates some confusion to the user.

Best regards.
From 6c7267744f8a1effeda813d5c0105247e46b19a5 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Wed, 5 Sep 2012 21:07:03 +0200
Subject: [PATCH] Unhighlight selection when selection is owner by other
 window

st marks the active selection using reverse colors in the box selection, but
once that another window becomes owner of the selection, it is very
confusing that st keeps highlight the old selection. Usually terminal
emulators remove the highlight when it is not valid anymore.

X sends a SelectionClear event in this situation, so we only have to add a
callback which unhighlight the selectin box.
---
 st.c |9 +
 1 file changed, 9 insertions(+)

diff --git a/st.c b/st.c
index cf329fd..fbf5a46 100644
--- a/st.c
+++ b/st.c
@@ -310,6 +310,7 @@ static void brelease(XEvent *);
 static void bpress(XEvent *);
 static void bmotion(XEvent *);
 static void selnotify(XEvent *);
+static void selclear(XEvent *);
 static void selrequest(XEvent *);
 
 static void selinit(void);
@@ -335,6 +336,7 @@ static void (*handler[LASTEvent])(XEvent *) = {
 	[MotionNotify] = bmotion,
 	[ButtonPress] = bpress,
 	[ButtonRelease] = brelease,
+	[SelectionClear] = selclear,
 	[SelectionNotify] = selnotify,
 	[SelectionRequest] = selrequest,
 };
@@ -611,6 +613,13 @@ selpaste() {
 	XConvertSelection(xw.dpy, XA_PRIMARY, sel.xtarget, XA_PRIMARY, xw.win, CurrentTime);
 }
 
+void selclear(XEvent *e) {
+	if(sel.bx == -1)
+		return;
+	sel.bx = -1;
+	tsetdirt(sel.b.y, sel.e.y);
+}
+
 void
 selrequest(XEvent *e) {
 	XSelectionRequestEvent *xsre;
-- 
1.7.10.4



[dev] [st] New patches

2012-09-12 Thread Roberto E. Vargas Caballero
From 39992c36c5306d8907365c8e62ea070982676afc Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Fri, 7 Sep 2012 12:18:26 +0200
Subject: [PATCH] Add xmalloc and xrealloc wrappers

If malloc  or realloc fail they return NULL. Theorically this condition
should be tested in the code, but it's a strange condition today (basically
if this is hapenning thenyou have a big problem), and even Linux never returns
NULL in the default configuration (only if the process don't have room in
the space address, something a bit impossible in the case of st). But stis
enough small for being executed in low resources computers where this can be
a real problem. So the easy way is creating a wrappers function for them and
call to die in case of error.
---
 st.c |   44 +++-
 1 file changed, 31 insertions(+), 13 deletions(-)

diff --git a/st.c b/st.c
index 7d93802..c7ab04a 100644
--- a/st.c
+++ b/st.c
@@ -326,6 +326,9 @@ static int utf8encode(long *, char *);
 static int utf8size(char *);
 static int isfullutf8(char *, int);
 
+static void *xmalloc(size_t);
+static void *xrealloc(void *, size_t);
+
 static void (*handler[LASTEvent])(XEvent *) = {
 	[KeyPress] = kpress,
 	[ClientMessage] = cmessage,
@@ -359,6 +362,21 @@ static char *opt_title = NULL;
 static char *opt_embed = NULL;
 static char *opt_class = NULL;
 
+void *
+xmalloc(size_t len) {
+	void *p = malloc(len);
+	if(!p)
+		die(Out of memory);
+	return p;
+}
+
+void *
+xrealloc(void *p, size_t len) {
+	if((p = xrealloc(p, len)) == NULL)
+		die(Out of memory);
+	return p;
+}
+
 int
 utf8decode(char *s, long *u) {
 	uchar c;
@@ -565,7 +583,7 @@ selcopy(void) {
 
 	else {
 		bufsize = (term.col+1) * (sel.e.y-sel.b.y+1) * UTF_SIZ;
-		ptr = str = malloc(bufsize);
+		ptr = str = xmalloc(bufsize);
 
 		/* append every set  selected glyph to the selection */
 		for(y = 0; y  term.row; y++) {
@@ -920,14 +938,14 @@ void
 tnew(int col, int row) {
 	/* set screen size */
 	term.row = row, term.col = col;
-	term.line = malloc(term.row * sizeof(Line));
-	term.alt  = malloc(term.row * sizeof(Line));
-	term.dirty = malloc(term.row * sizeof(*term.dirty));
-	term.tabs = malloc(term.col * sizeof(*term.tabs));
+	term.line = xmalloc(term.row * sizeof(Line));
+	term.alt  = xmalloc(term.row * sizeof(Line));
+	term.dirty = xmalloc(term.row * sizeof(*term.dirty));
+	term.tabs = xmalloc(term.col * sizeof(*term.tabs));
 
 	for(row = 0; row  term.row; row++) {
-		term.line[row] = malloc(term.col * sizeof(Glyph));
-		term.alt [row] = malloc(term.col * sizeof(Glyph));
+		term.line[row] = xmalloc(term.col * sizeof(Glyph));
+		term.alt [row] = xmalloc(term.col * sizeof(Glyph));
 		term.dirty[row] = 0;
 	}
 	memset(term.tabs, 0, term.col * sizeof(*term.tabs));
@@ -1761,16 +1779,16 @@ tresize(int col, int row) {
 	}
 
 	/* resize to new height */
-	term.line = realloc(term.line, row * sizeof(Line));
-	term.alt  = realloc(term.alt,  row * sizeof(Line));
-	term.dirty = realloc(term.dirty, row * sizeof(*term.dirty));
-	term.tabs = realloc(term.tabs, col * sizeof(*term.tabs));
+	term.line = xrealloc(term.line, row * sizeof(Line));
+	term.alt  = xrealloc(term.alt,  row * sizeof(Line));
+	term.dirty = xrealloc(term.dirty, row * sizeof(*term.dirty));
+	term.tabs = xrealloc(term.tabs, col * sizeof(*term.tabs));
 
 	/* resize each row to new width, zero-pad if needed */
 	for(i = 0; i  minrow; i++) {
 		term.dirty[i] = 1;
-		term.line[i] = realloc(term.line[i], col * sizeof(Glyph));
-		term.alt[i]  = realloc(term.alt[i],  col * sizeof(Glyph));
+		term.line[i] = xrealloc(term.line[i], col * sizeof(Glyph));
+		term.alt[i]  = xrealloc(term.alt[i],  col * sizeof(Glyph));
 		for(x = mincol; x  col; x++) {
 			term.line[i][x].state = 0;
 			term.alt[i][x].state = 0;
-- 
1.7.10.4

From 24b6ac1e65f68ae23c93ffa69993386d533d5eb2 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Fri, 7 Sep 2012 11:31:04 +0200
Subject: [PATCH] Remove buffering to fileio instead of calling fflush

By default text files are line buffered, and this means that -f option will
not write the line until a \n is printed. This is not very useful for
debugging, so a call to fflush was added. This patch substitute this call
(which will be done by each character painted) by the full remove of the
buffering in the file.
---
 st.c |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/st.c b/st.c
index 75c6cea..7d93802 100644
--- a/st.c
+++ b/st.c
@@ -810,6 +810,8 @@ ttynew(void) {
 		opt_io, strerror(errno));
 }
 			}
+			if (fileio)
+setvbuf(fileio, NULL, _IONBF, 0);
 		}
 	}
 }
@@ -1581,10 +1583,8 @@ void
 tputc(char *c) {
 	char ascii = *c;
 
-	if(fileio) {
+	if(fileio)
 		putc(ascii, fileio);
-		fflush(fileio);
-	}
 
 	if(term.esc  ESC_START) {
 		if(term.esc  ESC_CSI) {
-- 
1.7.10.4



Re: [dev] [st] New patches

2012-09-12 Thread Roberto E. Vargas Caballero

Hi,


Don't try apply theses patches, they introduce a big failure. I am debugging 
them now (again ...).


Best regards,



Re: [dev] [st] New patches

2012-09-12 Thread Roberto E. Vargas Caballero

Already fixed the problem,



 Hi,


 Don't try apply theses patches, they introduce a big failure. I am debugging 
 them now (again ...).


 Best regards,
From 39992c36c5306d8907365c8e62ea070982676afc Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Fri, 7 Sep 2012 12:18:26 +0200
Subject: [PATCH] Add xmalloc and xrealloc wrappers

If malloc  or realloc fail they return NULL. Theorically this condition
should be tested in the code, but it's a strange condition today (basically
if this is hapenning thenyou have a big problem), and even Linux never returns
NULL in the default configuration (only if the process don't have room in
the space address, something a bit impossible in the case of st). But stis
enough small for being executed in low resources computers where this can be
a real problem. So the easy way is creating a wrappers function for them and
call to die in case of error.
---
 st.c |   44 +++-
 1 file changed, 31 insertions(+), 13 deletions(-)

diff --git a/st.c b/st.c
index 7d93802..c7ab04a 100644
--- a/st.c
+++ b/st.c
@@ -326,6 +326,9 @@ static int utf8encode(long *, char *);
 static int utf8size(char *);
 static int isfullutf8(char *, int);
 
+static void *xmalloc(size_t);
+static void *xrealloc(void *, size_t);
+
 static void (*handler[LASTEvent])(XEvent *) = {
 	[KeyPress] = kpress,
 	[ClientMessage] = cmessage,
@@ -359,6 +362,21 @@ static char *opt_title = NULL;
 static char *opt_embed = NULL;
 static char *opt_class = NULL;
 
+void *
+xmalloc(size_t len) {
+	void *p = malloc(len);
+	if(!p)
+		die(Out of memory);
+	return p;
+}
+
+void *
+xrealloc(void *p, size_t len) {
+	if((p = xrealloc(p, len)) == NULL)
+		die(Out of memory);
+	return p;
+}
+
 int
 utf8decode(char *s, long *u) {
 	uchar c;
@@ -565,7 +583,7 @@ selcopy(void) {
 
 	else {
 		bufsize = (term.col+1) * (sel.e.y-sel.b.y+1) * UTF_SIZ;
-		ptr = str = malloc(bufsize);
+		ptr = str = xmalloc(bufsize);
 
 		/* append every set  selected glyph to the selection */
 		for(y = 0; y  term.row; y++) {
@@ -920,14 +938,14 @@ void
 tnew(int col, int row) {
 	/* set screen size */
 	term.row = row, term.col = col;
-	term.line = malloc(term.row * sizeof(Line));
-	term.alt  = malloc(term.row * sizeof(Line));
-	term.dirty = malloc(term.row * sizeof(*term.dirty));
-	term.tabs = malloc(term.col * sizeof(*term.tabs));
+	term.line = xmalloc(term.row * sizeof(Line));
+	term.alt  = xmalloc(term.row * sizeof(Line));
+	term.dirty = xmalloc(term.row * sizeof(*term.dirty));
+	term.tabs = xmalloc(term.col * sizeof(*term.tabs));
 
 	for(row = 0; row  term.row; row++) {
-		term.line[row] = malloc(term.col * sizeof(Glyph));
-		term.alt [row] = malloc(term.col * sizeof(Glyph));
+		term.line[row] = xmalloc(term.col * sizeof(Glyph));
+		term.alt [row] = xmalloc(term.col * sizeof(Glyph));
 		term.dirty[row] = 0;
 	}
 	memset(term.tabs, 0, term.col * sizeof(*term.tabs));
@@ -1761,16 +1779,16 @@ tresize(int col, int row) {
 	}
 
 	/* resize to new height */
-	term.line = realloc(term.line, row * sizeof(Line));
-	term.alt  = realloc(term.alt,  row * sizeof(Line));
-	term.dirty = realloc(term.dirty, row * sizeof(*term.dirty));
-	term.tabs = realloc(term.tabs, col * sizeof(*term.tabs));
+	term.line = xrealloc(term.line, row * sizeof(Line));
+	term.alt  = xrealloc(term.alt,  row * sizeof(Line));
+	term.dirty = xrealloc(term.dirty, row * sizeof(*term.dirty));
+	term.tabs = xrealloc(term.tabs, col * sizeof(*term.tabs));
 
 	/* resize each row to new width, zero-pad if needed */
 	for(i = 0; i  minrow; i++) {
 		term.dirty[i] = 1;
-		term.line[i] = realloc(term.line[i], col * sizeof(Glyph));
-		term.alt[i]  = realloc(term.alt[i],  col * sizeof(Glyph));
+		term.line[i] = xrealloc(term.line[i], col * sizeof(Glyph));
+		term.alt[i]  = xrealloc(term.alt[i],  col * sizeof(Glyph));
 		for(x = mincol; x  col; x++) {
 			term.line[i][x].state = 0;
 			term.alt[i][x].state = 0;
-- 
1.7.10.4

From 24b6ac1e65f68ae23c93ffa69993386d533d5eb2 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Fri, 7 Sep 2012 11:31:04 +0200
Subject: [PATCH] Remove buffering to fileio instead of calling fflush

By default text files are line buffered, and this means that -f option will
not write the line until a \n is printed. This is not very useful for
debugging, so a call to fflush was added. This patch substitute this call
(which will be done by each character painted) by the full remove of the
buffering in the file.
---
 st.c |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/st.c b/st.c
index 75c6cea..7d93802 100644
--- a/st.c
+++ b/st.c
@@ -810,6 +810,8 @@ ttynew(void) {
 		opt_io, strerror(errno));
 }
 			}
+			if (fileio)
+setvbuf(fileio, NULL, _IONBF, 0);
 		}
 	}
 }
@@ -1581,10 +1583,8 @@ void
 tputc(char *c) {
 	char ascii = *c;
 
-	if(fileio) {
+	if(fileio)
 		putc(ascii, fileio);
-		fflush(fileio);
-	}
 
 	if(term.esc  ESC_START) {
 		if(term.esc

Re: [dev] [st] New patches

2012-09-12 Thread Roberto E. Vargas Caballero
I agree with you that it is a bit stupid, and maybe we should use directly
write. Look these new patches.

 Couldn't the file output feature be implemented with dup2 in the child
 process? Using the buffered IO API and flushing at every character is
 stupid.
From 5fada178da8db9d73170d30bb74106c34e552ae6 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Fri, 7 Sep 2012 12:18:26 +0200
Subject: [PATCH] Add xmalloc and xrealloc wrappers

If malloc  or realloc fail they return NULL. Theorically this condition
should be tested in the code, but it's a strange condition today (basically
if this is hapenning thenyou have a big problem), and even Linux never returns
NULL in the default configuration (only if the process don't have room in
the space address, something a bit impossible in the case of st). But stis
enough small for being executed in low resources computers where this can be
a real problem. So the easy way is creating a wrappers function for them and
call to die in case of error.
---
 st.c |   44 +++-
 1 file changed, 31 insertions(+), 13 deletions(-)

diff --git a/st.c b/st.c
index f4384b9..19d0a86 100644
--- a/st.c
+++ b/st.c
@@ -326,6 +326,9 @@ static int utf8encode(long *, char *);
 static int utf8size(char *);
 static int isfullutf8(char *, int);
 
+static void *xmalloc(size_t);
+static void *xrealloc(void *, size_t);
+
 static void (*handler[LASTEvent])(XEvent *) = {
 	[KeyPress] = kpress,
 	[ClientMessage] = cmessage,
@@ -359,6 +362,21 @@ static char *opt_title = NULL;
 static char *opt_embed = NULL;
 static char *opt_class = NULL;
 
+void *
+xmalloc(size_t len) {
+	void *p = malloc(len);
+	if(!p)
+		die(Out of memory);
+	return p;
+}
+
+void *
+xrealloc(void *p, size_t len) {
+	if((p = realloc(p, len)) == NULL)
+		die(Out of memory);
+	return p;
+}
+
 int
 utf8decode(char *s, long *u) {
 	uchar c;
@@ -565,7 +583,7 @@ selcopy(void) {
 
 	else {
 		bufsize = (term.col+1) * (sel.e.y-sel.b.y+1) * UTF_SIZ;
-		ptr = str = malloc(bufsize);
+		ptr = str = xmalloc(bufsize);
 
 		/* append every set  selected glyph to the selection */
 		for(y = 0; y  term.row; y++) {
@@ -918,14 +936,14 @@ void
 tnew(int col, int row) {
 	/* set screen size */
 	term.row = row, term.col = col;
-	term.line = malloc(term.row * sizeof(Line));
-	term.alt  = malloc(term.row * sizeof(Line));
-	term.dirty = malloc(term.row * sizeof(*term.dirty));
-	term.tabs = malloc(term.col * sizeof(*term.tabs));
+	term.line = xmalloc(term.row * sizeof(Line));
+	term.alt  = xmalloc(term.row * sizeof(Line));
+	term.dirty = xmalloc(term.row * sizeof(*term.dirty));
+	term.tabs = xmalloc(term.col * sizeof(*term.tabs));
 
 	for(row = 0; row  term.row; row++) {
-		term.line[row] = malloc(term.col * sizeof(Glyph));
-		term.alt [row] = malloc(term.col * sizeof(Glyph));
+		term.line[row] = xmalloc(term.col * sizeof(Glyph));
+		term.alt [row] = xmalloc(term.col * sizeof(Glyph));
 		term.dirty[row] = 0;
 	}
 	memset(term.tabs, 0, term.col * sizeof(*term.tabs));
@@ -1759,16 +1777,16 @@ tresize(int col, int row) {
 	}
 
 	/* resize to new height */
-	term.line = realloc(term.line, row * sizeof(Line));
-	term.alt  = realloc(term.alt,  row * sizeof(Line));
-	term.dirty = realloc(term.dirty, row * sizeof(*term.dirty));
-	term.tabs = realloc(term.tabs, col * sizeof(*term.tabs));
+	term.line = xrealloc(term.line, row * sizeof(Line));
+	term.alt  = xrealloc(term.alt,  row * sizeof(Line));
+	term.dirty = xrealloc(term.dirty, row * sizeof(*term.dirty));
+	term.tabs = xrealloc(term.tabs, col * sizeof(*term.tabs));
 
 	/* resize each row to new width, zero-pad if needed */
 	for(i = 0; i  minrow; i++) {
 		term.dirty[i] = 1;
-		term.line[i] = realloc(term.line[i], col * sizeof(Glyph));
-		term.alt[i]  = realloc(term.alt[i],  col * sizeof(Glyph));
+		term.line[i] = xrealloc(term.line[i], col * sizeof(Glyph));
+		term.alt[i]  = xrealloc(term.alt[i],  col * sizeof(Glyph));
 		for(x = mincol; x  col; x++) {
 			term.line[i][x].state = 0;
 			term.alt[i][x].state = 0;
-- 
1.7.10.4

From fbf48b1dc6f08423b0499eac321a1a7949c36e18 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Fri, 7 Sep 2012 11:31:04 +0200
Subject: [PATCH] Remove buffering to fileio instead of calling fflush

By default text files are line buffered, and this means that -f option will
not write the line until a \n is printed. This is not very useful for
debugging, so a call to fflush was added. This patch substitute this call
(which will be done by each character painted) by the full remove of the
buffering in the file.
---
 st.c |   12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/st.c b/st.c
index 75c6cea..f4384b9 100644
--- a/st.c
+++ b/st.c
@@ -352,7 +352,7 @@ static STREscape strescseq;
 static int cmdfd;
 static pid_t pid;
 static Selection sel;
-static FILE *fileio;
+static int iofd = -1;
 static char **opt_cmd  = NULL;
 static char *opt_io= NULL;
 static char

[dev] [st] [PATCH 1/3] Add NUL character dealing

2012-09-13 Thread Roberto E. Vargas Caballero
NUL character is usually used as padding (basically  for timming purpouses),
and it should be ignorted. Some old telnet servers send it together each
character. It is also used in some terminfo entries (for example in xterm
terminfo entry).
---
 st.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/st.c b/st.c
index 0db81f4..26237de 100644
--- a/st.c
+++ b/st.c
@@ -1714,6 +1714,8 @@ tputc(char *c) {
if(sel.bx != -1  BETWEEN(term.c.y, sel.by, sel.ey))
sel.bx = -1;
switch(ascii) {
+   case '\0': /* padding character, do nothing */
+   break;
case '\t':
tputtab(1);
break;
--
1.7.10.4



[dev] [st] [PATCH 2/3] Restore default signal behaviour

2012-09-13 Thread Roberto E. Vargas Caballero
Signal handlers are inherited from parent process, so we can not be sure
which it is the handler our shell process has. This can cause some problems
with some window managers (for example with some wmii versions).
---
 st.c |7 +++
 1 file changed, 7 insertions(+)

diff --git a/st.c b/st.c
index 26237de..868300c 100644
--- a/st.c
+++ b/st.c
@@ -772,6 +772,13 @@ execsh(void) {
unsetenv(COLUMNS);
unsetenv(LINES);
unsetenv(TERMCAP);
+   signal(SIGCHLD, SIG_DFL);
+   signal(SIGHUP, SIG_DFL);
+   signal(SIGINT, SIG_DFL);
+   signal(SIGQUIT, SIG_DFL);
+   signal(SIGTERM, SIG_DFL);
+   signal(SIGALRM, SIG_DFL);
+

DEFAULT(envshell, SHELL);
putenv(TERM=TNAME);
--
1.7.10.4



[dev] [st] [PATCH 3/3] Move geometry initialization to xinit()

2012-09-13 Thread Roberto E. Vargas Caballero
xinit() is the function which performs all the X Windows initilization, so
it can be desired doing the geometry parsing into that function, and let the
argv loop of main as simple like other parameter cases.
---
 st.c |   53 +++--
 1 file changed, 27 insertions(+), 26 deletions(-)

diff --git a/st.c b/st.c
index 868300c..e87a0cd 100644
--- a/st.c
+++ b/st.c
@@ -358,6 +358,7 @@ static Selection sel;
 static int iofd = -1;
 static char **opt_cmd  = NULL;
 static char *opt_io= NULL;
+static char *opt_geo   = NULL;
 static char *opt_title = NULL;
 static char *opt_embed = NULL;
 static char *opt_class = NULL;
@@ -1965,6 +1966,11 @@ xinit(void) {
Cursor cursor;
Window parent;
int sw, sh;
+   int bitm, xr, yr;
+   unsigned int wr, hr;
+
+   xw.fw = xw.fh = xw.fx = xw.fy = 0;
+   xw.isfixed = False;

if(!(xw.dpy = XOpenDisplay(NULL)))
die(Can't open display\n);
@@ -1981,6 +1987,23 @@ xinit(void) {
xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
xloadcols();

+   if(opt_geo) {
+   bitm = XParseGeometry(opt_geo, xr, yr, wr, hr);
+   if(bitm  XValue)
+   xw.fx = xr;
+   if(bitm  YValue)
+   xw.fy = yr;
+   if(bitm  WidthValue)
+   xw.fw = (int)wr;
+   if(bitm  HeightValue)
+   xw.fh = (int)hr;
+   if(bitm  XNegative  xw.fx == 0)
+   xw.fx = -1;
+   if(bitm  XNegative  xw.fy == 0)
+   xw.fy = -1;
+   if(xw.fh != 0  xw.fw != 0)
+   xw.isfixed = True;
+   }
/* adjust fixed window geometry */
if(xw.isfixed) {
sw = DisplayWidth(xw.dpy, xw.scr);
@@ -2378,11 +2401,7 @@ run(void) {

 int
 main(int argc, char *argv[]) {
-   int i, bitm, xr, yr;
-   unsigned int wr, hr;
-
-   xw.fw = xw.fh = xw.fx = xw.fy = 0;
-   xw.isfixed = False;
+   int i;

for(i = 1; i  argc; i++) {
switch(argv[i][0] != '-' || argv[i][2] ? -1 : argv[i][1]) {
@@ -2398,31 +2417,13 @@ main(int argc, char *argv[]) {
case 'f':
if(++i  argc) opt_io = argv[i];
break;
+   case 'g':
+   if(++i  argc) opt_geo = argv[i];
+   break;
case 'e':
/* eat every remaining arguments */
if(++i  argc) opt_cmd = argv[i];
goto run;
-   case 'g':
-   if(++i = argc)
-   break;
-
-   bitm = XParseGeometry(argv[i], xr, yr, wr, hr);
-   if(bitm  XValue)
-   xw.fx = xr;
-   if(bitm  YValue)
-   xw.fy = yr;
-   if(bitm  WidthValue)
-   xw.fw = (int)wr;
-   if(bitm  HeightValue)
-   xw.fh = (int)hr;
-   if(bitm  XNegative  xw.fx == 0)
-   xw.fx = -1;
-   if(bitm  XNegative  xw.fy == 0)
-   xw.fy = -1;
-
-   if(xw.fh != 0  xw.fw != 0)
-   xw.isfixed = True;
-   break;
case 'v':
default:
die(USAGE);
--
1.7.10.4



[dev] [st] Removing timeouts in main loop

2012-09-16 Thread Roberto E. Vargas Caballero
This serie of patches try fix the problem of the timeout in main loop, which
causes st wakeup each 20 ms even thare is noting to do.

Please send comments and suggestion.

Best regards.
From 48aac423ea93820f8a406da3f4e53c8ce4bcb2a6 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Fri, 14 Sep 2012 21:09:51 +0200
Subject:  Call XdbeQueryExtension before of calling any Xdbe
 function

XdbeQueryExtension() tells to the caller if the Xdbe extension is present in
the X server, so it should be called for sanity. But like is said in
XdbeQueryExtension(3):

	No other Xdbe functions may be called before this function.  If a
	client violates this rule, the effects of all subsequent Xdbe calls
	that it makes are undefined.

it is mandatory call this function.
---
 st.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/st.c b/st.c
index 2e1ac67..b013bca 100644
--- a/st.c
+++ b/st.c
@@ -1970,7 +1970,7 @@ xinit(void) {
 	XSetWindowAttributes attrs;
 	Cursor cursor;
 	Window parent;
-	int sw, sh;
+	int sw, sh, major, minor;
 
 	if(!(xw.dpy = XOpenDisplay(NULL)))
 		die(Can't open display\n);
@@ -2021,9 +2021,10 @@ xinit(void) {
 			CWBackPixel | CWBorderPixel | CWBitGravity | CWEventMask
 			| CWColormap,
 			attrs);
+	if(!XdbeQueryExtension(xw.dpy, major, minor))
+		die(Xdbe extension is not present\n);
 	xw.buf = XdbeAllocateBackBufferName(xw.dpy, xw.win, XdbeCopied);
 
-
 	/* input methods */
 	xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL);
 	xw.xic = XCreateIC(xw.xim, XNInputStyle, XIMPreeditNothing
-- 
1.7.10.4

From 56695b6abf41b1d3b7880666d959b7dadef741da Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Sat, 15 Sep 2012 12:03:37 +0200
Subject:  Call XSync in redraw

It is necessary call to XSync if you want a good tput flash, because in
other way you can not be sure that white screen will be shown.
---
 st.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/st.c b/st.c
index b013bca..f4ad23d 100644
--- a/st.c
+++ b/st.c
@@ -2150,6 +2150,7 @@ redraw(void) {
 	struct timespec tv = {0, REDRAW_TIMEOUT * 1000};
 	tfulldirt();
 	draw();
+	XSync(xw.dpy, False); /* necessary for a good tput flash */
 	nanosleep(tv, NULL);
 }
 
-- 
1.7.10.4

From 124fe0dd1575401437093d1f6396ca7655ca5680 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Sat, 15 Sep 2012 20:55:27 +0200
Subject:  Remove timeout in the main loop

The main loop waits until there is some data to read in file descriptors of
the X server or the pseudo tty. But it uses a timeout in select(), which
causes that st awake each 20 ms, even it doesn't have something to do. This
patch removes this problem removing the timeout, which is not needed.
---
 TODO |1 -
 st.c |   27 +++
 2 files changed, 3 insertions(+), 25 deletions(-)

diff --git a/TODO b/TODO
index 1996137..c77c105 100644
--- a/TODO
+++ b/TODO
@@ -15,7 +15,6 @@ code  interface
 
 * clean selection code
 * clean and complete terminfo entry
-* remove the timeouts in the main loop
 
 bugs
 
diff --git a/st.c b/st.c
index f4ad23d..d7ca875 100644
--- a/st.c
+++ b/st.c
@@ -53,8 +53,6 @@
 #define XK_NO_MOD UINT_MAX
 #define XK_ANY_MOD0
 
-#define SELECT_TIMEOUT (20*1000) /* 20 ms */
-#define DRAW_TIMEOUT  (20*1000) /* 20 ms */
 #define REDRAW_TIMEOUT (80*1000) /* 80 ms */
 
 #define SERRNO strerror(errno)
@@ -205,7 +203,6 @@ typedef struct {
 	int ch; /* char height */
 	int cw; /* char width  */
 	char state; /* focus, redraw, visible */
-	struct timeval lastdraw;
 } XWindow;
 
 typedef struct {
@@ -250,7 +247,6 @@ static void drawregion(int, int, int, int);
 static void execsh(void);
 static void sigchld(int);
 static void run(void);
-static bool last_draw_too_old(void);
 
 static void csidump(void);
 static void csihandle(void);
@@ -2158,7 +2154,6 @@ void
 draw() {
 	drawregion(0, 0, term.col, term.row);
 	xcopy();
-	gettimeofday(xw.lastdraw, NULL);
 }
 
 void
@@ -2345,41 +2340,25 @@ resize(XEvent *e) {
 	ttyresize(col, row);
 }
 
-bool
-last_draw_too_old(void) {
-	struct timeval now;
-	gettimeofday(now, NULL);
-	return TIMEDIFF(now, xw.lastdraw) = DRAW_TIMEOUT/1000;
-}
-
 void
 run(void) {
 	XEvent ev;
 	fd_set rfd;
 	int xfd = XConnectionNumber(xw.dpy);
-	struct timeval timeout = {0};
-	bool stuff_to_print = 0;
 
 	for(;;) {
 		FD_ZERO(rfd);
 		FD_SET(cmdfd, rfd);
 		FD_SET(xfd, rfd);
-		timeout.tv_sec  = 0;
-		timeout.tv_usec = SELECT_TIMEOUT;
-		if(select(MAX(xfd, cmdfd)+1, rfd, NULL, NULL, timeout)  0) {
+		if(select(MAX(xfd, cmdfd)+1, rfd, NULL, NULL, NULL)  0) {
 			if(errno == EINTR)
 continue;
 			die(select failed: %s\n, SERRNO);
 		}
-		if(FD_ISSET(cmdfd, rfd)) {
+		if(FD_ISSET(cmdfd, rfd))
 			ttyread();
-			stuff_to_print = 1;
-		}
 
-		if(stuff_to_print  last_draw_too_old()) {
-			stuff_to_print = 0;
-			draw();
-		}
+		draw();
 
 		while(XPending(xw.dpy)) {
 			XNextEvent(xw.dpy, ev);
-- 
1.7.10.4

From

Re: [dev] [st] New patches

2012-09-16 Thread Roberto E. Vargas Caballero
On Sun, Sep 16, 2012 at 12:33:34PM +0200, Aurélien Aptel wrote:
 I'm not exactly sure what this feature will be used for. If you want
 to script something around a program expecting to run in a term there
 are already better tools for that like expect [1]. I'm not the one who
 added this goal.

Main use of this feature (actually) is only helping to debug. When you are
debugging escape sequences is very useful have the ascii sequence that some
program writes to the terminal. I don't know if you can get it with expect.



Re: [dev] [st] Removing timeouts in main loop

2012-09-16 Thread Roberto E. Vargas Caballero
 The timeout problem was introduced to speed up the rendering when a
 lot of text is printed.
 The logic is basically to not redraw on every read when the throughput is 
 high:

I tried do the same thing putting the draw at the end of the loop, so if you
have a high throughput you will read more characters in ttyread and you will
do more operations that will not be rended.

Maybe a way to improve my patches is testing is some data can be read from
the file descriptors and in this case continue the loop. something like:

int i = 0;
for(;;) {
FD_ZERO(rfd);
FD_SET(cmdfd, rfd);
FD_SET(xfd, rfd);
if(select(MAX(xfd, cmdfd)+1, rfd, NULL, NULL, NULL)  0)
if(errno == EINTR)
 continue;
die(select failed: %s\n, SERRNO);
}
repeat:
if(FD_ISSET(cmdfd, rfd))
ttyread();

while(XPending(xw.dpy)) {
  XNextEvent(xw.dpy, ev);
  if(XFilterEvent(ev, xw.win))
  continue;
  if(handler[ev.type])
 (handler[ev.type])(ev);
}
if(i++  4) {
   struct timeval tv = {0};
   FD_ZERO(rfd);
   FD_SET(cmdfd, rfd);
   FD_SET(xfd, rfd);
   if(select(MAX(xfd, cmdfd)+1, rfd, NULL, NULL, tv)  0)
 goto repeat;
}
i = 0;
draw();
XFlush(xw.dpy);
}


 I don't have a unix machine at the moment but here is a simple testcase:

 $ dd if=/dev/random bs=4K count=100 | hexdump

 Increase the count and compare with other terms if necessary.

$ time dd if=/dev/zero bs=4K count=100 | hexdump -C -v

st before patches:

real  0m1.250s
user  0m0.616s
sys   0m0.308s

st after patches:

real 0m1.151s
user 0m0.536s
sys  0m0.296s


xterm:

real0m4.501s
user0m0.380s
sys 0m0.156s


uxterm:

real0m1.384s
user0m0.492s
sys 0m0.256s



Re: [dev] [st] Removing timeouts in main loop

2012-09-16 Thread Roberto E. Vargas Caballero
 Maybe a way to improve my patches is testing is some data can be read from
 the file descriptors and in this case continue the loop. something like:


   if(i++  4) {
  struct timeval tv = {0};
  FD_ZERO(rfd);
  FD_SET(cmdfd, rfd);
FD_SET(xfd, rfd);
  if(select(MAX(xfd, cmdfd)+1, rfd, NULL, NULL, tv)  0)
goto repeat;
 }
   i = 0;

Uhmmm, this is not a good idea, because it is pretty similar than
increase the input buffer by 4.



Re: [dev] [st] New patches

2012-09-16 Thread Roberto E. Vargas Caballero
 If the only use is to debug it shouldn't be exposed to users and it's

I only implemented a goal of the project (I don't know who insert that goal
to) that was very useful for me.

 doesn't need to be fast. Besides there's already a dump() function you
 can modify/use.
 There is also this great tool called teseq [1] to debug escape
 sequences, I don't know if you've heard of it. Really handy.

The problem is not debug the sequence itself, the problem is get the full
text of the terminal. For example I got some problems with some telnet
servers which sends some NUL and SOH characters, or I have a problem with
emacs which prints some garbage in the screen sometimes (but only with
TERM=st, because this problem is not preset with TERM=xterm).

I can not fix this problems if I don't know what it it writing the program.



[dev] [st] small fix after draw() changes

2012-09-16 Thread Roberto E. Vargas Caballero
I forgot this small change.
From dda44edaafd907e96080db2257842d0a796f8d19 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Sun, 16 Sep 2012 13:50:13 +0200
Subject: [PATCH] Remove call to draw in resize

In previous commits draw was removed from all the X events, but I forgot do
it in resize.
---
 st.c |3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/st.c b/st.c
index 12d6665..11460c7 100644
--- a/st.c
+++ b/st.c
@@ -2319,8 +2319,7 @@ resize(XEvent *e) {
 	row = (xw.h - 2*BORDER) / xw.ch;
 	if(col == term.col  row == term.row)
 		return;
-	if(tresize(col, row))
-		draw();
+	tresize(col, row);
 	xresize(col, row);
 	ttyresize(col, row);
 }
-- 
1.7.10.4



Re: [dev] [st] New patches

2012-09-16 Thread Roberto E. Vargas Caballero
   The ???f switch allows easy recording of st sessions and so is  useful  to
   the users.

Thinking a bit about it, it is true that you can get the session using
'script -f', and it is not necessary insert this feature inside of st.



Re: [dev] [st] New patches

2012-09-16 Thread Roberto E. Vargas Caballero
 As said on IRC: I really like the convenience of

   st -f - | cat -v

 Doing  it manually over a fifo is tiresome when I want to do fast debug???
 ging.

Well, you can use a named pipe and script -f, cat -v. But I think this is
too much complex, and the cost of -f option is minimum and don't add any
complexity to st.



Re: [dev] [st] fonts and diacriticals

2012-09-17 Thread Roberto E. Vargas Caballero

I use also the tip and I can use diacritics (I usually have to write a lot
of them in spanish). The font I use is
-*-terminus-medium-r-*-*-*-160-72-72-*-80-*-*. Could you use the -f option
and sent the session to us?.



[dev] [st] Patches

2012-09-17 Thread Roberto E. Vargas Caballero
Some new patches for st.
From 17025c9ab88bb8560bac3896c2384ad060c6e8d9 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Mon, 17 Sep 2012 19:03:35 +0200
Subject: Add xcalloc wrapper

malloc and realloc are called through xmalloc and xrealloc, so calloc should
be called through xcalloc.
---
 st.c |   13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/st.c b/st.c
index d5ecf61..df7f8d8 100644
--- a/st.c
+++ b/st.c
@@ -324,6 +324,7 @@ static int isfullutf8(char *, int);
 
 static void *xmalloc(size_t);
 static void *xrealloc(void *, size_t);
+static void *xcalloc(size_t nmemb, size_t size);
 
 static void (*handler[LASTEvent])(XEvent *) = {
 	[KeyPress] = kpress,
@@ -373,6 +374,14 @@ xrealloc(void *p, size_t len) {
 	return p;
 }
 
+void *
+xcalloc(size_t nmemb, size_t size) {
+	void *p = calloc(nmemb, size);
+	if(!p)
+		die(Out of memory\n);
+	return p;
+}
+
 int
 utf8decode(char *s, long *u) {
 	uchar c;
@@ -1801,8 +1810,8 @@ tresize(int col, int row) {
 	/* allocate any new rows */
 	for(/* i == minrow */; i  row; i++) {
 		term.dirty[i] = 1;
-		term.line[i] = calloc(col, sizeof(Glyph));
-		term.alt [i] = calloc(col, sizeof(Glyph));
+		term.line[i] = xcalloc(col, sizeof(Glyph));
+		term.alt [i] = xcalloc(col, sizeof(Glyph));
 	}
 	if(col  term.col) {
 		bool *bp = term.tabs + term.col;
-- 
1.7.10.4

From cd17e65b475b1eaccc73a2668f67953ac1e4 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Mon, 17 Sep 2012 19:05:06 +0200
Subject: Add newline in error messages

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

diff --git a/st.c b/st.c
index df7f8d8..c408ca9 100644
--- a/st.c
+++ b/st.c
@@ -363,14 +363,14 @@ void *
 xmalloc(size_t len) {
 	void *p = malloc(len);
 	if(!p)
-		die(Out of memory);
+		die(Out of memory\n);
 	return p;
 }
 
 void *
 xrealloc(void *p, size_t len) {
 	if((p = realloc(p, len)) == NULL)
-		die(Out of memory);
+		die(Out of memory\n);
 	return p;
 }
 
-- 
1.7.10.4

From b13844523254ef2e05a8c3d81b89b8aba09e3513 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Mon, 17 Sep 2012 20:19:48 +0200
Subject: Copy non set positions as spaces

st selection don't insert in the selection position whose value is not
set. This is correct for the positions in the end of the line, but cause
some problems in the beginning. For example echo -e 'a\tb' will print in the
screen:

a	b

but after selecting and copying in some place you get:

ab

because positions from 1 to 7 don't have any value. This patch deals all
positions without value as blank (even at the end of the line).
---
 st.c |   17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/st.c b/st.c
index c408ca9..b2e5e22 100644
--- a/st.c
+++ b/st.c
@@ -596,14 +596,17 @@ selcopy(void) {
 		/* append every set  selected glyph to the selection */
 		for(y = 0; y  term.row; y++) {
 			for(x = 0; x  term.col; x++) {
-is_selected = selected(x, y);
-if((term.line[y][x].state  GLYPH_SET)  is_selected) {
-	int size = utf8size(term.line[y][x].c);
-	memcpy(ptr, term.line[y][x].c, size);
-	ptr += size;
-}
+int size;
+char *p;
+Glyph *gp = term.line[y][x];
+
+if(!(is_selected = selected(x, y)))
+	continue;
+p = (gp-state  GLYPH_SET) ? gp-c :  ;
+size = utf8size(p);
+memcpy(ptr, p, size);
+ptr += size;
 			}
-
 			/* \n at the end of every selected line except for the last one */
 			if(is_selected  y  sel.e.y)
 *ptr++ = '\n';
-- 
1.7.10.4

From b6a73e21dfe968a8dbc8736799175a58cd8dfd8b Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Mon, 17 Sep 2012 20:24:19 +0200
Subject: Clean windows display after resizing

Some times the size after a resizing is not an exact multiply of a number of
characters, so redrawn the screen using the lines and columns of the neww
size can cause that some old graphics keep in the screen. Solution is clean
all the windows with the background color.
---
 st.c |3 +++
 1 file changed, 3 insertions(+)

diff --git a/st.c b/st.c
index b2e5e22..20e4512 100644
--- a/st.c
+++ b/st.c
@@ -1839,6 +1839,9 @@ void
 xresize(int col, int row) {
 	xw.w = MAX(1, 2*BORDER + col * xw.cw);
 	xw.h = MAX(1, 2*BORDER + row * xw.ch);
+	XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0,
+		   DisplayWidth(xw.dpy, xw.scr),
+		   DisplayHeight(xw.dpy, xw.scr));
 }
 
 void
-- 
1.7.10.4



Re: [dev] [st] fonts and diacriticals

2012-09-17 Thread Roberto E. Vargas Caballero

 TERM inside st = st-256color

Can you send the output of 'infocmp st-256color'?

 Here's the st -f output:
 http://sprunge.us/IfXW

Uhmmm, but in this file there isn't any diacritic :S. I need some of them in
order to try see where can be the problem.



Re: [dev] [st] fonts and diacriticals

2012-09-17 Thread Roberto E. Vargas Caballero
On Mon, Sep 17, 2012 at 02:37:44PM -0400, Peter Hartman wrote:
  http://sprunge.us/IfXW
 Note the first command I type in that is é ENTER

Interesting, because I can't see the 'è' in the file, so it is not a problem
of the fonts. I don't know why but st if doing something strange with the
character.



[dev] [st] fonts and diacriticals

2012-09-17 Thread Roberto E. Vargas Caballero
 Change all those little LC_ and LANG vars over now convinces st to behave.

The problem seems that st suppouse the input keyboard is a utf8 device, and
in the case you use a non utf8 locale it detects non ascii characters as
first byte of a multibyte utf8 character (if you have good luck, because it
is possible it detects it as an incorrect utf8 number). This is a new bug in
st (at least the temporary work around is easy).



[dev] [st] Patches

2012-09-19 Thread Roberto E. Vargas Caballero
Hi,

A new serie of patches for st. Please send comments or suggestions.

Best regards.
From 703b3cfc0cdb4998abca6815dd32699705a9f912 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Wed, 19 Sep 2012 19:42:48 +0200
Subject: Clear X window in tsetreset()

tsetreset() is called when it is necessary a full initialization of the
terminal, so it also should clean the full X window and not only the
terminal content. It is necessary change the order of the
initialization in main(), and put xinit before of tnew(), because tnew() 
calls to tsetreset(), and  this can cause a call to xreset() with
incorrect values.
---
 st.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/st.c b/st.c
index 35f6f16..7c05a6c 100644
--- a/st.c
+++ b/st.c
@@ -943,6 +943,7 @@ treset(void) {
 		term.tabs[i] = 1;
 	term.top = 0, term.bot = term.row - 1;
 	term.mode = MODE_WRAP;
+	xclear(0, 0, xw.w, xw.h);
 	tclearregion(0, 0, term.col-1, term.row-1);
 }
 
@@ -2445,9 +2446,9 @@ main(int argc, char *argv[]) {
 
  run:
 	setlocale(LC_CTYPE, );
+	xinit();
 	tnew(80, 24);
 	ttynew();
-	xinit();
 	selinit();
 	run();
 	return 0;
-- 
1.7.10.4

From 4671ab2615b1bd5f6e77bd8ec24765707b5f Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Wed, 19 Sep 2012 19:46:40 +0200
Subject: Remove unused parameters in ttyresize

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

diff --git a/st.c b/st.c
index 7c05a6c..43dbe32 100644
--- a/st.c
+++ b/st.c
@@ -283,7 +283,7 @@ static void tfulldirt(void);
 
 static void ttynew(void);
 static void ttyread(void);
-static void ttyresize(int, int);
+static void ttyresize(void);
 static void ttywrite(const char *, size_t);
 
 static void xdraws(char *, Glyph, int, int, int, int);
@@ -890,7 +890,7 @@ ttywrite(const char *s, size_t n) {
 }
 
 void
-ttyresize(int x, int y) {
+ttyresize(void) {
 	struct winsize w;
 
 	w.ws_row = term.row;
@@ -2339,7 +2339,7 @@ resize(XEvent *e) {
 	xclear(0, 0, xw.w, xw.h);
 	tresize(col, row);
 	xresize(col, row);
-	ttyresize(col, row);
+	ttyresize();
 }
 
 void
-- 
1.7.10.4

From b42c8e533bdbb694b35ba3d0ef74863e51c8808e Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Wed, 19 Sep 2012 19:49:48 +0200
Subject: Add KAM sequence

This sequence lock/unlock the keyboard ignoring all the key pressing events
from X server.
---
 st.c |8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/st.c b/st.c
index 43dbe32..7e369c7 100644
--- a/st.c
+++ b/st.c
@@ -107,7 +107,8 @@ enum term_mode {
 	MODE_MOUSEBTN= 32,
 	MODE_MOUSEMOTION = 64,
 	MODE_MOUSE   = 32|64,
-	MODE_REVERSE = 128
+	MODE_REVERSE = 128,
+	MODE_KBDLOCK = 256
 };
 
 enum escape_state {
@@ -1319,6 +1320,9 @@ tsetmode(bool priv, bool set, int *args, int narg) {
 			}
 		} else {
 			switch(*args) {
+			case 2:
+MODBIT(term.mode, set, MODE_KBDLOCK);
+break;
 			case 4:
 MODBIT(term.mode, set, MODE_INSERT);
 break;
@@ -2269,6 +2273,8 @@ kpress(XEvent *ev) {
 	int shift;
 	Status status;
 
+	if (IS_SET(MODE_KBDLOCK))
+		return;
 	meta = e-state  Mod1Mask;
 	shift = e-state  ShiftMask;
 	len = XmbLookupString(xw.xic, e, buf, sizeof(buf), ksym, status);
-- 
1.7.10.4

From fada4a6e23741745b85f8c60eacd8bbcf07d7483 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Wed, 19 Sep 2012 20:00:56 +0200
Subject: Fix LNM sequence

LNM sequence is a standard ANSI mode, not a DEC private mode.
---
 st.c |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/st.c b/st.c
index 7e369c7..4dd7547 100644
--- a/st.c
+++ b/st.c
@@ -1283,9 +1283,6 @@ tsetmode(bool priv, bool set, int *args, int narg) {
 			case 7:
 MODBIT(term.mode, set, MODE_WRAP);
 break;
-			case 20:
-MODBIT(term.mode, set, MODE_CRLF);
-break;
 			case 12: /* att610 -- Start blinking cursor (IGNORED) */
 break;
 			case 25:
@@ -1326,6 +1323,9 @@ tsetmode(bool priv, bool set, int *args, int narg) {
 			case 4:
 MODBIT(term.mode, set, MODE_INSERT);
 break;
+			case 20:
+MODBIT(term.mode, set, MODE_CRLF);
+break;
 			default:
 fprintf(stderr,
 	erresc: unknown set/reset mode %d\n,
-- 
1.7.10.4

From e328b3e0cf5db77cb3e37500cbed097d5477e117 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Wed, 19 Sep 2012 20:18:15 +0200
Subject: Add some documentetion to tsetmode

The names of the terminal modes supported by vt102 are (taken from the VT220
programmer reference manual):

Table 4-7 ANSI-Standardized Modes
Name  Mnemonic		Parameter (Ps)
Error (ignored)		- 0 (3/0)
Keyboard action		KAM	  2 (3/2)
Insert/replace		IRM	  4 (3/4)
Send/receive		SRM	  12 (3/1 3/2)
Line feed/new line	LNM   20 (3/2 3/0)

Table 4-8 ANSI-Compatible DEC Private Modes
Name  Mnemonic		  Parameter (Ps)
Error (ignored)		  -	0 (3/0)
Cursor key		  DECCKM

Re: [dev] [st] Patches

2012-09-19 Thread Roberto E. Vargas Caballero
Well... I was asking about comments and suggestion of the patches. I am not
the person who can accept or deny new suggestion, but I am going to give my
personal opinion.

 Would you also port st to wayland?

I think in case of being possible, st is very far to do this, because it has
a lot of things to fix before.

 How many patches are left to get scrollback buffer?

Idea of main developers is not add this feature to st, because you can get
it using other external programs, like for example tmux. This helps to keep
st very simple, efficient and clear. Maybe a good solution could be
integrate tmux inside of st (for example if STTMUX is defined, run tmux in
starup).



Re: [dev] [st] xft

2012-09-20 Thread Roberto E. Vargas Caballero
 Please report back if it works. I will then simply apply it.

It is not working fine for me. It seems have some problems with the size of
the fonts.

   XIC xic;
 + XftDraw *xft_draw;
 + Visual *vis;
   int scr;
   Bool isfixed; /* is fixed geometry? */
   int fx, fy, fw, fh; /* fixed geometry */
   int tw, th; /* tty width and height */
 + int bufw, bufh; /* pixmap width and height */
   int w;  /* window width */
   int h;  /* window height */
   int ch; /* char height */

After your last patch isfixed is no longer of type Bool (due to this patch
didn't applied cleanly), and bufw and bufh seems not be used in the patch
(maybe you forgot remove them from a previous patch version?).

Best regards,



Re: [dev] [st] Patches

2012-09-20 Thread Roberto E. Vargas Caballero

 Yeah! Oh, we could have a variable for everything that one could wish
 to start in st: STTMUX, STGNUSCREEN, STAALIBKDE...

 or we could just use -e.

Yeah, even when you start it from a menu like dmenu or it is automatically
spawned from a graphical application. It's true that a boolean variable may
not be the best solution, but -e also it is not the solution. Maybe a better
aproach can be a variable with the parameters for st (like LESS variable) or
something like this.



Re: [dev] st eight bit input

2012-09-20 Thread Roberto E. Vargas Caballero

 I wonder if it's possible to get something like xterm's
 eightBitInput=true in st. I would like to use the alt key for some vim
 mappings. I'm not at all savvy on terminal stuff so any hint about how
 to hack the code to get this working would be very much appreciated.


There isn't any switch for this in st. st can handle only utf-8 keyboards,
and I think it will do it forever. Alt is mapped to meta key in st, so it
does the same that xterm with altSendsEscape option. You can adjust your vim
mappings to this or hack the kpress function in st.

Best regards.



Re: [dev] [st] Patches

2012-09-20 Thread Roberto E. Vargas Caballero
 how is -e not a solution?

Uhmmm, I suck ^^!. dmenu allows you write the full command line, so you can
use -e with it.



Re: [dev] [st] xft: line drawing

2012-09-25 Thread Roberto E. Vargas Caballero
 Line drawing seems to be broke using the latest tip of st. I've tried it

I also have problems with them. Using the default font I have some problems
with line drawings and attributes (for example http://www.shike2.com/st.png).

Is it the problem you have?.


Best regards,



[dev] [st] Patch fix writing io file

2012-09-25 Thread Roberto E. Vargas Caballero
Fix a bug with multi byte characters.
From a7ad8ce85ebddfacd1cab80d7b5b2189d0842d53 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Mon, 24 Sep 2012 22:58:47 +0200
Subject: Fix bug in tputc writing to io file

If -f options is enabled then tputc() writes all the data to a file. Actual
code assumes that all the strings in 'c' parameters have always 1 byte
length, but this is not always true, because due to utf-8 encoding some
characters can have a diferent length. So it is necessary pass string length
to tputc in order it can call to write() correctly.
---
 st.c |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/st.c b/st.c
index 2d080e5..a0bd69f 100644
--- a/st.c
+++ b/st.c
@@ -278,7 +278,7 @@ static void tmoveto(int, int);
 static void tnew(int, int);
 static void tnewline(int);
 static void tputtab(bool);
-static void tputc(char*);
+static void tputc(char*, int);
 static void treset(void);
 static int tresize(int, int);
 static void tscrollup(int, int);
@@ -884,7 +884,7 @@ ttyread(void) {
 	while(buflen = UTF_SIZ || isfullutf8(ptr,buflen)) {
 		charsize = utf8decode(ptr, utf8c);
 		utf8encode(utf8c, s);
-		tputc(s);
+		tputc(s, charsize);
 		ptr+= charsize;
 		buflen -= charsize;
 	}
@@ -1641,11 +1641,11 @@ tputtab(bool forward) {
 }
 
 void
-tputc(char *c) {
+tputc(char *c, int len) {
 	char ascii = *c;
 
 	if(iofd != -1)
-		write(iofd, c, 1);
+		write(iofd, c, len);
 
 	if(term.esc  ESC_START) {
 		if(term.esc  ESC_CSI) {
-- 
1.7.10.4



Re: [dev] [st] xft: line drawing

2012-09-26 Thread Roberto E. Vargas Caballero
On Wed, Sep 26, 2012 at 08:49:43AM +0200, Christoph Lohmann wrote:
 Greetings comrades.

 You guys forced me to do it. Attached is a preliminary patch to add line
 drawing, which is using UTF-8 characters, to the latest tip of st.

Testing your patch, I saw that mutt doesn't use never \033 ( 0. I think it
see that locale is utf8 capable and directly writes utf8 codes, so my
problems are not related to the patch you sent. Surely they are part of the
incomplete font. Since I am using the default font, maybe we should change
the default font to other with better drawing support, as for example
Liberation Mono.


Sincerely.



[dev] Control characters patches

2012-09-26 Thread Roberto E. Vargas Caballero
Hello,

These patches fix some control codes problems.

Sincerely.
From 2a346a24efb6a79d25dcfa1d0fb718267b8f6bac Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Mon, 24 Sep 2012 23:03:34 +0200
Subject: Ignore all control characters not handled

Taken from vt100 programmer manual:

	Control characters have values of \000 - \037, and \177. The control
	characters recognized by the VT100 are shown in Table 3-10. All
	other control codes cause no action to be taken.

We have to take attention when we are using alternate charset, because in
this cases they are not used as control characters.
---
 st.c |   20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/st.c b/st.c
index 009ccb4..e1cb4a8 100644
--- a/st.c
+++ b/st.c
@@ -1642,7 +1642,7 @@ tputtab(bool forward) {
 
 void
 tputc(char *c, int len) {
-	char ascii = *c;
+	uchar ascii = *c;
 
 	if(iofd != -1)
 		write(iofd, c, len);
@@ -1761,8 +1761,6 @@ tputc(char *c, int len) {
 		if(sel.bx != -1  BETWEEN(term.c.y, sel.by, sel.ey))
 			sel.bx = -1;
 		switch(ascii) {
-		case '\0': /* padding character, do nothing */
-			break;
 		case '\t':
 			tputtab(1);
 			break;
@@ -1787,13 +1785,15 @@ tputc(char *c, int len) {
 			term.esc = ESC_START;
 			break;
 		default:
-			if(IS_SET(MODE_WRAP)  term.c.state  CURSOR_WRAPNEXT)
-tnewline(1); /* always go to first col */
-			tsetchar(c);
-			if(term.c.x+1  term.col)
-tmoveto(term.c.x+1, term.c.y);
-			else
-term.c.state |= CURSOR_WRAPNEXT;
+			if(ascii = '\020' || term.c.attr.mode  ATTR_GFX) {
+if(IS_SET(MODE_WRAP)  term.c.state  CURSOR_WRAPNEXT)
+	tnewline(1); /* always go to first col */
+tsetchar(c);
+if(term.c.x+1  term.col)
+	tmoveto(term.c.x+1, term.c.y);
+else
+	term.c.state |= CURSOR_WRAPNEXT;
+			}
 		}
 	}
 }
-- 
1.7.10.4

From bc5103baed408f79c1f0ba119816faab2284fe47 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Wed, 26 Sep 2012 20:41:28 +0200
Subject: Allow control characters inside escape sequences

Taken from vt100 manual programmer:

	Control characters (codes \0 to \37 inclusive) are specifically
	excluded from the control sequence syntax, but may be embedded
	within a control sequence. Embedded control characters are executed
	as soon as they are encountered by the VT100. The processing of the
	control sequence then continues with the next character received.
---
 st.c |   68 +-
 1 file changed, 34 insertions(+), 34 deletions(-)

diff --git a/st.c b/st.c
index e1cb4a8..16c6b8f 100644
--- a/st.c
+++ b/st.c
@@ -1647,6 +1647,32 @@ tputc(char *c, int len) {
 	if(iofd != -1)
 		write(iofd, c, len);
 
+	switch(ascii) {
+	case '\t':
+		tputtab(1);
+		return;
+	case '\b':
+		tmoveto(term.c.x-1, term.c.y);
+		return;
+	case '\r':
+		tmoveto(0, term.c.y);
+		return;
+	case '\f':
+	case '\v':
+	case '\n':
+		/* go to first col if the mode is set */
+		tnewline(IS_SET(MODE_CRLF));
+		return;
+	case '\a':
+		if(!(xw.state  WIN_FOCUSED))
+			xseturgency(1);
+		return;
+	case '\033':
+		csireset();
+		term.esc = ESC_START;
+		return;
+	}
+
 	if(term.esc  ESC_START) {
 		if(term.esc  ESC_CSI) {
 			csiescseq.buf[csiescseq.len++] = ascii;
@@ -1760,40 +1786,14 @@ tputc(char *c, int len) {
 	} else {
 		if(sel.bx != -1  BETWEEN(term.c.y, sel.by, sel.ey))
 			sel.bx = -1;
-		switch(ascii) {
-		case '\t':
-			tputtab(1);
-			break;
-		case '\b':
-			tmoveto(term.c.x-1, term.c.y);
-			break;
-		case '\r':
-			tmoveto(0, term.c.y);
-			break;
-		case '\f':
-		case '\v':
-		case '\n':
-			/* go to first col if the mode is set */
-			tnewline(IS_SET(MODE_CRLF));
-			break;
-		case '\a':
-			if(!(xw.state  WIN_FOCUSED))
-xseturgency(1);
-			break;
-		case '\033':
-			csireset();
-			term.esc = ESC_START;
-			break;
-		default:
-			if(ascii = '\020' || term.c.attr.mode  ATTR_GFX) {
-if(IS_SET(MODE_WRAP)  term.c.state  CURSOR_WRAPNEXT)
-	tnewline(1); /* always go to first col */
-tsetchar(c);
-if(term.c.x+1  term.col)
-	tmoveto(term.c.x+1, term.c.y);
-else
-	term.c.state |= CURSOR_WRAPNEXT;
-			}
+		if(ascii = '\020' || term.c.attr.mode  ATTR_GFX) {
+			if(IS_SET(MODE_WRAP)  term.c.state  CURSOR_WRAPNEXT)
+tnewline(1); /* always go to first col */
+			tsetchar(c);
+			if(term.c.x+1  term.col)
+tmoveto(term.c.x+1, term.c.y);
+			else
+term.c.state |= CURSOR_WRAPNEXT;
 		}
 	}
 }
-- 
1.7.10.4



Re: [dev] [st] [sandy] wierd things happens to the font after sandy use

2012-09-28 Thread Roberto E. Vargas Caballero
On Fri, Sep 28, 2012 at 05:36:42PM +0200, KarlOskar Rikås wrote:
This happens after i use sandy in st:
http://ompldr.org/vZm84bA/wierd.png (warning large picture)
Have anyone similar issues? I just updated st, sandy's config and st's are
default I've only changed colors and font to Droid Sans Mono.

I suppouse you are using last version of st from mercurial repository. St is
integrating xft fonts in this moment, and it is possible found errors due to
incorrect fonts. If a ugly font doesn't have some glyph then st can't render
such character, and then you will see the incorrect character glyph.

I suggest to you test with the default font, because it gives less problems
than others. If you continue having problems with the default font (Liberation
Mono) please let us knowing it.

Sincerely,



[dev] [st] New patches

2012-10-06 Thread Roberto E. Vargas Caballero
Hello,

This is a new serie of patches for st related to control codes. In
the case of 0003-Add-SI-and-SO-control-codes.patch code does the same that
linux virtual terminal and my real vt520, but xterm and uxterm have other
behaviour, so if someone could give some aditional information about this
issue then please say it. In the patch
0004-Print-control-codes-only-in-graphic-mode.patch I have changed the
priority of checks:


 1: If we are in a STR sequence then handle it and return.
 2: If ascii is a control code then handle it and continue.
 3: Else if we are in a ESC sequence handle it and return.
 4: Print the character. Control codes are printed only in graphic mode.

 After checked some strange sequences in xterm and uxterm this seems the
correct order, but I can not be sure about str sequences because I can not
find documentation about them (I think they were added by xterm).


 It is possible these patches can help with the problem of KarlOskar
Rikås with sandy, because maybe the lost glyph were some control codes, but
I can not be sure because I can not reproduce the problem in my computer.

Roberto Vargas,
From ea7f1156689131e069cfb302d7d97a68f6169565 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Thu, 27 Sep 2012 18:34:07 +0200
Subject: Add documentation to control codes

Add the documentation from the vt100 manual programmer:

Control 	Octal  Action Taken
Character	Code
---
NUL		000	Ignored on input (not stored in input buffer;
			see full duplex protocol).
ENQ		005	Transmit answerback message.
BEL		007	Sound bell tone from keyboard.
BS		010	Move the cursor to the left one character position,
			unless it is at the left margin,
			in which case no action occurs.
HT		011	Move the cursor to the next tab stop,
			or to the right margin if no further tab stops
			are present on the line.
LF		012	This code causes a line feed or
			a new line operation. (See new line mode).
VT		013	Interpreted as LF.
FF		014	Interpreted as LF.
CR		015	Move cursor to the left margin on the current line.
SO		016	Invoke G1 character set, as designated by SCS
			control sequence.
SI		017	Select G0 character set, as selected by ESC ( sequence.
XON		021	Causes terminal to resume transmission.
XOFF		023	Causes terminal to stop transmitted all codes
			except XOFF and XON.
CAN		030	If sent during a control sequence, the sequence is
			immediately terminated and not executed. It also causes
			the error character to be displayed.
SUB		032	Interpreted as CAN.
ESC		033	Invokes a control sequence.
DEL		177	Ignored on input (not stored in input buffer).

---
 st.c |   28 +++-
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/st.c b/st.c
index 64e0aff..aa5f085 100644
--- a/st.c
+++ b/st.c
@@ -1789,32 +1789,42 @@ tputc(char *c, int len) {
 		write(iofd, c, len);
 
 	switch(ascii) {
-	case '\t':
+	case '\t':	/* HT */
 		tputtab(1);
 		return;
-	case '\b':
+	case '\b':	/* BS */
 		tmoveto(term.c.x-1, term.c.y);
 		return;
-	case '\r':
+	case '\r':	/* CR */
 		tmoveto(0, term.c.y);
 		return;
-	case '\f':
-	case '\v':
-	case '\n':
+	case '\f':	/* LF */
+	case '\v':	/* VT */
+	case '\n':	/* LF */
 		/* go to first col if the mode is set */
 		tnewline(IS_SET(MODE_CRLF));
 		return;
-	case '\a':
+	case '\a':	/* BEL */
 		if(term.esc  ESC_STR)
 			break;
-
 		if(!(xw.state  WIN_FOCUSED))
 			xseturgency(1);
 		return;
-	case '\033':
+	case '\033':	/* ESC */
 		csireset();
 		term.esc = ESC_START;
 		return;
+	case '\016':	/* XXX: SO */
+	case '\017':	/* XXX: SI */
+	case '\032':	/* XXX: SUB */
+	case '\030':	/* XXX: CAN */
+	default:
+	/* case '\005':	ENQ (IGNORED) */
+	/* case '\000':	NUL (IGNORED) */
+	/* case '\021':	XON (IGNORED) */
+	/* case '\023':	XOFF (IGNORED) */
+	/* case 0177:	DEL (IGNORED) */
+		break;
 	}
 
 	if(term.esc  ESC_START) {
-- 
1.7.10.4

From 58b67250da632d4213f0dcf82eee5ce0585e5dfb Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Fri, 28 Sep 2012 22:04:17 +0200
Subject: Add SUB and CAN control codes

These control codes reset any escape sequence already initialised.
---
 st.c |7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/st.c b/st.c
index aa5f085..8e25d23 100644
--- a/st.c
+++ b/st.c
@@ -1816,8 +1816,11 @@ tputc(char *c, int len) {
 		return;
 	case '\016':	/* XXX: SO */
 	case '\017':	/* XXX: SI */
-	case '\032':	/* XXX: SUB */
-	case '\030':	/* XXX: CAN */
+		break;
+	case '\032':	/* SUB */
+	case '\030':	/* CAN */
+		csireset();
+		return;
 	default:
 	/* case '\005':	ENQ (IGNORED) */
 	/* case '\000':	NUL (IGNORED) */
-- 
1.7.10.4

From a3a3ce413ffad5110640444e70685b37787e8bc5 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Fri, 28 Sep 2012 22:06:02 +0200
Subject: Add SI and SO control codes

SI and SO allows change the G0

Re: [dev] [st] Patches

2012-10-07 Thread Roberto E. Vargas Caballero
On Sun, Oct 07, 2012 at 11:10:21AM +0200, Aurélien Aptel wrote:
 I don't think the DEC alignment test is necessary. Please read LEGACY
 in st repo.


I duded about this, but like I was not sure I sent the patch to the list in
order to begin a discussion about this. You can see that the message in the
commit was very clear about the sequence maybe was not necessary.



Re: [dev] [st] Patches

2012-10-07 Thread Roberto E. Vargas Caballero
 I applied the patch for it to have a reason to modularize the tsetchar()
 function. I think this will be needed for  another  feature  I  have  in
 mind.  Then the test loop will be removed.

Uhmmm, you could say me this and it was very easy for me split the patch and
keep only that part. Next time I will try split this kind of patches.



[dev] [st] fileio patch

2012-10-09 Thread Roberto E. Vargas Caballero
Improve the error handling writing to the fileio.
From 5321822f43782edfad107d71db558493552b3a65 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Tue, 9 Oct 2012 18:12:29 +0200
Subject: Add error control to iofile

write can write less bytes than we request, so it is necessary check the
return value, in case of error print a message and don't continnue writing
in the file.
---
 st.c |   39 ++-
 1 file changed, 30 insertions(+), 9 deletions(-)

diff --git a/st.c b/st.c
index 693739e..197dd79 100644
--- a/st.c
+++ b/st.c
@@ -340,6 +340,7 @@ static int utf8encode(long *, char *);
 static int utf8size(char *);
 static int isfullutf8(char *, int);
 
+static ssize_t xwrite(int, char *, size_t);
 static void *xmalloc(size_t);
 static void *xrealloc(void *, size_t);
 static void *xcalloc(size_t nmemb, size_t size);
@@ -379,6 +380,21 @@ static char *opt_embed = NULL;
 static char *opt_class = NULL;
 static char *opt_font = NULL;
 
+
+ssize_t
+xwrite(int fd, char *s, size_t len) {
+	size_t aux = len;
+
+	while(len  0) {
+		ssize_t r = write(fd, s, len);
+		if(r  0)
+			return r;
+		len -= r;
+		s += r;
+	}
+	return aux;
+}
+
 void *
 xmalloc(size_t len) {
 	void *p = malloc(len);
@@ -926,13 +942,12 @@ ttynew(void) {
 		cmdfd = m;
 		signal(SIGCHLD, sigchld);
 		if(opt_io) {
-			if(!strcmp(opt_io, -)) {
-iofd = STDOUT_FILENO;
-			} else {
-if((iofd = open(opt_io, O_WRONLY | O_CREAT, 0666))  0) {
-	fprintf(stderr, Error opening %s:%s\n,
-		opt_io, strerror(errno));
-}
+			iofd = (!strcmp(opt_io, -)) ?
+  STDOUT_FILENO :
+  open(opt_io, O_WRONLY | O_CREAT, 0666);
+			if(iofd  0) {
+fprintf(stderr, Error opening %s:%s\n,
+	opt_io, strerror(errno));
 			}
 		}
 	}
@@ -1793,8 +1808,14 @@ tputc(char *c, int len) {
 	uchar ascii = *c;
 	bool control = ascii  '\x20' || ascii == 0177;
 
-	if(iofd != -1)
-		write(iofd, c, len);
+	if(iofd != -1) {
+		if (xwrite(iofd, c, len)  0) {
+			fprintf(stderr, Error writting in %s:%s\n,
+opt_io, strerror(errno));
+			close(iofd);
+			iofd = -1;
+		}
+	}
 	/*
 	 * STR sequences must be checked before of anything
 	 * because it can use some control codes as part of the sequence
-- 
1.7.10.4



[dev] Adding utmpx stuff

2012-10-09 Thread Roberto E. Vargas Caballero
Hello,

This patch adds utmpx support in st, which means that st sessions
will be visible using who or, who is the correct behaviour of a terminal
emulator, but this means that the binary needs have setgid, which is
something we have to thing carefully.

  Other important about this patch is the portability of it. I have
used the POSIX definitions, but as far as I know, there are some BSD that
don't support very well this functions (specially OpenBSD). There are
different solutions for this:

  - A hell of ifdef inside in st.c
  - A pty.c where all this portability stuff is present.
  - A compat file (or one for each problematic System), where
this interfaces are adapted.

Please give your opinion, and don't worry if it is necessary modify this
patch.

Sincerely,


Roberto E. Vargas Caballero
From 0a9788863aaf76aa7e4cb87cfa99a549f81ae87d Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Mon, 8 Oct 2012 21:03:54 +0200
Subject: Initialize environment variables to correct values

Calling st without SHELL variable caused a segmentation fault, because no
test was done about this variable. It is responsability of the terminal
emulator set correct values for LOGNAME and USER, and the value for the
variable WINDOWID (It contains a numeric identifier of the window that
contains the terminal. (This allows X-aware applications that are run from
console to do some operations over the window, e.g. changing its icon.)

This patch doesn't overwrite values in SHELL and HOME because maybe the user
put some values here which can be useful for him.
---
 st.c |   37 -
 1 file changed, 32 insertions(+), 5 deletions(-)

diff --git a/st.c b/st.c
index 197dd79..46db942 100644
--- a/st.c
+++ b/st.c
@@ -5,6 +5,7 @@
 #include fcntl.h
 #include limits.h
 #include locale.h
+#include pwd.h
 #include stdarg.h
 #include stdbool.h
 #include stdio.h
@@ -261,6 +262,7 @@ static void die(const char *, ...);
 static void draw(void);
 static void redraw(void);
 static void drawregion(int, int, int, int);
+static void initenv(void);
 static void execsh(void);
 static void sigchld(int);
 static void run(void);
@@ -881,10 +883,6 @@ execsh(void) {
 	char **args;
 	char *envshell = getenv(SHELL);
 
-	unsetenv(COLUMNS);
-	unsetenv(LINES);
-	unsetenv(TERMCAP);
-
 	signal(SIGCHLD, SIG_DFL);
 	signal(SIGHUP, SIG_DFL);
 	signal(SIGINT, SIG_DFL);
@@ -893,7 +891,6 @@ execsh(void) {
 	signal(SIGALRM, SIG_DFL);
 
 	DEFAULT(envshell, SHELL);
-	putenv(TERM=TNAME);
 	args = opt_cmd ? opt_cmd : (char*[]){envshell, -i, NULL};
 	execvp(args[0], args);
 	exit(EXIT_FAILURE);
@@ -914,6 +911,35 @@ sigchld(int a) {
 }
 
 void
+initenv(void) {
+	const struct passwd *pass = getpwuid(getuid());
+	char buff[sizeof(long) * 8];
+
+	if(!pass)
+		die(Process is running with an incorrect uid\n);
+
+	unsetenv(COLUMNS);
+	unsetenv(LINES);
+	unsetenv(TERMCAP);
+	/*
+	 * We assume the first input in passwd with this uid
+	 * is the correct. If you have more of one user with the same
+	 * uid you suck a lot.
+	 */
+	setenv(LOGNAME, pass-pw_name, 1);
+	setenv(USER, pass-pw_name, 1);
+	setenv(SHELL, pass-pw_shell, 0);
+	setenv(HOME, pass-pw_dir, 0);
+	putenv(TERM= TNAME);
+	/*
+	 * we can be sure that DISPLAY is correct because we don't have
+	 * a -diplay option
+	 */
+	sprintf(buff, %lu, xw.win);
+	setenv(WINDOWID, buff, 1);
+}
+
+void
 ttynew(void) {
 	int m, s;
 	struct winsize w = {term.row, term.col, 0, 0};
@@ -935,6 +961,7 @@ ttynew(void) {
 			die(ioctl TIOCSCTTY failed: %s\n, SERRNO);
 		close(s);
 		close(m);
+		initenv();
 		execsh();
 		break;
 	default:
-- 
1.7.10.4

From 607a9cf9b4a61fb77bfefba7d166f0b8681079a2 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Tue, 9 Oct 2012 18:29:27 +0200
Subject: Add utmp stuff

When it is initiated a terminal emulator it is also created a new tty
(pseudo) and a new login is done. This imply that the usual job done by
login program must be done in the emulator, basically updating utmpx
database. With this patch sessions created by the emulator will be shown in
w or who.

Writing in utmpx means having enough privileges for writing in it, so the
binary needs have setgid. In this case we need this special privileges only
for two functions call, so it is not a security risk. Also, st can continue
working without setgid bit, but in this case utmpx stuff will not work.

utmpx stuff was standardised by POSIX in 2001, but some BSD distribution
lack good support for this. FreeBSD added this functions in January of 2012
and OpenBSD doesn't support them.
---
 Makefile |3 ++
 st.c |  100 +++---
 2 files changed, 99 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile
index 8fc9674..8680e04 100644
--- a/Makefile
+++ b/Makefile
@@ -5,6 +5,7 @@ include config.mk
 
 SRC = st.c
 OBJ = ${SRC:.c=.o}
+GROUP = utmp
 
 all: options st

Re: [dev] [st] Tip adds non-existing trailing whitespace upon mouse selection + fix

2012-10-09 Thread Roberto E. Vargas Caballero
On Tue, Oct 09, 2012 at 04:07:54PM +0200, pancake wrote:
 i feel this annoying too, but someone told me this was an
 intentional behaviour.

The problem is that tab characters means a movement of the cursor. so if you
apply your patch and run something like:

$ printf a\tb

you will see in the screen:

a   b

but if you try copy/paste it you will copy only the character a and b,
getting:

ab


Solution of copying all the characters needs some work, because I agree it sucks
when you copy this non existing leading paces. I think the solution should be a
variable by line saying maximum column written in it. I think other terminal
emulators do something like this.

Of course actual solution converts all tabs into spaces, but fix this is
reallt complex and I think all the emulator take this aproach.


Sincerely,

Roberto E. Vargas Caballero.



Re: [dev] Adding utmpx stuff

2012-10-09 Thread Roberto E. Vargas Caballero
 This  patch  is  fixing something st shouldn’t do. In my environment all
 the environment variables you propose to add are set.  That’s  something
 the  shell  should do and not the terminal emulator. A terminal emulator
 should be neutral to this. Sorry, but I think you are  fixing  something
 at  the  wrong  place in your environment. If this metadata for good old
 style tty’s is needed, well, try to fix this in the  existing  operating
 systems.

Relay in correct values of LOGNAME and USER is a security risk. If st
doesn't check against /etc/passwd you can get who(1) shows other user as
connected, for example. Usually these variables are set by login(1), and
like a terminal emulator is doing the login job, setting these variables are
work of st.



Re: [dev] Adding utmpx stuff

2012-10-09 Thread Roberto E. Vargas Caballero

 Relay in correct values of LOGNAME and USER is a security risk. If st
 doesn't check against /etc/passwd you can get who(1) shows other user as
 connected, for example. Usually these variables are set by login(1), and
 like a terminal emulator is doing the login job, setting these variables are
 work of st.

And if SHELL is not set, st before this patch segfault.



Re: [dev] Adding utmpx stuff

2012-10-09 Thread Roberto E. Vargas Caballero
 That  e‐mail has several reason to not support utmpx. The proposed patch
 has the same size of an equal dbus interface that would call  some  kind
 of  logind.  That’s  the kind of cruft people complain about before they
 start to reinvent it using Javascript or Go.

xterm uses libutempter, which is a library which calls to one program called
utempter (with setgid) and this program handle all the utmpx stuff. But I
think is not a good solution because:

   1) libutempter only supports GLIB and FreeBSD
   2) Having a program like utempter is a big mistake, because anyone can
  insert entries in utmpx only running it.

utmpx is necessary if you want use a lot of Unix tools (write, talk, biff,
and a lot). I agree that put all this stuff in st scary me to.



Re: [dev] Adding utmpx stuff

2012-10-09 Thread Roberto E. Vargas Caballero
  And if SHELL is not set, st before this patch segfault.

 Actually,  this  is a simple check to just use »/bin/sh«. Which environ‐
 ment today does not have SHELL set?

The code set SHELL only if is not set (3rd parameter of setenv). SHELL can
be unset if a ugly user unset it ;).



Re: [dev] Adding utmpx stuff

2012-10-09 Thread Roberto E. Vargas Caballero
 How  is  this  a possible security risk? St shouldn’t be used to control
 login shells. It’s there to show  escape  sequences  jump  around  on  a
 screen.

The problem is that the terminal emulation is too much related to the pty
stuff. The program who create the master/slave is the responsable of doing
all this things. Maybe we could split it, and put all the emulation in only
one program free all the pty stuff.



Re: [dev] Adding utmpx stuff

2012-10-09 Thread Roberto E. Vargas Caballero

It is also necessary set WINDOWID, because it is the XWindow ID of the
terminal. I suppouse w3m needs this variable to print images in the terminal.



Re: [dev] [st] Tip adds non-existing trailing whitespace upon mouse selection + fix

2012-10-10 Thread Roberto E. Vargas Caballero
 The GLYPH_SET flag can be used to compute the end of the line or we
 could add another flag like GLYPH_TAB when appropriate and test it in
 the copy function when it loops over the selection.

Instead of adding GLYPH_TAB we could use directly \t in c and then we don't
have to test anything in selcopy, but of couse we should check it in
drawregion.

But this solution doesn't fix this problem when you use a sequence to locate
the cursor in some place of the screen.



Re: [dev] [st] toggle font

2012-10-10 Thread Roberto E. Vargas Caballero
 I missed this feature a lot when light conditions and distance to
 display change, often so with a notebook, even more when different
 displays plugged. Of course, tmux helps -- kill, start new st, attach to
 the right session --, but I like this approach more.

I also need this feature, but maybe could be done in other way. I talked
about this with other persons of the list, and we liked let st be configured
using the stdin of st, so you can do it something like:

 configurator | st

And, for example, you could use dmenu and select the font you want to use.



Re: [dev] [st] toggle font

2012-10-11 Thread Roberto E. Vargas Caballero
 Eugh. That isn't the way anything else is configured. It's a pretty
 weird interface. config.h, argv switches and potentially keybindings
 are reasonable ways to configure programs. stdin is just silly.


St, like all others graphic terminal emualtors, receive escape sequences
which configure it, change color, set tittle screen, set blink ..., so add
new private sequences for things like chage font is not only no stupid, is
the correct way in this case.

Once you have the sequence, which can only be inserted from the own terminal
(for example with an echo), next step is allow these sequences in the non
used standard input, so st could accept them from others programs.



Re: [dev] [st] Tip adds non-existing trailing whitespace upon mouse selection + fix

2012-10-11 Thread Roberto E. Vargas Caballero
 The GLYPH_SET flag can be used to compute the end of the line or we

This patch uses this approach for locating the end of line and works fine for
me.
From 2192d284a3d002044d57592c6e36246a6d8882dc Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Thu, 11 Oct 2012 19:03:57 +0200
Subject: Avoid copying characters beyond last

Positions without GLYPH_SET are copied as spaces. This is correct for tabs
and others locate sequences, but is wrong in the end of lines, where you get
a lot of spaces where there isn't any text. This patch avoid these ghost
trailing whitespaces, but still transform tabs into spaces.
---
 st.c |7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/st.c b/st.c
index 8641a7a..532d706 100644
--- a/st.c
+++ b/st.c
@@ -691,7 +691,6 @@ void
 selcopy(void) {
 	char *str, *ptr, *p;
 	int x, y, bufsize, is_selected = 0, size;
-	Glyph *gp;
 
 	if(sel.bx == -1) {
 		str = NULL;
@@ -701,9 +700,11 @@ selcopy(void) {
 
 		/* append every set  selected glyph to the selection */
 		for(y = 0; y  term.row; y++) {
-			for(x = 0; x  term.col; x++) {
-gp = term.line[y][x];
+			Glyph *gp = term.line[y][0], *last = gp + term.col;
 
+			while(--last = gp  !(last-state  GLYPH_SET))
+/* nothing */;
+			for(x = 0; gp = last; x++, ++gp) {
 if(!(is_selected = selected(x, y)))
 	continue;
 p = (gp-state  GLYPH_SET) ? gp-c :  ;
-- 
1.7.10.4



Re: [dev] [st] toggle font

2012-10-16 Thread Roberto E. Vargas Caballero
 Surely, it would be better to use a separate control input stream,
 stdctl (or nstdctl), for configuration.

Are you talking about keep, for example, file descriptor 3 for control
operations?



Re: [dev] I don't want to live on this planet anymore

2012-10-31 Thread Roberto E. Vargas Caballero
My 3rd year computer science professor just said:
In order to have a good program, it must be large
*facepalm*

 This is something very common today. Teachers in the universities
create minds that only can do very difficult things. I has to say that in my
case was the same, and took long time to me see that this was shit, but
usually people can't understand it because they don't know other thing.



Re: [dev] [st] 0.3 release

2012-11-05 Thread Roberto E. Vargas Caballero
 We should try to improve and cleanup the selection code. It has not

I agree. It has some strange behaviour, like for example the first time you
press the mouse if you keep it pressed for a selection, then the selection
is not highlighted.



Re: [dev] [st] line drawing?

2012-11-06 Thread Roberto E. Vargas Caballero

 I just upgraded my st install to latest tip, and now all the line
 drawing characters (such as in mutt) are a lowercase 'd'.  This
 seems suboptimal.  Older st versions had stuff in config.h for
 configuring these, but that seems gone now.

I just have tested it and it seems work for me. What locale are you using?



Re: [dev] [st] line drawing?

2012-11-06 Thread Roberto E. Vargas Caballero
 If I switch to Liberation Mono it works.  This is a pretty serious
 regression, since I used to be able to use whatever font I wanted
 without issue.

It is a problem related to the switch to Xft. It impossible a font
has all the unicode glyphs, so if the font fails in a glyph you have a
problem. It is not clear for us how other terminals fix this problem, but
maybe we should add this issue to the TODO list.



Re: [dev] [st] line drawing?

2012-11-07 Thread Roberto E. Vargas Caballero
 I have the same problem. When I use Liberation Mono and start
 ncmcpp, everything
 is fine but when I quit the program, no cursor, I have to reset the
 terminal.

 When I'm using 'DejaVu Sans Mono', I have little squares in lieu of
 the drawing bars,
 but when I quit everything is fine.

I just have tested with 'DejaVu Sans Mono' and 'Anonymous Pro' and the
problem is the same. I can see when mutt exits it writes:

1: ESC[1@
2: ESC[61;28H
3: ESC[39;49m
4: ESC[0m
5: ESC[?25l
5: ESC[2;75H
6: ESC[?12l
7: ESC[?25h
8: ESC[61d
9: ESC[37m
10: ESC[39;49m
11: ESC[0m
12: ESC[61;1H
13: ESC[?1049l
14: ESC]0;

Important sequences here are:

5: ESC[?25l - Disable cursor
7: ESC[?25h - Enable cursor
13: ESC[?1049l - Disable main screen and restore cursor position.

And if you write directly them to st, they work perfectly.



[dev] [st] Patch

2012-11-07 Thread Roberto E. Vargas Caballero
This patch fixes the problems with hide/unhide.
From d14745fa4d678c0b9abb21f8f2fe2913e30c26b0 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Wed, 7 Nov 2012 10:38:05 +0100
Subject: [PATCH] Fix bug restoring cursor position

Sequences like DECSC, DECRC, ESC [?1047l or ESC [?1047h save and restore
cursor position, but not other attributes of the cursor, like Glyph or hide
mode, but st uses a full TCursor variable, which means that it changes all
the attributes of cursor.  This caused that depending of the order of
sequences sometimes the cursor was hide when it should be not hidden.
---
 st.c |   10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/st.c b/st.c
index f063029..af8bd9a 100644
--- a/st.c
+++ b/st.c
@@ -1044,13 +1044,15 @@ tfulldirt(void) {
 
 void
 tcursor(int mode) {
-	static TCursor c;
+	static int x,y;
 
 	if(mode == CURSOR_SAVE) {
-		c = term.c;
+		x = term.c.x;
+		y = term.c.y;
 	} else if(mode == CURSOR_LOAD) {
-		term.c = c;
-		tmoveto(c.x, c.y);
+		term.c.x = x;
+		term.c.y = y;
+		tmoveto(x, y);
 	}
 }
 
-- 
1.7.10.4



[dev] [st] Patch

2012-11-07 Thread Roberto E. Vargas Caballero
From 463bf62c9331f8a11e5dc41dc51b38f9746c45a3 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Wed, 7 Nov 2012 10:53:26 +0100
Subject: Clarify some or exclusive expressions

Since relational expresions are always evaluated to 0 or 1, we can use
bitwise xor operator instead of using more complex boolean expressions.
---
 st.c |   14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/st.c b/st.c
index af8bd9a..faaca74 100644
--- a/st.c
+++ b/st.c
@@ -1473,15 +1473,15 @@ tsetmode(bool priv, bool set, int *args, int narg) {
 break;
 			case 1049: /* = 1047 and 1048 */
 			case 47:
-			case 1047:
-if(IS_SET(MODE_ALTSCREEN))
+			case 1047: {
+bool alt = IS_SET(MODE_ALTSCREEN) != 0;
+if(alt)
 	tclearregion(0, 0, term.col-1, term.row-1);
-if((set  !IS_SET(MODE_ALTSCREEN)) ||
-		(!set  IS_SET(MODE_ALTSCREEN))) {
+if(set ^ alt)		/* set is always 1 or 0 */
 	tswapscreen();
-}
 if(*args != 1049)
 	break;
+			}
 /* pass through */
 			case 1048:
 tcursor((set) ? CURSOR_SAVE : CURSOR_LOAD);
@@ -2543,9 +2543,9 @@ drawregion(int x1, int y1, int x2, int y2) {
 	int ic, ib, x, y, ox, sl;
 	Glyph base, new;
 	char buf[DRAW_BUF_SIZ];
-	bool ena_sel = sel.bx != -1, alt = IS_SET(MODE_ALTSCREEN);
+	bool ena_sel = sel.bx != -1, alt = IS_SET(MODE_ALTSCREEN) != 0;
 
-	if((sel.alt  !alt) || (!sel.alt  alt))
+	if((sel.alt != 0) ^ alt)
 		ena_sel = 0;
 	if(!(xw.state  WIN_VISIBLE))
 		return;
-- 
1.7.10.4



[dev] [st] Keyboard patches

2012-11-13 Thread Roberto E. Vargas Caballero
Hello,

This is a new path series that fix some problems related to the
keyboard, and also add the key definitions that were missed in st.

Best regards.
From 22e55d15af79e23a6f78c685a2ed73c3f10db1e1 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Thu, 8 Nov 2012 16:32:28 +0100
Subject: Add SRM sequence

This sequence enable/disable the local echo.
---
 st.c |   76 --
 1 file changed, 56 insertions(+), 20 deletions(-)

diff --git a/st.c b/st.c
index 8b18607..8bf9337 100644
--- a/st.c
+++ b/st.c
@@ -110,17 +110,18 @@ enum glyph_state {
 };
 
 enum term_mode {
-	MODE_WRAP	= 1,
+	MODE_WRAP	 = 1,
 	MODE_INSERT  = 2,
 	MODE_APPKEYPAD   = 4,
 	MODE_ALTSCREEN   = 8,
-	MODE_CRLF	= 16,
+	MODE_CRLF	 = 16,
 	MODE_MOUSEBTN= 32,
 	MODE_MOUSEMOTION = 64,
 	MODE_MOUSE   = 32|64,
 	MODE_REVERSE = 128,
 	MODE_KBDLOCK = 256,
-	MODE_HIDE  = 512
+	MODE_HIDE	 = 512,
+	MODE_ECHO	 = 1024
 };
 
 enum escape_state {
@@ -320,6 +321,7 @@ static void tswapscreen(void);
 static void tsetdirt(int, int);
 static void tsetmode(bool, bool, int *, int);
 static void tfulldirt(void);
+static void techo(char *, int);
 
 static void ttynew(void);
 static void ttyread(void);
@@ -1534,7 +1536,8 @@ tsetmode(bool priv, bool set, int *args, int narg) {
 			case 4:  /* IRM -- Insertion-replacement */
 MODBIT(term.mode, set, MODE_INSERT);
 break;
-			case 12: /* XXX: SRM -- Send/Receive */
+			case 12: /* SRM -- Send/Receive */
+MODBIT(term.mode, !set, MODE_ECHO);
 break;
 			case 20: /* LNM -- Linefeed/new line */
 MODBIT(term.mode, set, MODE_CRLF);
@@ -1849,6 +1852,28 @@ tputtab(bool forward) {
 }
 
 void
+techo(char *buf, int len) {
+	for(; len  0; buf++, len--) {
+		char c = *buf;
+
+		if(c == '\033') {		/* escape */
+			tputc(^, 1);
+			tputc([, 1);
+		} else if (c  '\x20') {	/* control code */
+			if(c != '\n'  c != '\r'  c != '\t') {
+c |= '\x40';
+tputc(^, 1);
+			}
+			tputc(c, 1);
+		} else {
+			break;
+		}
+	}
+	if (len)
+		tputc(buf, len);
+}
+
+void
 tputc(char *c, int len) {
 	uchar ascii = *c;
 	bool control = ascii  '\x20' || ascii == 0177;
@@ -2679,7 +2704,7 @@ void
 kpress(XEvent *ev) {
 	XKeyEvent *e = ev-xkey;
 	KeySym ksym;
-	char buf[32], *customkey;
+	char xstr[31], buf[32], *customkey, *cp = buf;
 	int len, meta, shift, i;
 	Status status;
 
@@ -2688,7 +2713,7 @@ kpress(XEvent *ev) {
 
 	meta = e-state  Mod1Mask;
 	shift = e-state  ShiftMask;
-	len = XmbLookupString(xw.xic, e, buf, sizeof(buf), ksym, status);
+	len = XmbLookupString(xw.xic, e, xstr, sizeof(xstr), ksym, status);
 
 	/* 1. shortcuts */
 	for(i = 0; i  LEN(shortcuts); i++) {
@@ -2702,7 +2727,8 @@ kpress(XEvent *ev) {
 
 	/* 2. custom keys from config.h */
 	if((customkey = kmap(ksym, e-state))) {
-		ttywrite(customkey, strlen(customkey));
+		len = strlen(customkey);
+		memcpy(buf, customkey, len);
 	/* 2. hardcoded (overrides X lookup) */
 	} else {
 		switch(ksym) {
@@ -2714,34 +2740,44 @@ kpress(XEvent *ev) {
 			sprintf(buf, \033%c%c,
 IS_SET(MODE_APPKEYPAD) ? 'O' : '[',
 (shift ? dacb:DACB)[ksym - XK_Left]);
-			ttywrite(buf, 3);
+			len = 3;
 			break;
 		case XK_Insert:
-			if(shift)
+			if(shift) {
 selpaste();
+return;
+			}
+			memcpy(buf, xstr, len);
 			break;
 		case XK_Return:
+			len = 0;
 			if(meta)
-ttywrite(\033, 1);
+*cp++ = '\033', len++;
 
-			if(IS_SET(MODE_CRLF)) {
-ttywrite(\r\n, 2);
-			} else {
-ttywrite(\r, 1);
-			}
+			*cp++ = '\r', len++;
+
+			if(IS_SET(MODE_CRLF))
+*cp = '\n', len++;
 			break;
 			/* 3. X lookup  */
 		default:
-			if(len  0) {
-if(meta  len == 1)
-	ttywrite(\033, 1);
-ttywrite(buf, len);
-			}
+			if(len == 0)
+return;
+
+			if (len == 1  meta)
+*cp++ = '\033';
+
+			memcpy(cp, xstr, len);
+			len = cp - buf + len;
 			break;
 		}
 	}
+	ttywrite(buf, len);
+	if(IS_SET(MODE_ECHO))
+		techo(buf, len);
 }
 
+
 void
 cmessage(XEvent *e) {
 	/* See xembed specs
-- 
1.7.10.4

From f19b777a627598c1e94512b8e9027793e820b75d Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Fri, 9 Nov 2012 11:21:59 +0100
Subject: Fix keypad mode and cursor mode

Keypad mode is used for detecting when keys in the auxiliary keypad are
pressed, while cursor mode is used for detecting when a cursor is pressed,
but they are different modes.

St was mixing both modes and DECPAM and DECPNM modified the cursor mode, and
this was incorrect.
---
 st.c|5 +++--
 st.info |4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/st.c b/st.c
index 8bf9337..683a0e9 100644
--- a/st.c
+++ b/st.c
@@ -121,7 +121,8 @@ enum term_mode {
 	MODE_REVERSE = 128,
 	MODE_KBDLOCK = 256,
 	MODE_HIDE	 = 512,
-	MODE_ECHO	 = 1024
+	MODE_ECHO	 = 1024,
+	MODE_APPCURSOR	 = 2048
 };
 
 enum escape_state {
@@ -1471,7 +1472,7 @@ tsetmode(bool priv, bool set, int *args, int narg) {
 			switch(*args

Re: [dev] [st] Keyboard patches

2012-11-13 Thread Roberto E. Vargas Caballero
 The  patches  are removing the hardcoded values in st and make them more
 configurable to how terminals work. In the  future  important  shortcuts

Not only does this. There is some conditions that can not be handle with the
previous code. All the keypad keys can generate two values depend of the
keypad mode, one of them is the ansi sequence that the own terminal
understand for this function (KX_KP_Up generates \033[A, that is the
sequence for CUU), or one code that identify to the key (KX_KP_Up generates
\033Ox). This is done in this way because usual programs don't have to worry
about them, because they generate correct sequences and they don't need to
know if the sequence come from the key or the output of the program. But
when you are in raw mode you want to know what key was pressed, and the ansi
sequence does't give to you this information. you couldn't put any of these
values in the Key array because they depend of the keypad mode or cursor
mode, so the Key array was not useful.

 that  were  missed  but  some asshole is using them hardcoded in its so‐
 called »ncurses application« will be easier to add. But yes, most of  it
 is compatibility bloat.

I use a lot of these sequences. I know that it is not the typical usage of a
terminal emulator by a novice, but some of us have to use terminals for
other things. When you use telnet or ssh they disable the kernel echo in the
terminal and let to the other side the task of generating the
echo. Sometimes I have to connect to systems which don't generate the echo
(due to some reasons that are not important here) and It is very important
for me see what I am writing.

Best regards,



Re: [dev] [st] Keyboard patches

2012-11-14 Thread Roberto E. Vargas Caballero

This patch serie adds a lot of new keys and modify all the
previous. Although I have tested it deeply it is very possible that some of
them don't work (code error or terminfo entry error), like the tab key that
Christoph found, so it is necessary a lot of testing. Please if you find
some new error send the report here and I will try fix it.

Best regards,



[dev] [st] Fix the tab key

2012-11-14 Thread Roberto E. Vargas Caballero
Hello,

After last patch serie tab key was not working correctly and this
patch fix the problem. I also want to comment this line in kmap:

state = ~Mod2Mask

I don't know why this line is writing there, but it removes any combination
using Super key. I think it is necessary remove this line.

Best regards,



Re: [dev] [st] Fix the tab key

2012-11-14 Thread Roberto E. Vargas Caballero

I forgot the patch, sorry.


On Wed, Nov 14, 2012 at 11:08:27AM +0100, Roberto E. Vargas Caballero wrote:
 Hello,

   After last patch serie tab key was not working correctly and this
 patch fix the problem. I also want to comment this line in kmap:

   state = ~Mod2Mask

 I don't know why this line is writing there, but it removes any combination
 using Super key. I think it is necessary remove this line.

 Best regards,
From d87011d514e2e20a962d482bb432825bc713087b Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Wed, 14 Nov 2012 11:00:08 +0100
Subject: Fix tab key

When Shift + Tab is pressed X server send the event XK_ISO_Left_Tab with
ShiftMask, so this is the entry we need in config.def.h

This patch also revert the previous patch for this issue because it breaks
the keyboard.
---
 config.def.h |2 +-
 st.c |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/config.def.h b/config.def.h
index 7a785a3..68261a5 100644
--- a/config.def.h
+++ b/config.def.h
@@ -145,7 +145,7 @@ static Key key[] = {
 	{ XK_Right, ShiftMask,  \033[1;2C, 0,0,0},
 	{ XK_Right, ControlMask,\033[1;5C, 0,0,0},
 	{ XK_Right, Mod1Mask,   \033[1;3C, 0,0,0},
-	{ XK_Tab,   ShiftMask,  \033[Z,0,0,0},
+	{ XK_ISO_Left_Tab,  ShiftMask,  \033[Z,0,0,0},
 	{ XK_Return,XK_NO_MOD,  \n,0,0,   -1},
 	{ XK_Return,XK_NO_MOD,  \r\n,  0,0,   +1},
 	{ XK_Return,Mod1Mask,   \033\n,0,0,   -1},
diff --git a/st.c b/st.c
index ca4248a..932253c 100644
--- a/st.c
+++ b/st.c
@@ -2700,7 +2700,7 @@ kmap(KeySym k, uint state) {
 		if(kp-k != k)
 			continue;
 
-		if((state  mask) != mask ||
+		if((state  mask) != mask 
 (mask == XK_NO_MOD  state)) {
 			continue;
 		}
-- 
1.7.10.4



Re: [dev] [st] Fix the tab key

2012-11-15 Thread Roberto E. Vargas Caballero

Hello,

A new serie of patches that fix some problems detected in last serie:

- Tab problems
- Return problems in not newline modes
- arrow problems

Please, if you find some new errors (I am pretty sure something can happen)
notice me. This new series apply over the actual mercurial tip.

Best regards.
From 931003d3252ab1a0c97b762ae29c5f939db1de44 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Wed, 14 Nov 2012 11:00:08 +0100
Subject: Fix tab key

When Shift + Tab is pressed X server send the event XK_ISO_Left_Tab with
ShiftMask, so this is the entry we need in config.def.h

This patch also revert the previous patch for this issue because it breaks
the keyboard.
---
 config.def.h |2 +-
 st.c |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/config.def.h b/config.def.h
index 5d887fc..972285b 100644
--- a/config.def.h
+++ b/config.def.h
@@ -141,7 +141,7 @@ static Key key[] = {
 	{ XK_Right, ShiftMask,  \033[1;2C, 0,0,0},
 	{ XK_Right, ControlMask,\033[1;5C, 0,0,0},
 	{ XK_Right, Mod1Mask,   \033[1;3C, 0,0,0},
-	{ XK_Tab,   ShiftMask,  \033[Z,0,0,0},
+	{ XK_ISO_Left_Tab,  ShiftMask,  \033[Z,0,0,0},
 	{ XK_Return,XK_NO_MOD,  \n,0,0,   -1},
 	{ XK_Return,XK_NO_MOD,  \r\n,  0,0,   +1},
 	{ XK_Return,Mod1Mask,   \033\n,0,0,   -1},
diff --git a/st.c b/st.c
index ca4248a..932253c 100644
--- a/st.c
+++ b/st.c
@@ -2700,7 +2700,7 @@ kmap(KeySym k, uint state) {
 		if(kp-k != k)
 			continue;
 
-		if((state  mask) != mask ||
+		if((state  mask) != mask 
 (mask == XK_NO_MOD  state)) {
 			continue;
 		}
-- 
1.7.10.4

From b3c76defd2fc66584d221cadae3f8d85fb7fe0d5 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Thu, 15 Nov 2012 10:59:07 +0100
Subject: Fix XK_NO_MOD and XK_ANY_MOD behavior

XK_NO_MOD match a key without modifiers and XK_ANY_MOD match a key does not
matter what modifiers are pressed to. Like they are mask the best value for
XK_ANY_MOD is all the bits to 1, so the and with any state will be equal to
the state. This also imply that is necessary check the case for XK_NO_MOD
(no modifiers at all) with some modifier in state, and the inverse
(some mask different to XK_ANY_MOD or XK_NO_MOD and no modifiers in state).
---
 st.c |   12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/st.c b/st.c
index 932253c..b8b2bbf 100644
--- a/st.c
+++ b/st.c
@@ -59,8 +59,8 @@
 #define STR_ARG_SIZ   16
 #define DRAW_BUF_SIZ  20*1024
 #define UTF_SIZ   4
-#define XK_NO_MOD UINT_MAX
-#define XK_ANY_MOD0
+#define XK_ANY_MODUINT_MAX
+#define XK_NO_MOD 0
 
 #define REDRAW_TIMEOUT (80*1000) /* 80 ms */
 
@@ -2700,10 +2700,12 @@ kmap(KeySym k, uint state) {
 		if(kp-k != k)
 			continue;
 
-		if((state  mask) != mask 
-(mask == XK_NO_MOD  state)) {
+		if(mask == XK_NO_MOD  state)
+			continue;
+		if(mask != XK_ANY_MOD  mask != XK_NO_MOD  !state)
+			continue;
+		if((state  mask) != state)
 			continue;
-		}
 
 		if((kp-appkey  0  IS_SET(MODE_APPKEYPAD)) ||
 (kp-appkey  0  !IS_SET(MODE_APPKEYPAD))) {
-- 
1.7.10.4

From f752242029dc32ce6ce57bec3353e7f912931856 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Thu, 15 Nov 2012 11:09:36 +0100
Subject: Use XK_ANY_MOD instead of XK_NO_MOD in key definition

Usually terminal emulators don't generate any sequence for a combination
they don't have registered, for example Shift + Next, but st behavior
previous to the keyboard patch generates the sequence without the modifier,
in this example Next. This patch uses the XK_ANY_MOD in order to get this
same behaviour.
---
 config.def.h |  114 ++
 1 file changed, 59 insertions(+), 55 deletions(-)

diff --git a/config.def.h b/config.def.h
index 972285b..bd5a888 100644
--- a/config.def.h
+++ b/config.def.h
@@ -72,91 +72,95 @@ static unsigned int defaultucs = 257;
  * * 0: no value
  * *  0: crlf mode is enabled
  * *  0: crlf mode is disabled
+ *
+ * Be careful with the order of the definitons because st searchs in
+ * this table sequencially, so any XK_ANY_MOD must be in the last
+ * position for a key.
  */
 
 /* key, mask, output, keypad, cursor, crlf */
 static Key key[] = {
 	/* keysym mask string keypad cursor crlf */
-	{ XK_KP_Home,   XK_NO_MOD,  \033[H,0,0,0},
 	{ XK_KP_Home,   ShiftMask,  \033[1;2H, 0,0,0},
-	{ XK_KP_Up, XK_NO_MOD,  \033Ox,   +1,0,0},
-	{ XK_KP_Up, XK_NO_MOD,  \033[A,0,   -1,0},
-	{ XK_KP_Up, XK_NO_MOD,  \033OA,0,   +1,0},
-	{ XK_KP_Down,   XK_NO_MOD,  \033Or,   +1,0,0},
-	{ XK_KP_Down,   XK_NO_MOD

Re: [dev] [st] Add insert mode

2012-11-15 Thread Roberto E. Vargas Caballero
On Thu, Nov 15, 2012 at 03:25:52PM +0100, Eckehard Berns wrote:
 I added some code to make insert mode work in st. I don't know if I
 missed something, but It's Working For Me(tm). Patch attached.

I had a patch already ready for sending to solve this issue, but you were
faster ;). I put my code in tsetchar instead of tputc, but the code is
basically the same and the result is the same. It is ok.

Best regards.

 --
 Eckehard Berns

 diff -r 19ef42df8e7d st.c
 --- a/st.cWed Nov 14 06:37:24 2012 +0100
 +++ b/st.cThu Nov 15 15:19:52 2012 +0100
 @@ -2100,6 +2100,10 @@
   sel.bx = -1;
   if(IS_SET(MODE_WRAP)  term.c.state  CURSOR_WRAPNEXT)
   tnewline(1); /* always go to first col */
 + if(IS_SET(MODE_INSERT)  term.c.x+1  term.col)
 + memmove(term.line[term.c.y][term.c.x+1],
 + term.line[term.c.y][term.c.x],
 + (term.col - term.c.x - 1) * sizeof(Glyph));
   tsetchar(c, term.c.attr, term.c.x, term.c.y);
   if(term.c.x+1  term.col)
   tmoveto(term.c.x+1, term.c.y);
 diff -r 19ef42df8e7d st.info
 --- a/st.info Wed Nov 14 06:37:24 2012 +0100
 +++ b/st.info Thu Nov 15 15:19:52 2012 +0100
 @@ -153,6 +153,7 @@
   ritm=\E[23m,
   rmacs=\E(B,
   rmcup=\E[?1049l,
 + rmir=\E[4l,
   rmkx=\E[?1l\E,
   rmso=\E[23m,
   rmul=\E[m,
 @@ -168,6 +169,7 @@
   sitm=\E[3m,
   smacs=\E(0,
   smcup=\E[?1049h,
 + smir=\E[4h,
   smkx=\E[?1h\E=,
   smso=\E[3m,
   smul=\E[4m,



Re: [dev] [st] Add insert mode

2012-11-15 Thread Roberto E. Vargas Caballero
 What are you using this insert mode for?

The sequence for this mode was in st from historical times (before I met
it), it changes the st mode but does nothing. Maybe you should ask to
Aurielien why he implemented the set/reset sequences but not the behaviour.

Best regards,



Re: [dev] [st] Add insert mode

2012-11-15 Thread Roberto E. Vargas Caballero
 Ok, that seems like a legit feature. Which applications you encountered are
 using this mode? Only nvi and vi?

Theorically all good applications should use this mode, but in these days is
not always true. For example bash repaint the full line each time you write
a line, it is very funny when you run it in a 200bps line.



Re: [dev] [st] Fix the tab key

2012-11-15 Thread Roberto E. Vargas Caballero
On Thu, Nov 15, 2012 at 03:16:26PM +0100, Eckehard Berns wrote:
  Please, if you find some new errors (I am pretty sure something can happen)
  notice me.

 For me Shift+Insert inserts \E[2;2~ just before the selection.


I attach the patch which fix this problem.
From b06832d5f12d75daa8c640d91bc4ee97bad24bc2 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Thu, 15 Nov 2012 18:18:24 +0100
Subject: Fix Shift + Insert shortcut

This patch apply the same code for shortcuts that it is used now for defined
keys. So it is possible use now XK_NO_MOD and XK_ANY_MOD for defining shortcuts.
---
 st.c |   35 ---
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/st.c b/st.c
index ba93f2f..477a8f8 100644
--- a/st.c
+++ b/st.c
@@ -65,7 +65,6 @@
 #define REDRAW_TIMEOUT (80*1000) /* 80 ms */
 
 /* macros */
-#define CLEANMASK(mask) (mask  (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
 #define SERRNO strerror(errno)
 #define MIN(a, b)  ((a)  (b) ? (a) : (b))
 #define MAX(a, b)  ((a)  (b) ? (b) : (a))
@@ -329,6 +328,7 @@ static void tsetmode(bool, bool, int *, int);
 static void tfulldirt(void);
 static void techo(char *, int);
 
+static inline bool match(uint, uint);
 static void ttynew(void);
 static void ttyread(void);
 static void ttyresize(void);
@@ -2696,23 +2696,29 @@ focus(XEvent *ev) {
 	}
 }
 
+inline bool
+match(uint mask, uint state) {
+	if(mask == XK_NO_MOD  state)
+		return false;
+	if(mask != XK_ANY_MOD  mask != XK_NO_MOD  !state)
+		return false;
+	if((state  mask) != state)
+		return false;
+	return true;
+}
+
 char*
 kmap(KeySym k, uint state) {
 	uint mask;
 	Key *kp;
 
-	state = ~Mod2Mask;
 	for(kp = key; kp  key + LEN(key); kp++) {
 		mask = kp-mask;
 
 		if(kp-k != k)
 			continue;
 
-		if(mask == XK_NO_MOD  state)
-			continue;
-		if(mask != XK_ANY_MOD  mask != XK_NO_MOD  !state)
-			continue;
-		if((state  mask) != state)
+		if(!match(mask, state))
 			continue;
 
 		if((kp-appkey  0  IS_SET(MODE_APPKEYPAD)) ||
@@ -2741,21 +2747,20 @@ kpress(XEvent *ev) {
 	XKeyEvent *e = ev-xkey;
 	KeySym ksym;
 	char xstr[31], buf[32], *customkey, *cp = buf;
-	int len, i;
+	int len;
 	Status status;
+	Shortcut *bp;
 
 	if (IS_SET(MODE_KBDLOCK))
 		return;
 
 	len = XmbLookupString(xw.xic, e, xstr, sizeof(xstr), ksym, status);
-
+	e-state = ~Mod2Mask;
 	/* 1. shortcuts */
-	for(i = 0; i  LEN(shortcuts); i++) {
-		if((ksym == shortcuts[i].keysym)
- (CLEANMASK(shortcuts[i].mod) == \
-	CLEANMASK(e-state))
- shortcuts[i].func) {
-			shortcuts[i].func((shortcuts[i].arg));
+	for(bp = shortcuts; bp  shortcuts + LEN(shortcuts); bp++) {
+		if(ksym == bp-keysym  match(bp-mod, e-state)) {
+			bp-func((bp-arg));
+			return;
 		}
 	}
 
-- 
1.7.10.4



[dev] [st] some minor patches

2012-11-15 Thread Roberto E. Vargas Caballero
From fe3fa59836a389992cbf07f63a5007fb1e24f9e6 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Wed, 14 Nov 2012 19:20:28 +0100
Subject: Remove unused fields in cursor_movement

---
 st.c |4 
 1 file changed, 4 deletions(-)

diff --git a/st.c b/st.c
index 0a8382c..db21901 100644
--- a/st.c
+++ b/st.c
@@ -89,10 +89,6 @@ enum glyph_attribute {
 };
 
 enum cursor_movement {
-	CURSOR_UP,
-	CURSOR_DOWN,
-	CURSOR_LEFT,
-	CURSOR_RIGHT,
 	CURSOR_SAVE,
 	CURSOR_LOAD
 };
-- 
1.7.10.4

From fd65d3335331a2a4677494c5a232dfe32f815a23 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Thu, 15 Nov 2012 20:20:04 +0100
Subject: Fix speech error in comment

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

diff --git a/st.c b/st.c
index db21901..367ab51 100644
--- a/st.c
+++ b/st.c
@@ -2082,7 +2082,7 @@ tputc(char *c, int len) {
 			}
 		}
 		/*
-		 * All characters which forms part of a sequence are not
+		 * All characters which form part of a sequence are not
 		 * printed
 		 */
 		return;
-- 
1.7.10.4



[dev] [st] Home key

2012-11-16 Thread Roberto E. Vargas Caballero
This patch clean a bit the definition of Home key.
From 9eb08122011a9f2c19a5ba74208d73b6a1bde0f9 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Fri, 16 Nov 2012 09:11:25 +0100
Subject: Add application cursor sequences for Home

The commit 'Fixing some key issues with mc' fix the problem where mc didn't
recognize home key because the generated code and the terminfo entry were
different (terminfo khome = \E[1~ but generates \033[H).

Home key in ansi mode should generate the sequence CUP (\033[H) to 0,0 (home
position), but it is also interesting generate a application code which
identifies the key. Real vt520 only generates the ansi sequence CUP, linux
console generates only the application code \033[1~, xterm generates CUP in
ansi mode and \033OH in cursor application mode, rxvt only generates the
application code \033[7~.

This patch sets CUP in ansi mode and \033[1~ in cursor application mode, so
it can be used in both modes and the application mode value is similar to
near values (insert = \033[2~, Prior = \033[5~, Next = \033[6~, End =
\033[4~, Supr = \033[3).
---
 config.def.h |7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/config.def.h b/config.def.h
index 3a2e38b..023634e 100644
--- a/config.def.h
+++ b/config.def.h
@@ -98,7 +98,8 @@ static KeySym mappedkeys[] = { -1 };
 static Key key[] = {
 	/* keysym mask string keypad cursor crlf */
 	{ XK_KP_Home,   ShiftMask,  \033[1;2H, 0,0,0},
-	{ XK_KP_Home,   XK_ANY_MOD, \033[H,0,0,0},
+	{ XK_KP_Home,   XK_ANY_MOD, \033[H,0,   -1,0},
+	{ XK_KP_Home,   XK_ANY_MOD, \033[1~,   0,   +1,0},
 	{ XK_KP_Up, XK_ANY_MOD, \033Ox,   +1,0,0},
 	{ XK_KP_Up, XK_ANY_MOD, \033[A,0,   -1,0},
 	{ XK_KP_Up, XK_ANY_MOD, \033OA,0,   +1,0},
@@ -170,9 +171,9 @@ static Key key[] = {
 	{ XK_Insert,XK_ANY_MOD, \033[2~,   0,0,0},
 	{ XK_Delete,ShiftMask,  \033[3;2~, 0,0,0},
 	{ XK_Delete,XK_ANY_MOD, \033[3~,   0,0,0},
-	{ XK_Home,  XK_NO_MOD,  \033[1~,   0,0,0},
 	{ XK_Home,  ShiftMask,  \033[1;2H, 0,0,0},
-	{ XK_Home,  XK_ANY_MOD, \033[H,0,0,0},
+	{ XK_Home,  XK_ANY_MOD, \033[H,0,   -1,0},
+	{ XK_Home,  XK_ANY_MOD, \033[1~,   0,   +1,0},
 	{ XK_End,   ShiftMask,  \033[1;2F, 0,0,0},
 	{ XK_End,   XK_ANY_MOD, \033[4~,   0,0,0},
 	{ XK_Prior, XK_NO_MOD,  \033[5~,   0,0,0},
-- 
1.7.10.4



Re: [dev] [st] Terminus font

2012-11-25 Thread Roberto E. Vargas Caballero
On Sat, Nov 24, 2012 at 12:01:33AM +0400, p37si...@lavabit.com wrote:
 On Fri, Nov 23, 2012 at 02:27:28PM -0500, Carlos Torres wrote:
  That sounds like a fontconfig question,  you can probably set some options
  specific to terminus in your .fontconfig file

 Really, Terminus:file=ter-x16n.pcf.gz works.

Maybe this question could be in the FAQ file in the source tree of st.



[dev] [st] keymap patches

2012-11-25 Thread Roberto E. Vargas Caballero
Hello,

A new serie of patches which improves the ansi mode of st.

Best regards,
From 3410b47ebbdc92aadeed2841f001a02ea014a92c Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Fri, 16 Nov 2012 12:02:51 +0100
Subject: Fix value of ka1 terminfo capability

ka1 stands for upper left of keypad, so the correct value is the one
generated by Home in application keypad mode.
---
 st.info |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/st.info b/st.info
index bb8145b..d0064db 100644
--- a/st.info
+++ b/st.info
@@ -49,7 +49,7 @@ st| simpleterm,
 	invis=\E[8m,
 	is2=\E[4l\E,
 	it#8,
-	ka1=\E[E,
+	ka1=\E[1~,
 	ka3=\E[5~,
 	kc1=\E[4~,
 	kc3=\E[6~,
-- 
1.7.10.4

From 697eb4b5b1d5de3837e08d3d4deca437783df624 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Sun, 25 Nov 2012 11:01:58 +0100
Subject: Add support for insert key

Insert key stands for a key which allows enter or leaves insert mode, so let
it generates the correct sequence to change between these modes:

   - Insert: Enter in insert mode.
   - Shift + Insert: Leave insert mode (replace mode).
   - Control + Insert: Insert a blank line.

Like Shift + Insert also paste text, if a user want this feature be full
functional he has to modify such shortcut.
---
 config.def.h |   16 
 st.info  |3 +++
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/config.def.h b/config.def.h
index 7c55ef2..4eda119 100644
--- a/config.def.h
+++ b/config.def.h
@@ -121,8 +121,12 @@ static Key key= {
 	{ XK_KP_End,XK_ANY_MOD, \033[4~,   0,0,0},
 	{ XK_KP_Next,   ShiftMask,  \033[6;2~, 0,0,0},
 	{ XK_KP_Next,   XK_ANY_MOD, \033[6~,   0,0,0},
-	{ XK_KP_Insert, ShiftMask,  \033[2;2~, 0,0,0},
-	{ XK_KP_Insert, XK_ANY_MOD, \033[2~,   0,0,0},
+	{ XK_KP_Insert, ShiftMask,  \033[2;2~,+1,0,0},
+	{ XK_KP_Insert, ShiftMask,  \033[4l,  -1,0,0},
+	{ XK_KP_Insert, ControlMask,\033[L,   -1,0,0},
+	{ XK_KP_Insert, ControlMask,\033[2;5~,+1,0,0},
+	{ XK_KP_Insert, XK_ANY_MOD, \033[4h,  -1,0,0},
+	{ XK_KP_Insert, XK_ANY_MOD, \033[2~,  +1,0,0},
 	{ XK_KP_Delete, ShiftMask,  \033[3;2~, 0,0,0},
 	{ XK_KP_Delete, XK_ANY_MOD, \033[3~,   0,0,0},
 	{ XK_KP_Multiply,   XK_ANY_MOD, \033Oj,   +2,0,0},
@@ -169,8 +173,12 @@ static Key key= {
 	{ XK_Return,Mod1Mask,   \033\r\n,  0,0,   +1},
 	{ XK_Return,XK_ANY_MOD, \r,0,0,   -1},
 	{ XK_Return,XK_ANY_MOD, \r\n,  0,0,   +1},
-	{ XK_Insert,ShiftMask,  \033[2;2~, 0,0,0},
-	{ XK_Insert,XK_ANY_MOD, \033[2~,   0,0,0},
+	{ XK_Insert,ShiftMask,  \033[4l,  -1,0,0},
+	{ XK_Insert,ShiftMask,  \033[2;2~,+1,0,0},
+	{ XK_Insert,ControlMask,\033[L,   -1,0,0},
+	{ XK_Insert,ControlMask,\033[2;5~,+1,0,0},
+	{ XK_Insert,XK_ANY_MOD, \033[4h,  -1,0,0},
+	{ XK_Insert,XK_ANY_MOD, \033[2~,  +1,0,0},
 	{ XK_Delete,ShiftMask,  \033[3;2~, 0,0,0},
 	{ XK_Delete,XK_ANY_MOD, \033[3~,   0,0,0},
 	{ XK_Home,  ShiftMask,  \033[1;2H, 0,0,0},
diff --git a/st.info b/st.info
index d0064db..4fc9bdb 100644
--- a/st.info
+++ b/st.info
@@ -138,6 +138,9 @@ st| simpleterm,
 	kf62=\E[1;4Q,
 	kf63=\E[1;4R,
 	khome=\E[1~,
+	kil1=\E[2;5~,
+	krmir=\E[2;2~,
+	kich1=\E[2~,
 	knp=\E[6~,
 	kmous=\E[M,
 	kpp=\E[5~,
-- 
1.7.10.4

From daf1390655708013dafa003090b51156aea56e54 Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Sun, 25 Nov 2012 16:15:32 +0100
Subject: Add support for Supr key

Del : Delete character under cursor.
Shift + Del : Delete the line under cursor.
Ctrl + Del: Delete the full screen.
---
 config.def.h |   16 
 st.info  |2 ++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/config.def.h b/config.def.h
index 4eda119..755b316 100644
--- a/config.def.h
+++ b/config.def.h
@@ -127,8 +127,12 @@ static Key key= {
 	{ XK_KP_Insert, ControlMask,\033[2;5~,+1,0,0},
 	{ XK_KP_Insert, XK_ANY_MOD, \033[4h,  -1,0,0},
 	{ XK_KP_Insert, XK_ANY_MOD, \033[2~,  +1,0,0},
-	{ XK_KP_Delete, ShiftMask,  \033[3;2~, 0,0,0},
-	{ XK_KP_Delete, XK_ANY_MOD, \033[3~,   0,0,0},
+	{ XK_KP_Delete, ControlMask,\033[2J,  -1,0,0},
+	{ XK_KP_Delete, ControlMask,\033[3;5~,+1,0,0},
+	{ XK_KP_Delete, ShiftMask,  \033[2K,  +1,0,0},
+	{ XK_KP_Delete, ShiftMask

Re: [dev] [suckless] Migration to git

2012-11-26 Thread Roberto E. Vargas Caballero
  Dpb  on IRC showed me [0], which seems to do a near to perfect import of
  the old hg history. Anyone had bad experiences with this?

 I have experience with git and importing others vc to it, but I have never
 done it with Mercurial.


Uhmm, I have done it with st repository of course, I work with git against
the actual hg repository ^^!!!.



Re: [dev] [suckless] Migration to git

2012-11-26 Thread Roberto E. Vargas Caballero
 the following instructions depend on hggit module being installed
 and enabled
 in hgrc. fyi

 export hg repo to github
 
 $ hg log | grep ^user |sort -u |  sed -e 's, ,\t,g' |awk '{print
 $2=pancake panc...@nopcode.org}'  map
 $ vim map # remove user: and set=value
 $ hg convert -A map . _new
 $ cat map
 pancake=panc...@nopcode.org
 $ cd _new
 $ hg push git+ssh://g...@github.com/radare/acr
 $ git clone git://github.com/radare/acr
 $ git gc --aggressive
 [ recreate remote repo]
 $ git push --all


You need some extra steps. For example git needs a blank line between the
sumary and the rest of the commit message, or in other case you will see the
full description doing a git log --oneline. I have this problem git st
repository now. It is necessary doing some git filter-branch and fix some
stupid things like these.




Re: [dev] [suckless] Migration to git

2012-11-26 Thread Roberto E. Vargas Caballero
 if we're going to change vcs just to change, why not move back to darcs
 or something?  I'm still waiting for anyone to make any kind of case for
 changing to git other than lots of people use it.

I don't matter if the repositories change or not, I am using git now, but if
you want some reasons I am going to give you some of then:

- History rewriting: git rebase or git filter-branch
- Mail workflow support: git am, git format-patch or git email.
- Incremental commits: git add -i, git checkout -f.
- A diary of tip references: git reflog (this features saved my life a
  lot of times).
- Temporal changes: git stash.
- Be scriptable: git has a low-level set of commands that allow build
  any operation you need using a shell script : git commit-tree, git
  cat-file, git ls-tree ...

There are others reasons, like for example the speed changing between
branches, but they are not important in suckless projects.



Re: [dev] [suckless] Migration to git

2012-11-26 Thread Roberto E. Vargas Caballero
 The git source tree is more than four hundred percent bigger than the

are you comparing the size of a project in python with the size of a project
written in C?. The logical relation should be 2 times the size of hg, and
then you could say that they have a similar size.

 mercurial source tree.  git ships more than 160 *man pages*.  It is the

It is due to git keeps the api in small programs than you could use in your
scripts. These small programs are 100% Unix philosophy (do only one thing and
do it fine, write an output that can be used as input for other, ...). Work
with these low-level progams (plumbling in git vocabulary) is hard, and it
is the reason git have a 'user friendly' (porcelain in git vocabulary)
programs, which are pretty similar to these you can find in mercurial. If
you don't need an advanced use of git then you will read only the pages of
porcelain programs, whose number is similar to the programs in mercurial.

Maybe you like more have a library and have to link all the others programs
with it, and duplicate the work in all the binaries where the library is
linked, instead of using small programs.



Re: [dev] [suckless] Migration to git

2012-11-26 Thread Roberto E. Vargas Caballero

 All you've done is convince me that git is its own operating system.
 It's ludicrously complex and needlessly huge.  I don't care that it is
 trendy or popular with developers; most of the 'benefits' you listed are
 basically using git as though it were an entire disk filesystem.

I am going to stop this discussion because I think we will not gain anything
with it, but it is very funny that people here use the word 'complex' in some
religious way, and the things that they don't like directly are marked as
complex, without explaining why.



Re: [dev] Migration to git

2012-11-29 Thread Roberto E. Vargas Caballero
Quick question -
A long time ago I asked if it was possible to clone _all_ the hg
repositories without having to manually specify them from the suckless
site. The answer I got was no.
With the transfer to git, would it be possible for me to clone all of the
suckless repositories in one fell sweep?


This can be done easily with submodules. Both, git and hg, have support for
them, it is only necessary build the repository with the definition of the
submodules.



Re: [dev] Migration to git

2012-11-29 Thread Roberto E. Vargas Caballero
 How can be pathes for dwm  be managerd via git?
 I mean I need a patch queue somehow, I'm thinking branches, I'll
 create a local branch with my patches applied and I will hack
 through its history.

I usually work in this way. After generate the patch sequence I get the diff
with git format-patch and send them to the list, although now can be used
git send-email to. When the patches are applied in the main branch I join my
branch with the master branch with git rebase (I fetch the changes with git
fetch before, but it can be done in only one step with git pull --rebase,
but usually I prefer see the exact state of the repository before rebase the
master branch).


Best regards,



Re: [dev] [st] delete key didn't work correctly

2012-12-10 Thread Roberto E. Vargas Caballero
 Now, st's delete key didn't work, and I looked into the code long enough to
 say with confidence, there's nothing wrong with kmap().

I can see that you change the order of Delete definitions in your
patch. Theoretically this should not work because the keypdap column is
different. If your patch fixs the problem then we have other problem in kmap.

 Now great, the next problem is already here, in which HOME isn't working pro-
 perly in st + sandy, works in xterm and sandy, as well as in st + nano.

What value of value of TERM are you using?



Re: [dev] [st] Unexpected Insert key behavior in mc

2012-12-10 Thread Roberto E. Vargas Caballero
 It seems that in current version of st it is impossible to select files in mc
 using Insert key, instead it enters 4h in command prompt. I do not know why
 this happens, but I know that this did not happen in 0.2.

I have tested it with the HEAD and works fine for me. What value of TERM do you 
have?, and
are you sure you have installed last version of the terminfo definition?.



Re: [dev] [st] Unexpected Insert key behavior in mc

2012-12-10 Thread Roberto E. Vargas Caballero
  I did git pull before compiling today. Since I did not do install 
  previously
  I have tested it after doing install, thus with updated terminfo, it still 
  does
  not work correctly. My term is st-256color .
 

 same here with st-256color.

 I'm half way planning to look into this once more tonight. Thanks for
 the hint with mc, I'll use that (beside bash and sandy) for reference.
 Also also take note of entries in your ~/.terminfo which will take
 precedence afaik.

Could you send here the output of infocmp command?. If Insert or delete are not
working is due some mismatch between the values generated by st and the
terminfo entry. For delete the important value is dhc1, that should be \E[P;
in the instert case the important value is ich1, that should be \E[2~.

You can test what values st is generating using cat:

cat /dev/tty
^[= #this sequence enables the keypad application mode
^[[1h   #this sequence enables the cursor application mode
#you can check now what values each key generate

...
(^[ of counse means the esc key)



Re: [dev] [st] delete key didn't work correctly

2012-12-10 Thread Roberto E. Vargas Caballero
 On my machine, just toggling the keypad values on the delete lines
 worked at first (the ordering of them doesn't seem to matter for me),
 but then I did a make install and they stopped working. I copied over
 some old versions of st terminfo files (I can't remember from when)
 and they started working again. So is there a bug in the terminfo file
 also?


You can follow the discussion about this issue in Unexpected Insert key
behavior in mc thread, and if you can follow the steps that I give there
and send here the information, it should be great.

Thanks



Re: [dev] [st] Unexpected Insert key behavior in mc

2012-12-10 Thread Roberto E. Vargas Caballero
 Since we had these two discussions goin on parallel, my guts told me
 to revert my patch to config.h today. Then I did something a bit
 different. It now works for both sandy and mc correctly, likewise for
 DEL, INS and HOME which were making trouble yesterday. Attached is the
 patch which works here. Please test and report back.

Your patch is changing the idea of the table, and making others keys don't
work. Taken from the comment in config.def.h:

 * keypad value:
 * * 0: no value
 * *  0: keypad application mode enabled
 * *   = 2: term.numlock = 1
 * *  0: keypad application mode disabled


So, the changes:

 diff --git a/st.c b/st.c
 index fc64a77..43ce496 100644
 --- a/st.c
 +++ b/st.c
 @@ -2737,12 +2737,12 @@ kmap(KeySym k, uint state) {
   if(!match(mask, state))
   continue;

 - if(kp-appkey  0) {
 + if(kp-appkey  0) {
   if(!IS_SET(MODE_APPKEYPAD))
   continue;
   if(term.numlock  kp-appkey == 2)
   continue;
 - } else if (kp-appkey  0  IS_SET(MODE_APPKEYPAD)) {
 + } else if (kp-appkey  0  IS_SET(MODE_APPKEYPAD)) {
   continue;
   }

are making the table act in the reverse mode, changing it to:

 * keypad value:
 * * 0: no value
 * *  0: keypad application mode enabled
 * *   = 2: Does not matter because it is impossible enter in the first if...
 * *  0: keypad application mode disabled,

Doing that  XK_KP_0 until XK_KP_9 are not working any more, and for example
XK_End change its behaviour.


Please, could you send the information (infocmp and cat /dev/tty) I request
in the previous mail?. I suspect that maybe sandy is not writing the
sequence smkx, that is the sequence needed for putting the keypad in
application mode. I just have tested all the keys before these last patches
and it seems they were working fine.



[dev] [st] Add a newline to the string printed in die

2012-12-11 Thread Roberto E. Vargas Caballero
After a call to die the program exits and the shell take the control, so it
is better for the user the shell begins in an new line, and it is better for
the programmer don't have to explicitly add it in each call to die.
---
 st.c |   45 +++--
 1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/st.c b/st.c
index da5f78d..9789eef 100644
--- a/st.c
+++ b/st.c
@@ -431,7 +431,7 @@ xmalloc(size_t len) {
void *p = malloc(len);

if(!p)
-   die(Out of memory\n);
+   die(Out of memory);

return p;
 }
@@ -439,7 +439,7 @@ xmalloc(size_t len) {
 void *
 xrealloc(void *p, size_t len) {
if((p = realloc(p, len)) == NULL)
-   die(Out of memory\n);
+   die(Out of memory);

return p;
 }
@@ -449,7 +449,7 @@ xcalloc(size_t nmemb, size_t size) {
void *p = calloc(nmemb, size);

if(!p)
-   die(Out of memory\n);
+   die(Out of memory);

return p;
 }
@@ -890,6 +890,7 @@ die(const char *errstr, ...) {

va_start(ap, errstr);
vfprintf(stderr, errstr, ap);
+   fputc('\n', stderr);
va_end(ap);
exit(EXIT_FAILURE);
 }
@@ -934,7 +935,7 @@ sigchld(int a) {
int stat = 0;

if(waitpid(pid, stat, 0)  0)
-   die(Waiting for pid %hd failed: %s\n, pid, SERRNO);
+   die(Waiting for pid %hd failed: %s,   pid, SERRNO);

if(WIFEXITED(stat)) {
exit(WEXITSTATUS(stat));
@@ -950,11 +951,11 @@ ttynew(void) {

/* seems to work fine on linux, openbsd and freebsd */
if(openpty(m, s, NULL, NULL, w)  0)
-   die(openpty failed: %s\n, SERRNO);
+   die(openpty failed: %s, SERRNO);

switch(pid = fork()) {
case -1:
-   die(fork failed\n);
+   die(fork failed);
break;
case 0:
setsid(); /* create a new process group */
@@ -962,7 +963,7 @@ ttynew(void) {
dup2(s, STDOUT_FILENO);
dup2(s, STDERR_FILENO);
if(ioctl(s, TIOCSCTTY, NULL)  0)
-   die(ioctl TIOCSCTTY failed: %s\n, SERRNO);
+   die(ioctl TIOCSCTTY failed: %s, SERRNO);
close(s);
close(m);
execsh();
@@ -1004,7 +1005,7 @@ ttyread(void) {

/* append read bytes to unprocessed bytes */
if((ret = read(cmdfd, buf+buflen, LEN(buf)-buflen))  0)
-   die(Couldn't read from shell: %s\n, SERRNO);
+   die(Couldn't read from shell: %s, SERRNO);

/* process every complete utf8 char */
buflen += ret;
@@ -1024,7 +1025,7 @@ ttyread(void) {
 void
 ttywrite(const char *s, size_t n) {
if(write(cmdfd, s, n) == -1)
-   die(write error on tty: %s\n, SERRNO);
+   die(write error on tty: %s, SERRNO);
 }

 void
@@ -2204,7 +2205,7 @@ xloadcols(void) {
if(!colorname[i])
continue;
if(!XftColorAllocName(xw.dpy, xw.vis, xw.cmap, colorname[i], 
dc.col[i])) {
-   die(Could not allocate color '%s'\n, colorname[i]);
+   die(Could not allocate color '%s', colorname[i]);
}
}

@@ -2216,7 +2217,7 @@ xloadcols(void) {
color.green = g == 0 ? 0 : 0x3737 + 0x2828 * g;
color.blue = b == 0 ? 0 : 0x3737 + 0x2828 * b;
if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, 
color, dc.col[i])) {
-   die(Could not allocate color %d\n, i);
+   die(Could not allocate color %d, i);
}
i++;
}
@@ -2227,7 +2228,7 @@ xloadcols(void) {
color.red = color.green = color.blue = 0x0808 + 0x0a0a * r;
if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, color,
dc.col[i])) {
-   die(Could not allocate color %d\n, i);
+   die(Could not allocate color %d, i);
}
}
 }
@@ -2314,7 +2315,7 @@ xloadfonts(char *fontstr, int fontsize) {
}

if(!pattern)
-   die(st: can't open font %s\n, fontstr);
+   die(st: can't open font %s, fontstr);

if(fontsize  0) {
FcPatternDel(pattern, FC_PIXEL_SIZE);
@@ -2335,7 +2336,7 @@ xloadfonts(char *fontstr, int fontsize) {
}

if(xloadfont(dc.font, pattern))
-   die(st: can't open font %s\n, fontstr);
+   die(st: can't open font %s, fontstr);

/* Setting character width and height. */
xw.cw = dc.font.width;
@@ -2344,16 +2345,16 @@ xloadfonts(char *fontstr, int fontsize) {
FcPatternDel(pattern, FC_WEIGHT);

Re: [dev] [st] Add a newline to the string printed in die

2012-12-11 Thread Roberto E. Vargas Caballero

 No,  this will change the die() behaviour between all suckless projects.

Then, change die in all the projects, it is the usual way of working with
other issues, no?

 Please send patches as attached files.

Since we are using now git, it is easier and logic send the patches in this
way, so the code of the patch can be included and modified in replies. You
only have to use git am if you want to incorpore then to the main repository
,and it will keep the correct author and commiter, that I can see this
information is lost now (I think it is not the correct way put a 'thanks' in
the commit message).

Best regards,



Re: [dev] [st] Shift Tab does not work

2012-12-13 Thread Roberto E. Vargas Caballero

 But, it's error-prone to have two places to keep track of what keys
 get mapped.  So, I fixed this for myself a while ago by removing
 mappedkeys entirely.  Patch attached.


I agree with you that it is error-prone, but if we remove it then each time
a key is pressed it is necessary look up in table, but the usual case (a
latin key) it is the worst case, look in the table until the end. Since
keyboard typing depend of the user, it is not a big problem (good typists
can type 200 keys per minute) so the performance penalty will not be able
noticeable. Doing a binary search (bsearch call) is not easy, since define a
order in these key assignation is hard, so I think the best strategy is the
sequencial search.

My suggestion is applying your patch and try get a better solution.



[dev] [st] About some bugsy programs and st

2012-12-14 Thread Roberto E. Vargas Caballero

In the last days some persons have comment that they have problems with
the Delete key in bash or irssi. In this case, it is not a problem of st,
but a problem of bash or irssi. Taken from terminfo:

If  the terminal has a keypad that transmits codes when the keys
are pressed, this information can be given.  Note that it is not
possible to handle terminals where  the  keypad only  works  in
local (this applies, for example, to the unshifted HP 2621 keys).
If the keypad can be set to transmit or not transmit, give these
codes as smkx and rmkx.  Otherwise  the  keypad is assumed to
always transmit.


In our case smkx=\E[?1h\E= and rmkx=\E[?1l\E, so it is mandatory that
programs which want to test against keypad keys, have to send these
sequences. But bugsy bash and irssi for example don't do it. A fast
solution is write this command:

$ echo ^[?1h^[= /dev/tty

And all the problems will be removed. In the case of bash reading the 
manpage of readline you can see this text:

   enable-keypad (Off)
When  set  to  On,  readline  will try to enable the
application keypad when it is called.  Some systems
need this to enable the arrow keys.

so, adding this option in your .inputrc you will fix the problem with 
all applications which use readline. In the case of irssi this tip will
not help.


Some persons say that we should fix st and remove this problem (it is
very easy change the key assignament), but I don't agree. I think that
the problem is such applications which don't follow the terminfo rules,
so they should fix their problems.

I would like listen what think the people about this issue because it
begins to be a very common conversation point.


Thanks.



Re: [dev] [st] font fallback

2013-01-05 Thread Roberto E. Vargas Caballero
 That’s only partially true. The array is adding 48k, which another patch
 series will reduce. Most of the additional memory usage is  due  to  the
 font  handling. So the inability of font handling in X.org/Fontconfig is
 the reason why too much has to be done over and over again. Yet  another
 abstraction layer would hide it but waste the same resources.

 But unless I'm mistaken, the static arrays go in the .data or .bss
 section (which also increased, but not by 16x.)

The bbs segment is not present in the executable. All the static data not
initialized go to this segment, and the first thing that the executable does
is a memset to 0 of the bbs segment. The executable only has the definition
of the segment, begin address and size. This is the reason why is not the
same these declarations:


 static int dummy;

 static int dummy = 0;


The first goes to bbs and it is not present in the executable, and the
second goes to data and it is present in the executable (of course some
compilers can optimize it).



Re: [dev] [st] zsh and del/pos1 key

2013-01-06 Thread Roberto E. Vargas Caballero
On Sun, Jan 06, 2013 at 09:43:49PM +0400, p37si...@lavabit.com wrote:
 This patch fixes it for me.  Don't know how to fix it correctly yet.

Please take a look to this message in the list:

   http://lists.suckless.org/dev/1212/13848.html


Maybe we should add the information in the FAQ.



Re: [dev] [st] Vim background color doesn't fill entire line

2013-01-06 Thread Roberto E. Vargas Caballero
except one tiny thing: the background color of the text in Vim would not
fill in anything that wasn't a character. In Vim I have it set to a gray
and my term is black. Any ideas to properly fix this instead of changing
my term color? I would try and fix this myself but I have no experience

The important here is how vim is setting the background color. You can
send a log of the session using the -o switch.



Re: [dev] [st] zsh and del/pos1 key

2013-01-07 Thread Roberto E. Vargas Caballero
On Mon, Jan 07, 2013 at 08:47:08AM +0100, Roberto E. Vargas Caballero wrote:
 On Sun, Jan 06, 2013 at 09:43:49PM +0400, p37si...@lavabit.com wrote:
  This patch fixes it for me.  Don't know how to fix it correctly yet.

 Please take a look to this message in the list:

http://lists.suckless.org/dev/1212/13848.html


 Maybe we should add the information in the FAQ.


And here is the patch.
From 5fc234fb9674ded207fb39964b23d9eeec94bd8f Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Mon, 7 Jan 2013 09:07:52 +0100
Subject: Add info about Del key in the FAQ.

---
 FAQ |   31 +++
 1 file changed, 31 insertions(+)

diff --git a/FAQ b/FAQ
index b624145..e630d9f 100644
--- a/FAQ
+++ b/FAQ
@@ -37,4 +37,35 @@ back mode aka “copy mode”, it’s C-a ESC. You probably want defscrollback
 [0] http://en.wikipedia.org/wiki/GNU_Screen
 [1] http://en.wikipedia.org/wiki/Tmux
 --
+Why Del key doesn't work in some programs?
 
+Taken from terminfo:
+
+	If the terminal has a keypad that transmits codes when the keys
+	are pressed, this information can be given. Note that it is not
+	possible to handle terminals where the keypad only works in
+	local (this applies, for example, to the unshifted HP 2621 keys).
+	If the keypad can be set to transmit or not transmit, give these
+	codes as smkx and rmkx. Otherwise the keypad is assumed to
+	always transmit.
+
+
+In our case smkx=\E[?1h\E= and rmkx=\E[?1l\E, so it is mandatory that
+programs which want to test against keypad keys, have to send these
+sequences. But bugsy bash and irssi for example don't do it. A fast
+solution is write this command:
+
+	$ echo ^[?1h^[= /dev/tty
+
+And all the problems will be removed. In the case of bash reading the
+manpage of readline you can see this text:
+
+   enable-keypad (Off)
+		When set to On, readline will try to enable the
+		application keypad when it is called. Some systems
+		need this to enable the arrow keys.
+
+so, adding this option in your .inputrc you will fix the problem with
+all applications which use readline. In the case of irssi this tip will
+not help.
+--
-- 
1.7.10.4



Re: [dev] [st] zsh and del/pos1 key

2013-01-07 Thread Roberto E. Vargas Caballero
 Roberto E. Vargas Caballero:
   http://lists.suckless.org/dev/1212/13848.html

 This works for Del in bash.
 But it doesn't fix Pos1 or Del in zsh.


Even echo ^[?1h^[= /dev/tty command? (^[ means \01b, you can get it using ^v 
Esc)

In the thread we agreed that we should point the bug to the programs which
don't handle correctly the keypad, so you could send a patch request to zsh.


Best regards,



Re: [dev] [st] Shift+F1 should by F11?

2013-01-10 Thread Roberto E. Vargas Caballero
On Wed, Jan 09, 2013 at 10:59:59AM +, Mihail Zenkov wrote:
 I have problem in mc with Shift+Fx. In st Shift+F6 generate code for
 F18 but mc wait F16 for it.

 From http://aperiodic.net/phil/archives/Geekery/term-function-keys.html

 Shift-F1 through Shift-F10 function as F11 through F20 and generate escape 
 codes from ^[[23~ to ^[[34~, just like the VT220. Note that this means there 
 are two ways to get F11 and F12. (Actually, there are three, since Shift-F11 
 and Shift-F12 are also equivalent to F11 and F12.)


 I also check in pure console (without X): Shift+F1 = F11, Shift+F2 = F12


The case of the function keys is a problem in all the terminal
emulators. Original vt100 hasn't any function key, and vt102 has 12 function
keys, but the first 4 (PF1-4) were local function keys, they never generate
a code that a program could test, only generate code you could program for
them. These is the reason xterm generates F1-4:

kf1=\EOP,
kf2=\EOQ,
kf3=\EOR,
kf4=\EOS,

the default value for PF1-PF4 in a vt102, while for F5-12 it generates the
value for F5-12 in a vt220:

kf5=\E[15~,
kf6=\E[17~,
kf7=\E[18~,
kf8=\E[19~,
kf9=\E[20~,
kf10=\E[21~,
kf11=\E[23~,
kf12=\E[24~,

From this point, we have a problem because in terminfo definition you can
not specify what values generate the terminal for shifted and controled
versions of these keys. So any program that test such combinations are not
portable by definition.

I have tested xterm and it generates:

Shift-F1 = ^[[1;2P
F11 = ^[[23~

and st generates:

Shift-F1 = ^[[1;2P
F11 = ^[[23~

and the terminfo entry for xterm:

kf11=\E[23~
kf13=\E[1;2P

and st terminfor entry:

kf11=\E[23~
kf13=\E[1;2P

So they generates the same sequences in the case of Shift-F1, the value for
kf13 and not the value for kf11 like you are reporting. Reading the link you
posted:

Shift-F1 through Shift-F12 were used for F13 through F24, and
generated codes from ^[[11;2~ to ^[[24;2~. Similarly Ctrl-F1 through
Ctrl-F12 were used for F25 through F36 and generated codes ^[[11;5~
to ^[[24;5~, and Ctrl-Shift-F1 through Ctrl-Shift-F12 were used for
F37 through F48 and generated codes ^[[11;6~ to ^[[24;6

In this moment he is talking about the old key generating of xterm, but a
bit later you can find that he says:


Since the original VT220 didn't have F1 through F5, the XFree86 xterm 
uses
the escape sequences from the VT100's PF1 through PF4 for F1 through F4
while retaining the VT220-based escape sequences from the X Consortium 
xterm
for F5 through F12. So the differences from the earlier xterms are: F1
through F4 generate escape codes ^[OP through ^[OS, F13 to F16 generate
^[O2P to ^[O2S, F25 to F28 generate ^[O5P to ^[O5S, and F37 to F40 
generate
^[O6P to ^[O6S


But I have tested it in my version of xterm and it works in a different
way. In both cases (new and old function keys) it generates for F11 and
Shift-F1 the sequences I wrote before (I haven't a F13 key so I can not test
it).

I have also tested in the virtual terminal of the kenel (you called it 'pure
console') and I get the values you said:


  Shift-F1 = ^[[25~
  F11 = ^[[23~

I can see that the terminfo entry linux virtual terminal is:

kf11=\E[23~
kf13=\E[25

so in this case Shift-F1 also generates F13, but with a different value. In
both cases it should work if the binding is made to F13, but if you bind
something to Shift-F1 it will work or not.



Re: [dev] [st] Shift+F1 should by F11?

2013-01-11 Thread Roberto E. Vargas Caballero
On Thu, Jan 10, 2013 at 04:29:08PM +, Mihail Zenkov wrote:
 I also find in https://www.midnight-commander.org/wiki/roadmap:

  Use KDGKBENT ioctl on Linux console to find the mapping for shifted 
  functional keys.
  Two mappings are widely used (Shift-F1 = F11 and Shift-F1 = F13). mc should
  adjust the keys to the mapping.

 In this case this problem in mc. But Roberto say:
  From this point, we have a problem because in terminfo definition you can
  not specify what values generate the terminal for shifted and controled
  versions of these keys. So any program that test such combinations are not
  portable by definition.

 Any know how this case can by detected for x-terminals?


It can't be detected. You posted how mc has dedicated definitions for each
terminal. In your case was:

  /usr/share/mc/mc.lib:
[terminal:linux]
f15=\\e[28~
[terminal:xterm]
f15=\\e[28~;\\e[15\;2~


I suppouse mc look what terminal is running (using $TERM) and do dedicated
things for it. Since mc don't have support for st (yet ;)), the only
solution you have is doing local modifications to your config.h and get a st
similar to your xterm. Like I said, this kind of things are not portable,
and some sequences will work for you, but will not work for others. I
usually avoid this kind of binding due to this problem.

It is similar to the case of arrow keys in emacs, Shift-left doesn't work in
emacs under st with TERM=st, but it works in st with TERM=xterm (and I am
pretty sure is not a problem of the definition of terminfo).



Re: [dev] [st] zsh and del/pos1 key

2013-01-14 Thread Roberto E. Vargas Caballero
 This works for Del in bash.
 But it doesn't fix Pos1 or Del in zsh.


You can find the information in the zsh FAQ
(http://zsh.sourceforge.net/FAQ/zshfaq03.html#l25) about how get it working
with terminals with smkx and rmkx sequences.

I also add the patch to the st FAQ with the information.
From 6c8ebf8f9e8842a1278a769fce18408702082fdb Mon Sep 17 00:00:00 2001
From: Roberto E. Vargas Caballero k...@shike2.com
Date: Mon, 14 Jan 2013 11:37:18 +0100
Subject: [PATCH] Add information about zsh keymap solution

In the FAQ you can find some information about how get your bugsy bash be
able of reading Del key, and this patch adds the same information for the
also bugsy zsh. It also change the echo command by a standard printf without
special characters, so it is possible copy and paste the commands to the
shell.
---
 FAQ |   29 -
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/FAQ b/FAQ
index e630d9f..f7476dc 100644
--- a/FAQ
+++ b/FAQ
@@ -55,10 +55,11 @@ programs which want to test against keypad keys, have to send these
 sequences. But bugsy bash and irssi for example don't do it. A fast
 solution is write this command:
 
-	$ echo ^[?1h^[= /dev/tty
+	$ printf \033?1h\033= /dev/tty
 
-And all the problems will be removed. In the case of bash reading the
-manpage of readline you can see this text:
+And all the problems will be removed.
+
+In the case of bash reading the manpage of readline you can see this text:
 
enable-keypad (Off)
 		When set to On, readline will try to enable the
@@ -66,6 +67,24 @@ manpage of readline you can see this text:
 		need this to enable the arrow keys.
 
 so, adding this option in your .inputrc you will fix the problem with
-all applications which use readline. In the case of irssi this tip will
-not help.
+all applications which use readline.
+
+You can read in the zsh FAQ (http://zsh.sourceforge.net/FAQ/zshfaq03.html#l25):
+
+	It should be noted that the O / [ confusion can occur with other keys
+	such as Home and End. Some systems let you query the key sequences
+	sent by these keys from the system's terminal database, terminfo.
+	Unfortunately, the key sequences given there typically apply to the
+	mode that is not the one zsh uses by default (it's the application
+	mode rather than the raw mode). Explaining the use of terminfo is
+	outside the scope of this FAQ, but if you wish to use the key
+	sequences given there you can tell the line editor to turn on
+	application mode when it starts and turn it off when it stops:
+
+		function zle-line-init () { echoti smkx }
+		function zle-line-finish () { echoti rmkx }
+		zle -N zle-line-init
+		zle -N zle-line-finish
+
+So putting these options in your .zshrc you will fix the problem.
 --
-- 
1.7.10.4



  1   2   3   4   5   6   7   8   >