Created
May 9, 2014 06:53
-
-
Save axgle/e4a4ef7227ab0d2178e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/nsf/termbox-go" | |
) | |
var row int = 0 | |
func echo(str string) { | |
x := 0 | |
for _, v := range str { | |
termbox.SetCell(x, row, v, termbox.ColorBlack, termbox.ColorWhite) | |
x += rune_width(v) | |
} | |
row++ | |
termbox.Flush() | |
} | |
func main() { | |
err := termbox.Init() | |
if err != nil { | |
panic(err) | |
} | |
defer termbox.Close() | |
echo("hello,世界!") | |
echo("this is a second row") | |
termbox.PollEvent() | |
} | |
//rune_width is a private function in termbox_common.go | |
// somewhat close to what wcwidth does, except rune_width doesn't return 0 or | |
// -1, it's always 1 or 2 | |
func rune_width(r rune) int { | |
if r >= 0x1100 && | |
(r <= 0x115f || r == 0x2329 || r == 0x232a || | |
(r >= 0x2e80 && r <= 0xa4cf && r != 0x303f) || | |
(r >= 0xac00 && r <= 0xd7a3) || | |
(r >= 0xf900 && r <= 0xfaff) || | |
(r >= 0xfe30 && r <= 0xfe6f) || | |
(r >= 0xff00 && r <= 0xff60) || | |
(r >= 0xffe0 && r <= 0xffe6) || | |
(r >= 0x20000 && r <= 0x2fffd) || | |
(r >= 0x30000 && r <= 0x3fffd)) { | |
return 2 | |
} | |
return 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment