mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 21:35:54 +03:00
[GH-ISSUE #101] missing character in thai #81
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#81
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @prasertwi on GitHub (Apr 17, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/101
i test textview code from wiki but can't display correct thai character

and then i test with tcell code is correct
how to coding for solve problem ? Please suggestion for me
thank you .
tview code
`package main
import (
"fmt"
"strconv"
"strings"
"time"
)
const corporate =
เป็นมนุษย์ สุดประเสริฐ เลิศคุณค่า กว่าบรรดา ฝูงสัตว์ เดรัจฉาน จงฝ่าฟัน พัฒนา วิชาการ อย่าล้างผลาญ ฤๅเข่นฆ่า บีฑาใคร ไม่ถือโทษ โกรธแช่งซัด ฮึดฮัดด่า หัดอภัยเหมือน กีฬา อัชฌาสัย ปฏิบัติ ประพฤติกฎ กำหนดใจ พูดจาให้จ๊ะ ๆ จ๋า ๆ น่าฟังเอยฯfunc main() {
app := tview.NewApplication()
textView := tview.NewTextView().
SetDynamicColors(true).
SetRegions(true).
SetChangedFunc(func() {
app.Draw()
})
numSelections := 0
go func() {
for _, word := range strings.Split(corporate, " ") {
if word == "the" {
word = "[red]the[white]"
}
if word == "to" {
word = fmt.Sprintf(
["%d"]to[""], numSelections)numSelections++
}
fmt.Fprintf(textView, "%s ", word)
time.Sleep(200 * time.Millisecond)
}
}()
textView.SetDoneFunc(func(key tcell.Key) {
currentSelection := textView.GetHighlights()
if key == tcell.KeyEnter {
if len(currentSelection) > 0 {
textView.Highlight()
} else {
textView.Highlight("0").ScrollToHighlight()
}
} else if len(currentSelection) > 0 {
index, _ := strconv.Atoi(currentSelection[0])
if key == tcell.KeyTab {
index = (index + 1) % numSelections
} else if key == tcell.KeyBacktab {
index = (index - 1 + numSelections) % numSelections
} else {
return
}
textView.Highlight(strconv.Itoa(index)).ScrollToHighlight()
}
})
textView.SetBorder(true)
if err := app.SetRoot(textView, true).SetFocus(textView).Run(); err != nil {
panic(err)
}
}
**tcell code**package mainimport (
"fmt"
"os"
)
var row = 0
var style = tcell.StyleDefault
func putln(s tcell.Screen, str string) {
}
func puts(s tcell.Screen, style tcell.Style, x, y int, str string) {
i := 0
var deferred []rune
dwidth := 0
for _, r := range str {
switch runewidth.RuneWidth(r) {
case 0:
if len(deferred) == 0 {
deferred = append(deferred, ' ')
dwidth = 1
}
case 1:
if len(deferred) != 0 {
s.SetContent(x+i, y, deferred[0], deferred[1:], style)
i += dwidth
}
deferred = nil
dwidth = 1
case 2:
if len(deferred) != 0 {
s.SetContent(x+i, y, deferred[0], deferred[1:], style)
i += dwidth
}
deferred = nil
dwidth = 2
}
deferred = append(deferred, r)
}
if len(deferred) != 0 {
s.SetContent(x+i, y, deferred[0], deferred[1:], style)
i += dwidth
}
}
func main() {
}
`
@rivo commented on GitHub (Apr 19, 2018):
For someone who does not read Thai, can you explain what exactly is not correct?
@rivo commented on GitHub (Apr 27, 2018):
I'll reopen when there is more information.
@prasertwi commented on GitHub (Apr 28, 2018):
sorry i'm late.
Example
English = Visitor, (total 6 charector)
Thai = ผู้มาติดต่อ (total 11 charector)
thank rivo.
@rivo commented on GitHub (May 3, 2018):
Thanks a lot for the detailed explanation. Indeed, my handling of combining characters was wrong. I've fixed it just now. Let me know when you still find something that looks wrong.
@prasertwi commented on GitHub (May 5, 2018):
Ok, display correct for thai character.

Thank you for your hard work rivo.
@stephencheng commented on GitHub (May 17, 2018):
hi @rivo, I spotted a bug in this commit, it causes a unrecoverable panic. I spent quite some time to trace to the line of code: on Line of 364 in util.go
Note that I traced every commit for my code until this could be nailed down to this commit.
Some error messages for your information:
@stephencheng commented on GitHub (May 17, 2018):
@rivo submitting a pull request to fix this:
https://github.com/rivo/tview/pull/117/commits/e91e46ac1096a7c0bbdaef67094a6431be9d193b
Thanks
@rivo commented on GitHub (May 18, 2018):
Thanks for spotting this. I committed a fix to this myself. It also affected other parts of the code and the preferred solution in Line 364 was not to wrap it in an extra
ifstatement but simply to swap the partial conditions.I also think that in a pull request, bugfixes should not be mixed with new features or other, unrelated additions to the code. They should be sent in separate PRs.
@stephencheng commented on GitHub (May 19, 2018):
Thanks for fixing the this. Yes, I have no clue how to completely fix the root cause of the problem but just patch it. It did work for me though :)
@rivo commented on GitHub (May 19, 2018):
It's ok. :-) Your code did help me to find out what the problem was.