/
win32.py
43 lines (29 loc) · 860 Bytes
/
win32.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import msvcrt
import win_unicode_console
from .. import const
def init_output():
import colorama
win_unicode_console.enable()
colorama.init()
def get_key():
ch = msvcrt.getwch()
if ch in ('\x00', '\xe0'): # arrow or function key prefix?
ch = msvcrt.getwch() # second call returns the actual key code
if ch in const.KEY_MAPPING:
return const.KEY_MAPPING[ch]
if ch == 'H':
return const.KEY_UP
if ch == 'P':
return const.KEY_DOWN
return ch
def open_command(arg):
return 'cmd /c start ' + arg
try:
from pathlib import Path
except ImportError:
from pathlib2 import Path
def _expanduser(self):
return self.__class__(os.path.expanduser(str(self)))
# pathlib's expanduser fails on windows, see http://bugs.python.org/issue19776
Path.expanduser = _expanduser