66import termios
77
88
9- async def get_input (placeholder_text = None , placeholder_color : str = "gray" ) -> str :
9+ async def get_input (
10+ placeholder_text = None , placeholder_color : str = "gray" , multiline_support = True
11+ ) -> str :
1012 if placeholder_text is None :
1113 common_placeholders = [
1214 "How can I help you?" ,
@@ -15,7 +17,7 @@ async def get_input(placeholder_text=None, placeholder_color: str = "gray") -> s
1517 'Use """ for multi-line input' ,
1618 "Psst... try the wtf command" ,
1719 ]
18- very_rare_placeholders = ["Let's make history together! " ]
20+ very_rare_placeholders = ["" ]
1921
2022 # 69% common, 30% rare, 1% very rare
2123 rand = random .random ()
@@ -56,13 +58,15 @@ async def get_input(placeholder_text=None, placeholder_color: str = "gray") -> s
5658
5759 def redraw ():
5860 sys .stdout .write ("\r \033 [K" ) # Clear line
59- sys .stdout .write ("\r > " )
61+ if multiline_support :
62+ sys .stdout .write ("\r > " )
6063 if current_input :
6164 sys .stdout .write ("" .join (current_input ))
6265 elif show_placeholder :
6366 color_code = COLORS .get (placeholder_color .lower (), COLORS ["gray" ])
6467 sys .stdout .write (f"{ color_code } { placeholder_text } { RESET } " )
65- sys .stdout .write ("\r > " )
68+ if multiline_support :
69+ sys .stdout .write ("\r > " )
6670 sys .stdout .flush ()
6771
6872 try :
@@ -74,7 +78,18 @@ def redraw():
7478 if char == "\n " :
7579 if current_input :
7680 result = "" .join (current_input )
77- return result
81+ # Multiline support
82+ if multiline_support and result .startswith ('"""' ):
83+ while True :
84+ print ()
85+ extra_input = await get_input (multiline_support = False )
86+ if extra_input .endswith ('"""' ):
87+ result += extra_input
88+ return result
89+ else :
90+ result += extra_input
91+ else :
92+ return result
7893 else :
7994 redraw ()
8095 elif char == "\x7f " : # Backspace
0 commit comments