Skip to content

Commit

Permalink
actually support wide character display!
Browse files Browse the repository at this point in the history
this hack is taken from the termbox-go examples
  • Loading branch information
laochailan committed May 1, 2018
1 parent f180bf6 commit e62d0e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion mailbuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os/exec"
"strings"

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

Expand Down Expand Up @@ -96,7 +97,11 @@ func formatPlain(buf []termbox.Cell, y, w int, text string) ([]termbox.Cell, int
}

buf[y*w+x] = termbox.Cell{ch, fg, 0}
x++
runeWidth := runewidth.RuneWidth(ch)
if runeWidth == 0 || (runeWidth == 2 && runewidth.IsAmbiguousWidth(ch)) {
runeWidth = 1
}
x+=runeWidth
}

for ; x < w; x++ {
Expand Down
7 changes: 6 additions & 1 deletion uiutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"time"

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

Expand Down Expand Up @@ -38,7 +39,11 @@ func printLine(x, y int, text string, fg, bg int) {
if bg >= 0 {
cbuf[y*w+x+i].Bg = termbox.Attribute(bg)
}
i++
runeWidth := runewidth.RuneWidth(c)
if runeWidth == 0 || (runeWidth == 2 && runewidth.IsAmbiguousWidth(c)) {
runeWidth = 1
}
i += runeWidth
}
}

Expand Down

0 comments on commit e62d0e0

Please sign in to comment.