📄 window.c
字号:
Bwritea(s_clrscr); draw_Divider(first_win);}void redraw_screen(){ Unode *wp; Bwritea(s_clrscr); for (wp = win_ring.next; !wp->dummy; wp = wp->next) draw_Divider(wp); cmove(0, rows - 1); draw_prompt(); input_draw();}void auto_redraw(){ Func *func; func = find_func("redraw_hook"); if (func && func->cmd) run_prog(func->cmd); else redraw_screen();}Unode *split_window(win, loc) Unode *win; int loc;{ Unode *new; new = unalloc(); init_window(new, win->Wtop, loc - 1); win->Wtop = loc + 1; new->prev = win->prev; new->next = win; win->prev = win->prev->next = new; clear_space(new->Wtop, new->Wbot); draw_Divider(new); return new;}void close_window(win, dir) Unode *win; int dir;{ Unode *into; if (dir < 0) { into = win->prev; scroll(into->Wtop, win->Wbot + 1); scr_rev(win->Wbot - into->Wbot); into->Wbot = win->Wbot; if (win->next->dummy) { cmove(cols - 5, Divider); Bwritea(vtc_mode ? "VTC__" : "Text_"); } Bflush; } else { into = win->next; clear_space(win->Wtop, win->Wbot + 1); into->Wtop = win->Wtop; } if (win->Wrmt) win->Wrmt->Rwin = NULL; if (active_win == win) { active_win = into; mark(into, 1); } if (cur_win == win) cur_win = NULL; win->prev->next = win->next; win->next->prev = win->prev; destroy_pointers(win->frefs); break_pipe(win->Wghstack); break_pipe(win->Wglstack); break_pipe(win->Wrstack); discard_unode(win); curs_loc = CURS_ELSEWHERE;}void resize_window(win, row) Unode *win; int row;{ if (row - 1 > win->Wbot) { scroll(win->Wtop, row); scr_rev(row - win->Wbot - 1); } else if (row - 1 < win->Wbot) { scroll(win->Wtop, win->Wbot + 1); scr_fwd(win->Wbot - row + 1); } Bflush; win->next->Wtop = row + 1; win->Wbot = row - 1; curs_loc = CURS_ELSEWHERE;}void new_active_win(win) Unode *win;{ if (win == active_win) return; mark(active_win, 0); mark(win, 1); active_win = win; curs_loc = CURS_ELSEWHERE; update_echo_mode();}void resize_screen(new_rows, new_cols) int new_rows, new_cols;{ int new_Isize, new_ospace, old_ospace, pos = 0, used = 0, overrun; int num_wins = 0, size, decr = 0; Unode *w; if (new_rows < 4 || new_cols < 15) vtdie("Screen size too small"); for (w = win_ring.next; !w->dummy; w = w->next, num_wins++); old_ospace = rows - Isize - num_wins; while (num_wins > (new_rows - 1) / 3) { w = win_ring.prev; if (w->Wrmt) w->Wrmt->Rwin = NULL; if (active_win == w) active_win = w->prev; if (cur_win == w) cur_win = NULL; w->prev->next = &win_ring; win_ring.prev = w->prev; destroy_pointers(w->frefs); destroy_pipe(w->Wghstack); destroy_pipe(w->Wglstack); destroy_pipe(w->Wrstack); discard_unode(w); num_wins--; } new_Isize = min(Isize, new_rows - num_wins * 3); new_ospace = new_rows - new_Isize - num_wins; for (w = win_ring.next; !w->dummy; w = w->next) { size = ((w->Wbot - w->Wtop + 1) * new_ospace + old_ospace / 2) / old_ospace; size = max(size, 2); w->Wtop = pos; w->Wbot = pos + size - 1; pos += size + 1; used += size; } overrun = used - new_ospace; for (w = win_ring.next; !w->dummy; w = w->next) { w->Wtop -= decr; w->Wbot -= decr; if (overrun > 0 && w->Wbot - w->Wtop > 1) { w->Wbot--; decr++; overrun--; } } rows = new_rows; cols = new_cols; auto_redraw();}/* Input routines */static void draw_prompt(){ int pos = 0; while (pos < Oplen) { Bwritem(&prompt[pos], plen - pos, Margin); if ((pos += Margin) <= plen) Iscr_fwd; } icol = Oplen % Margin; Bflush;}static void clear_input_window(){ if (kpos + Oplen <= Isize * Margin) { input_cmove(0); while (plen > Margin) { Iscr_rev; plen -= Margin; } cmove(0, rows - 1); Bwritea(s_clreol); Bflush; } else clear_space(Itop, rows - 1);}void input_puts(cstr) Cstr cstr;{ int n; if (!echo_mode) return; while (cstr.l) { n = min(cstr.l, Margin - icol); Bwriteal(cstr.s, n); if (!(icol = (icol + n) % Margin)) Iscr_fwd; cstr = cstr_sl(cstr.s + n, cstr.l - n); } n = min(Klen - kpos, Margin - icol); Bwriteal(&Kptr[kpos], n); move_left(n, icol); Bflush;}void input_cmove(new) int new;{ int offset = new - kpos, pos, n; if (new == kpos || !echo_mode) return; if (new == kpos - 1 && icol) { Bputch('\010'); icol--; } else if (new == kpos + 1 && icol < Margin - 1) { Bputch(Kptr[kpos]); icol++; } else if (new > kpos) { pos = Round(kpos + Oplen, Margin) + Margin - Oplen; while (icol + offset >= Margin) { Iscr_fwd; Bwritem(&Kptr[pos], Klen - pos, Margin); pos += Margin; offset -= Margin; } cmove(icol += offset, rows - 1); } else { pos = Round(kpos + Oplen, Margin) - Oplen - Isize * Margin; while (icol + offset < 0) { Iscr_rev; if (pos >= 0) Bwritem(&Kptr[pos], Klen - pos, Margin); else if (pos + Oplen >= 0) { n = min(-pos, Margin); Bwriteal(&prompt[plen + pos], n); Bwritem(Kptr, Klen, Margin - n); } pos -= Margin; offset += Margin; } cmove(icol += offset, rows - 1); } Bflush;}void input_bdel(num) int num;{ int n; if (!num || !echo_mode) return; input_cmove(kpos - num); n = min(Klen - kpos, Margin - icol); Bwriteal(&Kptr[kpos], n); clear_end(min(num, Margin - icol - n)); move_left(n, icol); Bflush;}void input_fdel(num) int num;{ int n; if (!echo_mode) return; n = min(Klen - kpos - num, Margin - icol); Bwriteal(&Kptr[kpos + num], n); clear_end(min(num, Margin - icol - n)); move_left(n, icol); Bflush;}void input_clear(){ if (!echo_mode) return; if (kpos <= Isize * Margin) { input_cmove(0); Bwritea(s_clreol); } else { clear_space(Itop, rows - 1); draw_prompt(); } icol = Oplen % Margin; Bflush;}void input_draw(){ int pos = 0, n = 0, col; if (!echo_mode) return; col = Oplen % Margin; while (pos <= kpos) { n = min(Klen - pos, Margin - col); Bwriteal(&Kptr[pos], n); if ((pos += Margin) <= kpos) Iscr_fwd; col = 0; } icol = Oplen + kpos % Margin; move_left(n - icol, icol); Bflush;}void input_newline(){ input_cmove(Klen); Iscr_fwd; icol = 0; if (plen && !vtc_mode) { Discardstring(prompt); prompt = vtstrdup(""); plen = 0; } Bflush;}void change_prompt(new, l) char *new; int l;{ char *p, *q; if (!vtc_mode) { curs_input(); clear_input_window(); } Discardstring(prompt); for (p = new; *p; p++) { if (!isprint(*p)) l--; } q = prompt = Newarray(char, l + 1); for (p = new; *p; p++) { if (isprint(*p)) *q++ = *p; } *q = 0; plen = l; if (!vtc_mode) { draw_prompt(); input_draw(); }}void update_echo_mode(){ int new_mode = (active_win->Wrmt) ? active_win->Wrmt->Recho : 1; if (echo_mode != new_mode) { echo_mode = 1; curs_input(); if (new_mode) input_draw(); else input_clear(); echo_mode = new_mode; }}/* Output routines */void output(win, text) Unode *win; char *text;{ int norm, n; if (!win) { win = active_win; if (win->Wnl) output(win, "[background] "); } curs_window(win); if (win->Wnl) { Bputch('\n'); win->Wnl = 0; } while (1) { norm = strcspn(text, "\n\b\f\v\t\r"); n = cols - win->Wcol; for (; norm >= n; text += n, norm -= n, n = cols) { Bputch('\n'); cmove(win->Wcol, win->Wbot - 1); Bwriteal(text, n); cmove(0, win->Wbot); win->Wcol = 0; } Bwriteal(text, norm); win->Wcol = (win->Wcol + norm) % cols; text += norm; switch(*text++) { case '\0': Bflush; return; case '\n': case '\v': if (*text) Bputch('\n'); else win->Wnl = 1; win->Wcol = 0; Case '\b': if (win->Wcol) { Bputch('\b'); win->Wcol--; } Case '\f': clear_space(win->Wtop, win->Wbot); win->Wcol = 0; curs_window(win); Case '\t': if (win->Wcol == cols - 1) { Bputch('\n'); win->Wcol = 0; } else { do { Bputch(' '); win->Wcol++; } while (win->Wcol % 8 && win->Wcol < cols - 1); } Case '\r': Bputch('\r'); win->Wcol = 0; } }}#ifdef USE_STDARGvoid outputf(char *fmt, ...)#elsevoid outputf(va_alist) va_dcl#endif{ va_list ap; char *ptr, *sval, *intstr; String *buf = &wbufs[1]; int width = 0;#ifdef USE_STDARG va_start(ap, fmt);#else char *fmt; va_start(ap); fmt = va_arg(ap, char *);#endif s_term(buf, 0); ptr = strchr(fmt, '%'); while (ptr) { s_cat(buf, cstr_sl(fmt, ptr - fmt)); if (isdigit(*++ptr)) { width = atoi(ptr); while (isdigit(*++ptr)); } if (*ptr == 'd') { intstr = itoa(va_arg(ap, int)); for (width -= strlen(intstr); width > 0; width--) s_fadd(buf, ' '); s_acat(buf, intstr); } else if (*ptr == 's') { sval = va_arg(ap, char *); for (width -= strlen(sval); width > 0; width--) s_fadd(buf, ' '); s_acat(buf, sval); } else s_fadd(buf, *ptr); fmt = ptr + 1; ptr = strchr(fmt, '%'); } s_acat(buf, fmt); output(Cur_win, buf->c.s); va_end(ap);}void operror(s, rmt) char *s; Unode *rmt;{ char errbuf[128]; Unode *win = rmt ? rmt->Rwin : Cur_win; strcpy(errbuf, s); strcat(errbuf, ": "); strcat(errbuf, sys_errlist[errno]); strcat(errbuf, "\n"); output(win, errbuf);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -