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 
23cache : pip 
34language : 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
1212install :
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
1716script :
@@ -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
Original file line number Diff line number Diff line change @@ -960,3 +960,40 @@ returns a coroutines and is awaitable.
960960:func: `~prompt_toolkit.patch_stdout.patch_stdout ` context manager is
961961optional, but it's recommended, because other coroutines could print to stdout.
962962This 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+ 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():
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)
Original file line number Diff line number Diff 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 ()
Original file line number Diff line number Diff line change 88""" 
99import  array 
1010import  errno 
11+ import  io 
1112import  os 
1213import  sys 
1314from  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 
Original file line number Diff line number Diff line change 11#!/usr/bin/env python 
22""" 
3- Read Windows  input and print keys. 
3+ Read input and print keys. 
44For testing terminal input. 
5+ 
6+ Works on both Windows and Posix. 
57""" 
68import  asyncio 
79
8- from  prompt_toolkit .input . win32  import  Win32Input 
10+ from  prompt_toolkit .input  import  create_input 
911from  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 ():
Original file line number Diff line number Diff line change 22""" 
33Parse vt100 input and print keys. 
44For testing terminal input. 
5+ 
6+ (This does not use the `Input` implementation, but only the `Vt100Parser`.) 
57""" 
68import  sys 
79
                         You can’t perform that action at this time. 
           
                  
0 commit comments