Revision: 1570bbbfb179
Branch:   default
Author:   Pekka Klärck
Date:     Thu Sep 13 13:48:59 2012
Log:      Support ANSI colors on console also on Windows.

Update issue 1229
Status: Started
Implemented. Next up actual testing on our Windows CI. If colors work as expected, this still needs to be atested and documented.
http://code.google.com/p/robotframework/source/detail?r=1570bbbfb179

Modified:
 /src/robot/output/highlighting.py
 /src/robot/output/monitor.py

=======================================
--- /src/robot/output/highlighting.py   Tue Mar  6 00:46:30 2012
+++ /src/robot/output/highlighting.py   Thu Sep 13 13:48:59 2012
@@ -26,11 +26,11 @@

 def Highlighter(stream):
     if os.sep == '/':
-        return UnixHighlighter(stream)
+        return AnsiHighlighter(stream)
     return DosHighlighter(stream) if windll else NoHighlighting(stream)


-class UnixHighlighter(object):
+class AnsiHighlighter(object):
     _ANSI_GREEN  = '\033[32m'
     _ANSI_RED = '\033[31m'
     _ANSI_YELLOW = '\033[33m'
@@ -55,7 +55,7 @@
         self._stream.write(color)


-class NoHighlighting(UnixHighlighter):
+class NoHighlighting(AnsiHighlighter):

     def _set_color(self, color):
         pass
@@ -112,13 +112,13 @@
     class _COORD(Structure):
         _fields_ = [("X", c_short),
                     ("Y", c_short)]
-
+
     class _SMALL_RECT(Structure):
         _fields_ = [("Left", c_short),
                     ("Top", c_short),
                     ("Right", c_short),
                     ("Bottom", c_short)]
-
+
     class _CONSOLE_SCREEN_BUFFER_INFO(Structure):
         _fields_ = [("dwSize", _COORD),
                     ("dwCursorPosition", _COORD),
=======================================
--- /src/robot/output/monitor.py        Tue Sep  4 13:23:31 2012
+++ /src/robot/output/monitor.py        Thu Sep 13 13:48:59 2012
@@ -16,7 +16,7 @@

 from robot import utils

-from .highlighting import Highlighter, NoHighlighting
+from .highlighting import AnsiHighlighter, Highlighter, NoHighlighting
 from .loggerhelper import IsLogged


@@ -167,12 +167,13 @@
                                   for stream in streams)

     def _get_highlighter(self, stream, colors):
-        auto = isatty(stream)
-        enable = {'AUTO': auto,
-                  'ON': True,
-                  'FORCE': True,   # compatibility with 2.5.5 and earlier
-                  'OFF': False}.get(colors.upper(), auto)
-        return Highlighter(stream) if enable else NoHighlighting(stream)
+        auto = Highlighter if isatty(stream) else NoHighlighting
+        highlighter = {'AUTO': auto,
+                       'ON': Highlighter,
+ 'FORCE': Highlighter, # compatibility with 2.5.5 and earlier
+                       'OFF': NoHighlighting,
+                       'ANSI': AnsiHighlighter}.get(colors.upper(), auto)
+        return highlighter(stream)

     def highlight_status(self, status, stream):
         highlighter = self._start_status_highlighting(status, stream)

Reply via email to