From 753e12d6062d963364efb7be75ac0cbef8e3e087 Mon Sep 17 00:00:00 2001 From: Timothy Stack Date: Tue, 1 Aug 2017 10:17:30 -0700 Subject: [PATCH] [unicode] do not clobber wide chars when applying attributes Attempt to address #414 --- configure.ac | 2 ++ src/view_curses.cc | 12 ++++++------ test/Makefile.am | 3 +++ test/test_ncurses_unicode.cc | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 test/test_ncurses_unicode.cc diff --git a/configure.ac b/configure.ac index 086004d2..f6a3b1f6 100644 --- a/configure.ac +++ b/configure.ac @@ -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, diff --git a/src/view_curses.cc b/src/view_curses.cc index 40a076a9..4fe9400b 100644 --- a/src/view_curses.cc +++ b/src/view_curses.cc @@ -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; diff --git a/test/Makefile.am b/test/Makefile.am index 227a6850..c610f72d 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -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 diff --git a/test/test_ncurses_unicode.cc b/test/test_ncurses_unicode.cc new file mode 100644 index 00000000..ebe25cff --- /dev/null +++ b/test/test_ncurses_unicode.cc @@ -0,0 +1,35 @@ + +#include "config.h" +#define _XOPEN_SOURCE_EXTENDED 1 +#include + +#if defined HAVE_NCURSESW_CURSES_H +# include +#elif defined HAVE_NCURSESW_H +# include +#elif defined HAVE_NCURSES_CURSES_H +# include +#elif defined HAVE_NCURSES_H +# include +#elif defined HAVE_CURSES_H +# include +#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(); +}