|
Lines 95-101
Link Here
|
| 95 |
|
95 |
|
| 96 |
char *defcolors = "4x5x2x3x1x464301060203"; |
96 |
char *defcolors = "4x5x2x3x1x464301060203"; |
| 97 |
|
97 |
|
| 98 |
static int colors[C_NUMCOLORS][2]; |
98 |
/* colors for file types */ |
|
|
99 |
static struct { |
| 100 |
int num[2]; |
| 101 |
int bold; |
| 102 |
} colors[C_NUMCOLORS]; |
| 103 |
|
| 99 |
#endif |
104 |
#endif |
| 100 |
|
105 |
|
| 101 |
void |
106 |
void |
|
Lines 383-396
Link Here
|
| 383 |
{ |
388 |
{ |
| 384 |
char *ansiseq; |
389 |
char *ansiseq; |
| 385 |
|
390 |
|
| 386 |
if (colors[c][0] != -1) { |
391 |
if (colors[c].bold) |
| 387 |
ansiseq = tgoto(ansi_fgcol, 0, colors[c][0]); |
392 |
tputs(enter_bold, 1, putch); |
|
|
393 |
|
| 394 |
if (colors[c].num[0] != -1) { |
| 395 |
ansiseq = tgoto(ansi_fgcol, 0, colors[c].num[0]); |
| 388 |
if (ansiseq) |
396 |
if (ansiseq) |
| 389 |
tputs(ansiseq, 1, putch); |
397 |
tputs(ansiseq, 1, putch); |
| 390 |
} |
398 |
} |
| 391 |
|
399 |
|
| 392 |
if (colors[c][1] != -1) { |
400 |
if (colors[c].num[1] != -1) { |
| 393 |
ansiseq = tgoto(ansi_bgcol, 0, colors[c][1]); |
401 |
ansiseq = tgoto(ansi_bgcol, 0, colors[c].num[1]); |
| 394 |
if (ansiseq) |
402 |
if (ansiseq) |
| 395 |
tputs(ansiseq, 1, putch); |
403 |
tputs(ansiseq, 1, putch); |
| 396 |
} |
404 |
} |
|
Lines 401-406
Link Here
|
| 401 |
int sig; |
409 |
int sig; |
| 402 |
{ |
410 |
{ |
| 403 |
tputs(ansi_coloff, 1, sig ? writech : putch); |
411 |
tputs(ansi_coloff, 1, sig ? writech : putch); |
|
|
412 |
tputs(attrs_off, 1, sig ? writech : putch); |
| 404 |
} |
413 |
} |
| 405 |
|
414 |
|
| 406 |
static int |
415 |
static int |
|
Lines 455-460
Link Here
|
| 455 |
if (cs == NULL) cs = ""; /* LSCOLORS not set */ |
464 |
if (cs == NULL) cs = ""; /* LSCOLORS not set */ |
| 456 |
len = strlen(cs); |
465 |
len = strlen(cs); |
| 457 |
for (i = 0 ; i < C_NUMCOLORS ; i++) { |
466 |
for (i = 0 ; i < C_NUMCOLORS ; i++) { |
|
|
467 |
colors[i].bold = 0; |
| 468 |
|
| 458 |
if (len <= 2*i) { |
469 |
if (len <= 2*i) { |
| 459 |
c[0] = defcolors[2*i]; |
470 |
c[0] = defcolors[2*i]; |
| 460 |
c[1] = defcolors[2*i+1]; |
471 |
c[1] = defcolors[2*i+1]; |
|
Lines 464-480
Link Here
|
| 464 |
c[1] = cs[2*i+1]; |
475 |
c[1] = cs[2*i+1]; |
| 465 |
} |
476 |
} |
| 466 |
for (j = 0 ; j < 2 ; j++) { |
477 |
for (j = 0 ; j < 2 ; j++) { |
|
|
478 |
/* shifted 0-7 (!, @, #, etc) do bold */ |
| 467 |
if ((c[j] < '0' || c[j] > '7') && |
479 |
if ((c[j] < '0' || c[j] > '7') && |
| 468 |
tolower((unsigned char)c[j]) != 'x') { |
480 |
tolower((unsigned char)c[j]) != 'x' && |
|
|
481 |
c[j] != ')' && c[j] != '!' && c[j] != '@' && |
| 482 |
c[j] != '#' && c[j] != '$' && c[j] != '%' && |
| 483 |
c[j] != '^' && c[j] != '&') { |
| 469 |
fprintf(stderr, |
484 |
fprintf(stderr, |
| 470 |
"error: invalid character '%c' in LSCOLORS env var\n", |
485 |
"error: invalid character '%c' in LSCOLORS" |
| 471 |
c[j]); |
486 |
" env var\n", c[j]); |
| 472 |
c[j] = defcolors[2*i+j]; |
487 |
c[j] = defcolors[2*i+j]-'0'; |
|
|
488 |
} |
| 489 |
|
| 490 |
if (c[j] >= '0' && c[j] <= '7') |
| 491 |
colors[i].num[j] = c[j]-'0'; |
| 492 |
else if (tolower((unsigned char)c[j] == 'x')) |
| 493 |
colors[i].num[j] = -1; |
| 494 |
else { |
| 495 |
colors[i].bold = 1; |
| 496 |
|
| 497 |
switch (c[j]) { |
| 498 |
case ')': |
| 499 |
colors[i].num[j] = 0; |
| 500 |
break; |
| 501 |
case '!': |
| 502 |
colors[i].num[j] = 1; |
| 503 |
break; |
| 504 |
case '@': |
| 505 |
colors[i].num[j] = 2; |
| 506 |
break; |
| 507 |
case '#': |
| 508 |
colors[i].num[j] = 3; |
| 509 |
break; |
| 510 |
case '$': |
| 511 |
colors[i].num[j] = 4; |
| 512 |
break; |
| 513 |
case '%': |
| 514 |
colors[i].num[j] = 5; |
| 515 |
break; |
| 516 |
case '^': |
| 517 |
colors[i].num[j] = 6; |
| 518 |
break; |
| 519 |
case '&': |
| 520 |
colors[i].num[j] = 7; |
| 521 |
break; |
| 522 |
} |
| 473 |
} |
523 |
} |
| 474 |
if (tolower((unsigned char)c[j]) == 'x') |
|
|
| 475 |
colors[i][j] = -1; |
| 476 |
else |
| 477 |
colors[i][j] = c[j]-'0'; |
| 478 |
} |
524 |
} |
| 479 |
} |
525 |
} |
| 480 |
} |
526 |
} |