johnnovak / illwill

A curses inspired simple cross-platform console library for Nim
Do What The F*ck You Want To Public License
398 stars 27 forks source link

Problems with russian text. #15

Closed not-lum closed 3 years ago

not-lum commented 4 years ago

Hello. I have a problem with russian text. I just run the example of code from README.md:

import os, strutils
import illwill

# 1. Initialise terminal in fullscreen mode and make sure we restore the state
# of the terminal state when exiting.
proc exitProc() {.noconv.} =
  illwillDeinit()
  showCursor()
  quit(0)

illwillInit(fullscreen=true)
setControlCHook(exitProc)
hideCursor()

# 2. We will construct the next frame to be displayed in this buffer and then
# just instruct the library to display its contents to the actual terminal
# (double buffering is enabled by default; only the differences from the
# previous frame will be actually printed to the terminal).
var tb = newTerminalBuffer(terminalWidth(), terminalHeight())

# 3. Display some simple static UI that doesn't change from frame to frame.
tb.setForegroundColor(fgBlack, true)
tb.drawRect(0, 0, 40, 5)
tb.drawHorizLine(2, 38, 3, doubleStyle=true)

tb.write(2, 1, fgWhite, "Press any key to display its name")
tb.write(2, 2, "Press ", fgYellow, "ESC", fgWhite,
               " or ", fgYellow, "Q", fgWhite, " to quit")

# 4. This is how the main event loop typically looks like: we keep polling for
# user input (keypress events), do something based on the input, modify the
# contents of the terminal buffer (if necessary), and then display the new
# frame.

while true:
  var key = getKey()
  case key
  of Key.None: discard
  of Key.Escape, Key.Q: exitProc()
  else:
    tb.write(8, 4, ' '.repeat(31))
    tb.write(2, 4, resetStyle, "Key pressed: ", fgGreen, $key)

  tb.display()
  sleep(20)

It works fine when I pressing english letters. But when I changed my keyboard layout to russian, my console hunged and wrote this: [process exited with code 1] And I can't do anything! I can't press Ctrl+C to exit from the program. The only way to exit it's to close console. Problem

OS: Windows 10 Console Emulator: Windows Terminal

0xACE commented 4 years ago

I don't have access to a computer atm. Could you share a backtrace? (I'm assuming gdb can dump human readable backtraces for nim)

not-lum commented 4 years ago

@0xACE sorry, I can't, because on Linux(WSL) it works fine and when I press buttons on the russian layout program doesn't do anything. On Windows program hungs when I do the same. And how I know, gdb debugger works only on Linux.

adokitkat commented 3 years ago

@lumison I think gdb works on Windows via MinGW? Correct me if I am wrong but if you have installed Nim on Windows then it would install MinGW64 too (GNU utils for Windows) so gdb should be included. You have to compile the Nim code with debugging on: --d:debug --lineDir:on --debuginfo --debugger:native. Valgrind tool is Linux only.

Chris3606 commented 3 years ago

I ran into a similar issue with non-fullscreen applications, detailed here. I suspect it's the same general issue.

johnnovak commented 3 years ago

It seems like a codepage issue, not really related to illwill.