xdebug

next generation of mdebug (work in progress)
git clone http://frotz.net/git/xdebug.git
Log | Files | Refs | README

output.demo.c (2294B)


      1 #include <stdio.h>
      2 #include <string.h>
      3 #include "../termbox.h"
      4 
      5 static const char chars[] = "nnnnnnnnnbbbbbbbbbuuuuuuuuuBBBBBBBBB";
      6 
      7 static const uint16_t all_attrs[] = {
      8 	0,
      9 	TB_BOLD,
     10 	TB_UNDERLINE,
     11 	TB_BOLD | TB_UNDERLINE,
     12 };
     13 
     14 static int next_char(int current) {
     15 	current++;
     16 	if (!chars[current])
     17 		current = 0;
     18 	return current;
     19 }
     20 
     21 static void draw_line(int x, int y, uint16_t bg) {
     22 	int a, c;
     23 	int current_char = 0;
     24 	for (a = 0; a < 4; a++) {
     25 		for (c = TB_DEFAULT; c <= TB_WHITE; c++) {
     26 			uint16_t fg = all_attrs[a] | c;
     27 			tb_change_cell(x, y, chars[current_char], fg, bg);
     28 			current_char = next_char(current_char);
     29 			x++;
     30 		}
     31 	}
     32 }
     33 
     34 static void print_combinations_table(int sx, int sy, const uint16_t *attrs, int attrs_n) {
     35 	int i, c;
     36 	for (i = 0; i < attrs_n; i++) {
     37 		for (c = TB_DEFAULT; c <= TB_WHITE; c++) {
     38 			uint16_t bg = attrs[i] | c;
     39 			draw_line(sx, sy, bg);
     40 			sy++;
     41 		}
     42 	}
     43 }
     44 
     45 static void draw_all() {
     46 	tb_clear();
     47 
     48 	tb_select_output_mode(TB_OUTPUT_NORMAL);
     49 	static const uint16_t col1[] = {0, TB_BOLD};
     50 	static const uint16_t col2[] = {TB_REVERSE};
     51 	print_combinations_table(1, 1, col1, 2);
     52 	print_combinations_table(2 + strlen(chars), 1, col2, 1);
     53 	tb_present();
     54 
     55 	tb_select_output_mode(TB_OUTPUT_GRAYSCALE);
     56 	int c, x, y;
     57 	for (x = 0, y = 23; x < 24; ++x) {
     58 		tb_change_cell(x, y, '@', x, 0);
     59 		tb_change_cell(x+25, y, ' ', 0, x);
     60 	}
     61 	tb_present();
     62 
     63 	tb_select_output_mode(TB_OUTPUT_216);
     64 	y++;
     65 	for (c = 0, x = 0; c < 216; ++c, ++x) {
     66 		if (!(x%24)) {
     67 			x = 0;
     68 			++y;
     69 		}
     70 		tb_change_cell(x, y, '@', c, 0);
     71 		tb_change_cell(x+25, y, ' ', 0, c);
     72 	}
     73 	tb_present();
     74 
     75 	tb_select_output_mode(TB_OUTPUT_256);
     76 	y++;
     77 	for (c = 0, x = 0; c < 256; ++c, ++x) {
     78 		if (!(x%24)) {
     79 			x = 0;
     80 			++y;
     81 		}
     82 		tb_change_cell(x, y, '+', c | ((y & 1) ? TB_UNDERLINE : 0), 0);
     83 		tb_change_cell(x+25, y, ' ', 0, c);
     84 	}
     85 	tb_present();
     86 }
     87 
     88 int main(int argc, char **argv) {
     89 	(void)argc; (void)argv;
     90 	int ret = tb_init();
     91 	if (ret) {
     92 		fprintf(stderr, "tb_init() failed with error code %d\n", ret);
     93 		return 1;
     94 	}
     95 
     96 	draw_all();
     97 
     98 	struct tb_event ev;
     99 	while (tb_poll_event(&ev)) {
    100 		switch (ev.type) {
    101 		case TB_EVENT_KEY:
    102 			switch (ev.key) {
    103 			case TB_KEY_ESC:
    104 				goto done;
    105 				break;
    106 			}
    107 			break;
    108 		case TB_EVENT_RESIZE:
    109 			draw_all();
    110 			break;
    111 		}
    112 	}
    113 done:
    114 	tb_shutdown();
    115 	return 0;
    116 }