Skip to content

Commit d6cbe69

Browse files
author
4b796c65
committed
Added Typewriter class, path.py module.
1 parent 72c0271 commit d6cbe69

File tree

4 files changed

+268
-109
lines changed

4 files changed

+268
-109
lines changed

examples/interactive.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import code
77
import textwrap
88
import io
9+
import traceback
910

1011
sys.path.insert(0, '../')
1112
import tdl
@@ -16,10 +17,6 @@
1617
WIDTH, HEIGHT = 80, 50
1718
console = tdl.init(WIDTH, HEIGHT, 'Python Interpeter in TDL')
1819

19-
def scroll():
20-
console.blit(console, 0, 0, None, HEIGHT-1 , 0, 1)
21-
console.drawRect(0, HEIGHT-1, None, 1, ' ', (255, 255, 255), (0, 0, 0))
22-
2320
class TDLPrint(io.TextIOBase):
2421
def __init__(self, fgcolor=(255, 255, 255), bgcolor=(0, 0, 0)):
2522
self.colors = fgcolor, bgcolor
@@ -31,18 +28,20 @@ def write(self, string):
3128
console.drawStr(0, HEIGHT-1, string, *self.colors)
3229
tdl.flush()
3330

34-
sys.stdout = TDLPrint()
31+
#sys.stdout = TDLPrint()
32+
sys.stdout = tdl.Typewriter(console)
33+
sys.stdout.move(0, HEIGHT-1)
3534
olderr = sys.stderr
3635
newerr = TDLPrint((255, 255, 255), (127, 0, 0))
3736
interpeter = code.InteractiveConsole({'tdl':tdl, 'console':console})
37+
print()
3838
print('Python %s' % sys.version)
3939
print('Press ESC to quit')
4040
if __name__ == '__main__':
4141
buffer = ''
4242
commands = ['']
4343
banner = sys.ps1
4444
cursor = 0
45-
scroll()
4645
while 1:
4746
console.drawRect(0, HEIGHT-1, None, 1, ' ', (255, 255, 255), (0, 0, 0))
4847
console.drawStr(0, HEIGHT-1, banner + buffer)
@@ -60,11 +59,11 @@ def write(self, string):
6059
sys.stderr = newerr
6160
try:
6261
console.drawRect(0, HEIGHT-1, None, 1, None, (255, 255, 255), (0, 0, 0))
62+
console.scroll(0, -1)
6363
if interpeter.push(buffer):
6464
banner = sys.ps2
6565
else:
6666
banner = sys.ps1
67-
scroll()
6867
except SystemExit:
6968
raise
7069
except:

0 commit comments

Comments
 (0)