0

I am writing a messanger, and I need a some textbox, with some advanced features.

I had seen a curses.textpad, but it doesn't suit my needs.

Well, if I type Cyrillic chars, getch() return wrong characters, like Ð¿Ñ Ð²ÐивеÑ

import curses

class inputbox:
    def get():
        win = curses.newwin(3, 35, 4, 4)
        win.keypad(True)
        inp = True
        text = ""

        while inp:
            ch = win.getch()

            if ch == 10:
                text += "\n"
                inp = False
            if ch == 263 or ch == curses.KEY_BACKSPACE:
                text = text[:len(text)-1]
                currpos = win.getyx()
                win.addstr(currpos[0], currpos[1], " ")
                win.move(currpos[0], currpos[1])
            else:
                text += chr(ch)
            win.refresh()

        return text


def main(stdscr):
    curses.echo()
    inp = inputbox()
    text = inputbox.get()

    stdscr.addstr(0, 0, text)
    stdscr.getstr()

if __name__ == "__main__":
    curses.wrapper(main)
lenik
  • 23,228
  • 4
  • 34
  • 43
GENKY
  • 103
  • 8
  • https://stackoverflow.com/questions/56373360/n-curses-within-python-how-to-catch-and-print-non-ascii-character – daxim Nov 15 '19 at 13:19
  • Possible duplicate of [stdscr.getstr() ignore keys, just string](https://stackoverflow.com/questions/58781164/stdscr-getstr-ignore-keys-just-string) – Thomas Dickey Nov 15 '19 at 14:10
  • @ThomasDickey you can provide an example? – GENKY Nov 16 '19 at 15:41
  • @daxim or you can? I can not, i change ```getch``` on ```get_wch()```, and ```text += chr(ch)``` on ```text += ch```, but it does not work! – GENKY Nov 16 '19 at 15:43
  • A [mojibake](https://en.wikipedia.org/wiki/Mojibake) case. `azbuka = 'А Б В Г Д Е Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь Э Ю Я а б в г д е ж з и й к л м н о п р с т у ф х ц ч ш щ ъ ы ь э ю я'; print( azbuka.encode('utf-8').decode('cp1252', 'replace'));` returns `Ð� Б Ð’ Г Д Е Ж З И Й К Л М Ð� О П Р С Т У Ф Ð¥ Ц Ч Ш Щ Ъ Ы Ь Э Ю Я а б в г д е ж з и й к л м н о п Ñ€ Ñ� Ñ‚ у Ñ„ Ñ… ц ч ш щ ÑŠ Ñ‹ ÑŒ Ñ� ÑŽ Ñ�` – JosefZ Jan 23 '21 at 16:37
  • And `print(azbuka.encode('utf-8').decode('cp1252','ignore'))` returns `РБ Ð’ Г Д Е Ж З И Й К Л М РО П Р С Т У Ф Ð¥ Ц Ч Ш Щ Ъ Ы Ь Э Ю Я а б в г д е ж з и й к л м н о п Ñ€ Ñ Ñ‚ у Ñ„ Ñ… ц ч ш щ ÑŠ Ñ‹ ÑŒ Ñ ÑŽ Ñ` – JosefZ Jan 23 '21 at 16:54

0 Answers0