From 92e767c2269e7fcdacdd279c67adb83509a8c0fa Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Sat, 17 Aug 2019 22:11:20 +0900 Subject: [PATCH] Fix multibyte-strings On Windows 10, WriteConsoleOutputW break compatibility. When writing three unicode characters, the character is displayed overlayed with 3 cells. So this change insert spaces after the character for unicode characters. --- api_windows.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/api_windows.go b/api_windows.go index 5c1e388..373e6c7 100644 --- a/api_windows.go +++ b/api_windows.go @@ -2,6 +2,8 @@ package termbox import ( "syscall" + + "github.com/mattn/go-runewidth" ) // public API @@ -114,13 +116,23 @@ func Flush() error { update_size_maybe() prepare_diff_messages() for _, diff := range diffbuf { + chars := []char_info{} + for _, char := range diff.chars { + chars = append(chars, char) + if runewidth.RuneWidth(rune(char.char)) > 1 { + chars = append(chars, char_info{ + char: ' ', + attr: char.attr, + }) + } + } r := small_rect{ left: 0, top: diff.pos, right: term_size.x - 1, bottom: diff.pos + diff.lines - 1, } - write_console_output(out, diff.chars, r) + write_console_output(out, chars, r) } if !is_cursor_hidden(cursor_x, cursor_y) { move_cursor(cursor_x, cursor_y)