Mintty terminal, python, curses and utf8: incorrect display

I asked here , but I’m sure I won’t get an answer.

  • copy - paste this python code:
  • execute it
  • in the classic utf8 shell it works correctly and displays "Coordinates", but in my mintty terminal at home it displays "CoordonnM-CM-) es". Any idea how I can make it work, or where should I look (mintty has no character encoding options)?

the code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os, sys, time, random, copy, pprint
import termios, tty, fcntl
import thread, curses
import locale

def curses_main(stdscr, code):
    curses.curs_set(0)
    stdscr.addstr(2, 0, "Coordonnées")
    stdscr.refresh()
    # (1) = délai d'attente de 1/10 ème de seconde :
    curses.halfdelay(1)
    while True:
        try:
            c=stdscr.getch()
        except:
            c=-1
        if 0<c<256:
            if chr(c) in 'Qq':
                break
def main():
    locale.setlocale(locale.LC_ALL, '')
    code = locale.getpreferredencoding()
    curses.wrapper(curses_main, code)

if __name__ == '__main__':
    main()

Update

Error: I thought I found this: it is written everywhere to start with this code:

locale.setlocale(locale.LC_ALL, '')

so I tried with this and worked:

locale.setlocale(locale.LC_ALL, 'fr_FR')

=> forced in french

... he worked, but only for emphasis. If I try to print lines of line drawings:

stdscr.addstr(20,20, "─ │ ┌ ┘ ┐ └ ├ ┤ ┬ ┴ ┼ ═ ║ ╔ ╝ ╗ ╚ ╠ ╣ ╦ ╩ ╬")

gives me:

M-b~T~@ M-b~T~B M-b~T~L M-b~T~X M-...

, , vim . , ... python? Windows/cygwin/mintty, :

env | grep -i lang
LANG=C.UTF-8

Windows/cygwin/mintty, :

locale.setlocale(locale.LC_ALL, 'C.UTF-8')

.

, ? python, , ... , , vim. , , , ...

+3
2

. : cygwin, python , , minnty 0.9.5.1 (mintty-0.9.5-cygwin17.zip), . .

0

, tty- .

, sys.stdin.encoding sys.stdout.encoding, .

, mintty - UTF8, ( ) cp1252.

0

Source: https://habr.com/ru/post/1787411/


All Articles