File tree Expand file tree Collapse file tree 2 files changed +8
-7
lines changed Expand file tree Collapse file tree 2 files changed +8
-7
lines changed Original file line number Diff line number Diff line change 10
10
11
11
from prompt_toolkit .contrib .telnet .server import TelnetServer
12
12
from prompt_toolkit .formatted_text import HTML
13
- from prompt_toolkit .shortcuts import clear , prompt
13
+ from prompt_toolkit .shortcuts import clear , prompt , PromptSession
14
14
15
15
# Set up logging
16
16
logging .basicConfig ()
29
29
30
30
async def interact (connection ):
31
31
write = connection .send
32
+ prompt_session = PromptSession ()
32
33
33
34
# When a client is connected, erase the screen from the client and say
34
35
# Hello.
35
36
clear ()
36
37
write ('Welcome to our chat application!\n ' )
37
38
write ('All connected clients will receive what you say.\n ' )
38
39
39
- name = await prompt (message = 'Type your name: ' , async_ = True )
40
+ name = await prompt_session . prompt_async (message = 'Type your name: ' )
40
41
41
42
# Random color.
42
43
color = random .choice (COLORS )
@@ -53,7 +54,7 @@ async def interact(connection):
53
54
# Set Application.
54
55
while True :
55
56
try :
56
- result = await prompt (message = prompt_msg , async_ = True )
57
+ result = await prompt_session . prompt_async (message = prompt_msg )
57
58
_send_to_everyone (connection , name , result , color )
58
59
except KeyboardInterrupt :
59
60
pass
Original file line number Diff line number Diff line change 8
8
9
9
from prompt_toolkit .completion import WordCompleter
10
10
from prompt_toolkit .contrib .telnet .server import TelnetServer
11
- from prompt_toolkit .shortcuts import prompt
11
+ from prompt_toolkit .shortcuts import PromptSession
12
12
13
13
# Set up logging
14
14
logging .basicConfig ()
@@ -26,11 +26,11 @@ async def interact(connection):
26
26
def get_toolbar ():
27
27
return 'Bottom toolbar...'
28
28
29
- result = await prompt (
29
+ session = PromptSession ()
30
+ result = await session .prompt_async (
30
31
'Say something: ' ,
31
32
bottom_toolbar = get_toolbar ,
32
- completer = animal_completer ,
33
- async_ = True )
33
+ completer = animal_completer )
34
34
35
35
connection .send ('You said: {}\n ' .format (result ))
36
36
connection .send ('Bye.\n ' )
You can’t perform that action at this time.
0 commit comments