Comments (8)
work on winxp,and ssh on ubuntu.
package main
import (
"github.com/nsf/termbox-go"
)
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
}
func main() {
err := termbox.Init()
if err != nil {
panic(err)
}
defer termbox.Close()
//cn := []rune{'你', '好', ',', '世', '界', '!'}
cn := "你好, 世界!"
en := []rune{'a', 'b', 'c', 'd', 'e', 'f'}
x := 0
for _, v := range cn {
termbox.SetCell(x, 0, v, termbox.ColorBlack, termbox.ColorWhite)
x += rune_width(v)
}
for i := range en {
termbox.SetCell(i, 1, en[i], termbox.ColorRed, termbox.ColorWhite)
}
termbox.Flush()
termbox.PollEvent()
}
from termbox-go.
The problem is that with termbox it has no control over the terminal which in turn draws runes. It's possible to make a termbox implementation which will be drawing runes by itself, but it was never done so far, at the moment I have only a terminal-based backend. So, termbox simply assumes that each rune takes exactly one terminal cell and I know this assumption is false for some CJK rune cases. But I will need to read more about it, when and why terminals draw double-width runes. Will think what can I do about this.
from termbox-go.
Here's what I think. Even though it's possible to hack termbox so that it understands that CJK runes take 2 termbox cells, this approach isn't portable (on windows probably it doesn't work like that) and every termbox-based application should be aware of that fact too and handle the stuff in a special manner. So, I don't think I will do anything about it. If you want CJK support, hack termbox to suit your needs (it's a very simple library after all).
Honestly I just don't know how to make it work using current termbox abstractions. Termbox was designed around a notion of "cells" and this thing breaks it really hard. Perhaps there are terminals which render CJK runes with width == 1, but not sure how readable is that.
from termbox-go.
Thanks for getting back to it. Sure I'll try hacking it and send a pull request or something if I work out.
I don't think terminals that render CJK with width == 1 would be readable at all...
from termbox-go.
See also: #21
Should work now on linux/darwin. You can install https://github.com/nsf/godit to test it out.
from termbox-go.
Looks like it's working now. Just tested on OS X with iTerm2. Thanks!
from termbox-go.
I have to say the real output sequence is somthing like '\033[1;1H你\033[1;3H好\033[1;5H世\033[1;7H界' which inlcudes unnecessary CSI code. Anyway it is better than nothing.
from termbox-go.
I recommend to use go-runewidth
from termbox-go.
Related Issues (20)
- device not configured HOT 5
- tmux-256color $TERM unsupported
- panic: The handle is invalid. HOT 1
- Keybindings not working on FreeBSD HOT 2
- Wine panics ("Invalid handle")
- build failure on gnu/hurd HOT 3
- Understanding character codes / sequences HOT 3
- Copy-pastable line wrap HOT 2
- Version tagging HOT 1
- Panic on FreeBSD host HOT 5
- ShowCursor Function
- Save current history/screen in plain text HOT 4
- Why output is ahead of my command rather than after?
- can it support emoji HOT 1
- Chinese characters support issue HOT 1
- KeyEnter and KeyCtrlM map to the same Hex value HOT 1
- Chinese character width occupation problem HOT 3
- how to use with custom pty example ssh
- How do I detect a double-click mouse event?
- Add support for SetOutputMode other than OutputNormal for Windows Terminal
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from termbox-go.