📄 scrn.c
字号:
}void nescape(SCRN *t){ mouseclose(); npartial(t); cpos(t, 0, t->li - 1); eraeol(t, 0, t->li - 1, 0); if (t->te) texec(t->cap, t->te, 1, 0, 0, 0, 0);}void nreturn(SCRN *t){ mouseopen(); if (t->ti) texec(t->cap, t->ti, 1, 0, 0, 0, 0); if (!skiptop && t->cl) texec(t->cap, t->cl, 1, 0, 0, 0, 0); nredraw(t);}void nclose(SCRN *t){ mouseclose(); leave = 1; set_attr(t, 0); clrins(t); setregn(t, 0, t->li); cpos(t, 0, t->li - 1); if (t->te) texec(t->cap, t->te, 1, 0, 0, 0, 0); ttclose(); rmcap(t->cap); joe_free(t->scrn); joe_free(t->attr); joe_free(t->sary); joe_free(t->ofst); joe_free(t->htab); joe_free(t->ary); joe_free(t);}void nscrldn(SCRN *t, int top, int bot, int amnt){ int x; if (!amnt || top >= bot || bot > t->li) return; if ((amnt < bot - top && bot - top - amnt < amnt / 2) || !t->scroll) amnt = bot - top; if (amnt < bot - top) { for (x = bot; x != top + amnt; --x) { t->sary[x - 1] = (t->sary[x - amnt - 1] == t->li ? t->li : t->sary[x - amnt - 1] - amnt); t->updtab[x - 1] = t->updtab[x - amnt - 1]; } for (x = top; x != top + amnt; ++x) { t->updtab[x] = 1; } } if (amnt > bot - top) amnt = bot - top; msetI(t->sary + top, t->li, amnt); if (amnt == bot - top) { msetI(t->updtab + top, 1, amnt); }}void nscrlup(SCRN *t, int top, int bot, int amnt){ int x; if (!amnt || top >= bot || bot > t->li) return; if ((amnt < bot - top && bot - top - amnt < amnt / 2) || !t->scroll) amnt = bot - top; if (amnt < bot - top) { for (x = top + amnt; x != bot; ++x) { t->sary[x - amnt] = (t->sary[x] == t->li ? t->li : t->sary[x] + amnt); t->updtab[x - amnt] = t->updtab[x]; } for (x = bot - amnt; x != bot; ++x) { t->updtab[x] = 1; } } if (amnt > bot - top) amnt = bot - top; msetI(t->sary + bot - amnt, t->li, amnt); if (amnt == bot - top) { msetI(t->updtab + bot - amnt, 1, amnt); }}void nredraw(SCRN *t){ dostaupd = 1; msetI(t->scrn, ' ', t->co * skiptop); msetI(t->attr, BG_COLOR(bg_text), t->co * skiptop); msetI(t->scrn + skiptop * t->co, -1, (t->li - skiptop) * t->co); msetI(t->attr + skiptop * t->co, BG_COLOR(bg_text), (t->li - skiptop) * t->co); msetI(t->sary, 0, t->li); msetI(t->updtab + skiptop, -1, t->li - skiptop); t->x = -1; t->y = -1; t->top = t->li; t->bot = 0; t->attrib = -1; t->ins = -1; set_attr(t, BG_COLOR(bg_text)); clrins(t); setregn(t, 0, t->li); if (!skiptop) { if (t->cl) { texec(t->cap, t->cl, 1, 0, 0, 0, 0); t->x = 0; t->y = 0; msetI(t->scrn, ' ', t->li * t->co); msetI(t->attr, BG_COLOR(bg_text), t->li * t->co); } else if (t->cd) { cpos(t, 0, 0); texec(t->cap, t->cd, 1, 0, 0, 0, 0); msetI(t->scrn, ' ', t->li * t->co); msetI(t->attr, BG_COLOR(bg_text), t->li * t->co); } }}/* Convert color/attribute name into internal code */int meta_color_single(unsigned char *s){ if(!zcmp(s,USTR "inverse")) return INVERSE; else if(!zcmp(s,USTR "underline")) return UNDERLINE; else if(!zcmp(s,USTR "bold")) return BOLD; else if(!zcmp(s,USTR "blink")) return BLINK; else if(!zcmp(s,USTR "dim")) return DIM; /* ISO colors */ else if(!zcmp(s,USTR "white")) return FG_WHITE; else if(!zcmp(s,USTR "cyan")) return FG_CYAN; else if(!zcmp(s,USTR "magenta")) return FG_MAGENTA; else if(!zcmp(s,USTR "blue")) return FG_BLUE; else if(!zcmp(s,USTR "yellow")) return FG_YELLOW; else if(!zcmp(s,USTR "green")) return FG_GREEN; else if(!zcmp(s,USTR "red")) return FG_RED; else if(!zcmp(s,USTR "black")) return FG_BLACK; else if(!zcmp(s,USTR "bg_white")) return BG_WHITE; else if(!zcmp(s,USTR "bg_cyan")) return BG_CYAN; else if(!zcmp(s,USTR "bg_magenta")) return BG_MAGENTA; else if(!zcmp(s,USTR "bg_blue")) return BG_BLUE; else if(!zcmp(s,USTR "bg_yellow")) return BG_YELLOW; else if(!zcmp(s,USTR "bg_green")) return BG_GREEN; else if(!zcmp(s,USTR "bg_red")) return BG_RED; else if(!zcmp(s,USTR "bg_black")) return BG_BLACK; /* 16 color xterm support: codes 8 - 15 are brighter versions of above */ else if(!zcmp(s,USTR "WHITE")) return FG_BWHITE; else if(!zcmp(s,USTR "CYAN")) return FG_BCYAN; else if(!zcmp(s,USTR "MAGENTA")) return FG_BMAGENTA; else if(!zcmp(s,USTR "BLUE")) return FG_BBLUE; else if(!zcmp(s,USTR "YELLOW")) return FG_BYELLOW; else if(!zcmp(s,USTR "GREEN")) return FG_BGREEN; else if(!zcmp(s,USTR "RED")) return FG_BRED; else if(!zcmp(s,USTR "BLACK")) return FG_BBLACK; else if(!zcmp(s,USTR "bg_WHITE")) return BG_BWHITE; else if(!zcmp(s,USTR "bg_CYAN")) return BG_BCYAN; else if(!zcmp(s,USTR "bg_MAGENTA")) return BG_BMAGENTA; else if(!zcmp(s,USTR "bg_BLUE")) return BG_BBLUE; else if(!zcmp(s,USTR "bg_YELLOW")) return BG_BYELLOW; else if(!zcmp(s,USTR "bg_GREEN")) return BG_BGREEN; else if(!zcmp(s,USTR "bg_RED")) return BG_BRED; else if(!zcmp(s,USTR "bg_BLACK")) return BG_BBLACK; /* Look at the "256colres.pl" PERL script in the xterm source distribution to see how these work. */ /* 256 color xterm support: bg_RGB and fg_RGB, where R, G, and B range from 0 - 5 */ /* Codes 16 - 231 are a 6x6x6 color cube */ else if(s[0]=='f' && s[1]=='g' && s[2]=='_' && s[3]>='0' && s[3]<='5' && s[4]>='0' && s[4]<='5' && s[5]>='0' && s[5]<='5' && !s[6]) return FG_NOT_DEFAULT | ((16 + (s[3]-'0')*6*6 + (s[4]-'0')*6 + (s[5]-'0')) << FG_SHIFT); else if(s[0]=='b' && s[1]=='g' && s[2]=='_' && s[3]>='0' && s[3]<='5' && s[4]>='0' && s[4]<='5' && s[5]>='0' && s[5]<='5' && !s[6]) return BG_NOT_DEFAULT | ((16 + (s[3]-'0')*6*6 + (s[4]-'0')*6 + (s[5]-'0')) << BG_SHIFT); /* 256 color xterm support: shades of grey */ /* Codes 232 - 255 are shades of grey */ else if(s[0]=='f' && s[1]=='g' && s[2]=='_' && atoi((char *)(s+3)) >= 0 && atoi((char *)(s+3)) <= 23) return FG_NOT_DEFAULT | (232 + (atoi((char *)(s+3)) << FG_SHIFT)); else if(s[0]=='b' && s[1]=='g' && s[2]=='_' && atoi((char *)(s+3)) >= 0 && atoi((char *)(s+3)) <= 23) return BG_NOT_DEFAULT | (232 + (atoi((char *)(s+3)) << BG_SHIFT)); else return 0;}int meta_color(unsigned char *s){ int code = 0; while (*s) { unsigned char buf[32]; int x = 0; while (*s) if (*s && *s != '+') { if (x != sizeof(buf) - 1) buf[x++] = *s; ++s; } else break; if (*s == '+') ++s; buf[x] = 0; code |= meta_color_single(buf); } return code;}/* Generate a field * * 't' is SCRN to write to. * 'scrn' is address of field in character buffer * 'attr' is address of field in attribute buffer * 'x', 'y' are starting column and line numbers of field * 'ofst' is first column within string to display * 's', 'len' is string to generate in field * 'atr' is screeen attributes (and color) which should be used * 'width' is column width of field * 'flg' if set, erases to end of line * 'fmt' is array of attributes, one for each byte. OK if NULL. */void genfield(SCRN *t,int *scrn,int *attr,int x,int y,int ofst,unsigned char *s,int len,int atr,int width,int flg,int *fmt){ int col; struct utf8_sm sm; int last_col = x + width; utf8_init(&sm); for (col = 0;len != 0 && x < last_col; len--) { int c = *s++; int wid = -1; int my_atr = atr; if (fmt) my_atr |= *fmt++; if (locale_map->type) { /* UTF-8 mode: decode character and determine its width */ c = utf8_decode(&sm,c); if (c >= 0) wid = joe_wcwidth(1,c); } else { /* Byte mode: character is one column wide */ wid = 1 ; } if (wid>=0) { if (col >= ofst) { if (x + wid > last_col) { /* Character crosses end of field, so fill balance of field with '>' characters instead */ while (x < last_col) { outatr(locale_map, t, scrn, attr, x, y, '>', my_atr); ++scrn; ++attr; ++x; } } else if(wid) { /* Emit character */ outatr(locale_map, t, scrn, attr, x, y, c, my_atr); x += wid; scrn += wid; attr += wid; } } else if ((col + wid) > ofst) { /* Wide character crosses left side of field */ wid -= ofst - col; col = ofst; while (wid) { outatr(locale_map, t, scrn, attr, x, y, '<', my_atr); ++scrn; ++attr; ++x; ++col; --wid; } } else col += wid; } } /* Fill balance of field with spaces */ while (x < last_col) { outatr(locale_map, t, scrn, attr, x, y, ' ', atr); ++x; ++scrn; ++attr; } /* Erase to end of line */ if (flg) eraeol(t, x, y, atr);}/* Width function for above */int txtwidth(unsigned char *s,int len){ if (locale_map->type) { int col=0; struct utf8_sm sm; utf8_init(&sm); while(len--) { int d = utf8_decode(&sm,*s++); if (d >= 0) col += joe_wcwidth(1,d); } return col; } else return len;}/* Generate text with formatting escape sequences */void genfmt(SCRN *t, int x, int y, int ofst, unsigned char *s, int atr, int flg){ int *scrn = t->scrn + y * t->co + x; int *attr = t->attr + y * t->co + x; int col = 0; int c; struct utf8_sm sm; utf8_init(&sm); while ((c = *s++) != '\0') if (c == '\\') { switch (c = *s++) { case 'u': case 'U': atr ^= UNDERLINE; break; case 'i': case 'I': atr ^= INVERSE; break; case 'b': case 'B': atr ^= BOLD; break; case 'd': case 'D': atr ^= DIM; break; case 'f': case 'F': atr ^= BLINK; break; case 0: --s; break; default: { if (col++ >= ofst) { outatr(locale_map, t, scrn, attr, x, y, (c&0x7F), atr); ++scrn; ++attr; ++x; } break; } } } else { int wid = -1; if (locale_map->type) { /* UTF-8 mode: decode character and determine its width */ c = utf8_decode(&sm,c); if (c >= 0) { wid = joe_wcwidth(1,c); } } else { /* Byte mode: character is one column wide */ wid = 1 ; } if (wid>=0) { if (col >= ofst) { outatr(locale_map, t, scrn, attr, x, y, c, atr); scrn += wid; attr += wid; x += wid; col += wid; } else if (col+wid>ofst) { while (col<ofst) { ++col; --wid; } while (wid) { outatr(locale_map, t, scrn, attr, x, y, '<', atr); ++scrn; ++attr; ++x; ++col; --wid; } } else col += wid; } } if (flg) eraeol(t, x, y, atr);}/* Determine column width of string with format codes */int fmtlen(unsigned char *s){ int col = 0; struct utf8_sm sm; int c; utf8_init(&sm); while ((c= *s++)) { if (c == '\\') { switch (*s++) { case 'u': case 'i': case 'd': case 'f': case 'b': case 'U': case 'I': case 'D': case 'F': case 'B': continue; case 0: return col; default: ++col; continue; } } else { int wid = 0; if(locale_map->type) { c = utf8_decode(&sm,c); if (c>=0) wid = joe_wcwidth(1,c); } else { wid = 1; } col += wid; } } return col;}/* Return offset within format string which corresponds to a particular column *//* FIXME: this is not valid if we land in the middle of a double-wide character */int fmtpos(unsigned char *s, int goal){ unsigned char *org = s; int col = 0; int c; struct utf8_sm sm; utf8_init(&sm); while ((c= *s) && col<goal) { s++; if (c == '\\') { switch (*s++) { case 'u': case 'i': case 'd': case 'f': case 'b': case 'U': case 'I': case 'D': case 'F': case 'B': continue; case 0: --s; break; default: ++col; continue; } } else { int wid = 0; if(locale_map->type) { c = utf8_decode(&sm,c); if (c>=0) wid = joe_wcwidth(1,c); } else { wid = 1; } col += wid; } } return s - org + goal - col;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -