66import code
77import textwrap
88import io
9+ import traceback
910
1011sys .path .insert (0 , '../' )
1112import tdl
1617WIDTH , HEIGHT = 80 , 50
1718console = 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-
2320class 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 )
3534olderr = sys .stderr
3635newerr = TDLPrint ((255 , 255 , 255 ), (127 , 0 , 0 ))
3736interpeter = code .InteractiveConsole ({'tdl' :tdl , 'console' :console })
37+ print ()
3838print ('Python %s' % sys .version )
3939print ('Press ESC to quit' )
4040if __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