📄 color.c
字号:
put_str(" "); put_str(splat[d].name); put_crlf(); } return palette_full;}static voidncv_display(int m){ /* print the no_color_video (ncv) test line */ putchp('0' + m); putchp(' '); eat_cookie(); set_attr(1 << m); sprintf(temp, "%-11s", alt_modes[m].name); put_str(temp); new_color(COLOR_BLUE, COLOR_BLACK, TRUE); put_str("blue"); new_color(COLOR_BLACK, COLOR_GREEN, TRUE); put_str("green"); new_color(COLOR_WHITE, COLOR_BLACK, TRUE); put_str(alt_modes[m].name); eat_cookie(); set_attr(0); reset_colors(); put_crlf();}static voiddump_colors(void){ /* display the colors in some esthetic pattern */ static int xmap[8] = {0, 3, 4, 7, 1, 2, 5, 6}; int i, j, k, xi, xj, width, p, cs; int found_one; cs = color_step <= 125 ? 125 : color_step; width = (1000 / cs) + 1; for (xi = 0; xi < 16; xi++) { i = (xi & 8) ? xi ^ 15 : xi; R = i * cs; if (R <= 1000) { found_one = FALSE; for (xj = 0; xj < 32; xj++) { j = ((xj & 8) ? xj ^ 15 : xj) & 7; k = xmap[((xi >> 1) & 4) + (xj >> 3)]; G = j * cs; B = k * cs; if (G <= 1000 && B <= 1000) { p = (k * width + j) * width + i; if (set_a_background) { if (p >= max_colors) { continue; } send_color(p, R, G, B); tc_putp(tparm(set_a_background, p)); } else if (set_background) { if (p >= max_colors) { continue; } send_color(p, R, G, B); tc_putp(tparm(set_background, p)); } else { if (p >= max_pairs) { continue; } send_pair(p, R, G, B, R, G, B); tc_putp(tparm(set_color_pair, p)); } found_one = TRUE; putchp(' '); putchp(' '); } } if (found_one) { put_crlf(); } } }}/*** color_check(test_list, status, ch)**** test (colors) and (pairs)*/static voidcolor_check( struct test_list *t, int *state, int *ch){ if (max_colors <= 0 && max_pairs <= 0) { ptext("This is not a color terminal; (colors) and (pairs) are missing. "); *state |= MENU_STOP; } else { sprintf(temp, "This terminal can display %d colors and %d color pairs. (colors) (pairs)", max_colors, max_pairs); ptextln(temp); } generic_done_message(t, state, ch);}/*** color_setf(test_list, status, ch)**** test (setf) (setb) and (scp)*/static voidcolor_setf( struct test_list *t, int *state, int *ch){ int i, j; if (max_colors <= 0 && max_pairs <= 0) { ptext("This is not a color terminal; (colors) and (pairs) are missing. "); generic_done_message(t, state, ch); *state |= MENU_STOP; return; } if ((set_a_foreground == NULL || set_a_background == NULL) && (set_foreground == NULL || set_background == NULL) && set_color_pair == NULL) { ptextln("Both set foreground (setaf/setf) and set color pair (scp) are not present."); if (!set_a_background || !set_background) { ptextln("(setab/setb) set background not present"); } ptext("These must be defined for color testing. "); generic_done_message(t, state, ch); *state |= MENU_STOP; return; } /* initialize the color palette */ pairs_used = max_colors >= 8 ? 8 : max_colors; reset_colors(); new_color(COLOR_WHITE, COLOR_BLACK, FALSE); ptextln("(setf) (setb) (scp) The following colors are predefined:"); ptextln("\n Foreground Background"); put_crlf(); j = max_colors > 8 ? 8 : max_colors; /* * the black on white test is the same as the white on black test. */ for (i = 1; i < j; i++) { putchp('0' + def_colors[i].index); putchp(' '); sprintf(temp, " %s ", def_colors[i].name); new_color(def_colors[i].index, COLOR_BLACK, TRUE); put_str(temp); new_color(COLOR_BLACK, COLOR_BLACK, TRUE); put_str(" "); new_color(COLOR_BLACK, def_colors[i].index, TRUE); put_str(temp); new_color(COLOR_WHITE, COLOR_BLACK, FALSE); put_crlf(); } reset_colors(); put_crlf(); generic_done_message(t, state, ch);}/*** color_matrix(test_list, status, ch)**** test (pairs) (op)*/static voidcolor_matrix( struct test_list *t, int *state, int *ch){ int i, j, matrix_size, matrix_area, brightness; matrix_size = max_colors > 8 ? 8 : max_colors; sprintf(temp, "(pairs) There are %d color pairs.", max_pairs); ptextln(temp); for ( ; matrix_size; matrix_size--) { if (matrix_size * matrix_size <= max_pairs) { break; } } matrix_area = matrix_size * matrix_size; for (brightness = 0; brightness < 2; brightness++) { put_crlf(); sprintf(temp, "%dx%d matrix of foreground/background colors, bright *o%s*", matrix_size, matrix_size, brightness ? "n" : "ff"); put_str(temp); put_str("\n "); for (i = 0; i < matrix_size; i++) { (void) sprintf(temp, "%-8s", def_colors[i].name); put_str(temp); } for (j = 0; j < matrix_area; j++) { if (j % matrix_size == 0) { reset_colors(); put_crlf(); if (brightness) { tc_putp(exit_attribute_mode); } (void) sprintf(temp, "%-8s", def_colors[j / matrix_size].name); put_str(temp); if (brightness) { put_mode(enter_bold_mode); } } new_color(def_colors[j % matrix_size].index, def_colors[j / matrix_size].index, FALSE); put_str(" Hello "); } reset_colors(); if (brightness) { tc_putp(exit_attribute_mode); } put_crlf(); } generic_done_message(t, state, ch);}/*** color_ncv(test_list, status, ch)**** test (ncv)*/static voidcolor_ncv( struct test_list *t, int *state, int *ch){ int i; if (no_color_video == -1) { /* I have no idea what this means */ return; } sprintf(temp, "According to no_color_video (ncv) which is %d, the following attributes should work correctly with color.", no_color_video); ptextln(temp); put_crlf(); set_attr(0); ncv_display(0); for (i = 1; i <= 9; i++) { if (((no_color_video >> (mode_map[i] - 1)) & 1) == 0) { ncv_display(mode_map[i]); } } if (no_color_video & 0x3ff) { ptextln("\nThe following attributes should not work correctly with color. (ncv)\n"); for (i = 1; i <= 9; i++) { if ((no_color_video >> (mode_map[i] - 1)) & 1) { ncv_display(mode_map[i]); } } } reset_colors(); put_crlf(); generic_done_message(t, state, ch);}/*** color_bce(test_list, status, ch)**** test (bce) background color erase*/static voidcolor_bce( struct test_list *t, int *state, int *ch){ new_color(COLOR_CYAN, COLOR_BLUE, FALSE); put_clear(); put_newlines(2); reset_colors(); ptextln("If the two lines above are blue then back_color_erase (bce) should be true."); sprintf(temp, "(bce) is %s in the data base.", back_color_erase ? "true" : "false"); ptextln(temp); generic_done_message(t, state, ch);}/*** color_ccc(test_list, status, ch)**** test (ccc) color palette test (oc) (op) (initc) (initp)*/static voidcolor_ccc( struct test_list *t, int *state, int *ch){ int i, j; if (!can_change) { ptextln("Terminal can not change colors (ccc)"); generic_done_message(t, state, ch); return; } reset_colors(); pairs_used = 0; new_color(COLOR_WHITE, COLOR_BLACK, FALSE); sprintf(temp, "Reloading colors (init%c) using %s method", set_foreground ? 'c' : 'p', hue_lightness_saturation ? "HLS" : "RGB"); ptextln(temp); put_crlf(); j = max_colors > 7 ? 7 : max_colors; /* redisplay the above test with reinitialized colors */ /* If these colors don't look right to you... */ for (i = 0; i < j; i++) { sprintf(temp, " %s ", def_colors[i ^ 7].name); new_color(i ^ 7, COLOR_BLACK, TRUE); put_str(temp); new_color(COLOR_BLACK, COLOR_BLACK, TRUE); put_str(" "); new_color(COLOR_BLACK, i ^ 7, TRUE); put_str(temp); new_color(COLOR_WHITE, COLOR_BLACK, FALSE); put_crlf(); } generic_done_message(t, state, ch); if (*ch != 0 && *ch != 'n') { reset_colors(); return; } pairs_used = 0; cookie_monster = 0; if (magic_cookie_glitch > 0) { cookie_monster = ((set_a_foreground || set_foreground) ? magic_cookie_glitch : 0) + ((set_a_background || set_background) ? magic_cookie_glitch : 0) + (set_color_pair ? magic_cookie_glitch : 0); } set_color_step(); colors_per_line = max_colors > max_pairs ? max_pairs : max_colors; j = (columns - 14) / (cookie_monster + 1); if (colors_per_line > j) { colors_per_line = (j / i) * i; } sprintf(temp, "RGB color step %d, cookies %d", color_step, cookie_monster); ptextln(temp); R = G = B = 0; pairs_used = 0; for (;;) { if (rainbow(colors_per_line)) { break; } } generic_done_message(t, state, ch); if (*ch != 0 && *ch != 'n') { reset_colors(); return; } dump_colors(); reset_colors(); generic_done_message(t, state, ch);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -