diff --git a/plt_linux.go b/plt_linux.go index 6ff50ad..8d0b0f4 100644 --- a/plt_linux.go +++ b/plt_linux.go @@ -7,11 +7,12 @@ package main import ( "bufio" - tm "github.com/nsf/termbox-go" "net" "os" "strconv" "strings" + + tm "github.com/nsf/termbox-go" ) type ethrNetDevInfo struct { diff --git a/plt_windows.go b/plt_windows.go index 3dfa429..179c3d8 100644 --- a/plt_windows.go +++ b/plt_windows.go @@ -6,11 +6,12 @@ package main import ( - tm "github.com/nsf/termbox-go" "net" "strings" "syscall" "unsafe" + + tm "github.com/nsf/termbox-go" ) var kernel32 = syscall.NewLazyDLL("kernel32.dll") diff --git a/serverui.go b/serverui.go index 8204d1d..d767dc1 100644 --- a/serverui.go +++ b/serverui.go @@ -8,11 +8,12 @@ package main import ( "errors" "fmt" - tm "github.com/nsf/termbox-go" "os" "sync" "sync/atomic" "time" + + tm "github.com/nsf/termbox-go" ) type ethrTestResultAggregate struct { diff --git a/ui.go b/ui.go index 27d2fcc..2c38c23 100644 --- a/ui.go +++ b/ui.go @@ -7,9 +7,11 @@ package main import ( "fmt" - tm "github.com/nsf/termbox-go" "math" "time" + + "github.com/mattn/go-runewidth" + tm "github.com/nsf/termbox-go" ) const ( @@ -56,6 +58,12 @@ type table struct { border int } +func init() { + if runewidth.IsEastAsian() { + symbols = []rune{'+', '-', '+', '|', '+', '+', '+', '+', '+', '+', '+', ' ', '░', '▒', '▓', '█', '^', 'v'} + } +} + func (t *table) drawTblRow(ledge, redge, middle, spr rune, fg, bg tm.Attribute) { twidth := t.ccount + 1 for _, w := range t.cwidth { @@ -126,10 +134,14 @@ func printHLineText(x, y int, w int, text string) { for i := 0; i < w; i++ { tm.SetCell(x+i, y, symbols[horizontal], tm.ColorWhite, tm.ColorDefault) } - offset := (w - len(text)) / 2 + offset := (w - runewidth.StringWidth(text)) / 2 textArr := []rune(text) + xoff := 0 for i := 0; i < len(text); i++ { - tm.SetCell(x+offset+i, y, textArr[i], tm.ColorWhite, tm.ColorDefault) + tm.SetCell(x+offset+i+xoff, y, textArr[i], tm.ColorWhite, tm.ColorDefault) + if runewidth.RuneWidth(textArr[i]) == 2 { + xoff++ + } } } @@ -145,19 +157,27 @@ func printText(x, y, w int, text string, fg, bg tm.Attribute) { for i := 0; i < w; i++ { tm.SetCell(x+i, y, ' ', fg, bg) } + xoff := 0 for i := 0; i < len(textArr); i++ { - tm.SetCell(x+i, y, textArr[i], fg, bg) + tm.SetCell(x+i+xoff, y, textArr[i], fg, bg) + if runewidth.RuneWidth(textArr[i]) == 2 { + xoff++ + } } } func printCenterText(x, y, w int, text string, fg, bg tm.Attribute) { - offset := (w - len(text)) / 2 + offset := (w - runewidth.StringWidth(text)) / 2 textArr := []rune(text) for i := 0; i < w; i++ { tm.SetCell(x+i, y, ' ', fg, bg) } + xoff := 0 for i := 0; i < len(textArr); i++ { - tm.SetCell(x+offset+i, y, textArr[i], fg, bg) + tm.SetCell(x+offset+i+xoff, y, textArr[i], fg, bg) + if runewidth.RuneWidth(textArr[i]) == 2 { + xoff++ + } } }