📄 ansi.c
字号:
for (j = 0; j < (int) sizeof(buf); buf[j++] = ' ') ; for (j = l = 0; j < 255 && j - l < 50; j++) { sprintf(temp, "\033[%s%d$p", puc[i], j); tc_putp(temp); if (!valid_mode(('$' << 8) | 'y')) { /* not valid, save terminating value */ s = expand((const char *)ansi_buf); sprintf(tms, "%s%s%d %s ", tms, puc[i], j, s); break; } if (private_use != puc[i][0]) break; if (ansi_value[0] != j) break; if (ansi_value[1]) { l = j; if (k > 70) { buf[k] = '\0'; put_crlf(); ptextln(buf); for (k = 0; k < (int) sizeof(buf);) { buf[k++] = ' '; } k = 0; } sprintf(temp, " %d", j); ptext(temp); k += strlen(temp); buf[k - 1] = ansi_value[1] + '0'; if (modes_found >= MAX_MODES) continue; current_value[modes_found] = ansi_value[1] + '0'; /* some modes never return */ if ((i == 0 && j == 13) /* control execution */ || (puc[i][0] == '?' && j == 2)) /* VT52 */ set_value[modes_found] = reset_value[modes_found] = '-'; else set_value[modes_found] = reset_value[modes_found] = ' '; mode_puc[modes_found] = i; mode_number[modes_found++] = j; } } buf[k] = '\0'; if (buf[k - 1] != ' ') { put_crlf(); ptext(buf); } } if ((i = modes_found) != 0) { put_crlf(); put_crlf(); if (tms[0]) { ptextln(tms); } ptext("Hit 'Y' to test mode set/reset states: "); i = wait_here(); } if (i == 'y' || i == 'Y') while (1) {#ifdef STATUSFIX FILE *fp;#ifdef TEDANSI fp = fopen("ted.ansi", "w");#else fp = fopen("/dev/console", "w");#endif#endif for (i = j = 0; j < modes_found; j = ++i >> 1) { if (set_value[j] == '-') continue; k = (current_value[j] ^ i) & 1; sprintf(temp, "\033[%s%d%c\033[%s%d$p", puc[mode_puc[j]], mode_number[j], k ? 'l' : 'h', puc[mode_puc[j]], mode_number[j]);#ifdef STATUSFIX if (fp) { fprintf(fp, "%s\n", expand(temp)); fflush(fp); }#endif tc_putp(temp); if (!valid_mode(('$' << 8) | 'y')) continue; if (k) { reset_value[j] = ansi_value[1] + '0'; } else { set_value[j] = ansi_value[1] + '0'; } } put_str("\033[30l"); /* added for GORT bug (WY-185) */#ifdef STATUSFIX if (fp) fclose(fp);#endif tty_set(); /* print the results */ put_clear(); putln("mode (initial, set, reset)"); for (j = 0; j < modes_found; j++) { mode_display(puc[mode_puc[j]], mode_number[j], current_value[j], set_value[j], reset_value[j]); } ptext("\n\nHit 'R' to repeat test. 'S' to sort results: "); i = wait_here(); if (i == 's' || i == 'S') { /* print the same stuff, sorted by current_value */ put_crlf(); for (i = '1'; i <= '4'; i++) { for (j = 0; j < modes_found; j++) { if (current_value[j] == i) mode_display(puc[mode_puc[j]], mode_number[j], current_value[j], set_value[j], reset_value[j]); } } ptext("\n\nHit 'R' to repeat test: "); i = wait_here(); } if (i != 'r' && i != 'R') break; tty_raw(1, char_mask); } } else { tty_set(); }}/*** ansi_report_help()**** Display the informational data for the ANSI report test.*/static voidansi_report_help(void){ ptext("Begin ANSI status report testing. "); ptext(" Parity bit set will be displayed in reverse video. "); ptext(" If the terminal hangs, hit any alphabetic key. "); ptextln(" Use n to continue testing. Use q to quit."); put_crlf();}/*** test_ansi_reports()**** Test the ANSI status report functions*/voidtools_status( struct test_list *t GCC_UNUSED, int *state GCC_UNUSED, int *ch){ int i; put_clear(); ansi_report_help(); tty_raw(1, char_mask); do { i = read_reports(); if (i != 'r' && i != 'R') { *ch = i; return; } } while (i); if (terminal_class >= 63) { do { i = request_cfss(); } while (i == 'r' || i == 'R'); *ch = i; terminal_state(); } else { tty_set(); }}/*** display_sgr()**** Test a range of ANSI sgr attributes** puc -> Private Use Character*/static void display_sgr(int puc){ int k; temp[0] = puc; temp[1] = '\0'; for (k = 0; k < 80; k++) { if (char_count + 8 > 80) put_crlf(); else if (char_count + 8 > columns) put_crlf(); else if (k > 0) printf(" "); printf("\033[%s%dmMode %2d\033[0m", temp, k, k); char_count += 8; if (puc == '\0') { if (k == 19) printf("\033[10m"); if (k == 39) printf("\033[37m"); if (k == 49) printf("\033[40m"); } } put_crlf(); if (puc == '<') printf("\033[<1m"); else if (puc) printf("\033[%s0m", temp); set_attr(0);}/*** print_sgr20(on, off)**** print the sgr line for sgr20()*/static void print_sgr20(int on, int off){ if (char_count > columns - 13) { put_crlf(); } else if (char_count) { put_str(" "); } char_count += 11; printf("%d/%d \033[%dmon\033[%dm off\033[0m", on, off, on, off);}/*** sgr20(void)**** display the enter/exit attributes 1-9 and 20-29*/static void sgr20(void){ int k; put_crlf(); ptextln("Test enter/exit attributes 1-9 and 21-29."); for (k = 1; k < 10; k++) { print_sgr20(k, k + 20); } print_sgr20(1, 22); /* bold */ print_sgr20(2, 22); /* dim */ print_sgr20(8, 22); /* blank */ printf("\033[0m"); set_attr(0);}/*** tools_sgr(testlist, state, ch)**** Run the ANSI graphics rendition mode tool** Return the last character typed.*/voidtools_sgr( struct test_list *t GCC_UNUSED, int *state GCC_UNUSED, int *ch){ int k; put_clear(); for (k = 0;;) { display_sgr(k); put_crlf(); menu_prompt(); ptext("/sgr Enter =><?r [<cr>] > "); k = wait_here(); if ((k == 'r') || (k == 'R')) { k = 0; } else if ((k < '<') || (k > '?')) { break; } } sgr20(); put_newlines(2); *ch = REQUEST_PROMPT;}/***************************************************************************** * * Test ANSI graphics * *****************************************************************************//*** select_bank(bank)**** select a graphics character set for ANSI terminals*/static voidselect_bank(char *bank){ tc_putp(bank); switch (bank[1] & 3) { case 0: putchp('O' & 0x1f); /* control O */ break; case 1: putchp('N' & 0x1f); /* control N */ tc_putp("\033~"); break; case 2: tc_putp("\033n\033}"); break; case 3: tc_putp("\033o\033|"); break; }}/*** show_characters(bank, bias)**** print the ANSI graphics characters*/static voidshow_characters(char *bank, int bias){ int i; sprintf(temp, "G%d GL ", bank[1] & 3); ptext(temp); select_bank(bank); for (i = ' '; i < 0x80; i++) { if (char_count >= columns || (i != ' ' && (i & 31) == 0)) put_str("\n "); putchp(i + bias); } select_bank(default_bank); put_str(" DEL <"); select_bank(bank); putchp(0x7f + bias); select_bank(default_bank); putchp('>'); put_crlf(); put_crlf();}/* ANSI graphics test 94 96 character sets G0 ( , G1 ) - G2 * . G3 + /Standard Definitions A UK B US ASCIIDec extended definitions 0 Special graphics *//*** tools_charset(testlist, state, ch)**** Run the ANSI alt-charset mode tool*/voidtools_charset( struct test_list *t GCC_UNUSED, int *state GCC_UNUSED, int *chp GCC_UNUSED){ int j, ch; char bank[32]; put_clear(); ptext("Enter the bank ()*+,-./ followed by the character set"); ptext(" 0123456789:;<=>? for private use, and"); ptextln(" @A...Z[\\]^_`a...z{|}~ for standard sets."); strcpy(bank, "\033)0"); for (; bank[0];) { put_crlf(); show_characters(bank, 0); /* G0 will not print in GR */ if (bank[1] & 3) { show_characters(bank, 0x80); } ptext("bank+set> "); for (j = 1; (ch = getchp(char_mask)); j++) { if (ch == EOF) break; putchp(ch); if (j == 1 && ch > '/') j++; bank[j] = ch; if (ch < ' ' || ch > '/') break; if (j + 1 >= (int) sizeof(bank)) break; } if (j == 1) break; if (bank[j] < '0' || bank[j] > '~') break; bank[j + 1] = '\0'; } put_crlf();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -