Skip to content

Commit

Permalink
Fix multibyte-strings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mattn committed Aug 17, 2019
1 parent eeb6cd0 commit 92e767c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion api_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package termbox

import (
"syscall"

"github.com/mattn/go-runewidth"
)

// public API
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 92e767c

Please sign in to comment.