JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Enabling enacs and adding compatibility to xterm and urxvt for alternative
[st.git] / st.c
diff --git a/st.c b/st.c
index f7fecf8..efe309f 100644 (file)
--- a/st.c
+++ b/st.c
@@ -110,7 +110,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 {
@@ -201,7 +202,7 @@ typedef struct {
        XftDraw *xft_draw;
        Visual *vis;
        int scr;
-       Bool isfixed; /* is fixed geometry? */
+       bool isfixed; /* is fixed geometry? */
        int fx, fy, fw, fh; /* fixed geometry */
        int tw, th; /* tty width and height */
        int w;  /* window width */
@@ -277,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);
@@ -292,7 +293,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);
@@ -883,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;
        }
@@ -899,7 +900,7 @@ ttywrite(const char *s, size_t n) {
 }
 
 void
-ttyresize(int x, int y) {
+ttyresize(void) {
        struct winsize w;
 
        w.ws_row = term.row;
@@ -940,7 +941,7 @@ tcursor(int mode) {
 
 void
 treset(void) {
-       unsigned i;
+       uint i;
        term.c = (TCursor){{
                .mode = ATTR_NULL,
                .fg = DefaultFG,
@@ -952,6 +953,7 @@ treset(void) {
                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);
 }
 
@@ -1278,7 +1280,8 @@ tsetmode(bool priv, bool set, int *args, int narg) {
        for(lim = args + narg; args < lim; ++args) {
                if(priv) {
                        switch(*args) {
-                       case 1:
+                               break;
+                       case 1: /* DECCKM -- Cursor key */
                                MODBIT(term.mode, set, MODE_APPKEYPAD);
                                break;
                        case 5: /* DECSCNM -- Reverve video */
@@ -1287,12 +1290,14 @@ tsetmode(bool priv, bool set, int *args, int narg) {
                                if(mode != term.mode)
                                        redraw();
                                break;
-                       case 7:
+                       case 6: /* XXX: DECOM -- Origin */
+                               break;
+                       case 7: /* DECAWM -- Auto wrap */
                                MODBIT(term.mode, set, MODE_WRAP);
                                break;
-                       case 20:
-                               MODBIT(term.mode, set, MODE_CRLF);
+                       case 8: /* XXX: DECARM -- Auto repeat */
                                break;
+                       case 0:  /* Error (IGNORED) */
                        case 12: /* att610 -- Start blinking cursor (IGNORED) */
                                break;
                        case 25:
@@ -1320,6 +1325,12 @@ tsetmode(bool priv, bool set, int *args, int narg) {
                                tcursor((set) ? CURSOR_SAVE : CURSOR_LOAD);
                                break;
                        default:
+                       /* case 2:  DECANM -- ANSI/VT52 (NOT SUPPOURTED) */
+                       /* case 3:  DECCOLM -- Column  (NOT SUPPORTED) */
+                       /* case 4:  DECSCLM -- Scroll (NOT SUPPORTED) */
+                       /* case 18: DECPFF -- Printer feed (NOT SUPPORTED) */
+                       /* case 19: DECPEX -- Printer extent (NOT SUPPORTED) */
+                       /* case 42: DECNRCM -- National characters (NOT SUPPORTED) */
                                fprintf(stderr,
                                        "erresc: unknown private set/reset mode %d\n",
                                        *args);
@@ -1327,9 +1338,19 @@ tsetmode(bool priv, bool set, int *args, int narg) {
                        }
                } else {
                        switch(*args) {
-                       case 4:
+                       case 0:  /* Error (IGNORED) */
+                               break;
+                       case 2:  /* KAM -- keyboard action */
+                               MODBIT(term.mode, set, MODE_KBDLOCK);
+                               break;
+                       case 4:  /* IRM -- Insertion-replacement */
                                MODBIT(term.mode, set, MODE_INSERT);
                                break;
+                       case 12: /* XXX: SRM -- Send/Receive */
+                               break;
+                       case 20: /* LNM -- Linefeed/new line */
+                               MODBIT(term.mode, set, MODE_CRLF);
+                               break;
                        default:
                                fprintf(stderr,
                                        "erresc: unknown set/reset mode %d\n",
@@ -1603,7 +1624,7 @@ strreset(void) {
 
 void
 tputtab(bool forward) {
-       unsigned x = term.c.x;
+       uint x = term.c.x;
 
        if(forward) {
                if(x == term.col)
@@ -1620,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) {
@@ -1679,6 +1700,7 @@ tputc(char *c) {
                                strescseq.type = ascii;
                                term.esc |= ESC_STR;
                                break;
+                       case ')':
                        case '(':
                                term.esc |= ESC_ALTCHARSET;
                                break;
@@ -1707,6 +1729,7 @@ tputc(char *c) {
                        case 'c': /* RIS -- Reset to inital state */
                                treset();
                                term.esc = 0;
+                               xclear(0, 0, xw.w, xw.h);
                                xresettitle();
                                break;
                        case '=': /* DECPAM -- Application keypad */
@@ -2256,6 +2279,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);
@@ -2326,7 +2351,7 @@ resize(XEvent *e) {
        xclear(0, 0, xw.w, xw.h);
        tresize(col, row);
        xresize(col, row);
-       ttyresize(col, row);
+       ttyresize();
 }
 
 void
@@ -2381,7 +2406,7 @@ run(void) {
 int
 main(int argc, char *argv[]) {
        int i, bitm, xr, yr;
-       unsigned int wr, hr;
+       uint wr, hr;
 
        xw.fw = xw.fh = xw.fx = xw.fy = 0;
        xw.isfixed = False;