implemented an input abstraction
This commit is contained in:
+4
-6
@@ -3,11 +3,7 @@
|
|||||||
#
|
#
|
||||||
# Created by Luxferre in 2025, released into public domain
|
# Created by Luxferre in 2025, released into public domain
|
||||||
|
|
||||||
# init the tdeck_repl input where applicable
|
from deck.input import input
|
||||||
try:
|
|
||||||
from tdeck_repl import input
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
class DeckChat:
|
class DeckChat:
|
||||||
def __init__(self, start_state={}, chat_prefix='> ', command_prefix='/', paginate=0):
|
def __init__(self, start_state={}, chat_prefix='> ', command_prefix='/', paginate=0):
|
||||||
@@ -70,4 +66,6 @@ class DeckChat:
|
|||||||
print(output)
|
print(output)
|
||||||
if self.state is None:
|
if self.state is None:
|
||||||
break
|
break
|
||||||
except KeyboardInterrupt: break
|
except (KeyboardInterrupt, EOFError):
|
||||||
|
print()
|
||||||
|
break
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|
||||||
Reference in New Issue
Block a user