Commits

Anonymous committed 3b2758b

Fixed console.py function term_width_line() issue. #423

  • Participants
  • Parent commits be35ece

Comments (0)

Files changed (1)

File sphinx/util/console.py

 
 import os
 import sys
+import re
 
+_strip_core_re = re.compile('\x1b\\[(\\d\\d;){0,2}\\d\\dm')
 codes = {}
 
 def get_terminal_width():
         terminal_width = int(os.environ.get('COLUMNS', 80)) - 1
     return terminal_width
 
+
 _tw = get_terminal_width()
-
 def term_width_line(text):
     if not codes:
         # if no coloring, don't output fancy backspaces
         return text + '\n'
     else:
-        return text.ljust(_tw) + '\r'
+        # codes are not displayed and must be taken into account by introducing the correction factor
+        return text.ljust(_tw + len(text) - len(_strip_core_re.sub('', text))) + '\r'
 
 def color_terminal():
     if not hasattr(sys.stdout, 'isatty'):