-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinux.py
More file actions
33 lines (28 loc) · 1.01 KB
/
linux.py
File metadata and controls
33 lines (28 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Linux-specific input handling"""
import readline
import sys
def linux_input_handler(input_prompt="(Input text then press Ctrl+D to submit)"):
"""Linux-specific input handler with readline and Ctrl+D support"""
try:
lines = []
print(f"\n\033[1;32mUser: {input_prompt}\033[0m\n")
while True:
try:
line = input()
except EOFError:
break
except KeyboardInterrupt:
print("\033[1;36mSession terminated by Ctrl+C\033[0m")
sys.exit(0)
lines.append(line)
if len(lines) == 1:
if line.strip() in ['q', 's'] or line.strip().startswith('!'):
break
if line.strip() in ['c']:
lines = []
print("\033[1;36mInput cleared\033[0m")
break
return "\n".join(lines).strip()
except KeyboardInterrupt:
print("\033[1;36mSession terminated by Ctrl+C\033[0m")
sys.exit(0)