mirror of https://github.com/python/cpython.git
Still not a real test, but at least it runs again
This commit is contained in:
parent
1801aad5dc
commit
cb2554effa
|
@ -1,8 +1,11 @@
|
||||||
#
|
#
|
||||||
# Simple test program for ctb module: emulate a terminal.
|
# Simple test program for ctb module: emulate a terminal.
|
||||||
|
# To simplify matters use the python console window for output.
|
||||||
#
|
#
|
||||||
import ctb
|
import ctb
|
||||||
import macconsole
|
import Evt
|
||||||
|
import Events
|
||||||
|
import MacOS
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def cb(err):
|
def cb(err):
|
||||||
|
@ -12,29 +15,35 @@ def main():
|
||||||
if not ctb.available():
|
if not ctb.available():
|
||||||
print 'Communications Toolbox not available'
|
print 'Communications Toolbox not available'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
# c = macconsole.copen('Terminal window')
|
# Disable Python's event processing (we do that)
|
||||||
|
MacOS.EnableAppswitch(0)
|
||||||
print 'Minimal terminal emulator V1.0'
|
print 'Minimal terminal emulator V1.0'
|
||||||
print '(type @ to exit)'
|
print '(type command-Q to exit)'
|
||||||
print
|
print
|
||||||
c = macconsole.fopen(sys.stdin)
|
|
||||||
f = sys.stdin
|
|
||||||
c.setmode(macconsole.C_RAW)
|
|
||||||
|
|
||||||
l = ctb.CMNew('Serial Tool', None)
|
l = ctb.CMNew('Serial Tool', None)
|
||||||
l.Open(0)
|
l.Open(10)
|
||||||
|
l.SetConfig(l.GetConfig() + ' baud 4800')
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
l.Idle()
|
l.Idle() # Give time to ctb
|
||||||
d = f.read(1)
|
|
||||||
if d == '@':
|
ok, evt = Evt.WaitNextEvent(0xffff, 0)
|
||||||
break
|
if ok:
|
||||||
|
what, message, when, where, modifiers = evt
|
||||||
|
|
||||||
|
if what == Events.keyDown:
|
||||||
|
# It is ours. Check for command-. to terminate
|
||||||
|
ch = chr(message & Events.charCodeMask)
|
||||||
|
if ch == 'q' and (modifiers & Events.cmdKey):
|
||||||
|
break
|
||||||
|
l.Write(ch, ctb.cmData, -1, 0)
|
||||||
|
d, dummy = l.Read(1000, ctb.cmData, 1)
|
||||||
if d:
|
if d:
|
||||||
l.Write(d, ctb.cmData, -1, 0)
|
for ch in d:
|
||||||
l.Idle()
|
if ch != '\r':
|
||||||
d, dummy = l.Read(1000, ctb.cmData, 0)
|
sys.stdout.write(ch)
|
||||||
if d:
|
sys.stdout.flush()
|
||||||
f.write(d)
|
|
||||||
f.flush()
|
|
||||||
l.Close(-1, 1)
|
l.Close(-1, 1)
|
||||||
del l
|
del l
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue