From 43c27589080b2edf03e992f9a4c163c0b5c3bb67 Mon Sep 17 00:00:00 2001 From: ketmar Date: Mon, 5 Nov 2012 19:26:49 +0200 Subject: [PATCH] alot of renaming... --- src/commands.c | 48 ++++++------ src/decls.c | 68 +++++++++++++++++ src/globals.c | 4 +- src/mouseevents.c | 34 ++++----- src/selection.c | 58 +++++++-------- src/sterm.c | 62 +++++++++------- src/tcmdline.c | 16 ++-- src/termswitch.c | 8 +- src/tfatalbox.c | 98 ++++++++++++------------- src/ttyinit.c | 6 +- src/ttyputc.c | 174 +++++++++++++++++++++---------------------- src/ttyresize.c | 2 +- src/ttyrw.c | 64 ++++++++-------- src/ttyutils.c | 204 +++++++++++++++++++++++++-------------------------- src/utf8.c | 12 +-- src/x11draw.c | 44 +++++------ src/x11drawcmdline.c | 18 ++--- src/x11drawcur.c | 20 ++--- src/x11drawstr.c | 4 +- src/x11evtkbd.c | 16 ++-- src/x11evtvis.c | 24 +++--- src/x11misc.c | 4 +- 22 files changed, 531 insertions(+), 457 deletions(-) create mode 100644 src/decls.c diff --git a/src/commands.c b/src/commands.c index a0a389e..0eeb496 100644 --- a/src/commands.c +++ b/src/commands.c @@ -78,16 +78,16 @@ static void flushNewTerm (void) { if (newTermSwitch && curterm != NULL) curterm->lastActiveTime = mclock_ticks(); //curterm = newTerm; //termidx = newTermIdx; - tinitialize(newTerm, term_array[0]->col, term_array[0]->row); + k8t_tmInitialize(newTerm, term_array[0]->col, term_array[0]->row); termallocPixmap(newTerm); //TODO: check return result // - if (ttynew(newTerm) != 0) { + if (k8t_ttyNew(newTerm) != 0) { curterm = oldTerm; termidx = oldTermIdx; termfree(newTermIdx); } else { - selinit(newTerm); - ttyresize(newTerm); + k8t_selInit(newTerm); + k8t_ttyResize(newTerm); if (newTermSwitch) { curterm = NULL; termidx = 0; @@ -109,7 +109,7 @@ static void cmdNewTab (const char *cmdname, char *argstr) { // if (opt_disabletabs) return; flushNewTerm(); - if ((newTerm = termalloc()) == NULL) return; + if ((newTerm = k8t_termalloc()) == NULL) return; /*idx =*/ parseTabArgs(argstr, &noswitch, 0, termidx); idx = term_count-1; if (!noswitch) { @@ -190,8 +190,8 @@ static void cmdDefaultBG (const char *cmdname, char *argstr) { curterm->defbg = c; XSetWindowBackground(xw.dpy, xw.win, getColor(curterm->defbg)); if (newTerm == NULL) { - tfulldirt(curterm); - draw(curterm, 1); + k8t_tmFullDirty(curterm); + k8t_Draw(curterm, 1); xclearunused(); } } @@ -204,8 +204,8 @@ static void scrollHistory (K8Term *term, int delta) { term->topline += delta; if (term->topline > term->maxhistory) term->topline = term->maxhistory; if (term->topline < 0) term->topline = 0; - tfulldirt(term); - draw(term, 1); + k8t_tmFullDirty(term); + k8t_Draw(term, 1); } @@ -256,7 +256,7 @@ static void cmdCursor (const char *cmdname, char *argstr) { } else { if (strcasecmp(s, "show") == 0) curterm->c.state &= ~K8T_CURSOR_HIDE; else if (strcasecmp(s, "hide") == 0) curterm->c.state |= K8T_CURSOR_HIDE; - setWantRedraw(curterm, 0); + k8t_tmWantRedraw(curterm, 0); } } } @@ -270,10 +270,10 @@ static void cmdReset (const char *cmdname, char *argstr) { if (s != NULL) { switch (tolower(s[0])) { case 'a': // all - tresetmode(curterm); + k8t_tmResetMode(curterm); return; case 'c': // colors - tresetattrs(curterm); + k8t_tmResetAttrs(curterm); return; case 'g': // graphics curterm->mode &= ~(K8T_MODE_GFX0|K8T_MODE_GFX1); @@ -299,9 +299,9 @@ static void cmdScreen (const char *cmdname, char *argstr) { tcmdlinemsgf(curterm, &curterm->cmdline, "screen: %s", (K8T_ISSET(curterm, K8T_MODE_ALTSCREEN) ? "alt" : "norm")); } else { if (strcasecmp(s, "norm") == 0) { - if (K8T_ISSET(curterm, K8T_MODE_ALTSCREEN)) tswapscreen(curterm); + if (K8T_ISSET(curterm, K8T_MODE_ALTSCREEN)) k8t_tmSwapScreen(curterm); } else if (strcasecmp(s, "alt") == 0) { - if (!K8T_ISSET(curterm, K8T_MODE_ALTSCREEN)) tswapscreen(curterm); + if (!K8T_ISSET(curterm, K8T_MODE_ALTSCREEN)) k8t_tmSwapScreen(curterm); } } } @@ -408,7 +408,7 @@ static void cmdMonochrome (const char *cmdname, char *argstr) { curterm->blackandwhite = b; } } - tfulldirt(curterm); + k8t_tmFullDirty(curterm); updateTabBar = 1; } @@ -430,7 +430,7 @@ static void cmdCursorBlink (const char *cmdname, char *argstr) { curterm->curbhidden = 0; } } - tfulldirt(curterm); + k8t_tmFullDirty(curterm); updateTabBar = 1; } @@ -444,7 +444,7 @@ static void cmdCursorBlinkInactive (const char *cmdname, char *argstr) { iptr = (global ? &opt_cursorBlinkInactive : &curterm->curblinkinactive); if (b != -1) { if (toggle) *iptr = !(*iptr); else *iptr = b; - draw(curterm, 0); + k8t_Draw(curterm, 0); } } @@ -472,7 +472,7 @@ static void cmdMaxHistory (const char *cmdname, char *argstr) { if (b == -1) { tcmdlinemsgf(curterm, &curterm->cmdline, "MaxHistory: %d", (global?opt_maxhistory:curterm->maxhistory)); } else { - if (!global) tadjustmaxhistory(curterm, b); else opt_maxhistory = b; + if (!global) k8t_tmAdjMaxHistory(curterm, b); else opt_maxhistory = b; } } @@ -525,8 +525,8 @@ static void cmdTabPosition (const char *cmdname, char *argstr) { } else if (opt_tabposition != newpos) { opt_tabposition = newpos; updateTabBar = 1; - tfulldirt(curterm); - draw(curterm, 1); + k8t_tmFullDirty(curterm); + k8t_Draw(curterm, 1); xclearunused(); } } @@ -550,9 +550,9 @@ static void cmdTabCount (const char *cmdname, char *argstr) { static void cmdDoFullRedraw (const char *cmdname, char *argstr) { updateTabBar = 1; - tfulldirt(curterm); + k8t_tmFullDirty(curterm); xclearunused(); - draw(curterm, 1); + k8t_Draw(curterm, 1); } @@ -562,7 +562,7 @@ static void cmdTitle (const char *cmdname, char *argstr) { // if (iniParseArguments(argstr, "s-", &s) != NULL || s == NULL) return; memset(curterm->title, 0, sizeof(curterm->title)); - while (strlen(s) > K8T_ESC_TITLE_SIZ) utf8choplast(s); + while (strlen(s) > K8T_ESC_TITLE_SIZ) k8t_UTF8ChopLast(s); fprintf(stderr, "[%s]\n", s); strncpy(curterm->title, s, K8T_ESC_TITLE_SIZ); fixWindowTitle(curterm); @@ -581,7 +581,7 @@ static void cmdFastRedraw (const char *cmdname, char *argstr) { iptr = (global ? &opt_fastredraw : &curterm->fastredraw); if (b != -1) { if (toggle) *iptr = !(*iptr); else *iptr = b; - draw(curterm, 0); + k8t_Draw(curterm, 0); } else { tcmdlinemsgf(curterm, &curterm->cmdline, "FastRedraw: %s", (*iptr ? "yes" : "no")); } diff --git a/src/decls.c b/src/decls.c new file mode 100644 index 0000000..152ab7a --- /dev/null +++ b/src/decls.c @@ -0,0 +1,68 @@ +static void k8t_tmWantRedraw (K8Term *term, int forceFast); +static void k8t_tmDirtyMark (K8Term *term, int lineno, int flag); +static void k8t_selInit (K8Term *term); +static void k8t_selHide (K8Term *term); +static int k8t_isSelected (K8Term *term, int x, int y); +static void k8t_getButtonInfo (K8Term *term, XEvent *e, int *b, int *x, int *y); +static void k8t_mouseReport (K8Term *term, XEvent *e); +static void k8t_selXSet (K8Term *term, char *str); +static void k8t_selClear (K8Term *term); +static K8TLine k8t_selGet (K8Term *term, int y); +static void k8t_selCopy (K8Term *term); +static void k8t_tmDrawFatalBox (K8Term *term, const char *msg); +static int k8t_ttyNew (K8Term *term); +static void k8t_dbgCSIDump (K8Term *term); +static void k8t_tmResetAttrs (K8Term *term); +static void k8t_tmSetAttr (K8Term *term, int *attr, int l); +static int k8t_tmDoWrap (K8Term *term); +static void k8t_tmCSIHandle (K8Term *term); +static void k8t_tmCSIReset (K8Term *term); +static void k8t_tmCSIParse (K8Term *term); +static void k8t_tmPutTab (K8Term *term); +static int k8t_tmPutCtrl (K8Term *term, char ascii); +static void k8t_tmPutC (K8Term *term, const char *c); +static int k8t_ttyCanRead (K8Term *term); +static int k8t_ttyCanWrite (K8Term *term); +static int k8t_ttyRead (K8Term *term); +static void k8t_ttyFlushWriteBuf (K8Term *term); +static int k8t_ttyWriteRawChar (K8Term *term, const char *s, int len, int noenc); +static void k8t_ttyWriteNoEnc (K8Term *term, const char *s, size_t n); +static void k8t_ttyWrite (K8Term *term, const char *s, size_t n); +static void k8t_tmDirty (K8Term *term, int top, int bot); +static void k8t_tmFullDirty (K8Term *term); +static void k8t_tmMoveTo (K8Term *term, int x, int y); +static void k8t_tmClearRegion (K8Term *term, int x1, int y1, int x2, int y2); +static void k8t_tmCursor (K8Term *term, int mode); +static void k8t_tmAdjMaxHistory (K8Term *term, int maxh); +static void k8t_tmSwapScreen (K8Term *term); +static void k8t_tmScrollSelection (K8Term *term, int orig, int n, int tohistory); +static void k8t_tmScrollDown (K8Term *term, int orig, int n); +static void k8t_tmScrollUp (K8Term *term, int orig, int n, int tohistory); +static void k8t_tmCharWrap (K8Term *term, int y, int wrap); +static void k8t_tmNewLine (K8Term *term, int first_col); +static void k8t_tmSetChar (K8Term *term, const char *c); +static void k8t_tmDeleteChar (K8Term *term, int n); +static void k8t_tmInsertBlank (K8Term *term, int n); +static void k8t_tmInsertBlankLine (K8Term *term, int n); +static void k8t_tmDeleteLine (K8Term *term, int n); +static void k8t_tmSetScrollRegion (K8Term *term, int t, int b); +static void k8t_tmUnshowHistory (K8Term *term); +static void k8t_tmSendFocusEvent (K8Term *term, int focused); +static void k8t_tmResetMode (K8Term *term); +static void k8t_tmReset (K8Term *term); +static int k8t_tmInitialize (K8Term *term, int col, int row); +static int k8t_tmResize (K8Term *term, int col, int row); +static void k8t_ttyResize (K8Term *term); +static int k8t_UTF8Decode (uint32_t *u, const void *buf); +static int k8t_UTF8Encode (void *buf, uint32_t uc); +static int k8t_UTF8IsFull (const void *buf, int buflen); +static int k8t_UTF8Size (const void *buf); +static int k8t_UTF8strlen (const char *s); +static void k8t_UTF8ChopLast (char *s); +static void k8t_DrawLine (K8Term *term, int x1, int x2, int scry, int lineno, int dontcopy); +static void k8t_DrawRegion (K8Term *term, int x1, int y1, int x2, int y2, int forced); +static void k8t_Draw (K8Term *term, int forced); +static void k8t_DrawCursor (K8Term *term); +static void k8t_DrawString (K8Term *term, const char *s, const K8TGlyph *base, int x, int y, int charlen, int bytelen); +static void k8t_DrawClear (K8Term *term, int x1, int y1, int x2, int y2); +static void k8t_DrawCopy (K8Term *term, int x, int y, int cols, int rows); diff --git a/src/globals.c b/src/globals.c index 2acf24e..95404f1 100644 --- a/src/globals.c +++ b/src/globals.c @@ -63,8 +63,8 @@ static int firstVisibleTab = 0; static int exitcode = 0; static int closeRequestComes = 0; -static DC dc; -static XWindow xw; +static K8TXDC dc; +static K8TXWindow xw; static Atom XA_VT_SELECTION; static Atom XA_CLIPBOARD; diff --git a/src/mouseevents.c b/src/mouseevents.c index 0a8bae6..61a9f05 100644 --- a/src/mouseevents.c +++ b/src/mouseevents.c @@ -21,25 +21,25 @@ static void xevtcbbpress (XEvent *e) { // if ((e->xbutton.state&ShiftMask) != 0) { if (e->xbutton.button == Button1) { - if (curterm->sel.bx != -1) tsetdirt(curterm, curterm->sel.b.y, curterm->sel.e.y); + if (curterm->sel.bx != -1) k8t_tmDirty(curterm, curterm->sel.b.y, curterm->sel.e.y); curterm->sel.mode = 1; curterm->sel.b.y = curterm->sel.e.y = curterm->row+1; curterm->sel.ex = curterm->sel.bx = K8T_X2COL(e->xbutton.x); curterm->sel.ey = curterm->sel.by = K8T_Y2ROW(curterm, e->xbutton.y); //fprintf(stderr, "x=%d; y=%d\n", curterm->sel.bx, curterm->sel.by); - draw(curterm, 1); + k8t_Draw(curterm, 1); return; } /* if (e->xbutton.button == Button3) { curterm->sel.bx = -1; - selcopy(curterm); - draw(curterm, 1); + k8t_selCopy(curterm); + k8t_Draw(curterm, 1); } */ return; } - if (K8T_ISSET(curterm, K8T_MODE_MOUSE)) mousereport(curterm, e); + if (K8T_ISSET(curterm, K8T_MODE_MOUSE)) k8t_mouseReport(curterm, e); } @@ -56,7 +56,7 @@ static void xevtcbbrelease (XEvent *e) { } // if ((e->xbutton.state&ShiftMask) == 0 && !curterm->sel.mode) { - if (K8T_ISSET(curterm, K8T_MODE_MOUSE)) mousereport(curterm, e); + if (K8T_ISSET(curterm, K8T_MODE_MOUSE)) k8t_mouseReport(curterm, e); return; } // @@ -64,13 +64,13 @@ static void xevtcbbrelease (XEvent *e) { selpaste(curterm, XA_PRIMARY); } else if (e->xbutton.button == Button1) { curterm->sel.mode = 0; - getbuttoninfo(curterm, e, NULL, &curterm->sel.ex, &curterm->sel.ey); // this sets sel.b and sel.e + k8t_getButtonInfo(curterm, e, NULL, &curterm->sel.ex, &curterm->sel.ey); // this sets sel.b and sel.e // if (curterm->sel.bx == curterm->sel.ex && curterm->sel.by == curterm->sel.ey) { // single line, single char selection MSTime now; // - markDirty(curterm, curterm->sel.ey, 2); + k8t_tmDirtyMark(curterm, curterm->sel.ey, 2); curterm->sel.bx = -1; now = mclock_ticks(); if (now-curterm->sel.tclick2 <= opt_tripleclick_timeout) { @@ -80,7 +80,7 @@ static void xevtcbbrelease (XEvent *e) { curterm->sel.b.y = curterm->sel.e.y = curterm->sel.ey; } else if (now-curterm->sel.tclick1 <= opt_doubleclick_timeout) { /* double click to select word */ - K8TLine l = selgetlinebyy(curterm, curterm->sel.ey); + K8TLine l = k8t_selGet(curterm, curterm->sel.ey); // if (l != NULL) { //FIXME: write better word selection code @@ -99,16 +99,16 @@ static void xevtcbbrelease (XEvent *e) { } } // - selcopy(curterm); - draw(curterm, 1); + k8t_selCopy(curterm); + k8t_Draw(curterm, 1); } else { // multiline or multichar selection - selcopy(curterm); + k8t_selCopy(curterm); } } curterm->sel.tclick2 = curterm->sel.tclick1; curterm->sel.tclick1 = mclock_ticks(); - //draw(1); + //k8t_Draw(1); } @@ -127,15 +127,15 @@ static void xevtcbbmotion (XEvent *e) { if (curterm->sel.mode) { int oldey = curterm->sel.ey, oldex = curterm->sel.ex; // - getbuttoninfo(curterm, e, NULL, &curterm->sel.ex, &curterm->sel.ey); // this sets sel.b and sel.e + k8t_getButtonInfo(curterm, e, NULL, &curterm->sel.ex, &curterm->sel.ey); // this sets sel.b and sel.e if (oldey != curterm->sel.ey || oldex != curterm->sel.ex) { int starty = K8T_MIN(oldey, curterm->sel.ey); int endy = K8T_MAX(oldey, curterm->sel.ey); // - tsetdirt(curterm, starty, endy); - draw(curterm, 1); + k8t_tmDirty(curterm, starty, endy); + k8t_Draw(curterm, 1); } return; } - //if (K8T_ISSET(curterm, K8T_MODE_MOUSE) && e->xbutton.button != 0) mousereport(e); + //if (K8T_ISSET(curterm, K8T_MODE_MOUSE) && e->xbutton.button != 0) k8t_mouseReport(e); } diff --git a/src/selection.c b/src/selection.c index 1fb975f..b52672f 100644 --- a/src/selection.c +++ b/src/selection.c @@ -1,6 +1,6 @@ //////////////////////////////////////////////////////////////////////////////// // selection -static inline void setWantRedraw (K8Term *term, int forceFast) { +static void k8t_tmWantRedraw (K8Term *term, int forceFast) { if (term != NULL) { term->wantRedraw = 1; if (forceFast) term->lastDrawTime = 0; @@ -9,15 +9,15 @@ static inline void setWantRedraw (K8Term *term, int forceFast) { } -static void inline markDirty (K8Term *term, int lineno, int flag) { +static void k8t_tmDirtyMark (K8Term *term, int lineno, int flag) { if (term != NULL && lineno >= 0 && lineno < term->row) { term->dirty[lineno] |= flag; - setWantRedraw(term, 0); + k8t_tmWantRedraw(term, 0); } } -static void selinit (K8Term *term) { +static void k8t_selInit (K8Term *term) { if (term != NULL) { term->sel.tclick1 = term->sel.tclick2 = mclock_ticks(); term->sel.mode = 0; @@ -29,16 +29,16 @@ static void selinit (K8Term *term) { } -static void selhide (K8Term *term) { +static void k8t_selHide (K8Term *term) { if (term != NULL && term->sel.bx != -1) { term->sel.mode = 0; term->sel.bx = -1; - tfulldirt(term); + k8t_tmFullDirty(term); } } -static inline int isselected (K8Term *term, int x, int y) { +static int k8t_isSelected (K8Term *term, int x, int y) { if (term == NULL || term->sel.bx == -1) return 0; // if (y >= term->row) y = 0-(y-term->row+1); @@ -55,7 +55,7 @@ static inline int isselected (K8Term *term, int x, int y) { } -static void getbuttoninfo (K8Term *term, XEvent *e, int *b, int *x, int *y) { +static void k8t_getButtonInfo (K8Term *term, XEvent *e, int *b, int *x, int *y) { if (b != NULL) *b = e->xbutton.button; if (x != NULL) *x = K8T_X2COL(e->xbutton.x); if (y != NULL) *y = K8T_Y2ROW(term, e->xbutton.y); @@ -66,7 +66,7 @@ static void getbuttoninfo (K8Term *term, XEvent *e, int *b, int *x, int *y) { } -static void mousereport (K8Term *term, XEvent *e) { +static void k8t_mouseReport (K8Term *term, XEvent *e) { int x = K8T_X2COL(e->xbutton.x); int y = K8T_Y2ROW(term, e->xbutton.y); int button = e->xbutton.button; @@ -128,8 +128,8 @@ static void mousereport (K8Term *term, XEvent *e) { // coords switch (term->mousemode) { case 1005: /* utf-8 */ - p += utf8encode(p, x+1); - p += utf8encode(p, y+1); + p += k8t_UTF8Encode(p, x+1); + p += k8t_UTF8Encode(p, y+1); break; case 1006: /* sgr */ p += sprintf(p, "%d;%d%c", x+1, y+1, lastCh); @@ -151,7 +151,7 @@ static void mousereport (K8Term *term, XEvent *e) { fputs(">\n", stderr); } */ - ttywritestrnoenc(term, buf); + k8t_ttyWriteStrNoEnc(term, buf); } @@ -167,7 +167,7 @@ static void xfixsel (void) { } -static void xsetsel (K8Term *term, char *str) { +static void k8t_selXSet (K8Term *term, char *str) { /* register the selection for both the clipboard and the primary */ if (term == NULL) return; if (term->sel.clip != NULL) free(term->sel.clip); @@ -179,7 +179,7 @@ static void xsetsel (K8Term *term, char *str) { } -static void selclear (K8Term *term) { +static void k8t_selClear (K8Term *term) { if (lastSelStr != NULL) free(lastSelStr); lastSelStr = NULL; if (term != NULL) { @@ -188,19 +188,19 @@ static void selclear (K8Term *term) { term->sel.mode = 0; if (term->sel.bx != 0) { term->sel.bx = -1; - tfulldirt(term); - draw(term, 1); + k8t_tmFullDirty(term); + k8t_Draw(term, 1); } } } static void xevtcbselclear (XEvent *e) { - selclear(curterm); + k8t_selClear(curterm); } -static K8TLine selgetlinebyy (K8Term *term, int y) { +static K8TLine k8t_selGet (K8Term *term, int y) { K8TLine l; // if (y >= term->row) return NULL; @@ -214,7 +214,7 @@ static K8TLine selgetlinebyy (K8Term *term, int y) { } -static void selcopy (K8Term *term) { +static void k8t_selCopy (K8Term *term) { char *str, *ptr; int x, y, bufsize, is_selected = 0; // @@ -229,18 +229,18 @@ static void selcopy (K8Term *term) { fprintf(stderr, " b.x=%d; e.x=%d; b.y=%d; e.y=%d\n", term->sel.b.x, term->sel.b.y, term->sel.e.x, term->sel.e.y); fprintf(stderr, " sy=%d; ey=%d\n", sy, ey); */ - if (ey >= term->row) { selclear(term); return; } + if (ey >= term->row) { k8t_selClear(term); return; } bufsize = (term->col+1)*(ey-sy+1)*UTF_SIZ; ptr = str = malloc(bufsize); /* append every set and selected glyph to the selection */ for (y = sy; y <= ey; ++y) { - K8TLine l = selgetlinebyy(term, y); + K8TLine l = k8t_selGet(term, y); char *pstart = ptr; // if (l == NULL) continue; for (x = 0; x < term->col; ++x) { - if ((is_selected = isselected(term, x, y)) != 0) { - int size = utf8size(l[x].c); + if ((is_selected = k8t_isSelected(term, x, y)) != 0) { + int size = k8t_UTF8Size(l[x].c); // //if (size == 1) fprintf(stderr, "x=%d; y=%d; size=%d; c=%d\n", x, y, size, l[x].c[0]); if (size == 1) { @@ -257,12 +257,12 @@ static void selcopy (K8Term *term) { // trim trailing spaces while (ptr > pstart && ptr[-1] == ' ') --ptr; // \n at the end of every unwrapped selected line except for the last one - if (is_selected && y < ey && isselected(term, term->col-1, y) && !(l[term->col-1].state&K8T_GLYPH_WRAP)) *ptr++ = '\n'; + if (is_selected && y < ey && k8t_isSelected(term, term->col-1, y) && !(l[term->col-1].state&K8T_GLYPH_WRAP)) *ptr++ = '\n'; } *ptr = 0; } - xsetsel(term, str); - if (!str || !str[0]) selclear(term); + k8t_selXSet(term, str); + if (!str || !str[0]) k8t_selClear(term); } @@ -374,16 +374,16 @@ static void xevtcbselnotify (XEvent *e) { } else { if (nitems*format/8 > 0 && !wasbrk && K8T_ISSET(curterm, K8T_MODE_BRACPASTE)) { wasbrk = 1; - ttywritestrnoenc(curterm, "\x1b[200~"); + k8t_ttyWriteStrNoEnc(curterm, "\x1b[200~"); } - ttywrite(curterm, str, blen); + k8t_ttyWrite(curterm, str, blen); } XFree(data); /* number of 32-bit chunks returned */ ofs += nitems*format/32; } while (rem > 0); // - if (wasbrk) ttywritestrnoenc(curterm, "\x1b[201~"); + if (wasbrk) k8t_ttyWriteStrNoEnc(curterm, "\x1b[201~"); if (ucbuf != NULL) free(ucbuf); } diff --git a/src/sterm.c b/src/sterm.c index ef23988..68d386e 100644 --- a/src/sterm.c +++ b/src/sterm.c @@ -149,7 +149,7 @@ enum { K8T_ATTR_DEFBG = 0x20, }; -// cursor operations for tcursor() +// cursor operations for k8t_tmCursor() enum cursor_movement { K8T_CURSOR_SAVE, K8T_CURSOR_LOAD @@ -266,7 +266,7 @@ typedef struct { Pixmap pictab; int tabheight; //struct timeval lastdraw; -} XWindow; +} K8TXWindow; /* TODO: use better name for vars... */ @@ -297,7 +297,7 @@ typedef struct { XFontSet set; Font fid; } font[3]; -} DC; +} K8TXDC; typedef struct K8TCmdLine K8TCmdLine; @@ -421,15 +421,17 @@ struct K8Term { static void executeCommands (const char *str); static const char *findCommandCompletion (const char *str, int slen, const char *prev); -static void ttyresize (K8Term *term); -static void tsetattr (K8Term *term, int *attr, int l); -static void tresetattrs (K8Term *term); -static int tdowrap (K8Term *term); -static void tputc (K8Term *term, const char *c); // `c` is utf-8 -static void ttywrite (K8Term *term, const char *s, size_t n); -static void ttywritenoenc (K8Term *term, const char *s, size_t n); -static void tsetdirt (K8Term *term, int top, int bot); -static void tfulldirt (K8Term *term); +/* +static void k8t_ttyResize (K8Term *term); +static void k8t_tmSetAttr (K8Term *term, int *attr, int l); +static void k8t_tmResetAttrs (K8Term *term); +static int k8t_tmDoWrap (K8Term *term); +static void k8t_tmPutC (K8Term *term, const char *c); // `c` is utf-8 +static void k8t_ttyWrite (K8Term *term, const char *s, size_t n); +static void k8t_ttyWriteNoEnc (K8Term *term, const char *s, size_t n); +static void k8t_tmDirty (K8Term *term, int top, int bot); +static void k8t_tmFullDirty (K8Term *term); +*/ static void tdrawfatalmsg (K8Term *term, const char *msg); @@ -440,17 +442,21 @@ static void xblankPointer (void); static void xunblankPointer (void); static void xdrawTabBar (void); -static void draw (K8Term *term, int forced); +/* +static void k8t_Draw (K8Term *term, int forced); +*/ static void tcmdput (K8Term *term, K8TCmdLine *cmdline, const char *s, int len); +#include "decls.c" + //////////////////////////////////////////////////////////////////////////////// -static inline void ttywritestr (K8Term *term, const char *s) { if (s != NULL && s[0]) ttywrite(term, s, strlen(s)); } -static inline void ttywritestrnoenc (K8Term *term, const char *s) { if (s != NULL && s[0]) ttywritenoenc(term, s, strlen(s)); } +static inline void k8t_ttyWriteStr (K8Term *term, const char *s) { if (s != NULL && s[0]) k8t_ttyWrite(term, s, strlen(s)); } +static inline void k8t_ttyWriteStrNoEnc (K8Term *term, const char *s) { if (s != NULL && s[0]) k8t_ttyWriteNoEnc(term, s, strlen(s)); } //FIXME: do utf-8! -static inline void tputstr (K8Term *term, const char *s) { if (s != NULL) while (*s) { tputc(term, s); ++s; } } +static inline void k8t_ttyPutStr (K8Term *term, const char *s) { if (s != NULL) while (*s) { k8t_tmPutC(term, s); ++s; } } static inline uint32_t getColor (int idx) { @@ -510,14 +516,14 @@ static void xevtcbcmessage (XEvent *e) { if (e->xclient.data.l[1] == XEMBED_FOCUS_IN) { xw.state |= K8T_WIN_FOCUSED; xseturgency(0); - tsendfocusevent(curterm, 1); + k8t_tmSendFocusEvent(curterm, 1); } else if (e->xclient.data.l[1] == XEMBED_FOCUS_OUT) { xw.state &= ~K8T_WIN_FOCUSED; - tsendfocusevent(curterm, 0); + k8t_tmSendFocusEvent(curterm, 0); } - xdrawcursor(curterm); + k8t_DrawCursor(curterm); xdrawTabBar(); - xcopy(curterm, 0, 0, curterm->col, curterm->row); + k8t_DrawCopy(curterm, 0, 0, curterm->col, curterm->row); return; } // @@ -605,8 +611,8 @@ static void run (void) { if (!t->dead && t->cmdfd >= 0) { int rd = -1; // - if (t->pid != 0 && FD_ISSET(t->cmdfd, &wfd)) ttyflushwrbuf(t); - if (FD_ISSET(t->cmdfd, &rfd)) rd = ttyread(t); + if (t->pid != 0 && FD_ISSET(t->cmdfd, &wfd)) k8t_ttyFlushWriteBuf(t); + if (FD_ISSET(t->cmdfd, &rfd)) rd = k8t_ttyRead(t); // if (t->waitkeypress && t->exitmsg != NULL && rd < 0) { // there will be no more data @@ -616,7 +622,7 @@ static void run (void) { tdrawfatalmsg(t, t->exitmsg); free(t->exitmsg); t->exitmsg = NULL; - setWantRedraw(t, 1); + k8t_tmWantRedraw(t, 1); } } } @@ -641,7 +647,7 @@ static void run (void) { } } if (updateTabBar) xdrawTabBar(); - if (dodraw || last_draw_too_old()) draw(curterm, 0); + if (dodraw || last_draw_too_old()) k8t_Draw(curterm, 0); // if (XPending(xw.dpy)) { while (XPending(xw.dpy)) { @@ -830,13 +836,13 @@ cfgdone: summonChildKiller(); updateTabBar = 1; termidx = 0; - curterm = termalloc(); + curterm = k8t_termalloc(); if (curterm->execcmd != NULL) { free(curterm->execcmd); curterm->execcmd = NULL; } - tinitialize(curterm, 80, 25); - if (ttynew(curterm) != 0) die("can't run process"); + k8t_tmInitialize(curterm, 80, 25); + if (k8t_ttyNew(curterm) != 0) die("can't run process"); opt_cmd = NULL; xinit(); - selinit(curterm); + k8t_selInit(curterm); if (runcmd != NULL) executeCommands(runcmd); run(); return 0; diff --git a/src/tcmdline.c b/src/tcmdline.c index 294f869..1ddb3e7 100644 --- a/src/tcmdline.c +++ b/src/tcmdline.c @@ -1,8 +1,8 @@ //////////////////////////////////////////////////////////////////////////////// static void tcmdlinedirty (K8Term *term, K8TCmdLine *cmdline) { if (term != NULL) { - markDirty(term, term->row-term->topline-1, 2); - setWantRedraw(term, 1); + k8t_tmDirtyMark(term, term->row-term->topline-1, 2); + k8t_tmWantRedraw(term, 1); } } @@ -10,10 +10,10 @@ static void tcmdlinedirty (K8Term *term, K8TCmdLine *cmdline) { static void tcmdlinefixofs (K8Term *term, K8TCmdLine *cmdline) { int ofs, len; // - len = utf8strlen(cmdline->cmdline); + len = k8t_UTF8strlen(cmdline->cmdline); ofs = len-(term->col-1); if (ofs < 0) ofs = 0; - for (cmdline->cmdofs = 0; ofs > 0; --ofs) cmdline->cmdofs += utf8size(cmdline->cmdline+cmdline->cmdofs); + for (cmdline->cmdofs = 0; ofs > 0; --ofs) cmdline->cmdofs += k8t_UTF8Size(cmdline->cmdline+cmdline->cmdofs); tcmdlinedirty(term, cmdline); } @@ -36,7 +36,7 @@ static void tcmdlinemsg (K8Term *term, K8TCmdLine *cmdline, const char *msg) { cmdline->cmdcurtabc = NULL; // while (*msg) { - int len = utf8size(msg); + int len = k8t_UTF8Size(msg); // if (len < 1 || ofs+len >= sizeof(cmdline->cmdline)-1) break; memcpy(cmdline->cmdline+ofs, msg, len); @@ -101,7 +101,7 @@ static void tcmdlinechoplast (K8Term *term, K8TCmdLine *cmdline) { if (cmdline->cmdcl != 0) { cmdline->cmdcl = 0; } else { - if (strlen(cmdline->cmdline) > cmdline->cmdreslen) utf8choplast(cmdline->cmdline); + if (strlen(cmdline->cmdline) > cmdline->cmdreslen) k8t_UTF8ChopLast(cmdline->cmdline); } tcmdlinefixofs(term, cmdline); } @@ -109,7 +109,7 @@ static void tcmdlinechoplast (K8Term *term, K8TCmdLine *cmdline) { // utf-8 static void tcmdaddchar (K8Term *term, K8TCmdLine *cmdline, const char *s) { - int len = utf8size(s); + int len = k8t_UTF8Size(s); // if (len > 0) { int slen = strlen(cmdline->cmdline); @@ -130,7 +130,7 @@ static void tcmdput (K8Term *term, K8TCmdLine *cmdline, const char *s, int len) cmdline->cmdc[cmdline->cmdcl++] = *s++; cmdline->cmdc[cmdline->cmdcl] = 0; // - if ((ok = isfullutf8(cmdline->cmdc, cmdline->cmdcl)) != 0 || cmdline->cmdcl == UTF_SIZ) { + if ((ok = k8t_UTF8IsFull(cmdline->cmdc, cmdline->cmdcl)) != 0 || cmdline->cmdcl == UTF_SIZ) { if (ok) tcmdaddchar(term, cmdline, cmdline->cmdc); cmdline->cmdcl = 0; } diff --git a/src/termswitch.c b/src/termswitch.c index e22ae89..d1c3710 100644 --- a/src/termswitch.c +++ b/src/termswitch.c @@ -52,12 +52,12 @@ static void switchToTerm (int idx, int redraw) { fixFirstTab(); // xseturgency(0); - tfulldirt(curterm); + k8t_tmFullDirty(curterm); fixWindowTitle(curterm); updateTabBar = 1; XSetWindowBackground(xw.dpy, xw.win, getColor(curterm->defbg)); xclearunused(); - if (redraw) draw(curterm, 1); + if (redraw) k8t_Draw(curterm, 1); //FIXME: optimize memory allocations if (curterm->sel.clip != NULL && curterm->sel.bx >= 0) { if (lastSelStr != NULL) free(lastSelStr); @@ -81,7 +81,7 @@ static int termallocPixmap (K8Term *term) { } -static K8Term *termalloc (void) { +static K8Term *k8t_termalloc (void) { K8Term *t; // if (term_count >= term_array_size) { @@ -167,6 +167,6 @@ static void termcleanup (void) { // if (needredraw) { updateTabBar = 1; - draw(curterm, 1); + k8t_Draw(curterm, 1); } } diff --git a/src/tfatalbox.c b/src/tfatalbox.c index 9668389..463626b 100644 --- a/src/tfatalbox.c +++ b/src/tfatalbox.c @@ -1,6 +1,6 @@ //////////////////////////////////////////////////////////////////////////////// //SHITCODE! -static void tdrawfatalbox (K8Term *term, const char *msg) { +static void k8t_tmDrawFatalBox (K8Term *term, const char *msg) { if (term != NULL) { static const char *title = " GURU MEDITAION "; static const char *clr = "\x1b[0;1;33;41m"; @@ -10,10 +10,10 @@ static void tdrawfatalbox (K8Term *term, const char *msg) { if (msg == NULL) msg = ""; if ((mlen = strlen(msg))+4 > wdt) wdt = mlen+4; // - tputstr(term, clr); + k8t_ttyPutStr(term, clr); // if (term->col <= mlen+4) { - tputstr(term, msg); + k8t_ttyPutStr(term, msg); return; } // @@ -25,80 +25,80 @@ static void tdrawfatalbox (K8Term *term, const char *msg) { // just title int left = (wdt-2-mlen)/2, cnt = left+1+mlen; // - tputstr(term, "lq"); - tputstr(term, "\x1b[37m"); - tputstr(term, title); - tputstr(term, "\x1b[33m"); - tputstr(term, "qk"); + k8t_ttyPutStr(term, "lq"); + k8t_ttyPutStr(term, "\x1b[37m"); + k8t_ttyPutStr(term, title); + k8t_ttyPutStr(term, "\x1b[33m"); + k8t_ttyPutStr(term, "qk"); // - tputstr(term, clrdef); - tputstr(term, "\r\n"); - tputstr(term, clr); + k8t_ttyPutStr(term, clrdef); + k8t_ttyPutStr(term, "\r\n"); + k8t_ttyPutStr(term, clr); // - tputc(term, "x"); - while (left-- > 0) tputc(term, " "); + k8t_tmPutC(term, "x"); + while (left-- > 0) k8t_tmPutC(term, " "); term->charset = K8T_MODE_GFX0; - tputstr(term, msg); + k8t_ttyPutStr(term, msg); term->charset = K8T_MODE_GFX1; - while (cnt++ < wdt-1) tputc(term, " "); - tputstr(term, "x"); + while (cnt++ < wdt-1) k8t_tmPutC(term, " "); + k8t_ttyPutStr(term, "x"); // - tputstr(term, clrdef); - tputstr(term, "\r\n"); - tputstr(term, clr); + k8t_ttyPutStr(term, clrdef); + k8t_ttyPutStr(term, "\r\n"); + k8t_ttyPutStr(term, clr); // - tputc(term, "m"); - for (int f = 2; f < wdt; ++f) tputc(term, "q"); - tputc(term, "j"); + k8t_tmPutC(term, "m"); + for (int f = 2; f < wdt; ++f) k8t_tmPutC(term, "q"); + k8t_tmPutC(term, "j"); } else { int left = (wdt-2-tlen)/2, cnt = left+1+tlen; // - tputc(term, "l"); - while (left-- > 0) tputc(term, "q"); - tputstr(term, "\x1b[37m"); - tputstr(term, title); - tputstr(term, "\x1b[33m"); - while (cnt++ < wdt-1) tputc(term, "q"); - tputc(term, "k"); + k8t_tmPutC(term, "l"); + while (left-- > 0) k8t_tmPutC(term, "q"); + k8t_ttyPutStr(term, "\x1b[37m"); + k8t_ttyPutStr(term, title); + k8t_ttyPutStr(term, "\x1b[33m"); + while (cnt++ < wdt-1) k8t_tmPutC(term, "q"); + k8t_tmPutC(term, "k"); // - tputstr(term, clrdef); - tputstr(term, "\r\n"); - tputstr(term, clr); + k8t_ttyPutStr(term, clrdef); + k8t_ttyPutStr(term, "\r\n"); + k8t_ttyPutStr(term, clr); // - tputstr(term, "x "); + k8t_ttyPutStr(term, "x "); term->charset = K8T_MODE_GFX0; - tputstr(term, msg); + k8t_ttyPutStr(term, msg); term->charset = K8T_MODE_GFX1; - tputstr(term, " x"); + k8t_ttyPutStr(term, " x"); // - tputstr(term, clrdef); - tputstr(term, "\r\n"); - tputstr(term, clr); + k8t_ttyPutStr(term, clrdef); + k8t_ttyPutStr(term, "\r\n"); + k8t_ttyPutStr(term, clr); // - tputc(term, "m"); - for (int f = 2; f < wdt; ++f) tputc(term, "q"); - tputc(term, "j"); + k8t_tmPutC(term, "m"); + for (int f = 2; f < wdt; ++f) k8t_tmPutC(term, "q"); + k8t_tmPutC(term, "j"); } // term->charset = K8T_MODE_GFX0; //term->c.attr.attr &= ~K8T_ATTR_REVERSE; // - //tputstr(msg); + //k8t_ttyPutStr(msg); } - tputstr(term, "\x1b[0m"); + k8t_ttyPutStr(term, "\x1b[0m"); } static void tdrawfatalmsg (K8Term *term, const char *msg) { if (term != NULL && msg != NULL) { - tresetmode(term); + k8t_tmResetMode(term); term->c.state |= K8T_CURSOR_HIDE; - //tmoveto(0, term->c.y); - if (term->c.x != 0) tputstr(term, "\x1b[0m\r\n"); + //k8t_tmMoveTo(0, term->c.y); + if (term->c.x != 0) k8t_ttyPutStr(term, "\x1b[0m\r\n"); // - tdrawfatalbox(term, msg); + k8t_tmDrawFatalBox(term, msg); // - setWantRedraw(term, 1); - tfulldirt(term); + k8t_tmWantRedraw(term, 1); + k8t_tmFullDirty(term); } } diff --git a/src/ttyinit.c b/src/ttyinit.c index e8c38d1..4d25309 100644 --- a/src/ttyinit.c +++ b/src/ttyinit.c @@ -55,13 +55,13 @@ static __attribute__((noreturn)) void execsh (const char *str) { } -static int ttynew (K8Term *term) { +static int k8t_ttyNew (K8Term *term) { int m, s; struct winsize w = {term->row, term->col, 0, 0}; // if (openpty(&m, &s, NULL, NULL, &w) < 0) die("openpty failed: %s", strerror(errno)); term->cmdfd = m; - ttyresize(term); + k8t_ttyResize(term); term->cmdfd = -1; switch (term->pid = fork()) { case -1: /* error */ @@ -81,7 +81,7 @@ static int ttynew (K8Term *term) { close(s); term->cmdfd = m; term->dead = 0; - ttyresize(term); + k8t_ttyResize(term); break; } return 0; diff --git a/src/ttyputc.c b/src/ttyputc.c index 91bf632..21f080b 100644 --- a/src/ttyputc.c +++ b/src/ttyputc.c @@ -1,5 +1,5 @@ //////////////////////////////////////////////////////////////////////////////// -static void csidump (K8Term *term) { +static void k8t_dbgCSIDump (K8Term *term) { fprintf(stderr, "^["); for (int f = 0; f < term->escseq.len; ++f) { uint32_t c = (term->escseq.buf[f]&0xff); @@ -15,7 +15,7 @@ static void csidump (K8Term *term) { //////////////////////////////////////////////////////////////////////////////// -static void tresetattrs (K8Term *term) { +static void k8t_tmResetAttrs (K8Term *term) { term->c.attr.attr &= ~(K8T_ATTR_REVERSE|K8T_ATTR_UNDERLINE|K8T_ATTR_BOLD); term->c.attr.attr |= K8T_ATTR_DEFFG|K8T_ATTR_DEFBG; term->c.attr.fg = term->deffg; @@ -23,11 +23,11 @@ static void tresetattrs (K8Term *term) { } -static void tsetattr (K8Term *term, int *attr, int l) { +static void k8t_tmSetAttr (K8Term *term, int *attr, int l) { for (int f = 0; f < l; ++f) { switch (attr[f]) { case 0: - tresetattrs(term); + k8t_tmResetAttrs(term); break; case 1: term->c.attr.attr |= K8T_ATTR_BOLD; @@ -88,7 +88,7 @@ static void tsetattr (K8Term *term, int *attr, int l) { else if (K8T_BETWEEN(attr[f], 40, 47)) { term->c.attr.bg = attr[f]-40; term->c.attr.attr &= ~K8T_ATTR_DEFBG; } else if (K8T_BETWEEN(attr[f], 90, 97)) { term->c.attr.fg = attr[f]-90+8; term->c.attr.attr &= ~K8T_ATTR_DEFFG; } else if (K8T_BETWEEN(attr[f], 100, 107)) { term->c.attr.bg = attr[f]-100+8; term->c.attr.attr &= ~K8T_ATTR_DEFBG; } - else { fprintf(stderr, "erresc: gfx attr %d unknown\n", attr[f]); csidump(term); } + else { fprintf(stderr, "erresc: gfx attr %d unknown\n", attr[f]); k8t_dbgCSIDump(term); } break; } } @@ -99,14 +99,14 @@ static void tsetattr (K8Term *term, int *attr, int l) { // 0: no wrapping // 1: wrapped // -1: no-wrap mode and tries to wrap -static int tdowrap (K8Term *term) { +static int k8t_tmDoWrap (K8Term *term) { if (term->c.state&K8T_CURSOR_WRAPNEXT) { if (K8T_ISSET(term, K8T_MODE_WRAP)) { // always go to first col - tnewline(term, 2); // this will reset K8T_CURSOR_WRAPNEXT + k8t_tmNewLine(term, 2); // this will reset K8T_CURSOR_WRAPNEXT return 1; } else { - tsetcharwrap(term, term->c.y, 0); + k8t_tmCharWrap(term, term->c.y, 0); return -1; } } @@ -116,68 +116,68 @@ static int tdowrap (K8Term *term) { //////////////////////////////////////////////////////////////////////////////// // esc processing -static void csihandle (K8Term *term) { +static void k8t_tmCSIHandle (K8Term *term) { if (term->dumpescapes) { fprintf(stderr, "CSI: "); - csidump(term); + k8t_dbgCSIDump(term); } // switch (term->escseq.mode) { case '@': /* ICH -- Insert blank char */ K8T_DEFAULT(term->escseq.arg[0], 1); - tinsertblank(term, term->escseq.arg[0]); + k8t_tmInsertBlank(term, term->escseq.arg[0]); break; case 'A': /* CUU -- Cursor Up */ case 'e': K8T_DEFAULT(term->escseq.arg[0], 1); - tmoveto(term, term->c.x, term->c.y-term->escseq.arg[0]); + k8t_tmMoveTo(term, term->c.x, term->c.y-term->escseq.arg[0]); break; case 'B': /* CUD -- Cursor Down */ K8T_DEFAULT(term->escseq.arg[0], 1); - tmoveto(term, term->c.x, term->c.y+term->escseq.arg[0]); + k8t_tmMoveTo(term, term->c.x, term->c.y+term->escseq.arg[0]); break; case 'C': /* CUF -- Cursor Forward */ case 'a': K8T_DEFAULT(term->escseq.arg[0], 1); - tmoveto(term, term->c.x+term->escseq.arg[0], term->c.y); + k8t_tmMoveTo(term, term->c.x+term->escseq.arg[0], term->c.y); break; case 'D': /* CUB -- Cursor Backward */ K8T_DEFAULT(term->escseq.arg[0], 1); - tmoveto(term, term->c.x-term->escseq.arg[0], term->c.y); + k8t_tmMoveTo(term, term->c.x-term->escseq.arg[0], term->c.y); break; case 'E': /* CNL -- Cursor Down and first col */ K8T_DEFAULT(term->escseq.arg[0], 1); - tmoveto(term, 0, term->c.y+term->escseq.arg[0]); + k8t_tmMoveTo(term, 0, term->c.y+term->escseq.arg[0]); break; case 'F': /* CPL -- Cursor Up and first col */ K8T_DEFAULT(term->escseq.arg[0], 1); - tmoveto(term, 0, term->c.y-term->escseq.arg[0]); + k8t_tmMoveTo(term, 0, term->c.y-term->escseq.arg[0]); break; case 'G': /* CHA -- Move to */ case '`': /* XXX: HPA -- same? */ K8T_DEFAULT(term->escseq.arg[0], 1); - tmoveto(term, term->escseq.arg[0]-1, term->c.y); + k8t_tmMoveTo(term, term->escseq.arg[0]-1, term->c.y); break; case 'H': /* CUP -- Move to */ case 'f': /* XXX: HVP -- same? */ K8T_DEFAULT(term->escseq.arg[0], 1); K8T_DEFAULT(term->escseq.arg[1], 1); - tmoveto(term, term->escseq.arg[1]-1, term->escseq.arg[0]-1); + k8t_tmMoveTo(term, term->escseq.arg[1]-1, term->escseq.arg[0]-1); break; /* XXX: (CSI n I) CHT -- Cursor Forward Tabulation tab stops */ case 'J': /* ED -- Clear screen */ term->sel.bx = -1; switch (term->escseq.arg[0]) { case 0: /* below */ - tclearregion(term, term->c.x, term->c.y, term->col-1, term->c.y); - if (term->c.y < term->row-1) tclearregion(term, 0, term->c.y+1, term->col-1, term->row-1); + k8t_tmClearRegion(term, term->c.x, term->c.y, term->col-1, term->c.y); + if (term->c.y < term->row-1) k8t_tmClearRegion(term, 0, term->c.y+1, term->col-1, term->row-1); break; case 1: /* above */ - if (term->c.y > 1) tclearregion(term, 0, 0, term->col-1, term->c.y-1); - tclearregion(term, 0, term->c.y, term->c.x, term->c.y); + if (term->c.y > 1) k8t_tmClearRegion(term, 0, 0, term->col-1, term->c.y-1); + k8t_tmClearRegion(term, 0, term->c.y, term->c.x, term->c.y); break; case 2: /* all */ - tclearregion(term, 0, 0, term->col-1, term->row-1); + k8t_tmClearRegion(term, 0, 0, term->col-1, term->row-1); break; default: goto unknown; @@ -186,27 +186,27 @@ static void csihandle (K8Term *term) { case 'K': /* EL -- Clear line */ switch (term->escseq.arg[0]) { case 0: /* right */ - tclearregion(term, term->c.x, term->c.y, term->col-1, term->c.y); + k8t_tmClearRegion(term, term->c.x, term->c.y, term->col-1, term->c.y); break; case 1: /* left */ - tclearregion(term, 0, term->c.y, term->c.x, term->c.y); + k8t_tmClearRegion(term, 0, term->c.y, term->c.x, term->c.y); break; case 2: /* all */ - tclearregion(term, 0, term->c.y, term->col-1, term->c.y); + k8t_tmClearRegion(term, 0, term->c.y, term->col-1, term->c.y); break; } break; case 'S': /* SU -- Scroll line up */ K8T_DEFAULT(term->escseq.arg[0], 1); - tscrollup(term, term->top, term->escseq.arg[0], 0); + k8t_tmScrollUp(term, term->top, term->escseq.arg[0], 0); break; case 'T': /* SD -- Scroll line down */ K8T_DEFAULT(term->escseq.arg[0], 1); - tscrolldown(term, term->top, term->escseq.arg[0]); + k8t_tmScrollDown(term, term->top, term->escseq.arg[0]); break; case 'L': /* IL -- Insert blank lines */ K8T_DEFAULT(term->escseq.arg[0], 1); - tinsertblankline(term, term->escseq.arg[0]); + k8t_tmInsertBlankLine(term, term->escseq.arg[0]); break; case 'l': /* RM -- Reset Mode */ if (term->escseq.priv) { @@ -219,12 +219,12 @@ static void csihandle (K8Term *term) { case 5: /* DECSCNM -- Remove reverse video */ if (K8T_ISSET(term, K8T_MODE_REVERSE)) { term->mode &= ~K8T_MODE_REVERSE; - tfulldirt(term); + k8t_tmFullDirty(term); } break; case 7: /* autowrap off */ if (K8T_ISSET(term, K8T_MODE_WRAP)) { - tdowrap(term); + k8t_tmDoWrap(term); term->mode &= ~K8T_MODE_WRAP; } break; @@ -236,7 +236,7 @@ static void csihandle (K8Term *term) { case 25: /* hide cursor */ if ((term->c.state&K8T_CURSOR_HIDE) == 0) { term->c.state |= K8T_CURSOR_HIDE; - setWantRedraw(term, 0); + k8t_tmWantRedraw(term, 0); } break; case 1000: /* disable X11 xterm mouse reporting */ @@ -257,12 +257,12 @@ static void csihandle (K8Term *term) { case 47: case 1047: if (K8T_ISSET(term, K8T_MODE_ALTSCREEN)) { - tclearregion(term, 0, 0, term->col-1, term->row-1); - tswapscreen(term); + k8t_tmClearRegion(term, 0, 0, term->col-1, term->row-1); + k8t_tmSwapScreen(term); } if (term->escseq.arg[0] != 1049) break; case 1048: - tcursor(term, K8T_CURSOR_LOAD); + k8t_tmCursor(term, K8T_CURSOR_LOAD); break; case 2004: /* reset bracketed paste mode */ term->mode &= ~K8T_MODE_BRACPASTE; @@ -288,20 +288,20 @@ static void csihandle (K8Term *term) { break; case 'M': /* DL -- Delete lines */ K8T_DEFAULT(term->escseq.arg[0], 1); - tdeleteline(term, term->escseq.arg[0]); + k8t_tmDeleteLine(term, term->escseq.arg[0]); break; case 'X': /* ECH -- Erase char */ K8T_DEFAULT(term->escseq.arg[0], 1); - tclearregion(term, term->c.x, term->c.y, term->c.x + term->escseq.arg[0], term->c.y); + k8t_tmClearRegion(term, term->c.x, term->c.y, term->c.x + term->escseq.arg[0], term->c.y); break; case 'P': /* DCH -- Delete char */ K8T_DEFAULT(term->escseq.arg[0], 1); - tdeletechar(term, term->escseq.arg[0]); + k8t_tmDeleteChar(term, term->escseq.arg[0]); break; /* XXX: (CSI n Z) CBT -- Cursor Backward Tabulation tab stops */ case 'd': /* VPA -- Move to */ K8T_DEFAULT(term->escseq.arg[0], 1); - tmoveto(term, term->c.x, term->escseq.arg[0]-1); + k8t_tmMoveTo(term, term->c.x, term->escseq.arg[0]-1); break; case 'h': /* SM -- Set terminal mode */ if (term->escseq.priv) { @@ -314,12 +314,12 @@ static void csihandle (K8Term *term) { case 5: /* DECSCNM -- Reverve video */ if (!K8T_ISSET(term, K8T_MODE_REVERSE)) { term->mode |= K8T_MODE_REVERSE; - tfulldirt(term); + k8t_tmFullDirty(term); } break; case 7: if (!K8T_ISSET(term, K8T_MODE_WRAP)) { - if (term->c.state&K8T_CURSOR_WRAPNEXT) tmoveto(term, term->c.x, term->c.y); // reset 'wrap-next' flag + if (term->c.state&K8T_CURSOR_WRAPNEXT) k8t_tmMoveTo(term, term->c.x, term->c.y); // reset 'wrap-next' flag term->mode |= K8T_MODE_WRAP; } break; @@ -332,7 +332,7 @@ static void csihandle (K8Term *term) { case 25: if ((term->c.state&K8T_CURSOR_HIDE) != 0) { term->c.state &= ~K8T_CURSOR_HIDE; - setWantRedraw(term, 0); + k8t_tmWantRedraw(term, 0); } break; case 1000: /* 1000,1002: enable xterm mouse report */ @@ -352,10 +352,10 @@ static void csihandle (K8Term *term) { case 1049: /* = 1047 and 1048 */ case 47: case 1047: - if (K8T_ISSET(term, K8T_MODE_ALTSCREEN)) tclearregion(term, 0, 0, term->col-1, term->row-1); else tswapscreen(term); + if (K8T_ISSET(term, K8T_MODE_ALTSCREEN)) k8t_tmClearRegion(term, 0, 0, term->col-1, term->row-1); else k8t_tmSwapScreen(term); if (term->escseq.arg[0] != 1049) break; case 1048: - tcursor(term, K8T_CURSOR_SAVE); + k8t_tmCursor(term, K8T_CURSOR_SAVE); break; case 2004: /* set bracketed paste mode */ term->mode |= K8T_MODE_BRACPASTE; @@ -376,19 +376,19 @@ static void csihandle (K8Term *term) { } break; case 'm': /* SGR -- Terminal attribute (color) */ - tsetattr(term, term->escseq.arg, term->escseq.narg); + k8t_tmSetAttr(term, term->escseq.arg, term->escseq.narg); break; case 'n': if (!term->escseq.priv) { switch (term->escseq.arg[0]) { case 5: /* Device status report (DSR) */ - ttywritestr(term, "\x1b[0n"); + k8t_ttyWriteStr(term, "\x1b[0n"); break; case 6: { /* cursor position report */ char buf[32]; // sprintf(buf, "\x1b[%d;%dR", term->c.x+1, term->c.y+1); - ttywritestr(term, buf); + k8t_ttyWriteStr(term, buf); } break; } } @@ -404,8 +404,8 @@ static void csihandle (K8Term *term) { } else { K8T_DEFAULT(term->escseq.arg[0], 1); K8T_DEFAULT(term->escseq.arg[1], term->row); - tsetscroll(term, term->escseq.arg[0]-1, term->escseq.arg[1]-1); - tmoveto(term, 0, 0); + k8t_tmSetScrollRegion(term, term->escseq.arg[0]-1, term->escseq.arg[1]-1); + k8t_tmMoveTo(term, 0, 0); } break; case 's': /* DECSC -- Save cursor position (ANSI.SYS) */ @@ -415,27 +415,27 @@ static void csihandle (K8Term *term) { term->mode |= K8T_MODE_APPKEYPAD; if (term->dumpeskeys) fprintf(stderr, "*KPMODE: on (1001s)\n"); } else { - tcursor(term, K8T_CURSOR_SAVE); + k8t_tmCursor(term, K8T_CURSOR_SAVE); } break; case 'u': /* DECRC -- Restore cursor position (ANSI.SYS) */ - tcursor(term, K8T_CURSOR_LOAD); + k8t_tmCursor(term, K8T_CURSOR_LOAD); break; default: unknown: fprintf(stderr, "erresc: unknown csi "); - csidump(term); + k8t_dbgCSIDump(term); break; } } -static void csireset (K8Term *term) { +static void k8t_tmCSIReset (K8Term *term) { memset(&term->escseq, 0, sizeof(term->escseq)); } -static void csiparse (K8Term *term) { +static void k8t_tmCSIParse (K8Term *term) { const char *p = term->escseq.buf; // term->escseq.narg = 0; @@ -461,10 +461,10 @@ static void csiparse (K8Term *term) { //////////////////////////////////////////////////////////////////////////////// -static void tputtab (K8Term *term) { +static void k8t_tmPutTab (K8Term *term) { int space = opt_tabsize-term->c.x%opt_tabsize; // - if (space > 0) tmoveto(term, term->c.x+space, term->c.y); + if (space > 0) k8t_tmMoveTo(term, term->c.x+space, term->c.y); } @@ -473,18 +473,18 @@ static void tputtab (K8Term *term) { // return 1 if this was control character // return -1 if this should break esape sequence -static int tputc_ctrl (K8Term *term, char ascii) { +static int k8t_tmPutCtrl (K8Term *term, char ascii) { int res = 1; // if (term->esc&K8T_ESC_TITLE) return 0; // switch (ascii) { - case '\t': if (tdowrap(term) >= 0) tputtab(term); break; - case '\b': tdowrap(term); tmoveto(term, term->c.x-1, term->c.y); break; - case '\r': tdowrap(term); tmoveto(term, 0, term->c.y); break; + case '\t': if (k8t_tmDoWrap(term) >= 0) k8t_tmPutTab(term); break; + case '\b': k8t_tmDoWrap(term); k8t_tmMoveTo(term, term->c.x-1, term->c.y); break; + case '\r': k8t_tmDoWrap(term); k8t_tmMoveTo(term, 0, term->c.y); break; case '\f': case '\n': case '\v': - tdowrap(term); - tnewline(term, (K8T_ISSET(term, K8T_MODE_CRLF) ? 1 : 0)); /* go to first col if the mode is set */ + k8t_tmDoWrap(term); + k8t_tmNewLine(term, (K8T_ISSET(term, K8T_MODE_CRLF) ? 1 : 0)); /* go to first col if the mode is set */ break; case '\a': if (!(xw.state&K8T_WIN_FOCUSED) && (term->belltype&K8T_BELL_URGENT)) xseturgency(1); @@ -494,8 +494,8 @@ static int tputc_ctrl (K8Term *term, char ascii) { case 15: term->charset = K8T_MODE_GFX0; break; case 0x18: case 0x1a: res = -1; break; // do nothing, interrupt current escape sequence case 127: break; // ignore it - case '\033': csireset(term); term->esc = K8T_ESC_START; break; - //case 0x9b: csireset(term); term->esc = K8T_ESC_START|K8T_ESC_CSI; break; + case '\033': k8t_tmCSIReset(term); term->esc = K8T_ESC_START; break; + //case 0x9b: k8t_tmCSIReset(term); term->esc = K8T_ESC_START|K8T_ESC_CSI; break; default: res = 0; break; } // @@ -503,9 +503,9 @@ static int tputc_ctrl (K8Term *term, char ascii) { } -static void tputc (K8Term *term, const char *c) { +static void k8t_tmPutC (K8Term *term, const char *c) { char ascii = *c; - int ctl = tputc_ctrl(term, ascii); + int ctl = k8t_tmPutCtrl(term, ascii); // if (ctl > 0) return; // control char; should not break escape sequence if (ctl < 0) { @@ -513,14 +513,14 @@ static void tputc (K8Term *term, const char *c) { term->esc = 0; return; } - //dlogf("tputc: [%c]\n", c[0]); + //dlogf("k8t_tmPutC: [%c]\n", c[0]); if (term->esc&K8T_ESC_START) { if (term->esc&K8T_ESC_CSI) { term->escseq.buf[term->escseq.len++] = ascii; if (K8T_BETWEEN(ascii, 0x40, 0x7E) || term->escseq.len >= K8T_ESC_BUF_SIZ) { term->esc = 0; - csiparse(term); - csihandle(term); + k8t_tmCSIParse(term); + k8t_tmCSIHandle(term); } } else if (term->esc&K8T_ESC_OSC) { /* TODO: handle other OSC */ @@ -531,7 +531,7 @@ static void tputc (K8Term *term, const char *c) { //updateTabBar = 1; } } else if (term->esc&K8T_ESC_TITLE) { - int len = utf8size(c); + int len = k8t_UTF8Size(c); // if (ascii == '\a' || term->titlelen+len >= K8T_ESC_TITLE_SIZ) { term->esc = 0; @@ -603,27 +603,27 @@ static void tputc (K8Term *term, const char *c) { } switch (ascii) { case 'D': /* IND -- Linefeed */ - tdowrap(term); - if (term->c.y == term->bot) tscrollup(term, term->top, 1, 1); else tmoveto(term, term->c.x, term->c.y+1); + k8t_tmDoWrap(term); + if (term->c.y == term->bot) k8t_tmScrollUp(term, term->top, 1, 1); else k8t_tmMoveTo(term, term->c.x, term->c.y+1); break; case 'E': /* NEL -- Next line */ - tdowrap(term); - tnewline(term, 1); /* always go to first col */ + k8t_tmDoWrap(term); + k8t_tmNewLine(term, 1); /* always go to first col */ break; case 'M': /* RI -- Reverse linefeed */ if (term->c.state&K8T_CURSOR_WRAPNEXT) { - tsetcharwrap(term, term->c.y, 0); + k8t_tmCharWrap(term, term->c.y, 0); term->c.state &= ~K8T_CURSOR_WRAPNEXT; if (K8T_ISSET(term, K8T_MODE_WRAP)) { // we should move to the next line, so just stay where we are - tmoveto(term, term->c.x, term->c.y); + k8t_tmMoveTo(term, term->c.x, term->c.y); break; } } - if (term->c.y == term->top) tscrolldown(term, term->top, 1); else tmoveto(term, term->c.x, term->c.y-1); + if (term->c.y == term->top) k8t_tmScrollDown(term, term->top, 1); else k8t_tmMoveTo(term, term->c.x, term->c.y-1); break; case 'c': /* RIS -- Reset to inital state */ - treset(term); + k8t_tmReset(term); break; case '=': /* DECPAM -- Application keypad */ DUMP_KEYPAD_SWITCH("=", "ON"); @@ -642,17 +642,17 @@ static void tputc (K8Term *term, const char *c) { case '7': /* DECSC -- Save Cursor */ /* Save current state (cursor coordinates, attributes, character sets pointed at by G0, G1) */ //TODO? - tcursor(term, K8T_CURSOR_SAVE); + k8t_tmCursor(term, K8T_CURSOR_SAVE); break; case '8': /* DECRC -- Restore Cursor */ //TODO? - tcursor(term, K8T_CURSOR_LOAD); + k8t_tmCursor(term, K8T_CURSOR_LOAD); break; case 'F': /* Cursor to lower left corner of screen */ - tmoveto(term, 0, term->row-1); + k8t_tmMoveTo(term, 0, term->row-1); break; case 'Z': /* DEC private identification */ - ttywritestr(term, "\x1b[?1;2c"); + k8t_ttyWriteStr(term, "\x1b[?1;2c"); break; default: fprintf(stderr, "erresc: unknown sequence ESC 0x%02X ('%c')\n", (uint8_t)ascii, isprint(ascii)?ascii:'.'); @@ -666,15 +666,15 @@ static void tputc (K8Term *term, const char *c) { if (term->needConv && K8T_ISGFX(term->c.attr.attr)) { uint32_t cc; // - utf8decode(&cc, c); + k8t_UTF8Decode(&cc, c); if (cc < 32 || cc >= 127) break; //FIXME: nothing at all? } else { if ((unsigned char)ascii < 32 || ascii == 127) break; // seems that this chars are empty too } // - if (tdowrap(term) < 0) break; // wrapping, but wrap is off, don't want more chars - tsetchar(term, c); - if (term->c.x+1 < term->col) tmoveto(term, term->c.x+1, term->c.y); else term->c.state |= K8T_CURSOR_WRAPNEXT; + if (k8t_tmDoWrap(term) < 0) break; // wrapping, but wrap is off, don't want more chars + k8t_tmSetChar(term, c); + if (term->c.x+1 < term->col) k8t_tmMoveTo(term, term->c.x+1, term->c.y); else term->c.state |= K8T_CURSOR_WRAPNEXT; } while (0); } } diff --git a/src/ttyresize.c b/src/ttyresize.c index 9becc1e..33a32ef 100644 --- a/src/ttyresize.c +++ b/src/ttyresize.c @@ -22,7 +22,7 @@ static void xresize (K8Term *term, int col, int row) { XClearArea(xw.dpy, xw.win, 0, term->picbufh, xw.w, xw.h-term->picbufh, False); } term->picbuf = newbuf; - tfulldirt(term); + k8t_tmFullDirty(term); updateTabBar = 1; xw.state |= K8T_WIN_REDRAW; } diff --git a/src/ttyrw.c b/src/ttyrw.c index 47bfe22..d046461 100644 --- a/src/ttyrw.c +++ b/src/ttyrw.c @@ -1,6 +1,6 @@ //////////////////////////////////////////////////////////////////////////////// // tty r/w -static int ttycanread (K8Term *term) { +static int k8t_ttyCanRead (K8Term *term) { for (;;) { fd_set rfd; struct timeval timeout = {0}; @@ -19,7 +19,7 @@ static int ttycanread (K8Term *term) { } -static int ttycanwrite (K8Term *term) { +static int k8t_ttyCanWrite (K8Term *term) { for (;;) { fd_set wfd; struct timeval timeout = {0}; @@ -51,7 +51,7 @@ static void wrstr (const char *s, int len) { // return -1 if there was read error, 0 otherwise -static int ttyread (K8Term *term) { +static int k8t_ttyRead (K8Term *term) { char *ptr; int left; int res = 0; @@ -62,8 +62,8 @@ static int ttyread (K8Term *term) { term->xobuflen = term->obuflen; #endif left = OBUFSIZ-term->obuflen; - //fprintf(stderr, "0: ttyread before: free=%d, used=%d\n", left, term->obuflen); - while (left > 0 && ttycanread(term)) { + //fprintf(stderr, "0: k8t_ttyRead before: free=%d, used=%d\n", left, term->obuflen); + while (left > 0 && k8t_ttyCanRead(term)) { int ret; // //if ((ret = read(term->cmdfd, term->obuf+term->obuflen, 1)) < 0) die("Couldn't read from shell: %s", strerror(errno)); @@ -75,11 +75,11 @@ static int ttyread (K8Term *term) { } // if (ret == 0) break; - //fprintf(stderr, "ttyread: got %d bytes\n", ret); + //fprintf(stderr, "k8t_ttyRead: got %d bytes\n", ret); term->obuflen += ret; left -= ret; } - //fprintf(stderr, "1: ttyread after: free=%d, used=%d\n", left, term->obuflen); + //fprintf(stderr, "1: k8t_ttyRead after: free=%d, used=%d\n", left, term->obuflen); if (term->obuflen == 0) return res; /* process every complete utf8 char */ #ifdef DUMP_PROG_OUTPUT @@ -113,7 +113,7 @@ static int ttyread (K8Term *term) { #endif if (len > 0) { obuf[len] = 0; - tputc(term, obuf); + k8t_tmPutC(term, obuf); } ++ptr; --term->obuflen; @@ -121,13 +121,13 @@ static int ttyread (K8Term *term) { term->obuflen = 0; } else { // don't do any conversion - while (term->obuflen >= UTF_SIZ || isfullutf8(ptr, term->obuflen)) { + while (term->obuflen >= UTF_SIZ || k8t_UTF8IsFull(ptr, term->obuflen)) { uint32_t utf8c; char s[UTF_SIZ+1]; - int charsize = utf8decode(&utf8c, ptr); + int charsize = k8t_UTF8Decode(&utf8c, ptr); int len; // - len = utf8encode(s, utf8c); + len = k8t_UTF8Encode(s, utf8c); #ifdef DUMP_IO_READ { fprintf(stderr, "rdx: ["); @@ -138,13 +138,13 @@ static int ttyread (K8Term *term) { #endif if (len > 0) { s[len] = 0; - tputc(term, s); + k8t_tmPutC(term, s); } ptr += charsize; term->obuflen -= charsize; } if (res < 0) term->obuflen = 0; // there was read error, we should not expect more bytes - //dlogf("2: ttyread afterproc: used=%d", term->obuflen); + //dlogf("2: k8t_ttyRead afterproc: used=%d", term->obuflen); } /* keep any uncomplete utf8 char for the next call */ if (term->obuflen > 0) { @@ -156,14 +156,14 @@ static int ttyread (K8Term *term) { } -static void ttyflushwrbuf (K8Term *term) { +static void k8t_ttyFlushWriteBuf (K8Term *term) { if (term == NULL || term->dead || term->cmdfd < 0) return; if (term->wrbufpos >= term->wrbufused) { term->wrbufpos = term->wrbufused = 0; return; } - //dlogf("0: ttyflushwrbuf before: towrite=%d", term->wrbufused-term->wrbufpos); - while (term->wrbufpos < term->wrbufused && ttycanwrite(term)) { + //dlogf("0: k8t_ttyFlushWriteBuf before: towrite=%d", term->wrbufused-term->wrbufpos); + while (term->wrbufpos < term->wrbufused && k8t_ttyCanWrite(term)) { int ret; // if ((ret = write(term->cmdfd, term->wrbuf+term->wrbufpos, term->wrbufused-term->wrbufpos)) < 0) { @@ -185,13 +185,13 @@ static void ttyflushwrbuf (K8Term *term) { term->wrbufused = left; } } - //dlogf("1: ttyflushwrbuf after: towrite=%d", term->wrbufused-term->wrbufpos); + //dlogf("1: k8t_ttyFlushWriteBuf after: towrite=%d", term->wrbufused-term->wrbufpos); } // convert char to locale and write it // return<0: error; ==0: ok -static int ttywriterawchar (K8Term *term, const char *s, int len, int noenc) { +static int k8t_ttyWriteRawChar (K8Term *term, const char *s, int len, int noenc) { char loc[16]; int clen; // @@ -200,7 +200,7 @@ static int ttywriterawchar (K8Term *term, const char *s, int len, int noenc) { if (term->needConv) { if ((clen = utf2loc(loc, s, len)) < 1) return 0; } else { - if ((clen = utf8size(s)) < 1) return 0; + if ((clen = k8t_UTF8Size(s)) < 1) return 0; memmove(loc, s, clen); } } else { @@ -222,7 +222,7 @@ static int ttywriterawchar (K8Term *term, const char *s, int len, int noenc) { int res; // // force write at least one char - //dlogf("ttywrite: forced write"); + //dlogf("k8t_ttyWrite: forced write"); if ((res = write(term->cmdfd, term->wrbuf+term->wrbufpos, 1)) < 0) { //fprintf(stderr, "Warning: write error on tty #%d: %s\n", termidx, strerror(errno)); if (errno == EINTR) continue; @@ -230,7 +230,7 @@ static int ttywriterawchar (K8Term *term, const char *s, int len, int noenc) { } if (res == 0) return -1; //SHIT! ++term->wrbufpos; - ttyflushwrbuf(term); // make room for char + k8t_ttyFlushWriteBuf(term); // make room for char } memcpy(term->wrbuf+term->wrbufused, loc, clen); term->wrbufused += clen; @@ -239,16 +239,16 @@ static int ttywriterawchar (K8Term *term, const char *s, int len, int noenc) { } -static void ttywritenoenc (K8Term *term, const char *s, size_t n) { +static void k8t_ttyWriteNoEnc (K8Term *term, const char *s, size_t n) { if (n > 0) { term->ubufpos = 0; // discard possible utf-8 char - while (n-- > 0) ttywriterawchar(term, s++, 1, 1); + while (n-- > 0) k8t_ttyWriteRawChar(term, s++, 1, 1); } - ttyflushwrbuf(term); + k8t_ttyFlushWriteBuf(term); } -static void ttywrite (K8Term *term, const char *s, size_t n) { +static void k8t_ttyWrite (K8Term *term, const char *s, size_t n) { if (term == NULL || term->dead || term->cmdfd < 0) return; #ifdef DUMP_PROG_INPUT if (s != NULL && n > 0) { @@ -259,14 +259,14 @@ static void ttywrite (K8Term *term, const char *s, size_t n) { } } #endif - //ttyflushwrbuf(); + //k8t_ttyFlushWriteBuf(); if (s != NULL && n > 0) { while (n > 0) { unsigned char c = (unsigned char)(s[0]); // - if (term->ubufpos > 0 && isfullutf8(term->ubuf, term->ubufpos)) { + if (term->ubufpos > 0 && k8t_UTF8IsFull(term->ubuf, term->ubufpos)) { // have complete char - ttywriterawchar(term, term->ubuf, term->ubufpos, 0); + k8t_ttyWriteRawChar(term, term->ubuf, term->ubufpos, 0); term->ubufpos = 0; continue; } @@ -274,7 +274,7 @@ static void ttywrite (K8Term *term, const char *s, size_t n) { if (term->ubufpos == 0) { // new char if (c < 128) { - ttywriterawchar(term, s, 1, 0); + k8t_ttyWriteRawChar(term, s, 1, 0); } else if ((c&0xc0) == 0xc0) { // new utf-8 char term->ubuf[term->ubufpos++] = *s; @@ -295,12 +295,12 @@ static void ttywrite (K8Term *term, const char *s, size_t n) { term->ubuf[term->ubufpos++] = *s; ++s; --n; - if (isfullutf8(term->ubuf, term->ubufpos)) { + if (k8t_UTF8IsFull(term->ubuf, term->ubufpos)) { // have complete char - ttywriterawchar(term, term->ubuf, term->ubufpos, 0); + k8t_ttyWriteRawChar(term, term->ubuf, term->ubufpos, 0); term->ubufpos = 0; } } } - ttyflushwrbuf(term); + k8t_ttyFlushWriteBuf(term); } diff --git a/src/ttyutils.c b/src/ttyutils.c index 63a2a7a..d419cfb 100644 --- a/src/ttyutils.c +++ b/src/ttyutils.c @@ -1,67 +1,67 @@ -static void tsetdirt (K8Term *term, int top, int bot) { +static void k8t_tmDirty (K8Term *term, int top, int bot) { K8T_LIMIT(top, 0, term->row-1); K8T_LIMIT(bot, 0, term->row-1); - for (int y = top; y <= bot; ++y) markDirty(term, y, 2); + for (int y = top; y <= bot; ++y) k8t_tmDirtyMark(term, y, 2); } -static void tfulldirt (K8Term *term) { - tsetdirt(term, 0, term->row-1); +static void k8t_tmFullDirty (K8Term *term) { + k8t_tmDirty(term, 0, term->row-1); } -static void tmoveto (K8Term *term, int x, int y) { +static void k8t_tmMoveTo (K8Term *term, int x, int y) { K8T_LIMIT(x, 0, term->col-1); K8T_LIMIT(y, 0, term->row-1); term->c.state &= ~K8T_CURSOR_WRAPNEXT; if (term->c.x != x || term->c.y != y) { term->c.x = x; term->c.y = y; - setWantRedraw(term, 0); + k8t_tmWantRedraw(term, 0); } } -static void tclearregion (K8Term *term, int x1, int y1, int x2, int y2) { +static void k8t_tmClearRegion (K8Term *term, int x1, int y1, int x2, int y2) { int temp; // - //fprintf(stderr, "tclearregion: (%d,%d)-(%d,%d)\n", x1, y1, x2, y2); + //fprintf(stderr, "k8t_tmClearRegion: (%d,%d)-(%d,%d)\n", x1, y1, x2, y2); if (x1 > x2) { temp = x1; x1 = x2; x2 = temp; } if (y1 > y2) { temp = y1; y1 = y2; y2 = temp; } K8T_LIMIT(x1, 0, term->col-1); K8T_LIMIT(x2, 0, term->col-1); K8T_LIMIT(y1, 0, term->row-1); K8T_LIMIT(y2, 0, term->row-1); - //fprintf(stderr, " tclearregion: (%d,%d)-(%d,%d)\n", x1, y1, x2, y2); + //fprintf(stderr, " k8t_tmClearRegion: (%d,%d)-(%d,%d)\n", x1, y1, x2, y2); for (int y = y1; y <= y2; ++y) { K8TLine l = term->line[y]; // - markDirty(term, y, (x1 <= 0 && x2 >= term->col-1) ? 2 : 1); + k8t_tmDirtyMark(term, y, (x1 <= 0 && x2 >= term->col-1) ? 2 : 1); for (int x = x1; x <= x2; ++x) { l[x].fg = term->c.attr.fg; l[x].bg = term->c.attr.bg; l[x].state = K8T_GLYPH_DIRTY; l[x].attr = K8T_ATTR_NULL|(term->c.attr.attr&(K8T_ATTR_DEFFG|K8T_ATTR_DEFBG)); l[x].c[0] = ' '; - if (term->sel.bx != -1 && isselected(term, x, y)) selhide(term); + if (term->sel.bx != -1 && k8t_isSelected(term, x, y)) k8t_selHide(term); } l[term->col-1].state &= ~K8T_GLYPH_WRAP; } } -static void tcursor (K8Term *term, int mode) { +static void k8t_tmCursor (K8Term *term, int mode) { if (mode == K8T_CURSOR_SAVE) { term->csaved = term->c; } else if (mode == K8T_CURSOR_LOAD) { term->c = term->csaved; - tmoveto(term, term->c.x, term->c.y); - setWantRedraw(term, 0); + k8t_tmMoveTo(term, term->c.x, term->c.y); + k8t_tmWantRedraw(term, 0); } } -static void tadjustmaxhistory (K8Term *term, int maxh) { +static void k8t_tmAdjMaxHistory (K8Term *term, int maxh) { if (term != NULL) { K8T_LIMIT(maxh, 0, 65535); if (term->maxhistory < maxh) { @@ -100,9 +100,9 @@ static void tadjustmaxhistory (K8Term *term, int maxh) { } -static void tswapscreen (K8Term *term) { - selhide(term); - tdowrap(term); +static void k8t_tmSwapScreen (K8Term *term) { + k8t_selHide(term); + k8t_tmDoWrap(term); for (int f = 0; f < term->row; ++f) { K8TLine t = term->line[f]; // @@ -110,23 +110,23 @@ static void tswapscreen (K8Term *term) { term->alt[f] = t; } term->mode ^= K8T_MODE_ALTSCREEN; - tfulldirt(term); + k8t_tmFullDirty(term); term->justSwapped = 1; } //FIXME: works bad with history //FIXME: ugly code -static void selscroll (K8Term *term, int orig, int n, int tohistory) { +static void k8t_tmScrollSelection (K8Term *term, int orig, int n, int tohistory) { int docopy = 0; // if (term->sel.bx == -1) return; // - tfulldirt(term); // just in case + k8t_tmFullDirty(term); // just in case if (!tohistory) { if (K8T_BETWEEN(term->sel.by, orig, term->bot) || K8T_BETWEEN(term->sel.ey, orig, term->bot)) { if ((term->sel.by += n) > term->bot || (term->sel.ey += n) < term->top) { - selclear(term); + k8t_selClear(term); return; } if (term->sel.by < term->top) { @@ -146,13 +146,13 @@ static void selscroll (K8Term *term, int orig, int n, int tohistory) { } } else { // tohistory!=0; always scrolls full screen up (n == -1) - //fprintf(stderr, "selscroll to history\n"); + //fprintf(stderr, "k8t_tmScrollSelection to history\n"); term->sel.by += n; term->sel.ey += n; //fprintf(stderr, " by=%d; ey=%d; maxhistory=%d\n", term->sel.by, term->sel.ey, term->maxhistory); if (term->sel.ey < 0 && -(term->sel.ey) > term->maxhistory) { // out of screen completely - selclear(term); + k8t_selClear(term); return; } if (term->sel.by < 0 && -(term->sel.by) > term->maxhistory) { @@ -166,35 +166,35 @@ static void selscroll (K8Term *term, int orig, int n, int tohistory) { term->sel.e.y = term->sel.ey; } // - if (docopy) selcopy(term); + if (docopy) k8t_selCopy(term); } -static void tscrolldown (K8Term *term, int orig, int n) { +static void k8t_tmScrollDown (K8Term *term, int orig, int n) { K8TLine temp; // K8T_LIMIT(n, 0, term->bot-orig+1); if (n < 1) return; - selscroll(term, orig, n, 0); - //fprintf(stderr, "tscrolldown(%d, %d)\n", orig, n); - tclearregion(term, 0, term->bot-n+1, term->col-1, term->bot); + k8t_tmScrollSelection(term, orig, n, 0); + //fprintf(stderr, "k8t_tmScrollDown(%d, %d)\n", orig, n); + k8t_tmClearRegion(term, 0, term->bot-n+1, term->col-1, term->bot); for (int f = term->bot; f >= orig+n; --f) { temp = term->line[f]; term->line[f] = term->line[f-n]; term->line[f-n] = temp; - markDirty(term, f, 2); - markDirty(term, f-n, 2); + k8t_tmDirtyMark(term, f, 2); + k8t_tmDirtyMark(term, f-n, 2); } } -static void tscrollup (K8Term *term, int orig, int n, int tohistory) { +static void k8t_tmScrollUp (K8Term *term, int orig, int n, int tohistory) { K8TLine temp; // if (term == NULL) return; K8T_LIMIT(n, 0, term->bot-orig+1); if (n < 1) return; - //fprintf(stderr, "tscrollup(%d, %d)\n", orig, n); + //fprintf(stderr, "k8t_tmScrollUp(%d, %d)\n", orig, n); if (tohistory && !K8T_ISSET(term, K8T_MODE_ALTSCREEN) && term->maxhistory > 0) { K8TLine l = term->line[term->linecount-1]; // @@ -205,20 +205,20 @@ static void tscrollup (K8Term *term, int orig, int n, int tohistory) { tohistory = 0; } // - selscroll(term, orig, -n, tohistory); - //tclearregion(0, orig, term->col-1, orig+n-1); + k8t_tmScrollSelection(term, orig, -n, tohistory); + //k8t_tmClearRegion(0, orig, term->col-1, orig+n-1); for (int f = orig; f <= term->bot-n; ++f) { temp = term->line[f]; term->line[f] = term->line[f+n]; term->line[f+n] = temp; - markDirty(term, f, 2); - markDirty(term, f+n, 2); + k8t_tmDirtyMark(term, f, 2); + k8t_tmDirtyMark(term, f+n, 2); } - tclearregion(term, 0, term->bot-n+1, term->col-1, term->bot); + k8t_tmClearRegion(term, 0, term->bot-n+1, term->col-1, term->bot); } -static inline void tsetcharwrap (K8Term *term, int y, int wrap) { +static void k8t_tmCharWrap (K8Term *term, int y, int wrap) { if (y >= 0 && y < term->row) { if (wrap) term->line[y][term->col-1].state |= K8T_GLYPH_WRAP; else term->line[y][term->col-1].state &= ~K8T_GLYPH_WRAP; @@ -226,16 +226,16 @@ static inline void tsetcharwrap (K8Term *term, int y, int wrap) { } -static void tnewline (K8Term *term, int first_col) { +static void k8t_tmNewLine (K8Term *term, int first_col) { int y = term->c.y; // - tsetcharwrap(term, y, (first_col == 2)); // 2: wrapping - if (y == term->bot) tscrollup(term, term->top, 1, 1); else ++y; - tmoveto(term, (first_col ? 0 : term->c.x), y); + k8t_tmCharWrap(term, y, (first_col == 2)); // 2: wrapping + if (y == term->bot) k8t_tmScrollUp(term, term->top, 1, 1); else ++y; + k8t_tmMoveTo(term, (first_col ? 0 : term->c.x), y); } -static void tsetchar (K8Term *term, const char *c) { +static void k8t_tmSetChar (K8Term *term, const char *c) { char ub[UTF_SIZ]; int rev = 0, gfx = 0; int x = term->c.x, y = term->c.y; @@ -245,7 +245,7 @@ static void tsetchar (K8Term *term, const char *c) { if (!term->needConv && unimap != NULL && (unsigned char)c[0] >= 0x80) { uint32_t cc; // - utf8decode(&cc, c); + k8t_UTF8Decode(&cc, c); if (cc <= 65535) { uint16_t uc = unimap[cc]; // @@ -260,14 +260,14 @@ static void tsetchar (K8Term *term, const char *c) { ub[0] = (uc&0x7f); gfx = 1; } else { - utf8encode(ub, uc); + k8t_UTF8Encode(ub, uc); } } c = ub; } } } - markDirty(term, y, 1); + k8t_tmDirtyMark(term, y, 1); // term->line[y][x] = term->c.attr; if (rev) term->line[y][x].attr ^= K8T_ATTR_REVERSE; @@ -286,54 +286,54 @@ static void tsetchar (K8Term *term, const char *c) { if (c > 95 && c < 128) term->line[y][x].c[0] -= 95; else if (c > 127) term->line[y][x].c[0] = ' '; } - if (term->sel.bx != -1 && isselected(term, x, y)) selhide(term); - //dlogf("tsetchar(%d,%d): [%c] (%d); dirty=%d\n", x, y, c[0], term->wantRedraw, term->dirty[y]); + if (term->sel.bx != -1 && k8t_isSelected(term, x, y)) k8t_selHide(term); + //dlogf("k8t_tmSetChar(%d,%d): [%c] (%d); dirty=%d\n", x, y, c[0], term->wantRedraw, term->dirty[y]); } -static void tdeletechar (K8Term *term, int n) { +static void k8t_tmDeleteChar (K8Term *term, int n) { int src = term->c.x+n; int dst = term->c.x; int size = term->col-src; // - markDirty(term, term->c.y, 2); + k8t_tmDirtyMark(term, term->c.y, 2); if (src >= term->col) { - tclearregion(term, term->c.x, term->c.y, term->col-1, term->c.y); + k8t_tmClearRegion(term, term->c.x, term->c.y, term->col-1, term->c.y); } else { memmove(&term->line[term->c.y][dst], &term->line[term->c.y][src], size*sizeof(K8TGlyph)); - tclearregion(term, term->col-n, term->c.y, term->col-1, term->c.y); + k8t_tmClearRegion(term, term->col-n, term->c.y, term->col-1, term->c.y); } } -static void tinsertblank (K8Term *term, int n) { +static void k8t_tmInsertBlank (K8Term *term, int n) { int src = term->c.x; int dst = src+n; int size = term->col-dst; // - markDirty(term, term->c.y, 2); + k8t_tmDirtyMark(term, term->c.y, 2); if (dst >= term->col) { - tclearregion(term, term->c.x, term->c.y, term->col-1, term->c.y); + k8t_tmClearRegion(term, term->c.x, term->c.y, term->col-1, term->c.y); } else { memmove(&term->line[term->c.y][dst], &term->line[term->c.y][src], size*sizeof(K8TGlyph)); - tclearregion(term, src, term->c.y, dst-1, term->c.y); + k8t_tmClearRegion(term, src, term->c.y, dst-1, term->c.y); } } -static void tinsertblankline (K8Term *term, int n) { +static void k8t_tmInsertBlankLine (K8Term *term, int n) { if (term->c.y < term->top || term->c.y > term->bot) return; - tscrolldown(term, term->c.y, n); + k8t_tmScrollDown(term, term->c.y, n); } -static void tdeleteline (K8Term *term, int n) { +static void k8t_tmDeleteLine (K8Term *term, int n) { if (term->c.y < term->top || term->c.y > term->bot) return; - tscrollup(term, term->c.y, n, 0); + k8t_tmScrollUp(term, term->c.y, n, 0); } -static void tsetscroll (K8Term *term, int t, int b) { +static void k8t_tmSetScrollRegion (K8Term *term, int t, int b) { int temp; // K8T_LIMIT(t, 0, term->row-1); @@ -348,25 +348,25 @@ static void tsetscroll (K8Term *term, int t, int b) { } -static void tunshowhistory (K8Term *term) { +static void k8t_tmUnshowHistory (K8Term *term) { if (term != NULL && term->topline != 0) { term->topline = 0; - setWantRedraw(term, 1); + k8t_tmWantRedraw(term, 1); } } -static void tsendfocusevent (K8Term *term, int focused) { +static void k8t_tmSendFocusEvent (K8Term *term, int focused) { if (term != NULL && K8T_ISSET(term, K8T_MODE_FOCUSEVT)) { - ttywritestr(term, "\x1b["); - ttywrite(term, focused?"I":"O", 1); + k8t_ttyWriteStr(term, "\x1b["); + k8t_ttyWrite(term, focused?"I":"O", 1); } } //////////////////////////////////////////////////////////////////////////////// -// tty utilities -static void tresetmode (K8Term *term) { +// term utilities +static void k8t_tmResetMode (K8Term *term) { term->esc = 0; term->top = 0; term->bot = term->row-1; @@ -375,13 +375,13 @@ static void tresetmode (K8Term *term) { term->charset = K8T_MODE_GFX0; // term->c.state = K8T_CURSOR_DEFAULT; - tresetattrs(term); + k8t_tmResetAttrs(term); // - tcursor(term, K8T_CURSOR_SAVE); + k8t_tmCursor(term, K8T_CURSOR_SAVE); } -static void treset (K8Term *term) { +static void k8t_tmReset (K8Term *term) { K8TGlyph g; // term->c = (K8TCursor){{ @@ -397,10 +397,10 @@ static void treset (K8Term *term) { g.c[0] = ' '; g.c[1] = 0; // - tresetmode(term); - //tclearregion(0, 0, term->col-1, term->row-1); + k8t_tmResetMode(term); + //k8t_tmClearRegion(0, 0, term->col-1, term->row-1); for (int y = 0; y < term->row; ++y) { - markDirty(term, y, 2); + k8t_tmDirtyMark(term, y, 2); for (int x = 0; x < term->col; ++x) term->alt[y][x] = term->line[y][x] = g; } for (int y = term->row; y < term->linecount; ++y) { @@ -408,11 +408,11 @@ static void treset (K8Term *term) { } // term->topline = 0; - tfulldirt(term); + k8t_tmFullDirty(term); } -static int tinitialize (K8Term *term, int col, int row) { +static int k8t_tmInitialize (K8Term *term, int col, int row) { //memset(term, 0, sizeof(K8Term)); //term->needConv = needConversion ? 1 : 0; term->dumpescapes = 0; @@ -431,36 +431,21 @@ static int tinitialize (K8Term *term, int col, int row) { for (int y = 0; y < term->linecount; ++y) term->line[y] = calloc(term->col, sizeof(K8TGlyph)); for (int y = 0; y < term->row; ++y) term->alt[y] = calloc(term->col, sizeof(K8TGlyph)); /* setup screen */ - treset(term); + k8t_tmReset(term); return 1; } //////////////////////////////////////////////////////////////////////////////// -// tty resize ioctl -static void ttyresize (K8Term *term) { - if (term != NULL && term->cmdfd >= 0) { - struct winsize w; - // - w.ws_row = term->row; - w.ws_col = term->col; - w.ws_xpixel = w.ws_ypixel = 0; - if (ioctl(term->cmdfd, TIOCSWINSZ, &w) < 0) fprintf(stderr, "Warning: couldn't set window size: %s\n", strerror(errno)); - setWantRedraw(term, 1); - } -} - - -//////////////////////////////////////////////////////////////////////////////// // tty resising -static int tresize (K8Term *term, int col, int row) { +static int k8t_tmResize (K8Term *term, int col, int row) { int mincol = K8T_MIN(col, term->col); int slide = term->c.y-row+1; K8TGlyph g; // if (term == NULL || col < 1 || row < 1) return 0; // - selhide(term); + k8t_selHide(term); // g.state = K8T_GLYPH_DIRTY; g.attr = K8T_ATTR_NULL|K8T_ATTR_DEFFG|K8T_ATTR_DEFBG; @@ -470,8 +455,8 @@ static int tresize (K8Term *term, int col, int row) { g.c[1] = 0; // if (slide > 0) { - tsetscroll(term, 0, term->row-1); - for (; slide > 0; --slide) tscrollup(term, 0, 1, 1); // to fill history + k8t_tmSetScrollRegion(term, 0, term->row-1); + for (; slide > 0; --slide) k8t_tmScrollUp(term, 0, 1, 1); // to fill history } // if (row < term->row) { @@ -508,7 +493,7 @@ static int tresize (K8Term *term, int col, int row) { term->line[f] = realloc(term->line[f], col*sizeof(K8TGlyph)); for (int x = mincol; x < col; ++x) term->line[f][x] = g; if (f < row) { - markDirty(term, f, 2); + k8t_tmDirtyMark(term, f, 2); term->alt[f] = realloc(term->alt[f], col*sizeof(K8TGlyph)); for (int x = mincol; x < col; ++x) term->alt[f][x] = g; } @@ -517,10 +502,25 @@ static int tresize (K8Term *term, int col, int row) { term->topline = 0; term->col = col; term->row = row; - /* make use of the limit in tmoveto */ - tmoveto(term, term->c.x, term->c.y); + /* make use of the limit in k8t_tmMoveTo */ + k8t_tmMoveTo(term, term->c.x, term->c.y); /* reset scrolling region */ - tsetscroll(term, 0, row-1); - tfulldirt(term); + k8t_tmSetScrollRegion(term, 0, row-1); + k8t_tmFullDirty(term); return (slide > 0); } + + +//////////////////////////////////////////////////////////////////////////////// +// tty resize ioctl +static void k8t_ttyResize (K8Term *term) { + if (term != NULL && term->cmdfd >= 0) { + struct winsize w; + // + w.ws_row = term->row; + w.ws_col = term->col; + w.ws_xpixel = w.ws_ypixel = 0; + if (ioctl(term->cmdfd, TIOCSWINSZ, &w) < 0) fprintf(stderr, "Warning: couldn't set window size: %s\n", strerror(errno)); + k8t_tmWantRedraw(term, 1); + } +} diff --git a/src/utf8.c b/src/utf8.c index 27bade0..5b14c48 100644 --- a/src/utf8.c +++ b/src/utf8.c @@ -22,7 +22,7 @@ static const unsigned char utf8Length[256] = { // decode one utf-8 char from *buf to *u, return char length; return '?' on error -static int utf8decode (uint32_t *u, const void *buf) { +static int k8t_UTF8Decode (uint32_t *u, const void *buf) { const unsigned char *data = (const unsigned char *)buf; unsigned char len = utf8Length[*data]; uint32_t uc; @@ -51,7 +51,7 @@ static int utf8decode (uint32_t *u, const void *buf) { // encode one utf-8 char from u to *buf, return char length -static int utf8encode (void *buf, uint32_t uc) { +static int k8t_UTF8Encode (void *buf, uint32_t uc) { uint8_t *sp = (uint8_t *)buf; int n; // @@ -81,7 +81,7 @@ static int utf8encode (void *buf, uint32_t uc) { /* use this if your buffer is less than UTF_SIZ, it returns 1 if you can decode UTF-8 otherwise return 0 */ -static int isfullutf8 (const void *buf, int buflen) { +static int k8t_UTF8IsFull (const void *buf, int buflen) { if (buflen > 0) { const unsigned char *data = (const unsigned char *)buf; unsigned char len = utf8Length[*data++]; @@ -98,7 +98,7 @@ static int isfullutf8 (const void *buf, int buflen) { } -static inline int utf8size (const void *buf) { +static int k8t_UTF8Size (const void *buf) { const unsigned char *data = (const unsigned char *)buf; unsigned char len = utf8Length[*data]; // @@ -110,7 +110,7 @@ static inline int utf8size (const void *buf) { } -static int utf8strlen (const char *s) { +static int k8t_UTF8strlen (const char *s) { int len = 0; // while (*s) { @@ -121,7 +121,7 @@ static int utf8strlen (const char *s) { } -static void utf8choplast (char *s) { +static void k8t_UTF8ChopLast (char *s) { int lastpos = 0; // for (char *t = s; *t; ++t) { diff --git a/src/x11draw.c b/src/x11draw.c index 4c60860..9906bd0 100644 --- a/src/x11draw.c +++ b/src/x11draw.c @@ -1,10 +1,10 @@ -static void drawline (K8Term *term, int x1, int x2, int scry, int lineno, int dontcopy) { - //fprintf(stderr, "%d: drawline: x1=%d; x2=%d; scry=%d; row:%d; lineno=%d\n", mclock_ticks(), x1, x2, scry, term->row, lineno); +static void k8t_DrawLine (K8Term *term, int x1, int x2, int scry, int lineno, int dontcopy) { + //fprintf(stderr, "%d: k8t_DrawLine: x1=%d; x2=%d; scry=%d; row:%d; lineno=%d\n", mclock_ticks(), x1, x2, scry, term->row, lineno); if (term == NULL || scry < 0 || scry >= term->row) return; if (scry == term->row-1 && term->cmdline.cmdMode != K8T_CMDMODE_NONE) { xdrawcmdline(term, &term->cmdline, scry); return; } if (lineno < 0 || lineno >= term->linecount) { - xclear(term, 0, scry, term->col-1, scry); - xcopy(term, 0, scry, term->col, 1); + k8t_DrawClear(term, 0, scry, term->col-1, scry); + k8t_DrawCopy(term, 0, scry, term->col, 1); } else { int ic, ib, ox, sl; int stx, ex; @@ -43,34 +43,34 @@ static void drawline (K8Term *term, int x1, int x2, int scry, int lineno, int do } // base = l[stx]; - if (term->sel.bx != -1 && isselected(term, stx, lineno)) base.attr ^= K8T_ATTR_REVERSE; + if (term->sel.bx != -1 && k8t_isSelected(term, stx, lineno)) base.attr ^= K8T_ATTR_REVERSE; ic = ib = 0; ox = stx; - //xclear(term, stx, scry, ex-1, scry); //k8: actually, we don't need this for good monospace fonts, so... + //k8t_DrawClear(term, stx, scry, ex-1, scry); //k8: actually, we don't need this for good monospace fonts, so... for (int x = stx; x < ex; ++x) { new = l[x]; l[x].state &= ~K8T_GLYPH_DIRTY; //! - if (term->sel.bx != -1 && isselected(term, x, lineno)) new.attr ^= K8T_ATTR_REVERSE; + if (term->sel.bx != -1 && k8t_isSelected(term, x, lineno)) new.attr ^= K8T_ATTR_REVERSE; if (ib > 0 && (K8T_ATTRCMP(base, new) || ib >= DRAW_BUF_SIZ-UTF_SIZ)) { - // flush draw buffer - xdrawstr(term, term->drawbuf, &base, ox, scry, ic, ib); + // flush k8t_Draw buffer + k8t_DrawString(term, term->drawbuf, &base, ox, scry, ic, ib); ic = ib = 0; } if (ib == 0) { ox = x; base = new; } - sl = utf8size(new.c); + sl = k8t_UTF8Size(new.c); memcpy(term->drawbuf+ib, new.c, sl); ib += sl; ++ic; } - if (ib > 0) xdrawstr(term, term->drawbuf, &base, ox, scry, ic, ib); - //xcopy(term, 0, scry, term->col, 1); - //if (term->c.y == lineno && term->c.x >= stx && term->c.x < ex) xdrawcursor(); - if (!dontcopy) xcopy(term, stx, scry, ex-stx, 1); + if (ib > 0) k8t_DrawString(term, term->drawbuf, &base, ox, scry, ic, ib); + //k8t_DrawCopy(term, 0, scry, term->col, 1); + //if (term->c.y == lineno && term->c.x >= stx && term->c.x < ex) k8t_DrawCursor(); + if (!dontcopy) k8t_DrawCopy(term, stx, scry, ex-stx, 1); } } -static void drawregion (K8Term *term, int x1, int y1, int x2, int y2, int forced) { +static void k8t_DrawRegion (K8Term *term, int x1, int y1, int x2, int y2, int forced) { if (term != NULL) { int fulldirty = 0; // @@ -89,7 +89,7 @@ static void drawregion (K8Term *term, int x1, int y1, int x2, int y2, int forced } // if (term->topline < term->row) { - for (int y = y1; y < y2; ++y) drawline(term, x1, x2, y+term->topline, y, fulldirty); + for (int y = y1; y < y2; ++y) k8t_DrawLine(term, x1, x2, y+term->topline, y, fulldirty); } if (term->topline > 0) { int scry = K8T_MIN(term->topline, term->row), y = term->row; @@ -97,12 +97,12 @@ static void drawregion (K8Term *term, int x1, int y1, int x2, int y2, int forced fulldirty = 1; if (term->topline >= term->row) y += term->topline-term->row; while (--scry >= 0) { - drawline(term, 0, term->col, scry, y, 0); + k8t_DrawLine(term, 0, term->col, scry, y, 0); ++y; } } - if (fulldirty) xcopy(term, 0, 0, term->col, term->row); - xdrawcursor(term); + if (fulldirty) k8t_DrawCopy(term, 0, 0, term->col, term->row); + k8t_DrawCursor(term); xdrawTabBar(); //XFlush(xw.dpy); lastDrawTime = term->lastDrawTime = mclock_ticks(); @@ -111,9 +111,9 @@ static void drawregion (K8Term *term, int x1, int y1, int x2, int y2, int forced } -static void draw (K8Term *term, int forced) { +static void k8t_Draw (K8Term *term, int forced) { if (term != NULL) { - //fprintf(stderr, "draw(%d) (%d)\n", forced, mclock_ticks()); - drawregion(term, 0, 0, term->col, term->row, forced); + //fprintf(stderr, "k8t_Draw(%d) (%d)\n", forced, mclock_ticks()); + k8t_DrawRegion(term, 0, 0, term->col, term->row, forced); } } diff --git a/src/x11drawcmdline.c b/src/x11drawcmdline.c index fe054bc..dd26894 100644 --- a/src/x11drawcmdline.c +++ b/src/x11drawcmdline.c @@ -10,10 +10,10 @@ static void xdrawcmdline (K8Term *term, K8TCmdLine *cmdline, int scry) { base.state = 0; // hilighted for (sx = x = 0; x < term->col && cmdline->cmdline[cpos] && cpos < rslen; ++x) { - int l = utf8size(cmdline->cmdline+cpos); + int l = k8t_UTF8Size(cmdline->cmdline+cpos); // if (bc+l > DRAW_BUF_SIZ) { - xdrawstr(term, term->drawbuf, &base, sx, scry, x-sx, bc); + k8t_DrawString(term, term->drawbuf, &base, sx, scry, x-sx, bc); bc = 0; sx = x; } @@ -21,15 +21,15 @@ static void xdrawcmdline (K8Term *term, K8TCmdLine *cmdline, int scry) { cpos += l; bc += l; } - if (bc > 0) xdrawstr(term, term->drawbuf, &base, sx, scry, x-sx, bc); + if (bc > 0) k8t_DrawString(term, term->drawbuf, &base, sx, scry, x-sx, bc); // user input bc = 0; base.fg = 220; for (sx = x; x < term->col && cmdline->cmdline[cpos]; ++x) { - int l = utf8size(cmdline->cmdline+cpos); + int l = k8t_UTF8Size(cmdline->cmdline+cpos); // if (bc+l > DRAW_BUF_SIZ) { - xdrawstr(term, term->drawbuf, &base, sx, scry, x-sx, bc); + k8t_DrawString(term, term->drawbuf, &base, sx, scry, x-sx, bc); bc = 0; sx = x; } @@ -37,12 +37,12 @@ static void xdrawcmdline (K8Term *term, K8TCmdLine *cmdline, int scry) { cpos += l; bc += l; } - if (bc > 0) xdrawstr(term, term->drawbuf, &base, sx, scry, x-sx, bc); + if (bc > 0) k8t_DrawString(term, term->drawbuf, &base, sx, scry, x-sx, bc); // if (x < term->col && cmdline->cmdMode == K8T_CMDMODE_INPUT) { base.bg = base.fg; base.fg = back; - xdrawstr(term, " ", &base, x, scry, 1, 1); + k8t_DrawString(term, " ", &base, x, scry, 1, 1); ++x; } // @@ -54,9 +54,9 @@ static void xdrawcmdline (K8Term *term, K8TCmdLine *cmdline, int scry) { sx = x; x += DRAW_BUF_SIZ; if (x > term->col) x = term->col; - xdrawstr(term, term->drawbuf, &base, sx, scry, x-sx, x-sx); + k8t_DrawString(term, term->drawbuf, &base, sx, scry, x-sx, x-sx); } } // - xcopy(term, 0, scry, term->col, 1); + k8t_DrawCopy(term, 0, scry, term->col, 1); } diff --git a/src/x11drawcur.c b/src/x11drawcur.c index 5f1bd4d..b984370 100644 --- a/src/x11drawcur.c +++ b/src/x11drawcur.c @@ -1,4 +1,4 @@ -static void xdrawcursor (K8Term *term) { +static void k8t_DrawCursor (K8Term *term) { K8TGlyph g; int sl, scrx, scry, cmy; // @@ -20,12 +20,12 @@ static void xdrawcursor (K8Term *term) { (term->c.state&K8T_CURSOR_HIDE) || !(xw.state&K8T_WIN_FOCUSED)) { /* remove the old cursor */ - sl = utf8size(term->line[term->oldcy][scrx].c); + sl = k8t_UTF8Size(term->line[term->oldcy][scrx].c); g = term->line[term->oldcy][scrx]; - if (isselected(term, scrx, term->c.y)) g.attr ^= K8T_ATTR_REVERSE; - xdrawstr(term, g.c, &g, scrx, scry, 1, sl); - //xclear(term, scrx, term->oldcy, scrx, term->oldcy); - xcopy(term, scrx, scry, 1, 1); + if (k8t_isSelected(term, scrx, term->c.y)) g.attr ^= K8T_ATTR_REVERSE; + k8t_DrawString(term, g.c, &g, scrx, scry, 1, sl); + //k8t_DrawClear(term, scrx, term->oldcy, scrx, term->oldcy); + k8t_DrawCopy(term, scrx, scry, 1, 1); } if (term->curbhidden) term->curbhidden = 1; } @@ -34,7 +34,7 @@ static void xdrawcursor (K8Term *term) { if (term->cmdline.cmdMode != K8T_CMDMODE_NONE && term->oldcy == cmy) return; if ((term->c.state&K8T_CURSOR_HIDE) != 0) return; if (term->curbhidden) return; - /* draw the new one */ + /* k8t_Draw the new one */ scrx = term->c.x; scry = term->c.y+term->topline; if (scry >= 0 && scry < term->row) { @@ -58,11 +58,11 @@ static void xdrawcursor (K8Term *term) { g.state = 0; g.attr = K8T_ATTR_NULL; if (K8T_ISSET(term, K8T_MODE_REVERSE)) g.attr |= K8T_ATTR_REVERSE; - sl = utf8size(g.c); - xdrawstr(term, g.c, &g, scrx, scry, 1, sl); + sl = k8t_UTF8Size(g.c); + k8t_DrawString(term, g.c, &g, scrx, scry, 1, sl); } term->oldcx = scrx; term->oldcy = term->c.y; - xcopy(term, scrx, scry, 1, 1); + k8t_DrawCopy(term, scrx, scry, 1, 1); } } diff --git a/src/x11drawstr.c b/src/x11drawstr.c index ad983e5..4936723 100644 --- a/src/x11drawstr.c +++ b/src/x11drawstr.c @@ -1,4 +1,4 @@ -static void xdrawstr (K8Term *term, const char *s, const K8TGlyph *base, int x, int y, int charlen, int bytelen) { +static void k8t_DrawString (K8Term *term, const char *s, const K8TGlyph *base, int x, int y, int charlen, int bytelen) { if (term != NULL) { int fg = base->fg, bg = base->bg, temp; int winx = x*xw.cw, winy = y*xw.ch+dc.font[0].ascent, width = charlen*xw.cw; @@ -28,7 +28,7 @@ static void xdrawstr (K8Term *term, const char *s, const K8TGlyph *base, int x, /* { FILE *fo = fopen("zlog.log", "ab"); - fprintf(fo, "xdrawstr: x=%d; y=%d; charlen=%d; bytelen=%d\n", x, y, charlen, bytelen); + fprintf(fo, "k8t_DrawString: x=%d; y=%d; charlen=%d; bytelen=%d\n", x, y, charlen, bytelen); fclose(fo); } */ diff --git a/src/x11evtkbd.c b/src/x11evtkbd.c index 35d858d..b30bb27 100644 --- a/src/x11evtkbd.c +++ b/src/x11evtkbd.c @@ -108,14 +108,14 @@ static void xevtcbkpress (XEvent *ev) { // if ((kstr = kmap(do_keytrans(ksym), e->state)) != NULL) { if (kstr[0]) { - tunshowhistory(curterm); + k8t_tmUnshowHistory(curterm); if (curterm->dumpeskeys) { if (!isprint(kstr[0]) || kstr[1]) { fprintf(stderr, "KEY: "); eskdump(kstr); } } - ttywritestr(curterm, kstr); + k8t_ttyWriteStr(curterm, kstr); } } else { int meta = (e->state&Mod1Mask); @@ -137,18 +137,18 @@ static void xevtcbkpress (XEvent *ev) { } else { switch (ksym) { case XK_Return: - tunshowhistory(curterm); + k8t_tmUnshowHistory(curterm); if (meta) { - ttywritestr(curterm, "\x1b\x0a"); + k8t_ttyWriteStr(curterm, "\x1b\x0a"); } else { - if (K8T_ISSET(curterm, K8T_MODE_CRLF)) ttywritestr(curterm, "\r\n"); else ttywritestr(curterm, "\r"); + if (K8T_ISSET(curterm, K8T_MODE_CRLF)) k8t_ttyWriteStr(curterm, "\r\n"); else k8t_ttyWriteStr(curterm, "\r"); } break; default: if (!curterm->dead && len > 0) { - tunshowhistory(curterm); - if (meta && len == 1) ttywritestr(curterm, "\x1b"); - ttywrite(curterm, buf, len); + k8t_tmUnshowHistory(curterm); + if (meta && len == 1) k8t_ttyWriteStr(curterm, "\x1b"); + k8t_ttyWrite(curterm, buf, len); } break; } diff --git a/src/x11evtvis.c b/src/x11evtvis.c index d815f03..93e2eec 100644 --- a/src/x11evtvis.c +++ b/src/x11evtvis.c @@ -4,7 +4,7 @@ static void xevtcbexpose (XEvent *ev) { if (xw.state&K8T_WIN_REDRAW) { if (!e->count && curterm != NULL) { xw.state &= ~K8T_WIN_REDRAW; - xcopy(curterm, 0, 0, curterm->col, curterm->row); + k8t_DrawCopy(curterm, 0, 0, curterm->col, curterm->row); if (!updateTabBar) updateTabBar = -1; } xclearunused(); @@ -23,14 +23,14 @@ static void xevtcbexpose (XEvent *ev) { if (!updateTabBar) updateTabBar = -1; } //XCopyArea(xw.dpy, curterm->picbuf, xw.win, dc.gc, e->x, e->y, e->width, e->height, e->x, e->y+(opt_tabposition==1?xw.height:0))); - //xcopy(curterm, 0, 0, curterm->col, curterm->row); - //xclear(curterm, x0, y0, x1-x0+1, y1-y0+1); + //k8t_DrawCopy(curterm, 0, 0, curterm->col, curterm->row); + //k8t_DrawClear(curterm, x0, y0, x1-x0+1, y1-y0+1); K8T_LIMIT(x0, 0, curterm->col-1); K8T_LIMIT(x1, 0, curterm->col-1); K8T_LIMIT(y0, 0, curterm->row-1); K8T_LIMIT(y1, 0, curterm->row-1); //fprintf(stderr, "*:x0=%d; y0=%d; x1=%d; y1=%d\n", x0, y0, x1, y1); - xcopy(curterm, x0, y0, x1-x0+1, y1-y0+1); + k8t_DrawCopy(curterm, x0, y0, x1-x0+1, y1-y0+1); //xclearunused(); //FIXME: optimize this } else { if (!updateTabBar) updateTabBar = -1; @@ -66,16 +66,16 @@ static void xevtcbfocus (XEvent *ev) { if (ev->type == FocusIn) { xw.state |= K8T_WIN_FOCUSED; xseturgency(0); - tsendfocusevent(curterm, 1); + k8t_tmSendFocusEvent(curterm, 1); } else { xw.state &= ~K8T_WIN_FOCUSED; - tsendfocusevent(curterm, 0); + k8t_tmSendFocusEvent(curterm, 0); } - //draw(curterm, 1); + //k8t_Draw(curterm, 1); if (!updateTabBar) updateTabBar = -1; xdrawTabBar(); - xdrawcursor(curterm); - //xcopy(curterm, 0, 0, curterm->col, curterm->row); + k8t_DrawCursor(curterm); + //k8t_DrawCopy(curterm, 0, 0, curterm->col, curterm->row); } @@ -95,11 +95,11 @@ static void xevtcbresise (XEvent *e) { if (col == curterm->col && row == curterm->row) return; for (int f = 0; f < term_count; ++f) { K8Term *t = term_array[f]; - int trs = tresize(t, col, row); + int trs = k8t_tmResize(t, col, row); // - ttyresize(t); + k8t_ttyResize(t); xresize(t, col, row); - if (trs && t == curterm) draw(t, 1); + if (trs && t == curterm) k8t_Draw(t, 1); } XFreePixmap(xw.dpy, xw.pictab); xw.pictab = XCreatePixmap(xw.dpy, xw.win, xw.w, xw.tabheight>0?xw.tabheight:1, XDefaultDepth(xw.dpy, xw.scr)); diff --git a/src/x11misc.c b/src/x11misc.c index 2ffb64a..a256aae 100644 --- a/src/x11misc.c +++ b/src/x11misc.c @@ -1,13 +1,13 @@ //////////////////////////////////////////////////////////////////////////////// // x11 drawing and utils -static void xclear (K8Term *term, int x1, int y1, int x2, int y2) { +static void k8t_DrawClear (K8Term *term, int x1, int y1, int x2, int y2) { XSetForeground(xw.dpy, dc.gc, getColor(K8T_ISSET(term, K8T_MODE_REVERSE) ? term->deffg : term->defbg)); XFillRectangle(xw.dpy, term->picbuf, dc.gc, x1*xw.cw, y1*xw.ch, (x2-x1+1)*xw.cw, (y2-y1+1)*xw.ch); } /* copy buffer pixmap to screen pixmap */ -static void xcopy (K8Term *term, int x, int y, int cols, int rows) { +static void k8t_DrawCopy (K8Term *term, int x, int y, int cols, int rows) { if (term != NULL) { int src_x = x*xw.cw, src_y = y*xw.ch, src_w = cols*xw.cw, src_h = rows*xw.ch; int dst_x = src_x, dst_y = src_y; -- 2.11.4.GIT