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 188a50aba7160c4a67810e8fcef508b545f3db68

Fix statusline hi being broken by wide characters
Author: xaizek
Author date (UTC): 2018-11-09 17:36
Committer name: xaizek
Committer date (UTC): 2018-11-09 17:36
Parent(s): d4aedcb38a5c65b89ad9a9a3905df789d9ce8fcd
Signing key: 99DC5E4DB05F6BE2
Tree: 2d327e0e2cf66957dcb3ef92bcfd2823a1eeed5b
File Lines added Lines deleted
ChangeLog 2 0
src/ui/statusline.c 3 3
tests/misc/expand_status_line_macros.c 10 0
File ChangeLog changed (mode: 100644) (index 04c97ed87..4dd1d911b)
20 20 Fixed crash on previewing contents of directory without execute right in Fixed crash on previewing contents of directory without execute right in
21 21 miller view. Thanks to filterfalse. miller view. Thanks to filterfalse.
22 22
23 Fixed statusline highlighting being broken by wide characters.
24
23 25 0.9.1 to 0.10-beta (2018-10-28) 0.9.1 to 0.10-beta (2018-10-28)
24 26
25 27 Added support for arbitrary expressions in 'statusline': '%{...}', Added support for arbitrary expressions in 'statusline': '%{...}',
File src/ui/statusline.c changed (mode: 100644) (index fdf7e194b..0fe3de0c8)
... ... ui_stat_update(view_t *view, int lazy_redraw)
120 120 checked_wmove(stat_win, 0, 0); checked_wmove(stat_win, 0, 0);
121 121
122 122 LineWithAttrs result = expand_status_line_macros(view, cfg.status_line); LineWithAttrs result = expand_status_line_macros(view, cfg.status_line);
123 assert(strlen(result.attrs) == utf8_nstrlen(result.line) && "Broken attrs!");
123 assert(strlen(result.attrs) == utf8_strsw(result.line) && "Broken attrs!");
124 124 result.line = break_in_two(result.line, width, "%="); result.line = break_in_two(result.line, width, "%=");
125 125 result.attrs = break_in_two(result.attrs, width, "="); result.attrs = break_in_two(result.attrs, width, "=");
126 126 print_with_attrs(stat_win, result.line, result.attrs, default_attr); print_with_attrs(stat_win, result.line, result.attrs, default_attr);
 
... ... print_with_attrs(WINDOW *win, const char line[], const char attrs[],
157 157 wprinta(win, char_buf, attr); wprinta(win, char_buf, attr);
158 158
159 159 line += len; line += len;
160 ++attrs;
160 attrs += utf8_chrsw(char_buf);
161 161 } }
162 162 } }
163 163
 
... ... parse_view_macros(view_t *view, const char **format, const char macros[],
578 578 static int static int
579 579 sync_attrs(LineWithAttrs *result, int extra_width) sync_attrs(LineWithAttrs *result, int extra_width)
580 580 { {
581 const size_t nchars = utf8_nstrlen(result->line) + extra_width;
581 const size_t nchars = utf8_strsw(result->line) + extra_width;
582 582 if(result->attrs_len < nchars) if(result->attrs_len < nchars)
583 583 { {
584 584 char *const new_attrs = format_str("%s%*s", result->attrs, char *const new_attrs = format_str("%s%*s", result->attrs,
File tests/misc/expand_status_line_macros.c changed (mode: 100644) (index 221d66954..dc68ab9be)
12 12 #include "../../src/utils/str.h" #include "../../src/utils/str.h"
13 13 #include "../../src/status.h" #include "../../src/status.h"
14 14
15 #include "utils.h"
16
15 17 /* Checks that expanded string isn't equal to format string. */ /* Checks that expanded string isn't equal to format string. */
16 18 #define ASSERT_EXPANDED(format) \ #define ASSERT_EXPANDED(format) \
17 19 do \ do \
 
53 55 SETUP_ONCE() SETUP_ONCE()
54 56 { {
55 57 init_parser(&env_get); init_parser(&env_get);
58 try_enable_utf8_locale();
56 59 } }
57 60
58 61 SETUP() SETUP()
 
... ... TEST(non_empty_optional_preserves_attrs)
335 338 "2 "); "2 ");
336 339 } }
337 340
341 TEST(wide_characters_do_not_break_highlighting, IF(utf8_locale))
342 {
343 ASSERT_EXPANDED_TO_WITH_HI("%1*螺丝 %= 螺%2*丝",
344 "螺丝 %= 螺丝",
345 "1 = 2 ");
346 }
347
338 348 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */ /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
339 349 /* vim: set cinoptions+=t0 filetype=c : */ /* vim: set cinoptions+=t0 filetype=c : */
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