-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Displaying Multibyte Characters #32
Comments
What platform are you using? On Windows, multibyte character support is problematic in the standard command prompt. It should work a lot better on Linux and MacOS. Internally, illwill uses UTF-8 codepoints for everything, so things should just work. However, I haven't tested it specifically with languages that use multibyte characters heavily. I'm suspecting that what you're experiencing is more like a console limitation. Answering your questions:
|
Thanks for your reply! I using platform Linux(Manjaro). I will post the case together with the case in which the problem occurred. Source Code import illwill
import os
import json
import strformat
import strutils
# ------------------------------------
# Process to prepare content
# ------------------------------------
# Draw the preview screen on the left side of the screen
proc previewArea(tb: var TerminalBuffer, content: string) =
let width = toInt(tb.width / 3)
tb.setForegroundColor(fgYellow)
tb.drawRect(tb.width - width - 1, 0, tb.width-1, tb.height-1)
tb.write(tb.width - width, 1, content)
# Draw the selection menu on the right side of the screen
proc selectArea(tb: var TerminalBuffer, y: int, pos: int, datas: seq[Results]) =
for i, data in datas:
if i == pos:
tb.setForegroundColor(fgBlack, true)
tb.setBackgroundColor(bgGreen)
tb.write(2, y+i+1, data.title)
else:
tb.write(2, y+i+1, data.title)
tb.resetAttributes()
proc exitProc() {.noconv.} =
illwillDeinit()
showCursor()
quit(0)
illwillInit(fullscreen = true)
setControlCHook(exitProc)
hideCursor()
# cursor position
var pos: int
while true:
var tb = newTerminalBuffer(terminalWidth(), terminalHeight())
var key = getKey()
tb.selectArea(0, pos, results)
tb.previewArea(results[pos].content)
case key
of Key.J:
pos = pos + 1
if results.len <= pos:
pos = 0
of Key.K:
pos = pos - 1
if pos < 0:
pos = results.len - 1
continue
of Key.Escape, Key.Q: exitProc()
of Key.Enter:
exitProc()
echo pos
else: discard
tb.display()
sleep(20) |
So judging by your screenshot, I think what's happening is that the Japanese characters physically seem to take up the width of two Latin characters, but they're encoded as multiple UTF-8 code points, most likely not two codepoints, but perhaps more? Like I said, I don't speak Japanese and know very little about the Japanese language, the symbols, and how the symbols are encoded on computers. I just found this page and there seems to be a lot of complexity regarding Japanese encodings: https://www.sljfaq.org/afaq/encodings.html I'm somewhat interested in getting to the bottom of this as it might affect not just Japanese but other non-Latin languages as well. But you'll need to provide a program that I can compile and execute — the above program you posted does not compile; I'm guessing it's a part of a larger program, and it doesn't output any Japanese characters, so it doesn't allow me to reproduce the issue visually on my computer. Please don't assume anything, and provide all the following:
|
The encoding used in the terminal is UTF-8. This is a program that reads a file named test.txt in the current directory and displays it on the right side of the screen and a rectangle that imitates a preview window on the left side of the screen. Also, the screenshot here is a shot of these files opened in Vim. I have not encountered any problems displaying Japanese. Programs import illwill
import os
import strutils
proc loadTxtFile(path: string): seq[string] =
block:
var f : File = open("test.txt" , FileMode.fmRead)
defer :
close(f)
echo "closed"
return f.readAll().split("\n")
#echo f.readLine()
proc drawText(tb: var TerminalBuffer, texts: seq[string]) =
for idx, text in texts:
tb.write(0, terminalHeight()-idx, text)
proc exitProc() {.noconv.} =
illwillDeinit()
showCursor()
quit(0)
illwillInit(fullscreen = true)
setControlCHook(exitProc)
hideCursor()
var pos: int
var texts = loadTxtFile("test.txt")
while true:
var tb = newTerminalBuffer(terminalWidth(), terminalHeight())
var key = getKey()
tb.drawText(texts)
tb.drawRect(terminalWidth() div 2, 0, terminalWidth(), terminalHeight())
case key
of Key.Escape, Key.Q: exitProc()
of Key.Enter:
exitProc()
echo pos
else: discard
tb.display()
sleep(20) Text file used for loading. (Save the file as test.txt.)
|
Cheers, I'm busy with other stuff now, I'll have a look at this at some point. |
Try to modify displayFull() in illwill.nim .
|
@forthlee |
The code is referenced from Urwid |
Feel free to raise a PR if you think Japanese/Asian languages can be supported unobtrusively. |
thanks! |
I will consider sending PR when I have reached some degree. |
Sure thing. Good luck! 😎 |
Hello! I am creating a TUI application that displays Japanese using illwill.
However, I am having a problem with displaying Japanese characters with illwill, and I am wondering what to do about it.
I would appreciate it if you could tell me about the above two questions.
Thank you!
The text was updated successfully, but these errors were encountered: