📄 sldisply.c
字号:
}/* Returns 0 if all goes well, -1 if terminal capabilities cannot be deduced, * or -2 if terminal cannot position the cursor. */int SLtt_initialize (char *term){ char *t, ch; int is_xterm; int almost_vtxxx; if (SLang_TT_Write_FD == -1) { /* Apparantly, this cannot fail according to the man pages. */ SLang_TT_Write_FD = fileno (stdout); } if (term == NULL) { term = getenv ("TERM"); if (term == NULL) return -1; } if (_SLsecure_issetugid () && ((term[0] == '.') || (NULL != strchr(term, '/')))) return -1; Linux_Console = (!strncmp (term, "linux", 5)# ifdef linux || !strncmp(term, "con", 3)# endif ); t = term; if (strcmp(t, "vt52") && (*t++ == 'v') && (*t++ == 't') && (ch = *t, (ch >= '1') && (ch <= '9'))) Vt100_Like = 1; is_xterm = ((0 == strncmp (term, "xterm", 5)) || (0 == strncmp (term, "rxvt", 4)) || (0 == strncmp (term, "Eterm", 5))); almost_vtxxx = (Vt100_Like || Linux_Console || is_xterm || !strcmp (term, "screen"));# ifndef USE_TERMCAP if (NULL == (Terminfo = _SLtt_tigetent (term))) { if (almost_vtxxx) /* Special cases. */ { int vt102 = 1; if (!strcmp (term, "vt100")) vt102 = 0; get_color_info (); SLtt_set_term_vtxxx (&vt102); (void) SLtt_get_screen_size (); return 0; } return -1; }# else /* USE_TERMCAP */ if (1 != tgetent(Termcap_Buf, term)) return -1; Termcap_String_Ptr = Termcap_String_Buf;# endif /* NOT USE_TERMCAP */ Termcap_Initalized = 1; Cls_Str = SLtt_tgetstr ("cl"); Curs_Pos_Str = SLtt_tgetstr ("cm"); if ((NULL == (Ins_Mode_Str = SLtt_tgetstr("im"))) || ( NULL == (Eins_Mode_Str = SLtt_tgetstr("ei"))) || ( NULL == (Del_Char_Str = SLtt_tgetstr("dc")))) SLtt_Term_Cannot_Insert = 1; Visible_Bell_Str = SLtt_tgetstr ("vb"); Curs_Up_Str = SLtt_tgetstr ("up"); Rev_Scroll_Str = SLtt_tgetstr("sr"); Del_N_Lines_Str = SLtt_tgetstr("DL"); Add_N_Lines_Str = SLtt_tgetstr("AL"); /* Actually these are used to initialize terminals that use cursor * addressing. Hard to believe. */ Term_Init_Str = SLtt_tgetstr ("ti"); Term_Reset_Str = SLtt_tgetstr ("te"); /* If I do this for vtxxx terminals, arrow keys start sending ESC O A, * which I do not want. This is mainly for HP terminals. */ if ((almost_vtxxx == 0) || SLtt_Force_Keypad_Init) { Keypad_Init_Str = SLtt_tgetstr ("ks"); Keypad_Reset_Str = SLtt_tgetstr ("ke"); } /* Make up for defective termcap/terminfo databases */ if ((Vt100_Like && (term[2] != '1')) || Linux_Console || is_xterm ) { if (Del_N_Lines_Str == NULL) Del_N_Lines_Str = "\033[%dM"; if (Add_N_Lines_Str == NULL) Add_N_Lines_Str = "\033[%dL"; } Scroll_R_Str = SLtt_tgetstr("cs"); SLtt_get_screen_size (); if ((Scroll_R_Str == NULL) || (((NULL == Del_N_Lines_Str) || (NULL == Add_N_Lines_Str)) && (NULL == Rev_Scroll_Str))) { if (is_xterm || Linux_Console ) { /* Defective termcap mode!!!! */ SLtt_set_term_vtxxx (NULL); } else SLtt_Term_Cannot_Scroll = 1; } Del_Eol_Str = SLtt_tgetstr("ce"); Del_Bol_Str = SLtt_tgetstr("cb"); if (is_xterm && (Del_Bol_Str == NULL)) Del_Bol_Str = "\033[1K"; if (is_xterm && (Del_Eol_Str == NULL)) Del_Eol_Str = "\033[K"; Rev_Vid_Str = SLtt_tgetstr("mr"); if (Rev_Vid_Str == NULL) Rev_Vid_Str = SLtt_tgetstr("so"); Bold_Vid_Str = SLtt_tgetstr("md"); /* Although xterm cannot blink, it does display the blinking characters * as bold ones. Some Rxvt will display the background as high intensity. */ if ((NULL == (Blink_Vid_Str = SLtt_tgetstr("mb"))) && is_xterm) Blink_Vid_Str = "\033[5m"; UnderLine_Vid_Str = SLtt_tgetstr("us"); Start_Alt_Chars_Str = SLtt_tgetstr ("as"); /* smacs */ End_Alt_Chars_Str = SLtt_tgetstr ("ae"); /* rmacs */ Enable_Alt_Char_Set = SLtt_tgetstr ("eA"); /* enacs */ SLtt_Graphics_Char_Pairs = SLtt_tgetstr ("ac"); if (NULL == SLtt_Graphics_Char_Pairs) { /* make up for defective termcap/terminfo */ if (Vt100_Like) { Start_Alt_Chars_Str = "\016"; End_Alt_Chars_Str = "\017"; Enable_Alt_Char_Set = "\033)0"; } } /* aixterm added by willi */ if (is_xterm || !strncmp (term, "aixterm", 7)) { Start_Alt_Chars_Str = "\016"; End_Alt_Chars_Str = "\017"; Enable_Alt_Char_Set = "\033(B\033)0"; } if ((SLtt_Graphics_Char_Pairs == NULL) && ((Start_Alt_Chars_Str == NULL) || (End_Alt_Chars_Str == NULL))) { SLtt_Has_Alt_Charset = 0; Enable_Alt_Char_Set = NULL; } else SLtt_Has_Alt_Charset = 1;#ifdef AMIGA Enable_Alt_Char_Set = Start_Alt_Chars_Str = End_Alt_Chars_Str = NULL;#endif /* status line capabilities */ if ((SLtt_Has_Status_Line == -1) && (0 != (SLtt_Has_Status_Line = TGETFLAG ("hs")))) { Disable_Status_line_Str = SLtt_tgetstr ("ds"); Return_From_Status_Line_Str = SLtt_tgetstr ("fs"); Goto_Status_Line_Str = SLtt_tgetstr ("ts"); /* Status_Line_Esc_Ok = TGETFLAG("es"); */ Num_Status_Line_Columns = SLtt_tgetnum ("ws"); if (Num_Status_Line_Columns < 0) Num_Status_Line_Columns = 0; } if (NULL == (Norm_Vid_Str = SLtt_tgetstr("me"))) { Norm_Vid_Str = SLtt_tgetstr("se"); } Cursor_Invisible_Str = SLtt_tgetstr("vi"); Cursor_Visible_Str = SLtt_tgetstr("ve"); Curs_F_Str = SLtt_tgetstr("RI");# if 0 if (NULL != Curs_F_Str) { Len_Curs_F_Str = strlen(Curs_F_Str); } else Len_Curs_F_Str = strlen(Curs_Pos_Str);# endif Automatic_Margins = TGETFLAG ("am"); /* No_Move_In_Standout = !TGETFLAG ("ms"); */# ifdef HP_GLITCH_CODE Has_HP_Glitch = TGETFLAG ("xs");# else Worthless_Highlight = TGETFLAG ("xs");# endif if (Worthless_Highlight == 0) { /* Magic cookie glitch */ Worthless_Highlight = (SLtt_tgetnum ("sg") > 0); } if (Worthless_Highlight) SLtt_Has_Alt_Charset = 0; Reset_Color_String = SLtt_tgetstr ("op"); /* Apparantly the difference between "AF" and "Sf" is that AF uses RGB, * but Sf uses BGR. */ Color_Fg_Str = SLtt_tgetstr ("AF"); /* ANSI setaf */ if (Color_Fg_Str == NULL) { Color_Fg_Str = SLtt_tgetstr ("Sf"); /* setf */ Is_Fg_BGR = (Color_Fg_Str != NULL); } Color_Bg_Str = SLtt_tgetstr ("AB"); /* ANSI setbf */ if (Color_Bg_Str == NULL) { Color_Bg_Str = SLtt_tgetstr ("Sb"); /* setb */ Is_Fg_BGR = (Color_Bg_Str != NULL); } if ((Max_Terminfo_Colors = SLtt_tgetnum ("Co")) < 0) Max_Terminfo_Colors = 8; if ((Color_Bg_Str != NULL) && (Color_Fg_Str != NULL)) SLtt_Use_Ansi_Colors = 1; else {#if 0 Color_Fg_Str = "%?%p1%{7}%>%t\033[1;3%p1%{8}%m%dm%e\033[3%p1%dm%;"; Color_Bg_Str = "%?%p1%{7}%>%t\033[5;4%p1%{8}%m%dm%e\033[4%p1%dm%;"; Max_Terminfo_Colors = 16;#else Color_Fg_Str = "\033[3%dm"; Color_Bg_Str = "\033[4%dm"; Max_Terminfo_Colors = 8;#endif }#if SLTT_HAS_NON_BCE_SUPPORT Can_Background_Color_Erase = TGETFLAG ("ut"); /* bce */ /* Modern xterms have the BCE capability as well as the linux console */ if (Can_Background_Color_Erase == 0) { Can_Background_Color_Erase = (Linux_Console# if SLTT_XTERM_ALWAYS_BCE || is_xterm# endif ); }#endif get_color_info (); if ((Cls_Str == NULL) || (Curs_Pos_Str == NULL)) return -2; return 0;}#endif/* Unix *//* specific to vtxxx only */void SLtt_enable_cursor_keys (void){#ifdef __unix__ if (Vt100_Like)#endif tt_write_string("\033=\033[?1l");}#ifdef VMSint SLtt_initialize (char *term){ SLtt_get_terminfo (); return 0;}void SLtt_get_terminfo (){ int zero = 0; /* Apparantly, this cannot fail according to the man pages. */ if (SLang_TT_Write_FD == -1) SLang_TT_Write_FD = fileno (stdout); Can_Background_Color_Erase = 0; Color_Fg_Str = "\033[3%dm"; Color_Bg_Str = "\033[4%dm"; Max_Terminfo_Colors = 8; get_color_info (); SLtt_set_term_vtxxx(&zero); Start_Alt_Chars_Str = "\016"; End_Alt_Chars_Str = "\017"; SLtt_Has_Alt_Charset = 1; SLtt_Graphics_Char_Pairs = "aaffgghhjjkkllmmnnooqqssttuuvvwwxx"; Enable_Alt_Char_Set = "\033(B\033)0"; SLtt_get_screen_size ();}#endif/* This sets term for vt102 terminals it parameter vt100 is 0. If vt100 * is non-zero, set terminal appropriate for a only vt100 * (no add line capability). */void SLtt_set_term_vtxxx(int *vt100){ Norm_Vid_Str = "\033[m"; Scroll_R_Str = "\033[%i%d;%dr"; Cls_Str = "\033[2J\033[H"; Rev_Vid_Str = "\033[7m"; Bold_Vid_Str = "\033[1m"; Blink_Vid_Str = "\033[5m"; UnderLine_Vid_Str = "\033[4m"; Del_Eol_Str = "\033[K"; Del_Bol_Str = "\033[1K"; Rev_Scroll_Str = "\033M"; Curs_F_Str = "\033[%dC"; /* Len_Curs_F_Str = 5; */ Curs_Pos_Str = "\033[%i%d;%dH"; if ((vt100 == NULL) || (*vt100 == 0)) { Ins_Mode_Str = "\033[4h"; Eins_Mode_Str = "\033[4l"; Del_Char_Str = "\033[P"; Del_N_Lines_Str = "\033[%dM"; Add_N_Lines_Str = "\033[%dL"; SLtt_Term_Cannot_Insert = 0; } else { Del_N_Lines_Str = NULL; Add_N_Lines_Str = NULL; SLtt_Term_Cannot_Insert = 1; } SLtt_Term_Cannot_Scroll = 0; /* No_Move_In_Standout = 0; */}int SLtt_init_video (void){ /* send_string_to_term("\033[?6h"); */ /* relative origin mode */ tt_write_string (Term_Init_Str); tt_write_string (Keypad_Init_Str); SLtt_reset_scroll_region(); SLtt_end_insert(); tt_write_string (Enable_Alt_Char_Set); Video_Initialized = 1; return 0;}int SLtt_reset_video (void){ SLtt_goto_rc (SLtt_Screen_Rows - 1, 0); Cursor_Set = 0; SLtt_normal_video (); /* MSKermit requires this */ tt_write_string(Norm_Vid_Str); Current_Fgbg = 0xFFFFFFFFU; SLtt_set_alt_char_set (0); if (SLtt_Use_Ansi_Colors) { if (Reset_Color_String == NULL) { SLtt_Char_Type attr; if (-1 != make_color_fgbg (NULL, NULL, &attr)) write_attributes (attr); else tt_write_string ("\033[0m\033[m"); } else tt_write_string (Reset_Color_String); Current_Fgbg = 0xFFFFFFFFU; } SLtt_erase_line (); tt_write_string (Keypad_Reset_Str); tt_write_string (Term_Reset_Str); SLtt_flush_output (); Video_Initialized = 0; return 0;}void SLtt_bold_video (void){ tt_write_string (Bold_Vid_Str);}int SLtt_set_mouse_mode (int mode, int force){ char *term; if (force == 0) { if (NULL == (term = (char *) getenv("TERM"))) return -1; if (strncmp ("xterm", term, 5)) return -1; } if (mode) tt_write_string ("\033[?9h"); else tt_write_string ("\033[?9l"); return 0;}void SLtt_disable_status_line (void){ if (SLtt_Has_Status_Line > 0) { tt_write_string (Disable_Status_line_Str); SLtt_flush_output (); }}int SLtt_write_to_status_line (char *s, int col){ if ((SLtt_Has_Status_Line <= 0) || (Goto_Status_Line_Str == NULL) || (Return_From_Status_Line_Str == NULL)) return -1; tt_printf (Goto_Status_Line_Str, col, 0); tt_write_string (s); tt_write_string (Return_From_Status_Line_Str); return 0;}void SLtt_get_screen_size (void){#ifdef VMS int status, code; unsigned short chan; $DESCRIPTOR(dev_dsc, "SYS$INPUT:");#endif int r = 0, c = 0;#ifdef TIOCGWINSZ struct winsize wind_struct; do { if ((ioctl(1,TIOCGWINSZ,&wind_struct) == 0) || (ioctl(0, TIOCGWINSZ, &wind_struct) == 0) || (ioctl(2, TIOCGWINSZ, &wind_struct) == 0)) { c = (int) wind_struct.ws_col; r = (int) wind_struct.ws_row; break; } } while (errno == EINTR);#endif#ifdef VMS status = sys$assign(&dev_dsc,&chan,0,0,0); if (status & 1) { code = DVI$_DEVBUFSIZ; status = lib$getdvi(&code, &chan,0, &c, 0,0); if (!(status & 1)) c = 80; code = DVI$_TT_PAGE; status = lib$getdvi(&code, &chan,0, &r, 0,0); if (!(status & 1)) r = 24; sys$dassgn(chan); }#endif if (r <= 0) { char *s = getenv ("LINES"); if (s != NULL) r = atoi (s); } if (c <= 0) { char *s = getenv ("COLUMNS"); if (s != NULL) c = atoi (s); } if ((r <= 0) || (r > SLTT_MAX_SCREEN_ROWS)) r = 24; if ((c <= 0) || (c > SLTT_MAX_SCREEN_COLS)) c = 80; SLtt_Screen_Rows = r; SLtt_Screen_Cols = c;}#if SLTT_HAS_NON_BCE_SUPPORTint _SLtt_get_bce_color_offset (void){ if ((SLtt_Use_Ansi_Colors == 0) || Can_Background_Color_Erase || SLtt_Use_Blink_For_ACS) /* in this case, we cannot lose a color */ Bce_Color_Offset = 0; else { if (GET_BG(Ansi_Color_Map[0].fgbg) == SLSMG_COLOR_DEFAULT) Bce_Color_Offset = 0; else Bce_Color_Offset = 1; } return Bce_Color_Offset;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -