From 9b63dd9f435408caf3f91b4dfa9144a611302dd6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aur=C3=A9lien=20Aptel?= Date: Sun, 3 Apr 2011 21:00:55 +0200 Subject: [PATCH 01/16] fix utf8 clipboard. (thx Petr Sabata) --- st.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st.c b/st.c index ed750e6..d0f2f5e 100644 --- a/st.c +++ b/st.c @@ -483,7 +483,7 @@ selrequest(XEvent *e) { XA_ATOM, 32, PropModeReplace, (unsigned char *) &string, 1); xev.property = xsre->property; - } else if(xsre->target == XA_STRING) { + } else if(xsre->target == sel.xtarget) { XChangeProperty(xsre->display, xsre->requestor, xsre->property, xsre->target, 8, PropModeReplace, (unsigned char *) sel.clip, strlen(sel.clip)); -- 2.20.1 From 89c8a3a2d9735fe10bcd85b90c8405fa20b4199e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aur=C3=A9lien=20Aptel?= Date: Sun, 3 Apr 2011 21:03:48 +0200 Subject: [PATCH 02/16] take BORDER into account for selection. (thx Petr Sabata) --- st.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/st.c b/st.c index d0f2f5e..a6fb766 100644 --- a/st.c +++ b/st.c @@ -392,8 +392,8 @@ getbuttoninfo(XEvent *e, int *b, int *x, int *y) { if(b) *b = e->xbutton.button; - *x = e->xbutton.x/xw.cw; - *y = e->xbutton.y/xw.ch; + *x = (e->xbutton.x - BORDER)/xw.cw; + *y = (e->xbutton.y - BORDER)/xw.ch; sel.b.x = sel.by < sel.ey ? sel.bx : sel.ex; sel.b.y = MIN(sel.by, sel.ey); sel.e.x = sel.by < sel.ey ? sel.ex : sel.bx; @@ -403,8 +403,8 @@ getbuttoninfo(XEvent *e, int *b, int *x, int *y) { void bpress(XEvent *e) { sel.mode = 1; - sel.ex = sel.bx = e->xbutton.x/xw.cw; - sel.ey = sel.by = e->xbutton.y/xw.ch; + sel.ex = sel.bx = (e->xbutton.x - BORDER)/xw.cw; + sel.ey = sel.by = (e->xbutton.y - BORDER)/xw.ch; } void -- 2.20.1 From 73e37f562964c2d1cb6029693d1d79a69a22ff14 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aur=C3=A9lien=20Aptel?= Date: Sun, 3 Apr 2011 21:04:45 +0200 Subject: [PATCH 03/16] update VERSION. --- config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.mk b/config.mk index 01a3779..ea5b5ef 100644 --- a/config.mk +++ b/config.mk @@ -1,5 +1,5 @@ # st version -VERSION = 0.0 +VERSION = 0.1.1 # Customize below to fit your system -- 2.20.1 From 742a4a18c2a071bf48133a7db6791ec7b74c68b4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aur=C3=A9lien=20Aptel?= Date: Sun, 3 Apr 2011 21:05:41 +0200 Subject: [PATCH 04/16] quick bug-fixing 0.1.1 release. --- .hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgtags b/.hgtags index 66ee2f3..4959fd3 100644 --- a/.hgtags +++ b/.hgtags @@ -1 +1,2 @@ cbc18c988236c63a58ed24031805e8d36a3ad01a 0.1 +f245ac2efd8ac2f1ac6bffae876c2663e794f79d 0.1.1 -- 2.20.1 From d3c5aba2d9b0f6046e4cc72fb056cbd56c6314e6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aur=C3=A9lien=20Aptel?= Date: Sun, 3 Apr 2011 21:40:33 +0200 Subject: [PATCH 05/16] update README. --- README | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README b/README index 09a7fff..f6c5d78 100644 --- a/README +++ b/README @@ -21,7 +21,14 @@ necessary as root): Running st ---------- -See the man page for details. +If you don't install st, define TNAME to "xterm" in config.h or make sure to at +least compile st terminfo entry with the following command: + + tic -s st.info + +It should print the path of the compiled terminfo entry. You can +safely remove it if you don't plan to use st anymore. +See the man page for additional details. Credits ------- -- 2.20.1 From 9d5ea14b9dffac863b41432e4ce12b5624592000 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aur=C3=A9lien=20Aptel?= Date: Fri, 22 Apr 2011 00:18:53 +0200 Subject: [PATCH 06/16] selection clicks, shift+arrow keys, fast(er) redraw, key mask in config.h (thx Magnus Leuthner) --- config.def.h | 47 ++++++++++-------- st.c | 136 ++++++++++++++++++++++++++++++++++++--------------- st.info | 4 ++ 3 files changed, 126 insertions(+), 61 deletions(-) diff --git a/config.def.h b/config.def.h index ced3000..c1afd88 100644 --- a/config.def.h +++ b/config.def.h @@ -26,32 +26,33 @@ static const char *colorname[] = { }; /* Default colors (colorname index) */ -/* foreground, background, cursor */ +/* foreground, background, cursor */ #define DefaultFG 7 #define DefaultBG 0 #define DefaultCS 1 -/* Special keys */ +/* Special keys (change & recompile st.info accordingly) */ +/* key, mask, output */ static Key key[] = { - { XK_BackSpace, "\177" }, - { XK_Insert, "\033[2~" }, - { XK_Delete, "\033[3~" }, - { XK_Home, "\033[1~" }, - { XK_End, "\033[4~" }, - { XK_Prior, "\033[5~" }, - { XK_Next, "\033[6~" }, - { XK_F1, "\033OP" }, - { XK_F2, "\033OQ" }, - { XK_F3, "\033OR" }, - { XK_F4, "\033OS" }, - { XK_F5, "\033[15~" }, - { XK_F6, "\033[17~" }, - { XK_F7, "\033[18~" }, - { XK_F8, "\033[19~" }, - { XK_F9, "\033[20~" }, - { XK_F10, "\033[21~" }, - { XK_F11, "\033[23~" }, - { XK_F12, "\033[24~" }, + { XK_BackSpace, 0, "\177" }, + { XK_Insert, 0, "\033[2~" }, + { XK_Delete, 0, "\033[3~" }, + { XK_Home, 0, "\033[1~" }, + { XK_End, 0, "\033[4~" }, + { XK_Prior, 0, "\033[5~" }, + { XK_Next, 0, "\033[6~" }, + { XK_F1, 0, "\033OP" }, + { XK_F2, 0, "\033OQ" }, + { XK_F3, 0, "\033OR" }, + { XK_F4, 0, "\033OS" }, + { XK_F5, 0, "\033[15~" }, + { XK_F6, 0, "\033[17~" }, + { XK_F7, 0, "\033[18~" }, + { XK_F8, 0, "\033[19~" }, + { XK_F9, 0, "\033[20~" }, + { XK_F10, 0, "\033[21~" }, + { XK_F11, 0, "\033[23~" }, + { XK_F12, 0, "\033[24~" }, }; /* Line drawing characters (sometime specific to each font...) */ @@ -61,3 +62,7 @@ static char gfx[] = { ['i'] = '#', [255] = 0, }; + +/* double-click timeout (in milliseconds) between clicks for selection */ +#define DOUBLECLICK_TIMEOUT 300 +#define TRIPLECLICK_TIMEOUT (2*DOUBLECLICK_TIMEOUT) diff --git a/st.c b/st.c index a6fb766..11ea9fc 100644 --- a/st.c +++ b/st.c @@ -22,6 +22,9 @@ #include #include +#include +#include + #if defined(__linux) #include #elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) @@ -45,11 +48,12 @@ #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) < (b) ? (b) : (a)) #define LEN(a) (sizeof(a) / sizeof(a[0])) -#define DEFAULT(a, b) (a) = (a) ? (a) : (b) +#define DEFAULT(a, b) (a) = (a) ? (a) : (b) #define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b)) #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x) #define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg) #define IS_SET(flag) (term.mode & (flag)) +#define TIMEDIFFERENCE(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + (t1.tv_usec-t2.tv_usec)/1000) /* Attribute, Cursor, Character state, Terminal mode, Screen draw mode */ enum { ATTR_NULL=0 , ATTR_REVERSE=1 , ATTR_UNDERLINE=2, ATTR_BOLD=4, ATTR_GFX=8 }; @@ -57,10 +61,9 @@ enum { CURSOR_UP, CURSOR_DOWN, CURSOR_LEFT, CURSOR_RIGHT, CURSOR_SAVE, CURSOR_LOAD }; enum { CURSOR_DEFAULT = 0, CURSOR_HIDE = 1, CURSOR_WRAPNEXT = 2 }; enum { GLYPH_SET=1, GLYPH_DIRTY=2 }; -enum { MODE_WRAP=1, MODE_INSERT=2, MODE_APPKEYPAD=4, MODE_ALTSCREEN=8, +enum { MODE_WRAP=1, MODE_INSERT=2, MODE_APPKEYPAD=4, MODE_ALTSCREEN=8, MODE_CRLF=16 }; enum { ESC_START=1, ESC_CSI=2, ESC_OSC=4, ESC_TITLE=8, ESC_ALTCHARSET=16 }; -enum { SCREEN_UPDATE, SCREEN_REDRAW }; enum { WIN_VISIBLE=1, WIN_REDRAW=2, WIN_FOCUSED=4 }; #undef B0 @@ -87,21 +90,21 @@ typedef struct { /* ESC '[' [[ [] [;]] ] */ typedef struct { char buf[ESC_BUF_SIZ]; /* raw string */ - int len; /* raw string length */ + int len; /* raw string length */ char priv; int arg[ESC_ARG_SIZ]; - int narg; /* nb of args */ + int narg; /* nb of args */ char mode; } CSIEscape; /* Internal representation of the screen */ typedef struct { - int row; /* nb row */ + int row; /* nb row */ int col; /* nb col */ Line* line; /* screen */ Line* alt; /* alternate screen */ TCursor c; /* cursor */ - int top; /* top scroll limit */ + int top; /* top scroll limit */ int bot; /* bottom scroll limit */ int mode; /* terminal mode flags */ int esc; /* escape state flags */ @@ -118,17 +121,18 @@ typedef struct { XIM xim; XIC xic; int scr; - int w; /* window width */ + int w; /* window width */ int h; /* window height */ int bufw; /* pixmap width */ int bufh; /* pixmap height */ int ch; /* char height */ int cw; /* char width */ char state; /* focus, redraw, visible */ -} XWindow; +} XWindow; typedef struct { KeySym k; + unsigned int mask; char s[ESC_BUF_SIZ]; } Key; @@ -150,15 +154,18 @@ typedef struct { int mode; int bx, by; int ex, ey; - struct {int x, y;} b, e; + struct {int x, y;} b, e; char *clip; Atom xtarget; + struct timeval tclick1; + struct timeval tclick2; } Selection; #include "config.h" static void die(const char *errstr, ...); -static void draw(int); +static void draw(); +static void drawregion(int, int, int, int); static void execsh(void); static void sigchld(int); static void run(void); @@ -206,7 +213,7 @@ static void xresize(int, int); static void expose(XEvent *); static void visibility(XEvent *); static void unmap(XEvent *); -static char* kmap(KeySym); +static char* kmap(KeySym, unsigned int state); static void kpress(XEvent *); static void resize(XEvent *); static void focus(XEvent *); @@ -219,7 +226,7 @@ static void selrequest(XEvent *); static void selinit(void); static inline int selected(int, int); static void selcopy(void); -static void selpaste(void); +static void selpaste(); static int utf8decode(char *, long *); static int utf8encode(long *, char *); @@ -340,7 +347,7 @@ isfullutf8(char *s, int b) { else if((*c1&(B7|B6|B5)) == (B7|B6) && b == 1) return 0; else if((*c1&(B7|B6|B5|B4)) == (B7|B6|B5) && - ((b == 1) || + ((b == 1) || ((b == 2) && (*c2&(B7|B6)) == B7))) return 0; else if((*c1&(B7|B6|B5|B4|B3)) == (B7|B6|B5|B4) && @@ -362,12 +369,14 @@ utf8size(char *s) { return 2; else if ((c&(B7|B6|B5|B4)) == (B7|B6|B5)) return 3; - else + else return 4; } void selinit(void) { + sel.tclick1.tv_sec = 0; + sel.tclick1.tv_usec = 0; sel.mode = 0; sel.bx = -1; sel.clip = NULL; @@ -376,14 +385,14 @@ selinit(void) { sel.xtarget = XA_STRING; } -static inline int +static inline int selected(int x, int y) { if(sel.ey == y && sel.by == y) { int bx = MIN(sel.bx, sel.ex); int ex = MAX(sel.bx, sel.ex); return BETWEEN(x, bx, ex); } - return ((sel.b.y < y&&y < sel.e.y) || (y==sel.e.y && x<=sel.e.x)) + return ((sel.b.y < y&&y < sel.e.y) || (y==sel.e.y && x<=sel.e.x)) || (y==sel.b.y && x>=sel.b.x && (x<=sel.e.x || sel.b.y!=sel.e.y)); } @@ -511,30 +520,63 @@ xsetsel(char *str) { XFlush(xw.dpy); } -/* TODO: doubleclick to select word */ void brelease(XEvent *e) { int b; sel.mode = 0; getbuttoninfo(e, &b, &sel.ex, &sel.ey); - if(sel.bx==sel.ex && sel.by==sel.ey) { + + if(sel.bx == sel.ex && sel.by == sel.ey) { sel.bx = -1; - if(b==2) + if(b == 2) selpaste(); + + else if(b == 1) { + /* double click to select word */ + struct timeval now; + gettimeofday(&now, NULL); + + if(TIMEDIFFERENCE(now, sel.tclick1) <= DOUBLECLICK_TIMEOUT) { + sel.bx = sel.ex; + while(term.line[sel.ey][sel.bx-1].state & GLYPH_SET && + term.line[sel.ey][sel.bx-1].c[0] != ' ') sel.bx--; + sel.b.x = sel.bx; + while(term.line[sel.ey][sel.ex+1].state & GLYPH_SET && + term.line[sel.ey][sel.ex+1].c[0] != ' ') sel.ex++; + sel.e.x = sel.ex; + sel.b.y = sel.e.y = sel.ey; + selcopy(); + } + + /* triple click on the line */ + if(TIMEDIFFERENCE(now, sel.tclick2) <= TRIPLECLICK_TIMEOUT) { + sel.b.x = sel.bx = 0; + sel.e.x = sel.ex = term.col; + sel.b.y = sel.e.y = sel.ey; + selcopy(); + } + } } else { - if(b==1) + if(b == 1) selcopy(); } - draw(1); + memcpy(&sel.tclick2, &sel.tclick1, sizeof(struct timeval)); + gettimeofday(&sel.tclick1, NULL); + draw(); } void bmotion(XEvent *e) { - if (sel.mode) { + if(sel.mode) { + int oldey = sel.ey, + oldex = sel.ex; getbuttoninfo(e, NULL, &sel.ex, &sel.ey); - /* XXX: draw() can't keep up, disabled for now. - selection is visible on button release. - draw(1); */ + + if(oldey != sel.ey || oldex != sel.ex) { + int starty = MIN(oldey, sel.ey); + int endy = MAX(oldey, sel.ey); + drawregion(0, (starty > 0 ? starty : 0), term.col, (sel.ey < term.row ? endy+1 : term.row)); + } } } @@ -641,6 +683,10 @@ ttyread(void) { void ttywrite(const char *s, size_t n) { + {size_t nn; + for(nn = 0; nn < n; nn++) + dump(s[nn]); + } if(write(cmdfd, s, n) == -1) die("write error on tty: %s\n", SERRNO); } @@ -1640,8 +1686,13 @@ xdrawc(int x, int y, Glyph g) { dc.gc, r.x, r.y+dc.font.ascent, g.c, sl); } +void +drawregion(int x0, int x1, int y0, int y1) { + draw(); +} + void -draw(int dummy) { +draw() { int x, y; xclear(0, 0, term.col-1, term.row-1); @@ -1657,8 +1708,13 @@ draw(int dummy) { #else /* optimized drawing routine */ +void +draw() { + drawregion(0, 0, term.col, term.row); +} + void -draw(int redraw_all) { +drawregion(int x1, int y1, int x2, int y2) { int ic, ib, x, y, ox, sl; Glyph base, new; char buf[DRAW_BUF_SIZ]; @@ -1666,13 +1722,13 @@ draw(int redraw_all) { if(!(xw.state & WIN_VISIBLE)) return; - xclear(0, 0, term.col-1, term.row-1); - for(y = 0; y < term.row; y++) { + xclear(x1, y1, x2-1, y2-1); + for(y = y1; y < y2; y++) { base = term.line[y][0]; ic = ib = ox = 0; - for(x = 0; x < term.col; x++) { + for(x = x1; x < x2; x++) { new = term.line[y][x]; - if(sel.bx!=-1 && *(new.c) && selected(x, y)) + if(sel.bx != -1 && *(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)) { @@ -1705,7 +1761,7 @@ expose(XEvent *ev) { if(xw.state & WIN_REDRAW) { if(!e->count) { xw.state &= ~WIN_REDRAW; - draw(SCREEN_REDRAW); + draw(); } } else XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, e->x-BORDER, e->y-BORDER, @@ -1742,14 +1798,14 @@ focus(XEvent *ev) { xseturgency(0); } else xw.state &= ~WIN_FOCUSED; - draw(SCREEN_UPDATE); + draw(); } char* -kmap(KeySym k) { +kmap(KeySym k, unsigned int state) { int i; for(i = 0; i < LEN(key); i++) - if(key[i].k == k) + if(key[i].k == k && (key[i].mask == 0 || key[i].mask & state)) return (char*)key[i].s; return NULL; } @@ -1770,7 +1826,7 @@ kpress(XEvent *ev) { len = XmbLookupString(xw.xic, e, buf, sizeof(buf), &ksym, &status); /* 1. custom keys from config.h */ - if((customkey = kmap(ksym))) + if((customkey = kmap(ksym, e->state))) ttywrite(customkey, strlen(customkey)); /* 2. hardcoded (overrides X lookup) */ else @@ -1779,7 +1835,7 @@ kpress(XEvent *ev) { case XK_Down: case XK_Left: case XK_Right: - sprintf(buf, "\033%c%c", IS_SET(MODE_APPKEYPAD) ? 'O' : '[', "DACB"[ksym - XK_Left]); + sprintf(buf, "\033%c%c", IS_SET(MODE_APPKEYPAD) ? 'O' : '[', (shift ? "dacb":"DACB")[ksym - XK_Left]); ttywrite(buf, 3); break; case XK_Insert: @@ -1817,7 +1873,7 @@ resize(XEvent *e) { if(col == term.col && row == term.row) return; if(tresize(col, row)) - draw(SCREEN_REDRAW); + draw(); ttyresize(col, row); xresize(col, row); } @@ -1839,7 +1895,7 @@ run(void) { } if(FD_ISSET(cmdfd, &rfd)) { ttyread(); - draw(SCREEN_UPDATE); + draw(); } while(XPending(xw.dpy)) { XNextEvent(xw.dpy, &ev); diff --git a/st.info b/st.info index 863c387..6be3eaf 100644 --- a/st.info +++ b/st.info @@ -49,6 +49,10 @@ st| simpleterm, kcud1=\E[B, kcuf1=\E[C, kcuu1=\E[A, + kLFT=\E[d, + kRIT=\E[c, + kind=\E[a, + kri=\E[b, kdch1=\E[3~, kich1=\E[2~, kend=\E[4~, -- 2.20.1 From aede91e22a41cbf4b11d64faa42575d1bdbd8446 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aur=C3=A9lien=20Aptel?= Date: Fri, 22 Apr 2011 00:42:58 +0200 Subject: [PATCH 07/16] update TODO --- TODO | 11 ++++++++--- st.c | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index 3b2774b..ef68386 100644 --- a/TODO +++ b/TODO @@ -9,7 +9,12 @@ code & interface ---------------- * clean selection code -* use the real x11 clipboard -* clean terminfo entry -* utf8 +* clean and complete terminfo entry +* fix shift up/down (shift selection in emacs) * ... + +misc +---- + + $ grep -nE 'XXX|TODO' st.c + diff --git a/st.c b/st.c index 11ea9fc..e6bb91f 100644 --- a/st.c +++ b/st.c @@ -1835,6 +1835,7 @@ kpress(XEvent *ev) { case XK_Down: case XK_Left: case XK_Right: + /* XXX: shift up/down doesn't work */ sprintf(buf, "\033%c%c", IS_SET(MODE_APPKEYPAD) ? 'O' : '[', (shift ? "dacb":"DACB")[ksym - XK_Left]); ttywrite(buf, 3); break; -- 2.20.1 From babf4db52b58da74c9e1072d14cb0b9ef5b4dee7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aur=C3=A9lien=20Aptel?= Date: Tue, 26 Apr 2011 20:22:15 +0200 Subject: [PATCH 08/16] cleanup. --- st.c | 104 ++++++++++++++++------------------------------------------- 1 file changed, 27 insertions(+), 77 deletions(-) diff --git a/st.c b/st.c index e6bb91f..6a6ea75 100644 --- a/st.c +++ b/st.c @@ -163,8 +163,8 @@ typedef struct { #include "config.h" -static void die(const char *errstr, ...); -static void draw(); +static void die(const char*, ...); +static void draw(void); static void drawregion(int, int, int, int); static void execsh(void); static void sigchld(int); @@ -363,11 +363,11 @@ int utf8size(char *s) { unsigned char c = *s; - if (~c&B7) + if(~c&B7) return 1; - else if ((c&(B7|B6|B5)) == (B7|B6)) + else if((c&(B7|B6|B5)) == (B7|B6)) return 2; - else if ((c&(B7|B6|B5|B4)) == (B7|B6|B5)) + else if((c&(B7|B6|B5|B4)) == (B7|B6|B5)) return 3; else return 4; @@ -523,20 +523,25 @@ xsetsel(char *str) { void brelease(XEvent *e) { int b; + sel.mode = 0; getbuttoninfo(e, &b, &sel.ex, &sel.ey); - if(sel.bx == sel.ex && sel.by == sel.ey) { sel.bx = -1; if(b == 2) selpaste(); - else if(b == 1) { - /* double click to select word */ struct timeval now; gettimeofday(&now, NULL); - if(TIMEDIFFERENCE(now, sel.tclick1) <= DOUBLECLICK_TIMEOUT) { + if(TIMEDIFFERENCE(now, sel.tclick2) <= TRIPLECLICK_TIMEOUT) { + /* triple click on the line */ + sel.b.x = sel.bx = 0; + sel.e.x = sel.ex = term.col; + sel.b.y = sel.e.y = sel.ey; + selcopy(); + } else if(TIMEDIFFERENCE(now, sel.tclick1) <= DOUBLECLICK_TIMEOUT) { + /* double click to select word */ sel.bx = sel.ex; while(term.line[sel.ey][sel.bx-1].state & GLYPH_SET && term.line[sel.ey][sel.bx-1].c[0] != ' ') sel.bx--; @@ -547,19 +552,9 @@ brelease(XEvent *e) { sel.b.y = sel.e.y = sel.ey; selcopy(); } - - /* triple click on the line */ - if(TIMEDIFFERENCE(now, sel.tclick2) <= TRIPLECLICK_TIMEOUT) { - sel.b.x = sel.bx = 0; - sel.e.x = sel.ex = term.col; - sel.b.y = sel.e.y = sel.ey; - selcopy(); - } } - } else { - if(b == 1) - selcopy(); - } + } else if(b == 1) + selcopy(); memcpy(&sel.tclick2, &sel.tclick1, sizeof(struct timeval)); gettimeofday(&sel.tclick1, NULL); draw(); @@ -683,10 +678,6 @@ ttyread(void) { void ttywrite(const char *s, size_t n) { - {size_t nn; - for(nn = 0; nn < n; nn++) - dump(s[nn]); - } if(write(cmdfd, s, n) == -1) die("write error on tty: %s\n", SERRNO); } @@ -921,9 +912,9 @@ tsetattr(int *attr, int l) { term.c.attr.mode &= ~ATTR_REVERSE; break; case 38: - if (i + 2 < l && attr[i + 1] == 5) { + if(i + 2 < l && attr[i + 1] == 5) { i += 2; - if (BETWEEN(attr[i], 0, 255)) + if(BETWEEN(attr[i], 0, 255)) term.c.attr.fg = attr[i]; else fprintf(stderr, "erresc: bad fgcolor %d\n", attr[i]); @@ -935,9 +926,9 @@ tsetattr(int *attr, int l) { term.c.attr.fg = DefaultFG; break; case 48: - if (i + 2 < l && attr[i + 1] == 5) { + if(i + 2 < l && attr[i + 1] == 5) { i += 2; - if (BETWEEN(attr[i], 0, 255)) + if(BETWEEN(attr[i], 0, 255)) term.c.attr.bg = attr[i]; else fprintf(stderr, "erresc: bad bgcolor %d\n", attr[i]); @@ -1348,7 +1339,6 @@ tputc(char *c) { tmoveto(term.c.x+1, term.c.y); else term.c.state |= CURSOR_WRAPNEXT; - break; } } } @@ -1447,7 +1437,7 @@ xloadcols(void) { unsigned long white = WhitePixel(xw.dpy, xw.scr); for(i = 0; i < 16; i++) { - if (!XAllocNamedColor(xw.dpy, xw.cmap, colorname[i], &color, &color)) { + if(!XAllocNamedColor(xw.dpy, xw.cmap, colorname[i], &color, &color)) { dc.col[i] = white; fprintf(stderr, "Could not allocate color '%s'\n", colorname[i]); } else @@ -1461,7 +1451,7 @@ xloadcols(void) { color.red = r == 0 ? 0 : 0x3737 + 0x2828 * r; color.green = g == 0 ? 0 : 0x3737 + 0x2828 * g; color.blue = b == 0 ? 0 : 0x3737 + 0x2828 * b; - if (!XAllocColor(xw.dpy, xw.cmap, &color)) { + if(!XAllocColor(xw.dpy, xw.cmap, &color)) { dc.col[i] = white; fprintf(stderr, "Could not allocate color %d\n", i); } else @@ -1488,8 +1478,7 @@ xclear(int x1, int y1, int x2, int y2) { } void -xhints(void) -{ +xhints(void) { XClassHint class = {opt_class ? opt_class : TNAME, TNAME}; XWMHints wm = {.flags = InputHint, .input = 1}; XSizeHints size = { @@ -1505,8 +1494,7 @@ xhints(void) } XFontSet -xinitfont(char *fontstr) -{ +xinitfont(char *fontstr) { XFontSet set; char *def, **missing; int n; @@ -1522,8 +1510,7 @@ xinitfont(char *fontstr) } void -xgetfontinfo(XFontSet set, int *ascent, int *descent, short *lbearing, short *rbearing) -{ +xgetfontinfo(XFontSet set, int *ascent, int *descent, short *lbearing, short *rbearing) { XFontStruct **xfonts; char **font_names; int i, n; @@ -1540,8 +1527,7 @@ xgetfontinfo(XFontSet set, int *ascent, int *descent, short *lbearing, short *rb } void -initfonts(char *fontstr, char *bfontstr) -{ +initfonts(char *fontstr, char *bfontstr) { if((dc.font.set = xinitfont(fontstr)) == NULL || (dc.bfont.set = xinitfont(bfontstr)) == NULL) die("Can't load font %s\n", dc.font.set ? BOLDFONT : FONT); @@ -1674,40 +1660,6 @@ xdrawcursor(void) { } } -#ifdef DEBUG -/* basic drawing routines */ -void -xdrawc(int x, int y, Glyph g) { - int sl = utf8size(g.c); - XRectangle r = { x * xw.cw, y * xw.ch, xw.cw, xw.ch }; - XSetBackground(xw.dpy, dc.gc, dc.col[g.bg]); - XSetForeground(xw.dpy, dc.gc, dc.col[g.fg]); - XmbDrawImageString(xw.dpy, xw.buf, g.mode&ATTR_BOLD?dc.bfont.fs:dc.font.fs, - dc.gc, r.x, r.y+dc.font.ascent, g.c, sl); -} - -void -drawregion(int x0, int x1, int y0, int y1) { - draw(); -} - -void -draw() { - int x, y; - - xclear(0, 0, term.col-1, term.row-1); - for(y = 0; y < term.row; y++) - for(x = 0; x < term.col; x++) - if(term.line[y][x].state & GLYPH_SET) - xdrawc(x, y, term.line[y][x]); - - xdrawcursor(); - XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER); - XFlush(xw.dpy); -} - -#else -/* optimized drawing routine */ void draw() { drawregion(0, 0, term.col, term.row); @@ -1753,8 +1705,6 @@ drawregion(int x1, int y1, int x2, int y2) { XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER); } -#endif - void expose(XEvent *ev) { XExposeEvent *e = &ev->xexpose; @@ -1900,7 +1850,7 @@ run(void) { } while(XPending(xw.dpy)) { XNextEvent(xw.dpy, &ev); - if (XFilterEvent(&ev, xw.win)) + if(XFilterEvent(&ev, xw.win)) continue; if(handler[ev.type]) (handler[ev.type])(&ev); -- 2.20.1 From 8eaed2cdda375e8e951eb389af3859e18761eddc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aur=C3=A9lien=20Aptel?= Date: Tue, 26 Apr 2011 20:29:28 +0200 Subject: [PATCH 09/16] whitespace. --- st.c | 66 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/st.c b/st.c index 6a6ea75..56c3c6b 100644 --- a/st.c +++ b/st.c @@ -398,7 +398,7 @@ selected(int x, int y) { void getbuttoninfo(XEvent *e, int *b, int *x, int *y) { - if(b) + if(b) *b = e->xbutton.button; *x = (e->xbutton.x - BORDER)/xw.cw; @@ -543,17 +543,17 @@ brelease(XEvent *e) { } else if(TIMEDIFFERENCE(now, sel.tclick1) <= DOUBLECLICK_TIMEOUT) { /* double click to select word */ sel.bx = sel.ex; - while(term.line[sel.ey][sel.bx-1].state & GLYPH_SET && + while(term.line[sel.ey][sel.bx-1].state & GLYPH_SET && term.line[sel.ey][sel.bx-1].c[0] != ' ') sel.bx--; sel.b.x = sel.bx; - while(term.line[sel.ey][sel.ex+1].state & GLYPH_SET && + while(term.line[sel.ey][sel.ex+1].state & GLYPH_SET && term.line[sel.ey][sel.ex+1].c[0] != ' ') sel.ex++; sel.e.x = sel.ex; sel.b.y = sel.e.y = sel.ey; selcopy(); } } - } else if(b == 1) + } else if(b == 1) selcopy(); memcpy(&sel.tclick2, &sel.tclick1, sizeof(struct timeval)); gettimeofday(&sel.tclick1, NULL); @@ -563,7 +563,7 @@ brelease(XEvent *e) { void bmotion(XEvent *e) { if(sel.mode) { - int oldey = sel.ey, + int oldey = sel.ey, oldex = sel.ex; getbuttoninfo(e, NULL, &sel.ex, &sel.ey); @@ -597,7 +597,7 @@ execsh(void) { exit(EXIT_FAILURE); } -void +void sigchld(int a) { int stat = 0; if(waitpid(pid, &stat, 0) < 0) @@ -650,7 +650,7 @@ dump(char c) { void ttyread(void) { static char buf[BUFSIZ]; - static int buflen = 0; + static int buflen = 0; char *ptr; char s[UTF_SIZ]; int charsize; /* size of utf8 char in bytes */ @@ -706,8 +706,8 @@ tcursor(int mode) { void treset(void) { term.c = (TCursor){{ - .mode = ATTR_NULL, - .fg = DefaultFG, + .mode = ATTR_NULL, + .fg = DefaultFG, .bg = DefaultBG }, .x = 0, .y = 0, .state = CURSOR_DEFAULT}; @@ -762,9 +762,9 @@ tscrollup(int orig, int n) { tclearregion(0, orig, term.col-1, orig+n-1); - for(i = orig; i <= term.bot-n; i++) { + for(i = orig; i <= term.bot-n; i++) { temp = term.line[i]; - term.line[i] = term.line[i+n]; + term.line[i] = term.line[i+n]; term.line[i+n] = temp; } } @@ -894,22 +894,22 @@ tsetattr(int *attr, int l) { term.c.attr.bg = DefaultBG; break; case 1: - term.c.attr.mode |= ATTR_BOLD; + term.c.attr.mode |= ATTR_BOLD; break; - case 4: + case 4: term.c.attr.mode |= ATTR_UNDERLINE; break; - case 7: - term.c.attr.mode |= ATTR_REVERSE; + case 7: + term.c.attr.mode |= ATTR_REVERSE; break; - case 22: - term.c.attr.mode &= ~ATTR_BOLD; + case 22: + term.c.attr.mode &= ~ATTR_BOLD; break; - case 24: + case 24: term.c.attr.mode &= ~ATTR_UNDERLINE; break; - case 27: - term.c.attr.mode &= ~ATTR_REVERSE; + case 27: + term.c.attr.mode &= ~ATTR_REVERSE; break; case 38: if(i + 2 < l && attr[i + 1] == 5) { @@ -920,7 +920,7 @@ tsetattr(int *attr, int l) { fprintf(stderr, "erresc: bad fgcolor %d\n", attr[i]); } else - fprintf(stderr, "erresc: gfx attr %d unknown\n", attr[i]); + fprintf(stderr, "erresc: gfx attr %d unknown\n", attr[i]); break; case 39: term.c.attr.fg = DefaultFG; @@ -934,7 +934,7 @@ tsetattr(int *attr, int l) { fprintf(stderr, "erresc: bad bgcolor %d\n", attr[i]); } else - fprintf(stderr, "erresc: gfx attr %d unknown\n", attr[i]); + fprintf(stderr, "erresc: gfx attr %d unknown\n", attr[i]); break; case 49: term.c.attr.bg = DefaultBG; @@ -948,7 +948,7 @@ tsetattr(int *attr, int l) { term.c.attr.fg = attr[i] - 90 + 8; else if(BETWEEN(attr[i], 100, 107)) term.c.attr.fg = attr[i] - 100 + 8; - else + else fprintf(stderr, "erresc: gfx attr %d unknown\n", attr[i]), csidump(); break; @@ -968,7 +968,7 @@ tsetscroll(int t, int b) { b = temp; } term.top = t; - term.bot = b; + term.bot = b; } void @@ -1193,7 +1193,7 @@ csihandle(void) { } void -csidump(void) { +csidump(void) { int i; printf("ESC [ %s", escseq.priv ? "? " : ""); if(escseq.narg) @@ -1226,7 +1226,7 @@ tputc(char *c) { csiparse(), csihandle(); } /* TODO: handle other OSC */ - } else if(term.esc & ESC_OSC) { + } else if(term.esc & ESC_OSC) { if(ascii == ';') { term.titlelen = 0; term.esc = ESC_START | ESC_TITLE; @@ -1550,7 +1550,7 @@ xinit(void) { initfonts(FONT, BOLDFONT); /* XXX: Assuming same size for bold font */ - xw.cw = dc.font.rbearing - dc.font.lbearing; + xw.cw = dc.font.rbearing - dc.font.lbearing; xw.ch = dc.font.ascent + dc.font.descent; /* colors */ @@ -1582,8 +1582,8 @@ xinit(void) { /* input methods */ xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL); - xw.xic = XCreateIC(xw.xim, XNInputStyle, XIMPreeditNothing - | XIMStatusNothing, XNClientWindow, xw.win, + xw.xic = XCreateIC(xw.xim, XNInputStyle, XIMPreeditNothing + | XIMStatusNothing, XNClientWindow, xw.win, XNFocusWindow, xw.win, NULL); /* gc */ dc.gc = XCreateGC(xw.dpy, xw.win, 0, NULL); @@ -1591,7 +1591,7 @@ xinit(void) { /* white cursor, black outline */ cursor = XCreateFontCursor(xw.dpy, XC_xterm); XDefineCursor(xw.dpy, xw.win, cursor); - XRecolorCursor(xw.dpy, cursor, + XRecolorCursor(xw.dpy, cursor, &(XColor){.red = 0xffff, .green = 0xffff, .blue = 0xffff}, &(XColor){.red = 0x0000, .green = 0x0000, .blue = 0x0000}); @@ -1626,7 +1626,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) { } XmbDrawImageString(xw.dpy, xw.buf, base.mode & ATTR_BOLD ? dc.bfont.set : dc.font.set, - dc.gc, winx, winy, s, bytelen); + dc.gc, winx, winy, s, bytelen); if(base.mode & ATTR_UNDERLINE) XDrawLine(xw.dpy, xw.buf, dc.gc, winx, winy+1, winx+width-1, winy+1); @@ -1660,7 +1660,7 @@ xdrawcursor(void) { } } -void +void draw() { drawregion(0, 0, term.col, term.row); } @@ -1846,7 +1846,7 @@ run(void) { } if(FD_ISSET(cmdfd, &rfd)) { ttyread(); - draw(); + draw(); } while(XPending(xw.dpy)) { XNextEvent(xw.dpy, &ev); -- 2.20.1 From 80da37203e1699d9143cacfcfaeae7e7645c645d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aur=C3=A9lien=20Aptel?= Date: Tue, 10 May 2011 22:22:44 +0200 Subject: [PATCH 10/16] support for x11 xterm mouse reporting --- st.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/st.c b/st.c index 56c3c6b..65c7532 100644 --- a/st.c +++ b/st.c @@ -62,7 +62,7 @@ enum { CURSOR_UP, CURSOR_DOWN, CURSOR_LEFT, CURSOR_RIGHT, enum { CURSOR_DEFAULT = 0, CURSOR_HIDE = 1, CURSOR_WRAPNEXT = 2 }; enum { GLYPH_SET=1, GLYPH_DIRTY=2 }; enum { MODE_WRAP=1, MODE_INSERT=2, MODE_APPKEYPAD=4, MODE_ALTSCREEN=8, - MODE_CRLF=16 }; + MODE_CRLF=16, MODE_MOUSE=32 }; enum { ESC_START=1, ESC_CSI=2, ESC_OSC=4, ESC_TITLE=8, ESC_ALTCHARSET=16 }; enum { WIN_VISIBLE=1, WIN_REDRAW=2, WIN_FOCUSED=4 }; @@ -409,8 +409,36 @@ getbuttoninfo(XEvent *e, int *b, int *x, int *y) { sel.e.y = MAX(sel.by, sel.ey); } +void +mousereport(XEvent *e) { + int x = (e->xbutton.x - BORDER)/xw.cw; + int y = (e->xbutton.y - BORDER)/xw.ch; + int button = e->xbutton.button; + int state = e->xbutton.state; + char buf[] = { '\033', '[', 'M', 0, 32+x+1, 32+y+1 }; + + if(!IS_SET(MODE_MOUSE)) + return; + + /* from urxvt */ + if(e->xbutton.type == ButtonRelease || button == AnyButton) + button = 3; + else { + button -= Button1; + if(button >= 3) + button += 64 - 3; + } + + buf[3] = 32 + button + (state & ShiftMask ? 4 : 0) + + (state & Mod4Mask ? 8 : 0) + + (state & ControlMask ? 16 : 0); + + ttywrite(buf, sizeof(buf)); +} + void bpress(XEvent *e) { + mousereport(e); sel.mode = 1; sel.ex = sel.bx = (e->xbutton.x - BORDER)/xw.cw; sel.ey = sel.by = (e->xbutton.y - BORDER)/xw.ch; @@ -526,6 +554,7 @@ brelease(XEvent *e) { sel.mode = 0; getbuttoninfo(e, &b, &sel.ex, &sel.ey); + mousereport(e); if(sel.bx == sel.ex && sel.by == sel.ey) { sel.bx = -1; if(b == 2) @@ -1085,6 +1114,9 @@ csihandle(void) { case 25: term.c.state |= CURSOR_HIDE; break; + case 1000: /* disable X11 xterm mouse reporting */ + term.mode &= ~MODE_MOUSE; + break; case 1049: /* = 1047 and 1048 */ case 1047: if(IS_SET(MODE_ALTSCREEN)) { @@ -1148,6 +1180,9 @@ csihandle(void) { case 25: term.c.state &= ~CURSOR_HIDE; break; + case 1000: /* enable X11 xterm mouse reporting */ + term.mode |= MODE_MOUSE; + break; case 1049: /* = 1047 and 1048 */ case 1047: if(IS_SET(MODE_ALTSCREEN)) -- 2.20.1 From 0107293a446725551ceb756affe50b4853046f05 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aur=C3=A9lien=20Aptel?= Date: Tue, 10 May 2011 22:54:30 +0200 Subject: [PATCH 11/16] add mouse report escape to terminfo entry. --- st.info | 1 + 1 file changed, 1 insertion(+) diff --git a/st.info b/st.info index 6be3eaf..ece22fa 100644 --- a/st.info +++ b/st.info @@ -70,6 +70,7 @@ st| simpleterm, kf9=\E[20~, khome=\E[1~, knp=\E[6~, + kmous=\E[M, kpp=\E[5~, lines#24, mir, -- 2.20.1 From 5beae6a62ee15dfe36048e377ebf86df09a0cf82 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aur=C3=A9lien=20Aptel?= Date: Tue, 10 May 2011 22:55:35 +0200 Subject: [PATCH 12/16] macro cleanup. --- st.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/st.c b/st.c index 65c7532..8347dbe 100644 --- a/st.c +++ b/st.c @@ -53,7 +53,9 @@ #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x) #define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg) #define IS_SET(flag) (term.mode & (flag)) -#define TIMEDIFFERENCE(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + (t1.tv_usec-t2.tv_usec)/1000) +#define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + (t1.tv_usec-t2.tv_usec)/1000) +#define X2COL(x) (((x) - BORDER)/xw.cw) +#define Y2ROW(y) (((y) - BORDER)/xw.ch) /* Attribute, Cursor, Character state, Terminal mode, Screen draw mode */ enum { ATTR_NULL=0 , ATTR_REVERSE=1 , ATTR_UNDERLINE=2, ATTR_BOLD=4, ATTR_GFX=8 }; @@ -401,8 +403,8 @@ getbuttoninfo(XEvent *e, int *b, int *x, int *y) { if(b) *b = e->xbutton.button; - *x = (e->xbutton.x - BORDER)/xw.cw; - *y = (e->xbutton.y - BORDER)/xw.ch; + *x = X2COL(e->xbutton.x); + *y = Y2ROW(e->xbutton.y); sel.b.x = sel.by < sel.ey ? sel.bx : sel.ex; sel.b.y = MIN(sel.by, sel.ey); sel.e.x = sel.by < sel.ey ? sel.ex : sel.bx; @@ -411,8 +413,8 @@ getbuttoninfo(XEvent *e, int *b, int *x, int *y) { void mousereport(XEvent *e) { - int x = (e->xbutton.x - BORDER)/xw.cw; - int y = (e->xbutton.y - BORDER)/xw.ch; + int x = X2COL(e->xbutton.x); + int y = Y2ROW(e->xbutton.y); int button = e->xbutton.button; int state = e->xbutton.state; char buf[] = { '\033', '[', 'M', 0, 32+x+1, 32+y+1 }; @@ -440,8 +442,8 @@ void bpress(XEvent *e) { mousereport(e); sel.mode = 1; - sel.ex = sel.bx = (e->xbutton.x - BORDER)/xw.cw; - sel.ey = sel.by = (e->xbutton.y - BORDER)/xw.ch; + sel.ex = sel.bx = X2COL(e->xbutton.x); + sel.ey = sel.by = Y2ROW(e->xbutton.y); } void @@ -563,13 +565,13 @@ brelease(XEvent *e) { struct timeval now; gettimeofday(&now, NULL); - if(TIMEDIFFERENCE(now, sel.tclick2) <= TRIPLECLICK_TIMEOUT) { + if(TIMEDIFF(now, sel.tclick2) <= TRIPLECLICK_TIMEOUT) { /* triple click on the line */ sel.b.x = sel.bx = 0; sel.e.x = sel.ex = term.col; sel.b.y = sel.e.y = sel.ey; selcopy(); - } else if(TIMEDIFFERENCE(now, sel.tclick1) <= DOUBLECLICK_TIMEOUT) { + } else if(TIMEDIFF(now, sel.tclick1) <= DOUBLECLICK_TIMEOUT) { /* double click to select word */ sel.bx = sel.ex; while(term.line[sel.ey][sel.bx-1].state & GLYPH_SET && -- 2.20.1 From 7d352f143655ace75dd4e40432199f18f296da5e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aur=C3=A9lien=20Aptel?= Date: Sat, 14 May 2011 17:47:37 +0200 Subject: [PATCH 13/16] applied parts of Connor Lane Smith's cleanup patch. --- st.1 | 26 +++++++++++++------------- st.c | 14 +++++++------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/st.1 b/st.1 index f1f41a7..69cfe86 100644 --- a/st.1 +++ b/st.1 @@ -1,4 +1,4 @@ -.TH ST 1 st-VERSION +.TH ST 1 st\-VERSION .SH NAME st \- simple terminal .SH SYNOPSIS @@ -9,24 +9,24 @@ st \- simple terminal .IR title ] .RB [ \-v ] .RB [ \-e -.IR cmd ] +.IR command ...] .SH DESCRIPTION .B st is a simple terminal emulator. .SH OPTIONS .TP -.B \-t title -Overrides the default title (st) +.BI \-t " title" +defines the window title (default 'st'). .TP -.B \-c class -Overrides the default class ($TERM) +.BI \-c " class" +defines the window class (default $TERM). .TP .B \-v -Prints version information to standard output, then exits. +prints version information to stderr, then exits. .TP -.B \-e cmd [arguments] -Execute cmd instead of the shell. Type your command as you would on your -shell. If this option is used, it -.BI "must be the last" -on the command-line. This is the same behaviour as xterm/rxvt. - +.BI \-e " program " [ " arguments " "... ]" +st executes +.I program +instead of the shell. If this is used it +.B must be the last option +on the command line, as in xterm / rxvt. diff --git a/st.c b/st.c index 8347dbe..01ffa21 100644 --- a/st.c +++ b/st.c @@ -34,8 +34,8 @@ #endif #define USAGE \ - "st-" VERSION ", (c) 2010 st engineers\n" \ - "usage: st [-t title] [-c class] [-v] [-e cmd]\n" + "st-" VERSION ", (c) 2010-2011 st engineers\n" \ + "usage: st [-t title] [-c class] [-v] [-e command...]\n" /* Arbitrary sizes */ #define ESC_TITLE_SIZ 256 @@ -1907,17 +1907,17 @@ main(int argc, char *argv[]) { case 'c': if(++i < argc) opt_class = argv[i]; break; - case 'e': + case 'e': + /* eat every remaining arguments */ if(++i < argc) opt_cmd = &argv[i]; - break; + goto run; case 'v': default: die(USAGE); } - /* -e eats every remaining arguments */ - if(opt_cmd) - break; } + + run: setlocale(LC_CTYPE, ""); tnew(80, 24); ttynew(); -- 2.20.1 From 6734de9b6e1e74e6c713a6a3e22322e80884828d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aur=C3=A9lien=20Aptel?= Date: Sun, 22 May 2011 16:57:27 +0200 Subject: [PATCH 14/16] =?utf8?q?set=20title=20before=20mapping=20window=20?= =?utf8?q?(thx=20Kamil=20Cholewi=C5=84ski).?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- st.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st.c b/st.c index 01ffa21..1d01925 100644 --- a/st.c +++ b/st.c @@ -1632,9 +1632,9 @@ xinit(void) { &(XColor){.red = 0xffff, .green = 0xffff, .blue = 0xffff}, &(XColor){.red = 0x0000, .green = 0x0000, .blue = 0x0000}); + XStoreName(xw.dpy, xw.win, opt_title ? opt_title : "st"); XMapWindow(xw.dpy, xw.win); xhints(); - XStoreName(xw.dpy, xw.win, opt_title ? opt_title : "st"); XSync(xw.dpy, 0); } -- 2.20.1 From b2db58c2a05168257ee4e4b941f0533c6dde2a10 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aur=C3=A9lien=20Aptel?= Date: Wed, 1 Jun 2011 19:57:48 +0200 Subject: [PATCH 15/16] add status bar (window title) to terminfo. (thx Rafa Gallego) --- st.info | 3 +++ 1 file changed, 3 insertions(+) diff --git a/st.info b/st.info index ece22fa..1cc6349 100644 --- a/st.info +++ b/st.info @@ -33,8 +33,10 @@ st| simpleterm, ed=\E[J, el=\E[K, el1=\E[1K, + fsl=^G, home=\E[H, hpa=\E[%i%p1%dG, + hs, ht=^I, hts=\EH, ich=\E[%p1%d@, @@ -93,6 +95,7 @@ st| simpleterm, smso=\E[7m, smul=\E[4m, tbc=\E[2g, + tsl=\E]0;, ul, xenl, -- 2.20.1 From d59f92d6f19a4a914ba99168fdc42d1783eee1ba Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aur=C3=A9lien=20Aptel?= Date: Wed, 8 Jun 2011 12:40:35 +0200 Subject: [PATCH 16/16] =?utf8?q?reverse=20video=20mode.=20(thx=20Bert=20M?= =?utf8?q?=C3=BCnnich)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- st.c | 31 +++++++++++++++++++++++-------- st.info | 1 + 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/st.c b/st.c index 1d01925..a4aca51 100644 --- a/st.c +++ b/st.c @@ -64,7 +64,7 @@ enum { CURSOR_UP, CURSOR_DOWN, CURSOR_LEFT, CURSOR_RIGHT, enum { CURSOR_DEFAULT = 0, CURSOR_HIDE = 1, CURSOR_WRAPNEXT = 2 }; enum { GLYPH_SET=1, GLYPH_DIRTY=2 }; enum { MODE_WRAP=1, MODE_INSERT=2, MODE_APPKEYPAD=4, MODE_ALTSCREEN=8, - MODE_CRLF=16, MODE_MOUSE=32 }; + MODE_CRLF=16, MODE_MOUSE=32, MODE_REVERSE=64 }; enum { ESC_START=1, ESC_CSI=2, ESC_OSC=4, ESC_TITLE=8, ESC_ALTCHARSET=16 }; enum { WIN_VISIBLE=1, WIN_REDRAW=2, WIN_FOCUSED=4 }; @@ -1103,7 +1103,11 @@ csihandle(void) { case 1: term.mode &= ~MODE_APPKEYPAD; break; - case 5: /* TODO: DECSCNM -- Remove reverse video */ + case 5: /* DECSCNM -- Remove reverse video */ + if(IS_SET(MODE_REVERSE)) { + term.mode &= ~MODE_REVERSE; + draw(); + } break; case 7: term.mode &= ~MODE_WRAP; @@ -1167,7 +1171,10 @@ csihandle(void) { term.mode |= MODE_APPKEYPAD; break; case 5: /* DECSCNM -- Reverve video */ - /* TODO: set REVERSE on the whole screen (f) */ + if(!IS_SET(MODE_REVERSE)) { + term.mode |= MODE_REVERSE; + draw(); + } break; case 7: term.mode |= MODE_WRAP; @@ -1508,7 +1515,7 @@ xloadcols(void) { void xclear(int x1, int y1, int x2, int y2) { - XSetForeground(xw.dpy, dc.gc, dc.col[DefaultBG]); + XSetForeground(xw.dpy, dc.gc, dc.col[IS_SET(MODE_REVERSE) ? DefaultFG : DefaultBG]); XFillRectangle(xw.dpy, xw.buf, dc.gc, x1 * xw.cw, y1 * xw.ch, (x2-x1+1) * xw.cw, (y2-y1+1) * xw.ch); @@ -1640,14 +1647,20 @@ xinit(void) { void xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) { - unsigned long xfg, xbg; + unsigned long xfg = dc.col[base.fg], xbg = dc.col[base.bg], temp; int winx = x*xw.cw, winy = y*xw.ch + dc.font.ascent, width = charlen*xw.cw; int i; + + /* only switch default fg/bg if term is in RV mode */ + if(IS_SET(MODE_REVERSE)) { + if(base.fg == DefaultFG) + xfg = dc.col[DefaultBG]; + if(base.bg == DefaultBG) + xbg = dc.col[DefaultFG]; + } if(base.mode & ATTR_REVERSE) - xfg = dc.col[base.bg], xbg = dc.col[base.fg]; - else - xfg = dc.col[base.fg], xbg = dc.col[base.bg]; + temp = xfg, xfg = xbg, xbg = temp; XSetBackground(xw.dpy, dc.gc, xbg); XSetForeground(xw.dpy, dc.gc, xfg); @@ -1692,6 +1705,8 @@ xdrawcursor(void) { /* draw the new one */ if(!(term.c.state & CURSOR_HIDE) && (xw.state & WIN_FOCUSED)) { sl = utf8size(g.c); + if(IS_SET(MODE_REVERSE)) + g.mode |= ATTR_REVERSE, g.fg = DefaultCS, g.bg = DefaultFG; xdraws(g.c, g, term.c.x, term.c.y, 1, sl); oldx = term.c.x, oldy = term.c.y; } diff --git a/st.info b/st.info index 1cc6349..489908f 100644 --- a/st.info +++ b/st.info @@ -33,6 +33,7 @@ st| simpleterm, ed=\E[J, el=\E[K, el1=\E[1K, + flash=\E[?5h\E[?5l, fsl=^G, home=\E[H, hpa=\E[%i%p1%dG, -- 2.20.1