📄 sldisply.c
字号:
if (cust_esc != NULL) { SLfree (cust_esc); FgBg_Stats[(Ansi_Color_Map[obj].fgbg >> 8) & 0x7F] -= 1; Ansi_Color_Map[obj].custom_esc = NULL; } Ansi_Color_Map[obj].fgbg = attr; if (obj == 0) Color_0_Modified = 1; if (_SLtt_color_changed_hook != NULL) (*_SLtt_color_changed_hook)();}SLtt_Char_Type SLtt_get_color_object (int obj){ if ((obj < 0) || (obj >= JMAX_COLORS)) return 0; return Ansi_Color_Map[obj].fgbg;}void SLtt_add_color_attribute (int obj, SLtt_Char_Type attr){ if ((obj < 0) || (obj >= JMAX_COLORS)) return; Ansi_Color_Map[obj].fgbg |= (attr & ATTR_MASK); if (obj == 0) Color_0_Modified = 1; if (_SLtt_color_changed_hook != NULL) (*_SLtt_color_changed_hook)();}static SLtt_Char_Type fb_to_fgbg (SLtt_Char_Type f, SLtt_Char_Type b){ SLtt_Char_Type attr; if (Max_Terminfo_Colors != 8) { if (f != SLSMG_COLOR_DEFAULT) f %= Max_Terminfo_Colors; if (b != SLSMG_COLOR_DEFAULT) b %= Max_Terminfo_Colors; return ((f << 8) | (b << 16)); } /* Otherwise we have 8 ansi colors. Try to get bright versions * by using the BOLD and BLINK attributes. */ attr = 0; /* Note: If f represents default, it will have the value 0xFF */ if (f != SLSMG_COLOR_DEFAULT) { if (f & 0x8) attr = SLTT_BOLD_MASK; f &= 0x7; } if (b != SLSMG_COLOR_DEFAULT) { if (b & 0x8) attr |= SLTT_BLINK_MASK; b &= 0x7; } return ((f << 8) | (b << 16) | attr);}/* This looks for colors with name form 'colorN'. If color is of this * form, N is passed back via parameter list. */static int parse_color_digit_name (char *color, SLtt_Char_Type *f){ unsigned int i; unsigned char ch; if (strncmp (color, "color", 5)) return -1; color += 5; if (*color == 0) return -1; i = 0; while (1) { unsigned int j; ch = (unsigned char) *color++; if (ch == 0) break; if ((ch > '9') || (ch < '0')) return -1; if (i > 0xFFFFFFFFU / 10) return -1; j = (i *= 10); i += (ch - '0'); if (i < j) return -1; } *f = (SLtt_Char_Type) i; return 0;}static int make_color_fgbg (char *fg, char *bg, SLtt_Char_Type *fgbg){ SLtt_Char_Type f = 0xFFFFFFFFU, b = 0xFFFFFFFFU; char *dfg, *dbg; unsigned int i; if ((fg != NULL) && (*fg == 0)) fg = NULL; if ((bg != NULL) && (*bg == 0)) bg = NULL; if ((fg == NULL) || (bg == NULL)) { if (-1 == get_default_colors (&dfg, &dbg)) return -1; if (fg == NULL) fg = dfg; if (bg == NULL) bg = dbg; } if (-1 == parse_color_digit_name (fg, &f)) { for (i = 0; i < MAX_COLOR_NAMES; i++) { if (strcmp(fg, Color_Defs[i].name)) continue; f = Color_Defs[i].color; break; } } if (-1 == parse_color_digit_name (bg, &b)) { for (i = 0; i < MAX_COLOR_NAMES; i++) { if (strcmp(bg, Color_Defs[i].name)) continue; b = Color_Defs[i].color; break; } } if ((f == 0xFFFFFFFFU) || (b == 0xFFFFFFFFU)) return -1; *fgbg = fb_to_fgbg (f, b); return 0;}void SLtt_set_color (int obj, char *what, char *fg, char *bg){ SLtt_Char_Type fgbg; (void) what; if ((obj < 0) || (obj >= JMAX_COLORS)) return; if (-1 != make_color_fgbg (fg, bg, &fgbg)) SLtt_set_color_object (obj, fgbg);}void SLtt_set_color_fgbg (int obj, SLtt_Char_Type f, SLtt_Char_Type b){ SLtt_set_color_object (obj, fb_to_fgbg (f, b));}void SLtt_set_color_esc (int obj, char *esc){ char *cust_esc; SLtt_Char_Type fgbg = 0; int i; if ((obj < 0) || (obj >= JMAX_COLORS)) { return; } cust_esc = Ansi_Color_Map[obj].custom_esc; if (cust_esc != NULL) { SLfree (cust_esc); FgBg_Stats[(Ansi_Color_Map[obj].fgbg >> 8) & 0x7F] -= 1; } cust_esc = (char *) SLmalloc (strlen(esc) + 1); if (cust_esc != NULL) strcpy (cust_esc, esc); Ansi_Color_Map[obj].custom_esc = cust_esc; if (cust_esc == NULL) fgbg = 0; else { /* The whole point of this is to generate a unique fgbg */ for (i = 0; i < JMAX_COLORS; i++) { if (FgBg_Stats[i] == 0) fgbg = i; if (obj == i) continue; if ((Ansi_Color_Map[i].custom_esc) == NULL) continue; if (!strcmp (Ansi_Color_Map[i].custom_esc, cust_esc)) { fgbg = (Ansi_Color_Map[i].fgbg >> 8) & 0x7F; break; } } FgBg_Stats[fgbg] += 1; } fgbg |= 0x80; Ansi_Color_Map[obj].fgbg = (fgbg | (fgbg << 8)) << 8; if (obj == 0) Color_0_Modified = 1; if (_SLtt_color_changed_hook != NULL) (*_SLtt_color_changed_hook)();}void SLtt_set_alt_char_set (int i){ static int last_i; if (SLtt_Has_Alt_Charset == 0) return; i = (i != 0); if (i == last_i) return; tt_write_string (i ? Start_Alt_Chars_Str : End_Alt_Chars_Str ); last_i = i;}static void write_attributes (SLtt_Char_Type fgbg){ int bg0, fg0; int unknown_attributes; if (Worthless_Highlight) return; if (fgbg == Current_Fgbg) return; unknown_attributes = 0; /* Before spitting out colors, fix attributes */ if ((fgbg & ATTR_MASK) != (Current_Fgbg & ATTR_MASK)) { if (Current_Fgbg & ATTR_MASK) { tt_write_string(Norm_Vid_Str); /* In case normal video turns off ALL attributes: */ if (fgbg & SLTT_ALTC_MASK) Current_Fgbg &= ~SLTT_ALTC_MASK; SLtt_set_alt_char_set (0); } if ((fgbg & SLTT_ALTC_MASK) != (Current_Fgbg & SLTT_ALTC_MASK)) { SLtt_set_alt_char_set ((int) (fgbg & SLTT_ALTC_MASK)); } if (fgbg & SLTT_ULINE_MASK) tt_write_string (UnderLine_Vid_Str); if (fgbg & SLTT_BOLD_MASK) SLtt_bold_video (); if (fgbg & SLTT_REV_MASK) tt_write_string (Rev_Vid_Str); if (fgbg & SLTT_BLINK_MASK) { /* Someday Linux will have a blink mode that set high intensity * background. Lets be prepared. */ if (SLtt_Blink_Mode) tt_write_string (Blink_Vid_Str); } unknown_attributes = 1; } if (SLtt_Use_Ansi_Colors) { fg0 = (int) GET_FG(fgbg); bg0 = (int) GET_BG(fgbg); if (unknown_attributes || (fg0 != (int)GET_FG(Current_Fgbg))) { if (fg0 == SLSMG_COLOR_DEFAULT) tt_write_string (Default_Color_Fg_Str); else tt_printf (Color_Fg_Str, COLOR_ARG(fg0, Is_Bg_BGR), 0); } if (unknown_attributes || (bg0 != (int)GET_BG(Current_Fgbg))) { if (bg0 == SLSMG_COLOR_DEFAULT) tt_write_string (Default_Color_Bg_Str); else tt_printf (Color_Bg_Str, COLOR_ARG(bg0, Is_Bg_BGR), 0); } } Current_Fgbg = fgbg;}static int Video_Initialized;void SLtt_reverse_video (int color){ SLtt_Char_Type fgbg; char *esc; if (Worthless_Highlight) return; if ((color < 0) || (color >= JMAX_COLORS)) return; if (Video_Initialized == 0) { if (color == JNORMAL_COLOR) { tt_write_string (Norm_Vid_Str); } else tt_write_string (Rev_Vid_Str); Current_Fgbg = 0xFFFFFFFFU; return; } if (SLtt_Use_Ansi_Colors) { fgbg = Ansi_Color_Map[color].fgbg; if ((esc = Ansi_Color_Map[color].custom_esc) != NULL) { if (fgbg != Current_Fgbg) { Current_Fgbg = fgbg; tt_write_string (esc); return; } } } else fgbg = Ansi_Color_Map[color].mono; if (fgbg == Current_Fgbg) return; write_attributes (fgbg);}void SLtt_normal_video (void){ SLtt_reverse_video(JNORMAL_COLOR);}void SLtt_narrow_width (void){ tt_write_string("\033[?3l");}void SLtt_wide_width (void){ tt_write_string("\033[?3h");}/* Highest bit represents the character set. */#define COLOR_MASK 0x7F00#define COLOR_OF(x) (((x)&COLOR_MASK)>>8)#define CHAR_OF(x) ((x)&0x80FF)#if SLTT_HAS_NON_BCE_SUPPORTstatic int bce_color_eqs (unsigned int a, unsigned int b){ a = COLOR_OF(a); b = COLOR_OF(b); if (a == b) return 1; if (SLtt_Use_Ansi_Colors == 0) return Ansi_Color_Map[a].mono == Ansi_Color_Map[b].mono; if (Bce_Color_Offset == 0) return Ansi_Color_Map[a].fgbg == Ansi_Color_Map[b].fgbg; /* If either are color 0, then we do not know what that means since the * terminal does not support BCE */ if ((a == 0) || (b == 0)) return 0; return Ansi_Color_Map[a-1].fgbg == Ansi_Color_Map[b-1].fgbg;}#define COLOR_EQS(a,b) bce_color_eqs (a,b)#else# define COLOR_EQS(a, b) \ (SLtt_Use_Ansi_Colors \ ? (Ansi_Color_Map[COLOR_OF(a)].fgbg == Ansi_Color_Map[COLOR_OF(b)].fgbg)\ : (Ansi_Color_Map[COLOR_OF(a)].mono == Ansi_Color_Map[COLOR_OF(b)].mono))#endif#define CHAR_EQS(a, b) (((a) == (b))\ || ((CHAR_OF(a)==CHAR_OF(b)) && COLOR_EQS(a,b)))/* The whole point of this routine is to prevent writing to the last column * and last row on terminals with automatic margins. */static void write_string_with_care (char *str){ unsigned int len; if (str == NULL) return; len = strlen (str); if (Automatic_Margins && (Cursor_r + 1 == SLtt_Screen_Rows)) { if (len + (unsigned int) Cursor_c >= (unsigned int) SLtt_Screen_Cols) { /* For now, just do not write there. Later, something more * sophisticated will be implemented. */ if (SLtt_Screen_Cols > Cursor_c) len = SLtt_Screen_Cols - Cursor_c - 1; else len = 0; } } tt_write (str, len);}static void send_attr_str (SLsmg_Char_Type *s){ unsigned char out[SLTT_MAX_SCREEN_COLS], ch, *p; register SLtt_Char_Type attr; register SLsmg_Char_Type sh; int color, last_color = -1; p = out; while (0 != (sh = *s++)) { ch = sh & 0xFF; color = ((int) sh & 0xFF00) >> 8;#if SLTT_HAS_NON_BCE_SUPPORT if (Bce_Color_Offset && (color >= Bce_Color_Offset)) color -= Bce_Color_Offset;#endif if (color != last_color) { if (SLtt_Use_Ansi_Colors) attr = Ansi_Color_Map[color & 0x7F].fgbg; else attr = Ansi_Color_Map[color & 0x7F].mono; if (sh & 0x8000) /* alternate char set */ { if (SLtt_Use_Blink_For_ACS) { if (SLtt_Blink_Mode) attr |= SLTT_BLINK_MASK; } else attr |= SLTT_ALTC_MASK; } if (attr != Current_Fgbg) { if ((ch != ' ') || /* it is a space so only consider it different if it * has different attributes. */ (attr != Current_Fgbg)) /* The previous line was: */ /* (attr & BGALL_MASK) != (Current_Fgbg & BGALL_MASK)) */ /* However, it does not account for ACS */ { if (p != out) { *p = 0; write_string_with_care ((char *) out); Cursor_c += (int) (p - out); p = out; } if (SLtt_Use_Ansi_Colors && (NULL != Ansi_Color_Map[color & 0x7F].custom_esc)) { tt_write_string (Ansi_Color_Map[color & 0x7F].custom_esc); /* Just in case the custom escape sequence screwed up * the alt character set state... */ if ((attr & SLTT_ALTC_MASK) != (Current_Fgbg & SLTT_ALTC_MASK)) SLtt_set_alt_char_set ((int) (attr & SLTT_ALTC_MASK)); Current_Fgbg = attr; } else write_attributes (attr); last_color = color; } } } *p++ = ch; } *p = 0; if (p != out) write_string_with_care ((char *) out); Cursor_c += (int) (p - out);}static void forward_cursor (unsigned int n, int row){ char buf [1024]; /* if (Current_Fgbg & ~0xFF) */ /* { */ /* unsigned int num = 0; */ /* while (num < n) */ /* { */ /* write_string_with_care (" "); */ /* num++; */ /* } */ /* Cursor_c += n; */ /* return; */ /* } */ if (n <= 4) { SLtt_normal_video (); if (n >= sizeof (buf)) n = sizeof (buf) - 1; SLMEMSET (buf, ' ', n); buf[n] = 0; write_string_with_care (buf); Cursor_c += n; } else if (Curs_F_Str != NULL) { Cursor_c += n; n = tt_sprintf(buf, Curs_F_Str, (int) n, 0); tt_write(buf, n); } else SLtt_goto_rc (row, (int) (Cursor_c + n));}/* FIXME!! If the terminal does not support color, then this route has * problems of color object 0 has been assigned some monochrome attribute * such as reverse video. In such a case, space_char=' ' is not a simple * space character as is assumed below. */void SLtt_smart_puts(SLsmg_Char_Type *neww, SLsmg_Char_Type *oldd, int len, int row){ register SLsmg_Char_Type *p, *q, *qmax, *pmax, *buf; SLsmg_Char_Type buffer[SLTT_MAX_SCREEN_COLS+1]; unsigned int n_spaces; SLsmg_Char_Type *space_match, *last_buffered_match;#ifdef HP_GLITCH_CODE int handle_hp_glitch = 0;#endif SLsmg_Char_Type space_char;#define SLTT_USE_INSERT_HACK 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -