Revision: 4603
Author: KariHusa
Date: Thu Feb 3 23:29:34 2011
Log: monitor: Move highlight implementations to own modules
http://code.google.com/p/robotframework/source/detail?r=4603
Added:
/trunk/src/robot/output/dosstatustext.py
/trunk/src/robot/output/statustext.py
Modified:
/trunk/src/robot/output/monitor.py
=======================================
--- /dev/null
+++ /trunk/src/robot/output/dosstatustext.py Thu Feb 3 23:29:34 2011
@@ -0,0 +1,87 @@
+# Copyright 2008-2010 Nokia Siemens Networks Oyj
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+import sys
+from ctypes import windll, Structure, c_short, c_ushort, byref
+
+from statustext import PlainStatusText
+from robot import utils
+
+
+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),
+ ("wAttributes", c_ushort),
+ ("srWindow", SMALL_RECT),
+ ("dwMaximumWindowSize", COORD)]
+
+
+class DosHiglightedStatusText(PlainStatusText):
+ FOREGROUND_RED = 0x0004
+ FOREGROUND_YELLOW = 0x0006
+ FOREGROUND_GREEN = 0x0002
+ FOREGROUND_INTENSITY = 0x0008
+ FOREGROUND_GREY = 0x0007
+
+ STD_OUTPUT_HANDLE = -11
+
+ _highlight_colors = {'FAIL': FOREGROUND_RED,
+ 'ERROR': FOREGROUND_RED,
+ 'WARN': FOREGROUND_YELLOW,
+ 'PASS': FOREGROUND_GREEN}
+
+ def _write_encoded_with_tab_replacing(self, stream, message):
+ stream.write(utils.encode_output(message).replace('\t', ' '*8))
+
+ def write_status(self, newline=True, stream=sys.__stdout__):
+ self._write(None, ' |', '|', newline, stream)
+
+ def write_message(self, message, newline=True, stream=sys.__stderr__):
+ self._write(message, '[', ']', newline, stream)
+
+ def _write(self, message, start_sep, end_sep, newline=True,
stream=sys.__stdout__):
+ default_colors = self._get_text_attr()
+ default_fg = default_colors & 0x0007
+ default_bg = default_colors & 0x0070
+ self._write_encoded_with_tab_replacing(stream, start_sep)
+ self._set_text_attr(self._highlight_colors[self._msg] |
self.FOREGROUND_INTENSITY)
+ self._write_encoded_with_tab_replacing(stream, ' %s ' % self._msg)
+ self._set_text_attr(default_fg | default_bg |
self.FOREGROUND_INTENSITY)
+ self._write_encoded_with_tab_replacing(stream, end_sep)
+ if message:
+ stream.write(' %s' % message)
+ if newline:
+ self._write_encoded_with_tab_replacing(stream, '\n')
+
+ def _set_text_attr(self, color):
+
windll.kernel32.SetConsoleTextAttribute(windll.kernel32.GetStdHandle(self.STD_OUTPUT_HANDLE),
color)
+
+ def _get_text_attr(self):
+ csbi = CONSOLE_SCREEN_BUFFER_INFO()
+ windll.kernel32.GetConsoleScreenBufferInfo(self.STD_OUTPUT_HANDLE,
byref(csbi))
+ return csbi.wAttributes
=======================================
--- /dev/null
+++ /trunk/src/robot/output/statustext.py Thu Feb 3 23:29:34 2011
@@ -0,0 +1,57 @@
+# Copyright 2008-2010 Nokia Siemens Networks Oyj
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+import sys
+
+from robot import utils
+
+
+class PlainStatusText:
+
+ def __init__(self, msg):
+ self._msg = msg
+
+ def __str__(self):
+ return self._msg
+
+ def write_status(self, stream=sys.__stdout__):
+ self.write(' | %s |' % self._msg, stream)
+
+ def write_message(self, message):
+ self.write('[ %s ] %s' % (self._msg, message),
stream=sys.__stderr__)
+
+ def write(self, message, newline=True, stream=sys.__stdout__):
+ if newline:
+ message += '\n'
+ stream.write(utils.encode_output(message).replace('\t', ' '*8))
+ stream.flush()
+
+
+class HiglightedStatusText(PlainStatusText):
+ ANSI_RED = '\033[31m'
+ ANSI_GREEN = '\033[32m'
+ ANSI_YELLOW = '\033[33m'
+ ANSI_RESET = '\033[0m'
+
+ _highlight_colors = {'FAIL': ANSI_RED,
+ 'ERROR': ANSI_RED,
+ 'WARN': ANSI_YELLOW,
+ 'PASS': ANSI_GREEN}
+
+ def __init__(self, msg):
+ PlainStatusText.__init__(self, msg)
+ color = self._highlight_colors[self._msg]
+ reset = color != '' and self.ANSI_RESET or ''
+ self._msg = color + self._msg + reset
=======================================
--- /trunk/src/robot/output/monitor.py Wed Feb 2 06:09:52 2011
+++ /trunk/src/robot/output/monitor.py Thu Feb 3 23:29:34 2011
@@ -12,16 +12,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-
import os
import sys
from robot import utils
-from robot.errors import FrameworkError
-
+from robot.output.statustext import PlainStatusText, HiglightedStatusText
from loggerhelper import IsLogged
+def StatusText(msg, colors=True):
+ if not colors:
+ return PlainStatusText(msg)
+ if not os.sep == '\\':
+ return HiglightedStatusText(msg)
+ from dosstatustext import DosHiglightedStatusText
+ return DosHiglightedStatusText(msg)
+
+
class CommandLineMonitor:
def __init__(self, width=78, colors=True):
@@ -95,129 +102,3 @@
def _write_separator(self, sep_char):
self._write(sep_char * self._width)
-
-
-def StatusText(msg, colors=True):
- if colors:
- if os.sep == '\\':
- return DosHiglightedStatusText(msg)
- return HiglightedStatusText(msg)
- return PlainStatusText(msg)
-
-
-class PlainStatusText:
- _highlight_colors = {}
-
- def __init__(self, msg):
- self._msg = msg
-
- def __str__(self):
- return self._msg
-
- def write_status(self, stream=sys.__stdout__):
- self.write(' | %s |' % self._msg, stream)
-
- def write_message(self, message):
- self.write('[ %s ] %s' % (self._msg, message),
stream=sys.__stderr__)
-
- def write(self, message, newline=True, stream=sys.__stdout__):
- if newline:
- message += '\n'
- self._write_encoded_with_tab_replacing(stream, message)
- stream.flush()
-
- def _write_encoded_with_tab_replacing(self, stream, message):
- stream.write(utils.encode_output(message).replace('\t', ' '*8))
-
- def _get_highlight_color(self, text):
- if text in self._highlight_colors:
- return self._highlight_colors[text]
- raise FrameworkError
-
-
-class HiglightedStatusText(PlainStatusText):
- ANSI_RED = '\033[31m'
- ANSI_GREEN = '\033[32m'
- ANSI_YELLOW = '\033[33m'
- ANSI_RESET = '\033[0m'
-
- _highlight_colors = {'FAIL': ANSI_RED,
- 'ERROR': ANSI_RED,
- 'WARN': ANSI_YELLOW,
- 'PASS': ANSI_GREEN}
-
- def __init__(self, msg):
- PlainStatusText.__init__(self, msg)
- color = self._get_highlight_color(self._msg)
- reset = color != '' and self.ANSI_RESET or ''
- self._msg = color + self._msg + reset
-
-
-if os.pathsep == '\\':
- from ctypes import windll, Structure, c_short, c_ushort, byref
-
- SHORT = c_short
- WORD = c_ushort
-
- class COORD(Structure):
- _fields_ = [
- ("X", SHORT),
- ("Y", SHORT)]
-
- class SMALL_RECT(Structure):
- _fields_ = [
- ("Left", SHORT),
- ("Top", SHORT),
- ("Right", SHORT),
- ("Bottom", SHORT)]
-
- class CONSOLE_SCREEN_BUFFER_INFO(Structure):
- _fields_ = [
- ("dwSize", COORD),
- ("dwCursorPosition", COORD),
- ("wAttributes", WORD),
- ("srWindow", SMALL_RECT),
- ("dwMaximumWindowSize", COORD)]
-
-
- class DosHiglightedStatusText(PlainStatusText):
- FOREGROUND_RED = 0x0004
- FOREGROUND_YELLOW = 0x0006
- FOREGROUND_GREEN = 0x0002
- FOREGROUND_INTENSITY = 0x0008
- FOREGROUND_GREY = 0x0007
-
- STD_OUTPUT_HANDLE = -11
-
- _highlight_colors = {'FAIL': FOREGROUND_RED,
- 'ERROR': FOREGROUND_RED,
- 'WARN': FOREGROUND_YELLOW,
- 'PASS': FOREGROUND_GREEN}
-
- def write_status(self, newline=True, stream=sys.__stdout__):
- self._write(None, ' |', '|', newline, stream)
-
- def write_message(self, message, newline=True,
stream=sys.__stderr__):
- self._write(message, '[', ']', newline, stream)
-
- def _write(self, message, start_sep, end_sep, newline=True,
stream=sys.__stdout__):
- default_colors = self._get_text_attr()
- default_fg = default_colors & 0x0007
- default_bg = default_colors & 0x0070
- self._write_encoded_with_tab_replacing(stream, start_sep)
- self._set_text_attr(self._get_highlight_color(self._msg) |
self.FOREGROUND_INTENSITY)
- self._write_encoded_with_tab_replacing(stream, ' %s ' %
self._msg)
- self._set_text_attr(default_fg | default_bg |
self.FOREGROUND_INTENSITY)
- self._write_encoded_with_tab_replacing(stream, end_sep)
- if message:
- stream.write(' %s' % message)
- if newline:
- self._write_encoded_with_tab_replacing(stream, '\n')
-
- def _set_text_attr(self, color):
-
windll.kernel32.SetConsoleTextAttribute(windll.kernel32.GetStdHandle(self.STD_OUTPUT_HANDLE),
color)
-
- def _get_text_attr(self):
- csbi = CONSOLE_SCREEN_BUFFER_INFO()
-
windll.kernel32.GetConsoleScreenBufferInfo(self.STD_OUTPUT_HANDLE,
byref(csbi))
- return csbi.wAttributes