Commits

Tony Sloane committed 158a3e1

Work around JLine bug that breaks long prompt lines at column 80 (issue #1)

Comments (0)

Files changed (1)

ScalaWorksheet.py

         sanitise_errors = sublime.load_settings ("Preferences.sublime-settings").get ('scala_worksheet_sanitise_errors', True)
 
         output = wholeText (self.view)
+        output = self.workAroundJLineBug (output)
         if successful or sanitise_errors:
             output = self.sanitise (output)
         input, output = self.align (output, successful)
     def prefixedWith (self, line, s):
         return (line[0:len (s)] == s)
 
-    def startPrompt (self, ):
+    def startPrompt (self):
         return 'scala> '
 
     def isStartPrompt (self, line):
     def isContPrompt (self, line):
         return self.prefixedWith (line, self.contPrompt ())
 
+    # This is a hack. A "feature" of JLine causes it to add space-CR pairs of characters
+    # at column 80 of prompt lines which causes the rest of the line to be split onto
+    # following lines, thereby messing up the output processing. After extensive
+    # exploration I can't see a way to turn this off since the width of 80 is the default
+    # if no terminal is being used. So for now, we process the output using this function
+    # to remove those extra characters before we do the rest of the processing. There is
+    # a remote chance that a real prompt line will have a space-CR in that spot so we
+    # will mess that one up.
+    def workAroundJLineBug (self, output):
+        return re.sub (r'(.{80}) \n', r'\1', output)
+
     # Process the sanitised output to form new input and output that are aligned
     def align (self, output, removeInputFromOutput):
         inputBuilder = TextBuilder ()