File tree Expand file tree Collapse file tree 7 files changed +61
-17
lines changed Expand file tree Collapse file tree 7 files changed +61
-17
lines changed Original file line number Diff line number Diff line change 1
- sudo : false
1
+ os : linux
2
+ dist : focal
2
3
cache : pip
3
4
language : python
4
5
5
- matrix :
6
+ jobs :
6
7
include :
8
+ - python : 3.8
7
9
- python : 3.7
8
- dist : xenial
9
- sudo : required
10
10
- python : 3.6
11
11
12
12
install :
13
- - pip install . pytest coverage codecov flake8 mypy
14
- - pip install isort black
13
+ - pip install . black coverage codecov flake8 isort mypy pytest
15
14
- pip list
16
15
17
16
script :
@@ -24,7 +23,7 @@ script:
24
23
25
24
# Check wheather the imports were sorted correctly.
26
25
# When this fails, please run ./tools/sort-imports.sh
27
- - isort -c -rc prompt_toolkit examples tests setup.py
26
+ - isort -c -rc --profile black prompt_toolkit examples tests setup.py
28
27
29
28
- black --check prompt_toolkit examples tests setup.py
30
29
Original file line number Diff line number Diff line change @@ -960,3 +960,40 @@ returns a coroutines and is awaitable.
960
960
The :func: `~prompt_toolkit.patch_stdout.patch_stdout ` context manager is
961
961
optional, but it's recommended, because other coroutines could print to stdout.
962
962
This ensures that other output won't destroy the prompt.
963
+
964
+
965
+ Reading keys from stdin, one key at a time, but without a prompt
966
+ ----------------------------------------------------------------
967
+
968
+ Suppose that you want to use prompt_toolkit to read the keys from stdin, one
969
+ key at a time, but not render a prompt to the output, that is also possible:
970
+
971
+ .. code :: python
972
+
973
+ import asyncio
974
+
975
+ from prompt_toolkit.input import create_input
976
+ from prompt_toolkit.keys import Keys
977
+
978
+
979
+ async def main () -> None :
980
+ done = asyncio.Event()
981
+ input = create_input()
982
+
983
+ def keys_ready ():
984
+ for key_press in input .read_keys():
985
+ print (key_press)
986
+
987
+ if key_press.key == Keys.ControlC:
988
+ done.set()
989
+
990
+ with input .raw_mode():
991
+ with input .attach(keys_ready):
992
+ await done.wait()
993
+
994
+
995
+ if __name__ == " __main__" :
996
+ asyncio.run(main())
997
+
998
+ The above snippet will print the `KeyPress ` object whenever a key is pressed.
999
+ This is also cross platform, and should work on Windows.
Original file line number Diff line number Diff line change @@ -202,8 +202,6 @@ def do_exit():
202
202
"window.border shadow" : "#444444" ,
203
203
"focused button" : "bg:#880000 #ffffff noinherit" ,
204
204
# Styling for Dialog widgets.
205
- "radiolist focused" : "noreverse" ,
206
- "radiolist focused radio.selected" : "reverse" ,
207
205
"button-bar" : "bg:#aaaaff" ,
208
206
}
209
207
)
Original file line number Diff line number Diff line change @@ -456,7 +456,7 @@ def _is_word_before_cursor_complete(
456
456
self , WORD : bool = False , pattern : Optional [Pattern [str ]] = None
457
457
) -> bool :
458
458
if pattern :
459
- return self .find_start_of_previous_word (pattern = pattern ) is None
459
+ return self .find_start_of_previous_word (WORD = WORD , pattern = pattern ) is None
460
460
else :
461
461
return (
462
462
self .text_before_cursor == "" or self .text_before_cursor [- 1 :].isspace ()
Original file line number Diff line number Diff line change 8
8
"""
9
9
import array
10
10
import errno
11
+ import io
11
12
import os
12
13
import sys
13
14
from typing import (
@@ -452,16 +453,21 @@ def from_pty(
452
453
(This will take the dimensions by reading the pseudo
453
454
terminal attributes.)
454
455
"""
456
+ fd : Optional [int ]
455
457
# Normally, this requires a real TTY device, but people instantiate
456
458
# this class often during unit tests as well. For convenience, we print
457
459
# an error message, use standard dimensions, and go on.
458
- fd = stdout .fileno ()
460
+ try :
461
+ fd = stdout .fileno ()
462
+ except io .UnsupportedOperation :
463
+ fd = None
459
464
460
- if not stdout .isatty () and fd not in cls ._fds_not_a_terminal :
465
+ if not stdout .isatty () and ( fd is None or fd not in cls ._fds_not_a_terminal ) :
461
466
msg = "Warning: Output is not a terminal (fd=%r).\n "
462
467
sys .stderr .write (msg % fd )
463
468
sys .stderr .flush ()
464
- cls ._fds_not_a_terminal .add (fd )
469
+ if fd is not None :
470
+ cls ._fds_not_a_terminal .add (fd )
465
471
466
472
def get_size () -> Size :
467
473
# If terminal (incorrectly) reports its size as 0, pick a
Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env python
2
2
"""
3
- Read Windows input and print keys.
3
+ Read input and print keys.
4
4
For testing terminal input.
5
+
6
+ Works on both Windows and Posix.
5
7
"""
6
8
import asyncio
7
9
8
- from prompt_toolkit .input . win32 import Win32Input
10
+ from prompt_toolkit .input import create_input
9
11
from prompt_toolkit .keys import Keys
10
12
11
13
12
- async def main ():
13
- input = Win32Input ()
14
+ async def main () -> None :
14
15
done = asyncio .Event ()
16
+ input = create_input ()
15
17
16
18
def keys_ready ():
17
19
for key_press in input .read_keys ():
Original file line number Diff line number Diff line change 2
2
"""
3
3
Parse vt100 input and print keys.
4
4
For testing terminal input.
5
+
6
+ (This does not use the `Input` implementation, but only the `Vt100Parser`.)
5
7
"""
6
8
import sys
7
9
You can’t perform that action at this time.
0 commit comments