Skip to content

Commit 1c3056d

Browse files
author
Bob Hyman
committed
Merge branch 'master' into th-threadsafe-load-2
2 parents 7a89563 + b872e2a commit 1c3056d

File tree

7 files changed

+61
-17
lines changed

7 files changed

+61
-17
lines changed

.travis.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
sudo: false
1+
os: linux
2+
dist: focal
23
cache: pip
34
language: python
45

5-
matrix:
6+
jobs:
67
include:
8+
- python: 3.8
79
- python: 3.7
8-
dist: xenial
9-
sudo: required
1010
- python: 3.6
1111

1212
install:
13-
- pip install . pytest coverage codecov flake8 mypy
14-
- pip install isort black
13+
- pip install . black coverage codecov flake8 isort mypy pytest
1514
- pip list
1615

1716
script:
@@ -24,7 +23,7 @@ script:
2423

2524
# Check wheather the imports were sorted correctly.
2625
# 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
2827

2928
- black --check prompt_toolkit examples tests setup.py
3029

docs/pages/asking_for_input.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,3 +960,40 @@ returns a coroutines and is awaitable.
960960
The :func:`~prompt_toolkit.patch_stdout.patch_stdout` context manager is
961961
optional, but it's recommended, because other coroutines could print to stdout.
962962
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.

examples/full-screen/full-screen-demo.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,6 @@ def do_exit():
202202
"window.border shadow": "#444444",
203203
"focused button": "bg:#880000 #ffffff noinherit",
204204
# Styling for Dialog widgets.
205-
"radiolist focused": "noreverse",
206-
"radiolist focused radio.selected": "reverse",
207205
"button-bar": "bg:#aaaaff",
208206
}
209207
)

prompt_toolkit/document.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ def _is_word_before_cursor_complete(
456456
self, WORD: bool = False, pattern: Optional[Pattern[str]] = None
457457
) -> bool:
458458
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
460460
else:
461461
return (
462462
self.text_before_cursor == "" or self.text_before_cursor[-1:].isspace()

prompt_toolkit/output/vt100.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""
99
import array
1010
import errno
11+
import io
1112
import os
1213
import sys
1314
from typing import (
@@ -452,16 +453,21 @@ def from_pty(
452453
(This will take the dimensions by reading the pseudo
453454
terminal attributes.)
454455
"""
456+
fd: Optional[int]
455457
# Normally, this requires a real TTY device, but people instantiate
456458
# this class often during unit tests as well. For convenience, we print
457459
# 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
459464

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):
461466
msg = "Warning: Output is not a terminal (fd=%r).\n"
462467
sys.stderr.write(msg % fd)
463468
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)
465471

466472
def get_size() -> Size:
467473
# If terminal (incorrectly) reports its size as 0, pick a

tools/debug_win_input.py renamed to tools/debug_input_cross_platform.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
#!/usr/bin/env python
22
"""
3-
Read Windows input and print keys.
3+
Read input and print keys.
44
For testing terminal input.
5+
6+
Works on both Windows and Posix.
57
"""
68
import asyncio
79

8-
from prompt_toolkit.input.win32 import Win32Input
10+
from prompt_toolkit.input import create_input
911
from prompt_toolkit.keys import Keys
1012

1113

12-
async def main():
13-
input = Win32Input()
14+
async def main() -> None:
1415
done = asyncio.Event()
16+
input = create_input()
1517

1618
def keys_ready():
1719
for key_press in input.read_keys():

tools/debug_vt100_input.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"""
33
Parse vt100 input and print keys.
44
For testing terminal input.
5+
6+
(This does not use the `Input` implementation, but only the `Vt100Parser`.)
57
"""
68
import sys
79

0 commit comments

Comments
 (0)