diff --git a/deck/chat.py b/deck/chat.py index c97c771..08da60d 100644 --- a/deck/chat.py +++ b/deck/chat.py @@ -3,11 +3,7 @@ # # Created by Luxferre in 2025, released into public domain -# init the tdeck_repl input where applicable -try: - from tdeck_repl import input -except: - pass +from deck.input import input class DeckChat: def __init__(self, start_state={}, chat_prefix='> ', command_prefix='/', paginate=0): @@ -70,4 +66,6 @@ class DeckChat: print(output) if self.state is None: break - except KeyboardInterrupt: break + except (KeyboardInterrupt, EOFError): + print() + break diff --git a/deck/input.py b/deck/input.py new file mode 100644 index 0000000..c68ad32 --- /dev/null +++ b/deck/input.py @@ -0,0 +1,26 @@ +# deck.input: Standard input abstraction library for max compatibility +# Created by Luxferre in 2025, released into public domain + +# init the tdeck_repl input where applicable +try: + from tdeck_repl import input +except: + pass + +input = input # reexport the standard Python input method + +def input_multi(prompt=None, terminator='.'): + """Multiline input method (ed-like)""" + buf = [] + if prompt is not None: + print(prompt, end='') + while True: + try: + s = input() + if s == terminator: break + else: buf.append(s) + except (KeyboardInterrupt, EOFError): + print() + break + return '\n'.join(buf) +