xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
Commit dccffdfe199e3e8189a546eee647de818824092b

Don't attempt to set COLORS in tests
At least on Cygwin64 it doesn't work.
Author: xaizek
Author date (UTC): 2018-11-06 13:20
Committer name: xaizek
Committer date (UTC): 2018-11-06 13:20
Parent(s): 48794f3859e3d42d68b588b66e919068fa0e4002
Signing key: 99DC5E4DB05F6BE2
Tree: 32847209d6485583f101ccdf37a2b84d55e8069f
File Lines added Lines deleted
src/modes/view.c 1 1
src/ui/escape.c 4 3
src/ui/escape.h 5 2
src/ui/quickview.c 1 1
tests/misc/esc_state_update.c 3 7
File src/modes/view.c changed (mode: 100644) (index 25da7be4a..b950991c5)
... ... draw(void)
635 635 return; return;
636 636 } }
637 637
638 esc_state_init(&state, &cs->color[WIN_COLOR]);
638 esc_state_init(&state, &cs->color[WIN_COLOR], COLORS);
639 639
640 640 ui_view_erase(vi->view); ui_view_erase(vi->view);
641 641
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)
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master