📄 slcurses.c
字号:
{ /* Curses seems to move current postion to top of window. */ win->_cury = win->_curx = 0; return -1; } win->modified = 1; ch = SLSMG_EXTRACT_CHAR(attr); if (attr == ch) color = win->color; else { /* hack to pick up the default color for graphics chars */ if (((attr & A_COLOR) == 0) && ((attr & A_ALTCHARSET) != 0)) { /* FIXME: priority=medium: Use SLSMG_?? instead of << */ attr |= win->color << 8; } color = map_attr_to_object (attr); } if (ch < ' ') { if (ch == '\n') { SLcurses_wclrtoeol (win); return do_newline (win); } if (ch == '\r') { win->_curx = 0; return 0; } if (ch == '\b') { if (win->_curx > 0) win->_curx--; return 0; } /* HACK HACK!!!! */ if (ch == '\t') ch = ' '; } if (win->_curx >= win->ncols) do_newline (win); b = win->lines[win->_cury] + win->_curx; *b = SLSMG_BUILD_CHAR(ch,color); win->_curx++; return 0;}int SLcurses_wnoutrefresh (SLcurses_Window_Type *w){ unsigned int len; unsigned int r, c; unsigned int i, imax; if (SLcurses_Is_Endwin) { if (TTY_State) init_tty (TTY_State - 1); SLsmg_resume_smg (); SLcurses_Is_Endwin = 0; } if (w == NULL) { SLsmg_refresh (); return -1; } if (w->modified == 0) return 0; r = w->_begy; c = w->_begx; len = w->ncols; imax = w->nrows; for (i = 0; i < imax; i++) { SLsmg_gotorc (r, c); SLsmg_write_color_chars (w->lines[i], len); r++; } if (w->has_box) SLsmg_draw_box(w->_begy, w->_begx, w->nrows, w->ncols); SLsmg_gotorc (w->_begy + w->_cury, w->_begx + w->_curx); w->modified = 0; return 0;}int SLcurses_wrefresh (SLcurses_Window_Type *w){ if (w == NULL) return -1; if (w->modified == 0) return 0; SLcurses_wnoutrefresh (w); SLsmg_refresh (); return 0;}int SLcurses_wclrtoeol (SLcurses_Window_Type *w){ SLsmg_Char_Type *b, *bmax; SLsmg_Char_Type blank; if (w == NULL) return -1; if (w->_cury >= w->nrows) return 0; w->modified = 1; blank = SLSMG_BUILD_CHAR(' ',w->color); b = w->lines[w->_cury]; bmax = b + w->ncols; b += w->_curx; while (b < bmax) *b++ = blank; return 0;}int SLcurses_wclrtobot (SLcurses_Window_Type *w){ SLsmg_Char_Type *b, *bmax; SLsmg_Char_Type blank; unsigned int r; if (w == NULL) return -1; w->modified = 1; blank = SLSMG_BUILD_CHAR(' ',w->color); SLcurses_wclrtoeol (w); for (r = w->_cury + 1; r < w->nrows; r++) { b = w->lines [r]; bmax = b + w->ncols; while (b < bmax) *b++ = blank; } return 0;}int SLcurses_wscrl (SLcurses_Window_Type *w, int n){ SLsmg_Char_Type **lines; unsigned int r, rmax, rmin, ncols; SLsmg_Char_Type color; if ((w == NULL) || (w->scroll_ok == 0)) return -1; w->modified = 1;#if 0 if (w->is_subwin) { SLang_reset_tty (); SLsmg_reset_smg (); fprintf (stderr, "\rAttempt to scroll a subwindow\n"); exit (1); }#endif color = w->color; ncols = w->ncols; lines = w->lines; rmax = w->scroll_max; rmin = w->scroll_min; if (rmax > w->nrows) rmax = w->nrows; if (rmin >= rmax) return 0; while (n > 0) { for (r = rmin + 1; r < rmax; r++) { /* lines[r - 1] = lines[r]; */ memcpy ((char *)lines[r - 1], (char *)lines[r], sizeof (SLsmg_Char_Type) * ncols); } blank_line (lines[rmax - 1], ncols, color); n--; } rmax--; while (n < 0) { for (r = rmax; r > rmin; r--) { memcpy ((char *)lines[r], (char *)lines[r - 1], sizeof (SLsmg_Char_Type) * ncols); } blank_line (lines[rmin], ncols, color); n++; } /* wmove (w, w->nrows - 1, 0); */ /* wclrtobot (w); */ return 0;}/* Note: if len is < 0, entire string will be used. */int SLcurses_waddnstr (SLcurses_Window_Type *w, char *str, int len){ SLsmg_Char_Type *b; SLsmg_Char_Type color; unsigned char ch; unsigned int nrows, ncols, crow, ccol; if ((w == NULL) || (str == NULL)) return -1; w->modified = 1; nrows = w->nrows; ncols = w->ncols; crow = w->_cury; ccol = w->_curx; color = w->color; if (w->scroll_max <= nrows) nrows = w->scroll_max; if (crow >= nrows) crow = 0; /* wrap back to top */ b = w->lines [crow] + ccol; while (len && ((ch = (unsigned char) *str++) != 0)) { len--; if (ch == '\n') { w->_cury = crow; w->_curx = ccol; SLcurses_wclrtoeol (w); do_newline (w); crow = w->_cury; ccol = w->_curx; b = w->lines[crow]; continue; } if (ccol >= ncols) { ccol = 0; crow++; if (crow >= nrows) { w->_curx = 0; w->_cury = crow; do_newline (w); crow = w->_cury; ccol = w->_curx; } b = w->lines [crow]; } if (ch == '\t') { unsigned int n = ccol; n += SLsmg_Tab_Width; n = SLsmg_Tab_Width - (n % SLsmg_Tab_Width); if (ccol + n > ncols) n = ncols - len; ccol += n; while (n--) *b++ = SLSMG_BUILD_CHAR(' ',color); continue; } *b++ = SLSMG_BUILD_CHAR(ch, color); ccol++; } w->_curx = ccol; w->_cury = crow; return 0;}/* This routine IS NOT CORRECT. It needs to compute the proper overlap * and copy accordingly. Here, I just assume windows are same size. */#if 0int SLcurses_overlay (SLcurses_Window_Type *swin, SLcurses_Window_Type *dwin){ SLsmg_Char_Type *s, *smax, *d, *dmax; if ((swin == NULL) || (dwin == NULL)) return -1; s = swin->buf; smax = swin->bufmax; d = dwin->buf; dmax = dwin->bufmax; while ((s < smax) && (d < dmax)) { SLsmg_Char_Type ch = *s++; if (SLSMG_EXTRACT_CHAR(ch) != ' ') *d = ch; d++; } return -1; /* not implemented */}#endifSLcurses_Window_Type *SLcurses_subwin (SLcurses_Window_Type *orig, unsigned int nlines, unsigned int ncols, unsigned int begin_y, unsigned int begin_x){ SLcurses_Window_Type *sw; int r, c; unsigned int i; if (orig == NULL) return NULL; sw = (SLcurses_Window_Type *) SLmalloc (sizeof (SLcurses_Window_Type)); if (sw == NULL) return NULL; SLMEMSET ((char *)sw, 0, sizeof (SLcurses_Window_Type));#if 1 r = begin_y - orig->_begy;#else r = 1 + ((int)orig->nrows - (int)nlines) / 2;#endif if (r < 0) r = 0; if (r + nlines > orig->nrows) nlines = orig->nrows - r; c = ((int)orig->ncols - (int)ncols) / 2; if (c < 0) c = 0; if (c + ncols > orig->ncols) ncols = orig->ncols - c; sw->scroll_min = 0; sw->scroll_max = sw->nrows = nlines; sw->ncols = ncols; sw->_begy = begin_y; sw->_begx = begin_x; sw->_maxx = (begin_x + ncols) - 1; sw->_maxy = (begin_y + nlines) - 1; sw->lines = (SLsmg_Char_Type **) SLmalloc (nlines * sizeof (SLsmg_Char_Type *)); if (sw->lines == NULL) { SLcurses_delwin (sw); return NULL; } for (i = 0; i < nlines; i++) { sw->lines [i] = orig->lines [r + i] + c; } sw->is_subwin = 1; return sw;}int SLcurses_wclear (SLcurses_Window_Type *w){ unsigned int i; if (w != NULL) w->modified = 1; for (i=0; i < w->nrows; i++) blank_line (w->lines[i], w->ncols, w->color); return 0;}int SLcurses_wdelch (SLcurses_Window_Type *w){ SLsmg_Char_Type *p, *p1, *pmax; p = w->lines[w->_cury]; pmax = p + w->ncols; p += w->_curx; p1 = p + 1; while (p1 < pmax) { *p = *p1; p = p1; p1++; } if (p < pmax) *p = SLSMG_BUILD_CHAR(' ',w->color); w->modified = 1; return 0;}int SLcurses_winsch (SLcurses_Window_Type *w, int ch){ SLsmg_Char_Type *p, *p1, *pmax; p = w->lines[w->_cury]; pmax = p + w->ncols; p += w->_curx; p1 = pmax - 1; while (pmax > p) { *pmax = *p1; pmax = p1; p1--; } if (p < pmax) *p = SLSMG_BUILD_CHAR(ch, w->color); w->modified = 1; return 0;}int SLcurses_endwin (void){ SLcurses_Is_Endwin = 1; SLsmg_suspend_smg (); SLang_reset_tty (); return 0;}#if 0int SLcurses_mvwscanw (SLcurses_Window_Type *w, unsigned int r, unsigned int c, char *fmt, ...){#if HAVE_VFSCANF int ret; va_list ap; SLcurses_wmove (w, r, c); SLcurses_wrefresh (w); va_start(ap, fmt); ret = vfscanf (stdin, fmt, ap); va_end(ap); return ret;#else return 0;#endif}int SLcurses_wscanw (SLcurses_Window_Type *w, char *fmt, ...){#if HAVE_VFSCANF va_list ap; int ret; SLcurses_wrefresh (w); va_start(ap, fmt); ret = vfscanf (stdin, fmt, ap); va_end(ap); return ret;#else return 0;#endif}int SLcurses_scanw (char *fmt, ...){#ifdef HAVE_VFSCANF va_list ap; int ret; SLcurses_wrefresh (SLcurses_Stdscr); va_start(ap, fmt); ret = vfscanf (stdin, fmt, ap); va_end(ap); return ret;#else return 0;#endif}#endifint SLcurses_clearok (SLcurses_Window_Type *w, int bf){ if (bf) { SLsmg_cls (); w->modified = 1; } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -