📄 scrn.c
字号:
if (assume_256color && t->Co < 256) { /* Force 256 color support */#ifndef TERMINFO if (t->md && t->md[0]=='\\' && t->md[1]=='E' && t->md[2]=='[') { t->assume_256 = 1;#ifdef junk t->ut = 1; t->Sf = USTR "\\E[38;5;%dm"; t->Sb = USTR "\\E[48;5;%dm";#endif }#else if (t->md && t->md[0]=='\033' && t->md[1]=='[') { t->assume_256 = 1;#ifdef junk t->ut = 1; t->Sf = USTR "\033[38;5;%p1%dm"; t->Sb = USTR "\033[48;5;%p1%dm";#endif }#endif } t->so = NULL; t->se = NULL; if (getnum(t->cap,USTR "sg") <= 0 && !t->mr && jgetstr(t->cap,USTR "se")) { if ((t->so = jgetstr(t->cap,USTR "so")) != NULL) t->avattr |= INVERSE; t->se = jgetstr(t->cap,USTR "se"); } if (getflag(t->cap,USTR "xs") || getflag(t->cap,USTR "xt")) t->so = NULL; t->us = NULL; t->ue = NULL; if (getnum(t->cap,USTR "ug") <= 0 && jgetstr(t->cap,USTR "ue")) { if ((t->us = jgetstr(t->cap,USTR "us")) != NULL) t->avattr |= UNDERLINE; t->ue = jgetstr(t->cap,USTR "ue"); } if (!(t->uc = jgetstr(t->cap,USTR "uc"))) if (t->ul) t->uc =USTR "_"; if (t->uc) t->avattr |= UNDERLINE; t->ms = getflag(t->cap,USTR "ms"); t->da = getflag(t->cap,USTR "da"); t->db = getflag(t->cap,USTR "db"); t->cs = jgetstr(t->cap,USTR "cs"); t->rr = getflag(t->cap,USTR "rr"); t->sf = jgetstr(t->cap,USTR "sf"); t->sr = jgetstr(t->cap,USTR "sr"); t->SF = jgetstr(t->cap,USTR "SF"); t->SR = jgetstr(t->cap,USTR "SR"); t->al = jgetstr(t->cap,USTR "al"); t->dl = jgetstr(t->cap,USTR "dl"); t->AL = jgetstr(t->cap,USTR "AL"); t->DL = jgetstr(t->cap,USTR "DL"); if (!getflag(t->cap,USTR "ns") && !t->sf) t->sf =USTR "\12"; if (!getflag(t->cap,USTR "in") && baud < 38400) { t->dc = jgetstr(t->cap,USTR "dc"); t->DC = jgetstr(t->cap,USTR "DC"); t->dm = jgetstr(t->cap,USTR "dm"); t->ed = jgetstr(t->cap,USTR "ed"); t->im = jgetstr(t->cap,USTR "im"); t->ei = jgetstr(t->cap,USTR "ei"); t->ic = jgetstr(t->cap,USTR "ic"); t->IC = jgetstr(t->cap,USTR "IC"); t->ip = jgetstr(t->cap,USTR "ip"); t->mi = getflag(t->cap,USTR "mi"); } else { t->dm = NULL; t->dc = NULL; t->DC = NULL; t->ed = NULL; t->im = NULL; t->ic = NULL; t->IC = NULL; t->ip = NULL; t->ei = NULL; t->mi = 1; } t->bs = NULL; if (jgetstr(t->cap,USTR "bc")) t->bs = jgetstr(t->cap,USTR "bc"); else if (jgetstr(t->cap,USTR "le")) t->bs = jgetstr(t->cap,USTR "le"); if (getflag(t->cap,USTR "bs")) t->bs =USTR "\10"; t->cbs = tcost(t->cap, t->bs, 1, 2, 2, 0, 0); t->lf =USTR "\12"; if (jgetstr(t->cap,USTR "do")) t->lf = jgetstr(t->cap,USTR "do"); t->clf = tcost(t->cap, t->lf, 1, 2, 2, 0, 0); t->up = jgetstr(t->cap,USTR "up"); t->cup = tcost(t->cap, t->up, 1, 2, 2, 0, 0); t->nd = jgetstr(t->cap,USTR "nd"); t->tw = 8; if (getnum(t->cap,USTR "it") > 0) t->tw = getnum(t->cap,USTR "it"); else if (getnum(t->cap,USTR "tw") > 0) t->tw = getnum(t->cap,USTR "tw"); if (!(t->ta = jgetstr(t->cap,USTR "ta"))) if (getflag(t->cap,USTR "pt")) t->ta =USTR "\11"; t->bt = jgetstr(t->cap,USTR "bt"); if (getflag(t->cap,USTR "xt")) { t->ta = NULL; t->bt = NULL; } if (!usetabs) { t->ta = NULL; t->bt = NULL; } t->cta = tcost(t->cap, t->ta, 1, 2, 2, 0, 0); t->cbt = tcost(t->cap, t->bt, 1, 2, 2, 0, 0); t->ho = jgetstr(t->cap,USTR "ho"); t->cho = tcost(t->cap, t->ho, 1, 2, 2, 0, 0); t->ll = jgetstr(t->cap,USTR "ll"); t->cll = tcost(t->cap, t->ll, 1, 2, 2, 0, 0); t->cr =USTR "\15"; if (jgetstr(t->cap,USTR "cr")) t->cr = jgetstr(t->cap,USTR "cr"); if (getflag(t->cap,USTR "nc") || getflag(t->cap,USTR "xr")) t->cr = NULL; t->ccr = tcost(t->cap, t->cr, 1, 2, 2, 0, 0); t->cRI = tcost(t->cap, t->RI = jgetstr(t->cap,USTR "RI"), 1, 2, 2, 0, 0); t->cLE = tcost(t->cap, t->LE = jgetstr(t->cap,USTR "LE"), 1, 2, 2, 0, 0); t->cUP = tcost(t->cap, t->UP = jgetstr(t->cap,USTR "UP"), 1, 2, 2, 0, 0); t->cDO = tcost(t->cap, t->DO = jgetstr(t->cap,USTR "DO"), 1, 2, 2, 0, 0); t->cch = tcost(t->cap, t->ch = jgetstr(t->cap,USTR "ch"), 1, 2, 2, 0, 0); t->ccv = tcost(t->cap, t->cv = jgetstr(t->cap,USTR "cv"), 1, 2, 2, 0, 0); t->ccV = tcost(t->cap, t->cV = jgetstr(t->cap,USTR "cV"), 1, 2, 2, 0, 0); t->ccm = tcost(t->cap, t->cm = jgetstr(t->cap,USTR "cm"), 1, 2, 2, 0, 0); t->cce = tcost(t->cap, t->ce = jgetstr(t->cap,USTR "ce"), 1, 2, 2, 0, 0);/* Make sure terminal can do absolute positioning */ if (t->cm) goto ok; if (t->ch && t->cv) goto ok; if (t->ho && (t->lf || t->DO || t->cv)) goto ok; if (t->ll && (t->up || t->UP || t->cv)) goto ok; if (t->cr && t->cv) goto ok; leave = 1; ttclose(); signrm(); fprintf(stderr,"cm=%p ch=%p cv=%p ho=%p lf=%p DO=%p ll=%p up=%p UP=%p cr=%p\n", t->cm, t->ch, t->cv, t->ho, t->lf, t->DO, t->ll, t->up, t->UP, t->cr); fprintf(stderr,(char *)joe_gettext(_("Sorry, your terminal can't do absolute cursor positioning.\nIt's broken\n"))); return NULL; ok:/* Determine if we can scroll */ if (((t->sr || t->SR) && (t->sf || t->SF) && t->cs) || ((t->al || t->AL) && (t->dl || t->DL))) t->scroll = 1; else { t->scroll = 0; if (baud < 38400) mid = 1; }/* Determine if we can ins/del within lines */ if ((t->im || t->ic || t->IC) && (t->dc || t->DC)) t->insdel = 1; else t->insdel = 0;/* Adjust for high baud rates */ if (baud >= 38400) { t->scroll = 0; t->insdel = 0; }/* Send out terminal initialization string */ 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);/* Initialize variable screen size dependant vars */ t->scrn = NULL; t->attr = NULL; t->sary = NULL; t->updtab = NULL; t->compose = NULL; t->ofst = NULL; t->ary = NULL; t->htab = (struct hentry *) joe_malloc(256 * sizeof(struct hentry)); nresize(t, t->co, t->li);/* Initialize mouse */ mouseopen(); return t;}/* Change size of screen */void nresize(SCRN *t, int w, int h){ if (h < 4) h = 4; if (w < 8) w = 8; t->li = h; t->co = w; if (t->sary) joe_free(t->sary); if (t->updtab) joe_free(t->updtab); if (t->scrn) joe_free(t->scrn); if (t->attr) joe_free(t->attr); if (t->compose) joe_free(t->compose); if (t->ofst) joe_free(t->ofst); if (t->ary) joe_free(t->ary); t->scrn = (int *) joe_malloc(t->li * t->co * sizeof(int)); t->attr = (int *) joe_malloc(t->li * t->co * sizeof(int)); t->sary = (int *) joe_calloc(t->li, sizeof(int)); t->updtab = (int *) joe_malloc(t->li * sizeof(int)); t->compose = (int *) joe_malloc(t->co * sizeof(int)); t->ofst = (int *) joe_malloc(t->co * sizeof(int)); t->ary = (struct hentry *) joe_malloc(t->co * sizeof(struct hentry)); nredraw(t);}/* Calculate cost of positioning the cursor using only relative cursor * positioning functions: t->(lf, DO, up, UP, bs, LE, RI, ta, bt) and rewriting * characters (to move right) * * This doesn't use the am and bw capabilities although it probably could. */static int relcost(register SCRN *t, register int x, register int y, register int ox, register int oy){ int cost = 0;/* If we don't know the cursor position, force use of absolute positioning */ if (oy == -1 || ox == -1) return 10000;/* First adjust row */ if (y > oy) { int dist = y - oy; /* Have to go down */ if (t->lf) { int mult = dist * t->clf; if (dist < 10 && t->cDO < mult) cost += t->cDO; else if (dist >= 10 && t->cDO + 1 < mult) cost += t->cDO + 1; else cost += mult; } else if (t->DO) if (dist < 10) cost += t->cDO; else cost += t->cDO + 1; else return 10000; } else if (y < oy) { int dist = oy - y; /* Have to go up */ if (t->up) { int mult = dist * t->cup; if (dist < 10 && t->cUP < mult) cost += t->cUP; else if (dist >= 10 && t->cUP < mult) cost += t->cUP + 1; else cost += mult; } else if (t->UP) if (dist < 10) cost += t->cUP; else cost += t->cUP + 1; else return 10000; }/* Now adjust column *//* Use tabs */ if (x > ox && t->ta) { int dist = x - ox; int ntabs = (dist + ox % t->tw) / t->tw; int cstunder = x % t->tw + t->cta * ntabs; int cstover; if (x + t->tw < t->co && t->bs) cstover = t->cbs * (t->tw - x % t->tw) + t->cta * (ntabs + 1); else cstover = 10000; if (dist < 10 && cstunder < t->cRI && cstunder < x - ox && cstover > cstunder) return cost + cstunder; else if (cstunder < t->cRI + 1 && cstunder < x - ox && cstover > cstunder) return cost + cstunder; else if (dist < 10 && cstover < t->cRI && cstover < x - ox) return cost + cstover; else if (cstover < t->cRI + 1 && cstover < x - ox) return cost + cstover; } else if (x < ox && t->bt) { int dist = ox - x; int ntabs = (dist + t->tw - ox % t->tw) / t->tw; int cstunder, cstover; if (t->bs) cstunder = t->cbt * ntabs + t->cbs * (t->tw - x % t->tw); else cstunder = 10000; if (x - t->tw >= 0) cstover = t->cbt * (ntabs + 1) + x % t->tw; else cstover = 10000; if (dist < 10 && cstunder < t->cLE && (t->bs ? cstunder < (ox - x) * t->cbs : 1) && cstover > cstunder) return cost + cstunder; if (cstunder < t->cLE + 1 && (t->bs ? cstunder < (ox - x) * t->cbs : 1) && cstover > cstunder) return cost + cstunder; else if (dist < 10 && cstover < t->cRI && (t->bs ? cstover < (ox - x) * t->cbs : 1)) return cost + cstover; else if (cstover < t->cRI + 1 && (t->bs ? cstover < (ox - x) * t->cbs : 1)) return cost + cstover; }/* Use simple motions */ if (x < ox) { int dist = ox - x; /* Have to go left */ if (t->bs) { int mult = dist * t->cbs; if (t->cLE < mult && dist < 10) cost += t->cLE; else if (t->cLE + 1 < mult) cost += t->cLE + 1; else cost += mult; } else if (t->LE) cost += t->cLE; else return 10000; } else if (x > ox) { int dist = x - ox; /* Have to go right */ /* Hmm.. this should take into account possible attribute changes */ if (t->cRI < dist && dist < 10) cost += t->cRI; else if (t->cRI + 1 < dist) cost += t->cRI + 1; else cost += dist; } return cost;}/* Find optimal set of cursor positioning commands to move from the current * cursor row and column (either or both of which might be unknown) to the * given new row and column and execute them. */static void cposs(register SCRN *t, register int x, register int y){ register int bestcost, cost; int bestway; int hy; int hl;/* Home y position is usually 0, but it is 'top' if we have scrolling region * relative addressing */ if (t->rr) { hy = t->top; hl = t->bot - 1; } else { hy = 0; hl = t->li - 1; }/* Assume best way is with only using relative cursor positioning */ bestcost = relcost(t, x, y, t->x, t->y); bestway = 0;/* Now check if combinations of absolute cursor positioning functions are * better (or necessary in case one or both cursor positions are unknown) */ if (t->ccm < bestcost) { cost = tcost(t->cap, t->cm, 1, y, x, 0, 0); if (cost < bestcost) { bestcost = cost; bestway = 6; } } if (t->ccr < bestcost) { cost = relcost(t, x, y, 0, t->y) + t->ccr; if (cost < bestcost) { bestcost = cost; bestway = 1; } } if (t->cho < bestcost) { cost = relcost(t, x, y, 0, hy) + t->cho; if (cost < bestcost) { bestcost = cost; bestway = 2; } } if (t->cll < bestcost) { cost = relcost(t, x, y, 0, hl) + t->cll; if (cost < bestcost) { bestcost = cost; bestway = 3; } } if (t->cch < bestcost && x != t->x) { cost = relcost(t, x, y, x, t->y) + tcost(t->cap, t->ch, 1, x, 0, 0, 0); if (cost < bestcost) { bestcost = cost; bestway = 4; } } if (t->ccv < bestcost && y != t->y) { cost = relcost(t, x, y, t->x, y) + tcost(t->cap, t->cv, 1, y, 0, 0, 0); if (cost < bestcost) { bestcost = cost; bestway = 5; } } if (t->ccV < bestcost) { cost = relcost(t, x, y, 0, y) + tcost(t->cap, t->cV, 1, y, 0, 0, 0); if (cost < bestcost) { bestcost = cost; bestway = 13; } } if (t->cch + t->ccv < bestcost && x != t->x && y != t->y) { cost = tcost(t->cap, t->cv, 1, y - hy, 0, 0, 0) + tcost(t->cap, t->ch, 1, x, 0, 0, 0); if (cost < bestcost) { bestcost = cost; bestway = 7; } } if (t->ccv + t->ccr < bestcost && y != t->y) { cost = tcost(t->cap, t->cv, 1, y, 0, 0, 0) + tcost(t->cap, t->cr, 1, 0, 0, 0, 0) + relcost(t, x, y, 0, y); if (cost < bestcost) { bestcost = cost; bestway = 8; } } if (t->cll + t->cch < bestcost) { cost = tcost(t->cap, t->ll, 1, 0, 0, 0, 0) + tcost(t->cap, t->ch, 1, x, 0, 0, 0) + relcost(t, x, y, x, hl); if (cost < bestcost) { bestcost = cost; bestway = 9; } } if (t->cll + t->ccv < bestcost) { cost = tcost(t->cap, t->ll, 1, 0, 0, 0, 0) + tcost(t->cap, t->cv, 1, y, 0, 0, 0) + relcost(t, x, y, 0, y); if (cost < bestcost) { bestcost = cost; bestway = 10; } } if (t->cho + t->cch < bestcost) { cost = tcost(t->cap, t->ho, 1, 0, 0, 0, 0) + tcost(t->cap, t->ch, 1, x, 0, 0, 0) + relcost(t, x, y, x, hy); if (cost < bestcost) { bestcost = cost; bestway = 11; } } if (t->cho + t->ccv < bestcost) { cost = tcost(t->cap, t->ho, 1, 0, 0, 0, 0) + tcost(t->cap, t->cv, 1, y, 0, 0, 0) + relcost(t, x, y, 0, y); if (cost < bestcost) { bestcost = cost; bestway = 12; } }/* Do absolute cursor positioning if we don't know the cursor position or * if it is faster than doing only relative cursor positioning */ switch (bestway) { case 1: texec(t->cap, t->cr, 1, 0, 0, 0, 0); t->x = 0; break; case 2: texec(t->cap, t->ho, 1, 0, 0, 0, 0); t->x = 0; t->y = hy; break; case 3: texec(t->cap, t->ll, 1, 0, 0, 0, 0); t->x = 0; t->y = hl; break; case 9: texec(t->cap, t->ll, 1, 0, 0, 0, 0); t->x = 0; t->y = hl; goto doch; case 11: texec(t->cap, t->ho, 1, 0, 0, 0, 0); t->x = 0; t->y = hy;doch: case 4: texec(t->cap, t->ch, 1, x, 0, 0, 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -