Skip to content

Commit a569df6

Browse files
committed
Further text-mode console client enhancements
- cleanup of color handling in both curses clients - v3_cons_tc cleanup for function key, etc, handling - v3_console selects the better of _tc and _sc depending on which have been built in the instalation
1 parent f4b69a7 commit a569df6

File tree

3 files changed

+208
-121
lines changed

3 files changed

+208
-121
lines changed

linux_usr/v3_cons_sc.c

+60-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121

2222
#include "v3_ctrl.h"
2323

24+
static int in_color = 0;
25+
static int color8 = 0;
26+
#define TRANS_STYLE(x) ( !color8 ? (x) : ((x)&0x7)|(((x)&0x70)>>1))
27+
2428
static int use_curses = 0;
2529
static int debug_enable = 0;
2630

@@ -117,9 +121,9 @@ static int handle_char_set(struct character_msg * msg) {
117121
return -1;
118122
}
119123

120-
wattron(console.win, COLOR_PAIR(msg->style));
124+
if (in_color) {wattron(console.win, COLOR_PAIR(TRANS_STYLE(msg->style)));}
121125
mvwaddch(console.win, msg->y, msg->x, c);
122-
wattroff(console.win, COLOR_PAIR(msg->style));
126+
if (in_color) {wattroff(console.win, COLOR_PAIR(TRANS_STYLE(msg->style)));}
123127

124128
} else {
125129
//stdout text display
@@ -403,10 +407,59 @@ int check_terminal_size (void)
403407
static void
404408
init_colors (void)
405409
{
410+
unsigned short i;
411+
412+
if (!has_colors()) {
413+
fprintf(stderr,"No color support\n");
414+
in_color=0;
415+
color8=0;
416+
return;
417+
}
418+
406419
start_color();
407-
int i;
408-
for (i = 0; i < 0x100; i++) {
409-
init_pair(i, i & 0xf, (i >> 4) & 0xf);
420+
421+
if (can_change_color() && COLORS>=16 && COLOR_PAIRS>=256) {
422+
fprintf(stderr, "Modifyable color support with enough colors available\n");
423+
// initialize first 16 colors to be the PC colors
424+
// then create all the pairings
425+
for (i=0;i<16;i++) {
426+
unsigned short red, green, blue, intens;
427+
// i = IRGB (4 bits)
428+
intens = i>>3 & 0x1;
429+
red = i>>2 & 0x1;
430+
green = i>>1 & 0x1;
431+
blue = i>>0 & 0x1;
432+
init_color(i, 500*(red+intens), 500*(blue+intens), 500*(green+intens));
433+
}
434+
for (i=0;i<256;i++) {
435+
init_pair(i, i & 0xf, (i >> 4) & 0xf);
436+
}
437+
in_color = 1;
438+
color8 = 0;
439+
return;
440+
} else {
441+
if (COLORS!=8 || COLOR_PAIRS<64) {
442+
fprintf(stderr,"Insufficient number of fixed colors (%d) or color pairs (%d)\n",COLORS,COLOR_PAIRS);
443+
in_color = 0;
444+
color8 = 0;
445+
return;
446+
}
447+
// We have only the low-intensity colors available, so
448+
// map just to these
449+
fprintf(stderr,"Only 8 color standard palette available\n");
450+
for (i=0;i<64;i++) {
451+
// VGA color order: black, blue, green, cyan, red, magenta, brown, gray
452+
// curses color order: black, red, green, yellow, blue, magenta, cyan, white
453+
short map[] = { 0, 4, 2, 6, 1, 5, 3, 7 };
454+
unsigned short fg, bg;
455+
// discard intensity bit
456+
bg = (i>>3 & 0x7);
457+
fg = i & 0x7;
458+
init_pair(i, map[fg], map[bg]);
459+
}
460+
in_color = 1;
461+
color8 = 1;
462+
return;
410463
}
411464
}
412465

@@ -468,7 +521,8 @@ int main(int argc, char* argv[]) {
468521
scrollok(console.win, 1);
469522

470523
erase();
471-
init_colors();
524+
init_colors();
525+
//abort();
472526
}
473527

474528
/*

0 commit comments

Comments
 (0)