From 402b9c289dec561f03370fd1781eae74a89022c0 Mon Sep 17 00:00:00 2001 From: uobikiemukot Date: Fri, 22 Jun 2012 01:48:31 +0900 Subject: [PATCH] =?UTF-8?q?*=20=E3=81=A1=E3=82=87=E3=81=A3=E3=81=A8?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- misc/256colors.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 misc/256colors.c diff --git a/misc/256colors.c b/misc/256colors.c new file mode 100644 index 0000000..dd423b2 --- /dev/null +++ b/misc/256colors.c @@ -0,0 +1,73 @@ +#include +#include +#include +#include +#include + +enum { + ANSI = 8, + ANSI_BOLD = 16, + COLORCUBE = 232, + MAX_COLOR = 256, +}; + +void fatal(char *message) +{ + fprintf(stderr, "%s\n", message); + exit(EXIT_FAILURE); +} + +void print_color_block(int color) +{ + char *str; + + str = tparm(set_a_background, color); + putp(str); + printf(" "); +} + +int main() +{ + int i, j, k, status, color; + + setupterm(NULL, STDOUT_FILENO, &status); + if (status != 1) + fatal("Error in setupterm"); + + if (set_a_foreground == NULL + || exit_attribute_mode == NULL) + return 1; + + printf("System colors:\n"); + for (i = 0; i < ANSI; i++) + print_color_block(i); + putp(exit_attribute_mode); + printf("\n"); + + for (i = ANSI; i < ANSI_BOLD; i++) + print_color_block(i); + putp(exit_attribute_mode); + printf("\n\n"); + + printf("Color cube, 6x6x6:\n"); + for (i = 0; i < 6; i++) { + for (j = 0; j < 6; j++) { + for (k = 0; k < 6; k++) { + color = 16 + (j * 36) + (i * 6) + k; + print_color_block(color); + } + putp(exit_attribute_mode); + printf(" "); + } + printf("\n"); + } + printf("\n"); + + printf("Grayscale ramp:\n"); + for (i = COLORCUBE; i < MAX_COLOR; i++) + print_color_block(i); + putp(exit_attribute_mode); + printf("\n"); + + return 0; +}