Improve cursor handling, improve tracebacks, improve lemonade game instructions
authorNick Downing <nick@ndcode.org>
Thu, 19 May 2022 09:27:38 +0000 (19:27 +1000)
committerNick Downing <nick@ndcode.org>
Thu, 19 May 2022 10:48:09 +0000 (20:48 +1000)
apple_io.py
applesoft_basic.py
lemonade/lemonade.bas.patch

index 44e5ae4..0c89d20 100755 (executable)
@@ -196,11 +196,13 @@ def init():
     attr = termios.tcgetattr(fd_in)
     atexit.register(deinit)
     tty.setraw(fd_in)
+    write('\x1b[?25l\x1b[0m') # hide cursor, reset attributes
 
 def deinit():
   global attr
 
   if attr is not None:
+    write('\x1b[?25h\x1b[0m') # show cursor, reset attributes
     termios.tcsetattr(fd_in, termios.TCSADRAIN, attr)
     atexit.unregister(deinit)
     attr = None
@@ -253,11 +255,13 @@ def get():
   return ch
 
 def input():
+  write('\x1b[?25h') # show cursor
   line = ''
   while True:
     ch = get()
     _print(ch)
     if ch == '\r':
+      write('\x1b[?25l') # hide cursor
       return line
     if ch == '\b':
       if len(line):
index fcb7956..41f110d 100755 (executable)
@@ -51,10 +51,10 @@ program.post_process(program)
 
 #print('apple_io.init()')
 apple_io.init()
-
-#print('context.run()')
-context = t_def.Context(program)
-context.run()
-
-#print('apple_io.deinit()')
-apple_io.deinit()
+try:
+  #print('context.run()')
+  context = t_def.Context(program)
+  context.run()
+finally:
+  #print('apple_io.deinit()')
+  apple_io.deinit()
index 958bed2..c7f63bd 100644 (file)
@@ -1,5 +1,5 @@
 --- lemonade.bas       2022-05-19 17:11:25.884056262 +1000
-+++ lemonade_patched.bas       2022-05-19 17:15:30.976066141 +1000
++++ lemonade_patched.bas       2022-05-19 19:25:27.892057149 +1000
 @@ -1,15 +1,5 @@
  1LOMEM:14080
 -5GOSUB10000:GOSUB11000:GOSUB16000:GOTO135
  11530DATA96,16,85,4,128,4,96,4,76,4,128,4,96,16,0,0
  11540DATA114,120,144,60,114,255,1,120,128,120,144,60,128,120,114,60,144,120,171,255,228,255,0,0
  11550DATA152,180,152,120,152,60,144,120,152,60,171,120,192,60,152,255,0,0
-@@ -327,8 +318,7 @@
+@@ -266,8 +257,10 @@
+ 13100HOME
+ 13110PRINT"TO MANAGE YOUR LEMONADE STAND, YOU WILL "
+ 13120PRINT"NEED TO MAKE THESE DECISIONS EVERY DAY: ":PRINT
+-13130PRINT"1. HOW MANY GLASSES OF LEMONADE TO MAKE    (ONLY ONE BATCH IS MADE EACH MORNING)"
+-13140PRINT"2. HOW MANY ADVERTISING SIGNS TO MAKE      (THE SIGNS COST FIFTEEN CENTS EACH)  "
++13130PRINT"1. HOW MANY GLASSES OF LEMONADE TO MAKE "
++13135PRINT"   (ONLY ONE BATCH IS MADE EACH MORNING)"
++13140PRINT"2. HOW MANY ADVERTISING SIGNS TO MAKE   "
++13145PRINT"   (THE SIGNS COST FIFTEEN CENTS EACH)  "
+ 13150PRINT"3. WHAT PRICE TO CHARGE FOR EACH GLASS  ":PRINT
+ 13160PRINT"YOU WILL BEGIN WITH $2.00 CASH (ASSETS)."
+ 13170PRINT"BECAUSE YOUR MOTHER GAVE YOU SOME SUGAR,"
+@@ -327,8 +320,7 @@
  15182IFSC=7THENHTAB15:PRINT" HOT AND DRY ";
  15184IFSC=10THENHTAB17:PRINT" CLOUDY ";
  15186IFSC=5THENHTAB14:PRINT" THUNDERSTORMS! ";:GOSUB17000