Commits

Anonymous committed 066346b

Far cleaner implementation of diag thanks to AKFoerster.

  • Participants
  • Parent commits 803bed1

Comments (0)

Files changed (1)

File rpg_lib/anyrpg.py

 
 __version__   = '0.1' 
 
+import sys
 from textrpg_1d6 import Char as ews_char
 from time import sleep # for autoscrolling
 
 	# Limitation: This looks really dumb, if the text is longer than one line. 
         else: 
 	    if text: 
-		print '\033[' + str(position_in_line) + 'G' + text[0]
+		sys.stdout.write('\033[' + str(position_in_line) + 'G')
+                sys.stdout.flush()
 	    else: 
 		self.diag("...press enter to read on...") # press enter to read on at each empty line, so readers can rest. 
                 # clear the line after the user pressed enter.
-		print "\033[1A", 
+                sys.stdout.write('\033[2A\033[' + str(position_in_line) + 'G')
 		for i in range(len(_("...press enter to read on..."))): 
-		    print " ",
-		print text
+		    sys.stdout.write(" ")
+                sys.stdout.flush()
 		sleep(line_wait)
             # First sleep 1/10th second. This ensures that the text gets shown before sleeping.
             sleep(char_wait)
 	    # If we have text, wait one 10th of a second per char. 
-	    for i in range(len(text)): 
+	    for i in text: 
 		# load the current cursor position
-		print '\033[1A\033[' + str(position_in_line) + 'G' + text[:i+1] # !!! this depends on the shell scape sequences to work !!!
+		sys.stdout.write(i)
+                sys.stdout.flush()
 		sleep(char_wait)
 	
-	# If we don't want a linebreak at the end, jump back up to the last line. 
-	if not end_with_linebreak: 
+	# If we want a linebreak at the end, add it. 
+	if end_with_linebreak: 
 	    # Move back after the last char on the last line. 
-	    print '\033[1A\033[' + str(len(text)) + 'G',
+	    sys.stdout.write("\n")
+            sys.stdout.flush()
 
 class Dialogs(object): 
     """Basic dialogs.