-
Notifications
You must be signed in to change notification settings - Fork 0
vtf io
srccircumflex edited this page Jan 5, 2023
·
2 revisions
The module contains functions and objects to create framework-typical inputs and to process them.
On the output side only one function is available in this module (out), the name io is chosen for a more convenient convention.
Below are examples of how to use the module, check the sub-modules for related documentation.
def echo_routing():
from vtframework.io import StdinAdapter, InputSuperModem, InputRouter
from vtframework.iodata import ManualESC
from vtframework.iosys.vtermios import mod_ansiin
mod_ansiin()
StdinAdapter()
router = InputRouter(thread_block=True, **{
k: InputSuperModem(
manual_esc_tt=0,
find_class_bindings_first=True,
use_alter_bindings=True
) for k in "udrl"
})
entry_label = "( l )"
def switch(entry):
nonlocal entry_label
entry_label = "( %s )" % entry
router.switch_gate(entry)
for modem in router.modems():
modem.__binder__.bind(object, lambda o, r: print(repr(o), entry_label))
modem.__binder__.bind(NavKey(NavKey.K.A_UP), lambda o, r: switch("u"))
modem.__binder__.bind(NavKey(NavKey.K.A_DOWN), lambda o, r: switch("d"))
modem.__binder__.bind(NavKey(NavKey.K.A_LEFT), lambda o, r: switch("l"))
modem.__binder__.bind(NavKey(NavKey.K.A_RIGHT), lambda o, r: switch("r"))
modem.__binder__.bind(ManualESC(''), lambda o, r: exit(0))
router.switch_gate("l")
router.start(daemon=False)
def test_oscolor_request():
from vtframework.iodata import RequestOSColor
from vtframework.io import Input
from vtframework.iosys.vtermios import mod_ansiout
mod_ansiout()
with Input() as _input_:
RequestOSColor.rel("red").out()
reply = _input_.read(block=False, smoothness=.02, flush_io=True)
print(repr(reply))
return bool(reply)
def visual_interpreters():
from vtframework.io import InputSuper, StdinAdapter
from vtframework.iosys.vtermios import mod_ansiin
from vtframework.iodata import EscEsc
import sys
mod_ansiin()
StdinAdapter()
sys.stdin: StdinAdapter
print(f"{repr(sys.stdin)=}")
_input_ = InputSuper(thread_block=True, manual_esc_tt=3, manual_esc_interpreter=True, manual_esc_finals=(0x1b,))
_input_.__interpreter__.SPACE_TARGETS.set(_input_.__interpreter__.SPACE_TARGETS.ANY)
_input_.__interpreter__.bind_esc(lambda: print("\nESC :: MAIN"))
_input_.__interpreter__.bind_intro(lambda c: print("%-4s :: MAIN" % repr(c)[2:-1]))
_input_.__interpreter__.bind_to_interpreter("any", "p", lambda i, c: print("%-4s :: ╚%s" % (repr(c)[2:-1], i.__class__.__name__)))
_input_.__interpreter__.bind_to_interpreter("any", "f", lambda i, c: print("%-4s :: ╚%s\n" % (repr(c)[2:-1], i.__class__.__name__)))
with _input_:
try:
while True:
_in_ = _input_.getch(block=True)
print("----> " + repr(_in_))
if _in_ in (EscEsc(), "\x1b"):
sys.stdin.stop()
print("\n\nPress any key > ", end="")
except EOFError:
pass
print(f"{repr(sys.stdin)=}")
Date: | 06 Nov 2022 |
---|---|
Version: | 0.1 |
Author: | Adrian Hoefflin [srccircumflex] |