#include #include #include #include #include #include #include #include #include "dat.h" #include "fns.h" extern Window *w; typedef enum { eZero=0, eTitle, eColor, eInfinite, } eType; enum { ESC = 0x1b, }; static void esctitle(const Rune* start, const Rune* end) { char* p; // fprint(2, "esctitle(%.*S)\n", end-start, start); p = smprint("%.*S", end-start-3, start+3); if(p){ drawsetlabel(p); free(w->dir); w->dir = p; /* remove trailing /-sysname if present */ p = strrchr(p, '/'); if(p && *(p+1) == '-'){ if(p == w->dir) p++; *p = 0; } } } static void esctitleonly(const Rune* start, const Rune* end) { esctitle(start+1, end); } static void esccolor(const Rune* start, const Rune* end) { // fprint(2, "_ecolor(%#.*S)\n", end-start, start); } static void escnop(const Rune* start, const Rune* end) { } /* this parsing method isn't sufficient for every case. for example erase n characters is ESC [ K so the color-wacking could eat too much if we get "ESC [Kwhatever, man" → "an" oops also, if we match the start, we don't backtrack if runstrnchar fails. */ struct { Rune start[5]; char end; eType esc; void (*fn)(const Rune*, const Rune*); } esc_tab[] = { {{0}, 0, 0, escnop}, {{']', ';', 0}, '\007', eTitle, esctitle}, {{']', '1', ';', 0}, '\007', eTitle, escnop}, // set "icon" title only {{']', '2', ';', 0}, '\007', eTitle, esctitleonly}, {{'[', 0}, 'm', eColor, esccolor}, 0 }; static Rune* runestrnchr(const Rune* r, char c, unsigned long len){ for(; len--; r++){ if (c == *r){ // fprint(2, "→ %.*S, %uld\n", len, r, len); return (Rune*)r; } } return 0; } eType matchEsc(const Rune* r, const Rune* er, Rune** start, Rune** end) { eType i; int j; int runesleft; if (er