| File src/ui/escape.c changed (mode: 100644) (index bc257bc01..5b28db9c3) |
| ... |
... |
esc_state_process_attr(esc_state *state, int n) |
| 476 |
476 |
state->mode = (n == 5) ? ESM_WAIT_BG_COLOR : ESM_SHORT; |
state->mode = (n == 5) ? ESM_WAIT_BG_COLOR : ESM_SHORT; |
| 477 |
477 |
break; |
break; |
| 478 |
478 |
case ESM_WAIT_FG_COLOR: |
case ESM_WAIT_FG_COLOR: |
| 479 |
|
if(n < COLORS) |
|
|
479 |
|
if(n < state->max_colors) |
| 480 |
480 |
{ |
{ |
| 481 |
481 |
state->fg = n; |
state->fg = n; |
| 482 |
482 |
} |
} |
| 483 |
483 |
state->mode = ESM_SHORT; |
state->mode = ESM_SHORT; |
| 484 |
484 |
break; |
break; |
| 485 |
485 |
case ESM_WAIT_BG_COLOR: |
case ESM_WAIT_BG_COLOR: |
| 486 |
|
if(n < COLORS) |
|
|
486 |
|
if(n < state->max_colors) |
| 487 |
487 |
{ |
{ |
| 488 |
488 |
state->bg = n; |
state->bg = n; |
| 489 |
489 |
} |
} |
| |
| ... |
... |
esc_state_set_attr(esc_state *state, int n) |
| 560 |
560 |
} |
} |
| 561 |
561 |
|
|
| 562 |
562 |
void |
void |
| 563 |
|
esc_state_init(esc_state *state, const col_attr_t *defaults) |
|
|
563 |
|
esc_state_init(esc_state *state, const col_attr_t *defaults, int max_colors) |
| 564 |
564 |
{ |
{ |
| 565 |
565 |
state->mode = ESM_SHORT; |
state->mode = ESM_SHORT; |
| 566 |
566 |
state->attrs = defaults->attr; |
state->attrs = defaults->attr; |
| 567 |
567 |
state->fg = defaults->fg; |
state->fg = defaults->fg; |
| 568 |
568 |
state->bg = defaults->bg; |
state->bg = defaults->bg; |
| 569 |
569 |
state->defaults = *defaults; |
state->defaults = *defaults; |
|
570 |
|
state->max_colors = max_colors; |
| 570 |
571 |
} |
} |
| 571 |
572 |
|
|
| 572 |
573 |
/* Converts the leading character of the str string to a printable string. Puts |
/* Converts the leading character of the str string to a printable string. Puts |
| File src/ui/escape.h changed (mode: 100644) (index d6d55d357..6038984c2) |
| ... |
... |
typedef struct |
| 49 |
49 |
int bg; /* Current background color. */ |
int bg; /* Current background color. */ |
| 50 |
50 |
|
|
| 51 |
51 |
col_attr_t defaults; /* Default values of other fields. */ |
col_attr_t defaults; /* Default values of other fields. */ |
|
52 |
|
int max_colors; /* Limit on number of colors. */ |
| 52 |
53 |
} |
} |
| 53 |
54 |
esc_state; |
esc_state; |
| 54 |
55 |
|
|
| |
| ... |
... |
char * esc_highlight_pattern(const char line[], const regex_t *re); |
| 73 |
74 |
int esc_print_line(const char line[], WINDOW *win, int col, int row, |
int esc_print_line(const char line[], WINDOW *win, int col, int row, |
| 74 |
75 |
int max_width, int dry_run, esc_state *state, int *printed); |
int max_width, int dry_run, esc_state *state, int *printed); |
| 75 |
76 |
|
|
| 76 |
|
/* Initializes escape sequence parsing state with values from the defaults. */ |
|
| 77 |
|
void esc_state_init(esc_state *state, const col_attr_t *defaults); |
|
|
77 |
|
/* Initializes escape sequence parsing state with values from the defaults and |
|
78 |
|
* limit on number of colors. */ |
|
79 |
|
void esc_state_init(esc_state *state, const col_attr_t *defaults, |
|
80 |
|
int max_colors); |
| 78 |
81 |
|
|
| 79 |
82 |
TSTATIC_DEFS( |
TSTATIC_DEFS( |
| 80 |
83 |
void esc_state_update(esc_state *state, const char str[]); |
void esc_state_update(esc_state *state, const char str[]); |
| File src/ui/quickview.c changed (mode: 100644) (index 200c0fe83..f73d65a80) |
| ... |
... |
view_stream(FILE *fp, int wrapped) |
| 547 |
547 |
const char *res; |
const char *res; |
| 548 |
548 |
esc_state state; |
esc_state state; |
| 549 |
549 |
|
|
| 550 |
|
esc_state_init(&state, &cs->color[WIN_COLOR]); |
|
|
550 |
|
esc_state_init(&state, &cs->color[WIN_COLOR], COLORS); |
| 551 |
551 |
|
|
| 552 |
552 |
skip_bom(fp); |
skip_bom(fp); |
| 553 |
553 |
res = get_line(fp, line, sizeof(line)); |
res = get_line(fp, line, sizeof(line)); |
| File tests/misc/esc_state_update.c changed (mode: 100644) (index 47a8029c3..73a6ed8c6) |
| 1 |
1 |
#include <stic.h> |
#include <stic.h> |
| 2 |
2 |
|
|
| 3 |
|
#include <curses.h> /* COLORS */ |
|
| 4 |
|
|
|
| 5 |
3 |
#include "../../src/cfg/config.h" |
#include "../../src/cfg/config.h" |
| 6 |
4 |
#include "../../src/ui/escape.h" |
#include "../../src/ui/escape.h" |
| 7 |
5 |
#include "../../src/utils/utils.h" |
#include "../../src/utils/utils.h" |
| |
| ... |
... |
static esc_state state; |
| 13 |
11 |
SETUP() |
SETUP() |
| 14 |
12 |
{ |
{ |
| 15 |
13 |
col_attr_t def_color = { .fg = 1, .bg = 2, .attr = 0 }; |
col_attr_t def_color = { .fg = 1, .bg = 2, .attr = 0 }; |
| 16 |
|
esc_state_init(&state, &def_color); |
|
|
14 |
|
esc_state_init(&state, &def_color, 16); |
| 17 |
15 |
} |
} |
| 18 |
16 |
|
|
| 19 |
17 |
TEST(color_palette_256_is_supported) |
TEST(color_palette_256_is_supported) |
| 20 |
18 |
{ |
{ |
| 21 |
|
int colors = COLORS; |
|
| 22 |
|
COLORS = 256; |
|
|
19 |
|
col_attr_t def_color = { .fg = 1, .bg = 2, .attr = 0 }; |
|
20 |
|
esc_state_init(&state, &def_color, 256); |
| 23 |
21 |
|
|
| 24 |
22 |
esc_state_update(&state, "\033[38;5;123m"); |
esc_state_update(&state, "\033[38;5;123m"); |
| 25 |
23 |
assert_int_equal(123, state.fg); |
assert_int_equal(123, state.fg); |
| 26 |
24 |
|
|
| 27 |
25 |
esc_state_update(&state, "\033[48;5;213m"); |
esc_state_update(&state, "\033[48;5;213m"); |
| 28 |
26 |
assert_int_equal(213, state.bg); |
assert_int_equal(213, state.bg); |
| 29 |
|
|
|
| 30 |
|
COLORS = colors; |
|
| 31 |
27 |
} |
} |
| 32 |
28 |
|
|
| 33 |
29 |
TEST(resetting_things_work) |
TEST(resetting_things_work) |