[unicode] do not clobber wide chars when applying attributes

Attempt to address #414
This commit is contained in:
Timothy Stack 2017-08-01 10:17:30 -07:00
parent 2e095fb03e
commit 753e12d606
4 changed files with 46 additions and 6 deletions

View File

@ -148,6 +148,8 @@ case "$host_os" in
;;
esac
AC_DEFINE([_XOPEN_SOURCE_EXTENDED], [1], [Wide character support for ncurses])
AS_VAR_SET(ALL_LDFLAGS, "$SQLITE3_LDFLAGS $READLINE_LDFLAGS $LDFLAGS")
AS_VAR_SET(static_lib_list,

View File

@ -377,18 +377,18 @@ void view_curses::mvwattrline(WINDOW *window,
if (attrs != 0) {
int x_pos = x + attr_range.lr_start;
int ch_width = min(awidth, (line_width - attr_range.lr_start));
chtype row_ch[ch_width + 1];
cchar_t row_ch[ch_width + 1];
mvwinchnstr(window, y, x_pos, row_ch, ch_width);
mvwin_wchnstr(window, y, x_pos, row_ch, ch_width);
for (int lpc = 0; lpc < ch_width; lpc++) {
if (color_pair > 0) {
row_ch[lpc] &= ~A_COLOR;
row_ch[lpc] |= (attrs & ~A_COLOR) | COLOR_PAIR(color_pair);
row_ch[lpc].attr = attrs & ~A_COLOR;
row_ch[lpc].ext_color = color_pair;
} else {
row_ch[lpc] |= (attrs);
row_ch[lpc].attr = attrs;
}
}
mvwaddchnstr(window, y, x_pos, row_ch, ch_width);
mvwadd_wchnstr(window, y, x_pos, row_ch, ch_width);
}
for (range_iter = iter;
range_iter != sa.end() && range_iter->sa_range == iter->sa_range;

View File

@ -46,6 +46,7 @@ check_PROGRAMS = \
test_json_ptr \
test_line_buffer2 \
test_log_accel \
test_ncurses_unicode \
test_pcrepp \
test_reltime \
test_top_status \
@ -127,6 +128,8 @@ test_json_ptr_LDADD = ../src/libdiag.a
test_reltime_SOURCES = test_reltime.cc
test_reltime_LDADD = ../src/libdiag.a
test_ncurses_unicode_SOURCES = test_ncurses_unicode.cc
lnav_doctests_SOURCES = lnav_doctests.cc
lnav_doctests_LDADD = ../src/libdiag.a

View File

@ -0,0 +1,35 @@
#include "config.h"
#define _XOPEN_SOURCE_EXTENDED 1
#include <locale.h>
#if defined HAVE_NCURSESW_CURSES_H
# include <ncursesw/curses.h>
#elif defined HAVE_NCURSESW_H
# include <ncursesw.h>
#elif defined HAVE_NCURSES_CURSES_H
# include <ncurses/curses.h>
#elif defined HAVE_NCURSES_H
# include <ncurses.h>
#elif defined HAVE_CURSES_H
# include <curses.h>
#else
# error "SysV or X/Open-compatible Curses header file required"
#endif
int main(int argc, char *argv[])
{
setlocale(LC_ALL, "");
WINDOW *stdscr = initscr();
cbreak();
char buf[1024];
FILE *file = fopen(argv[1], "r");
int row = 0;
while (!feof(file)) {
fgets(buf, sizeof(buf), file);
mvwaddstr(stdscr, row++, 0, buf);
}
getch();
endwin();
}