Show More
@@ -233,7 +233,7 try: | |||||
233 |
|
233 | |||
234 | # http://msdn.microsoft.com/en-us/library/ms682088%28VS.85%29.aspx |
|
234 | # http://msdn.microsoft.com/en-us/library/ms682088%28VS.85%29.aspx | |
235 | w32effects = { |
|
235 | w32effects = { | |
236 |
'none': |
|
236 | 'none': -1, | |
237 | 'black': 0, |
|
237 | 'black': 0, | |
238 | 'red': win32c.FOREGROUND_RED, |
|
238 | 'red': win32c.FOREGROUND_RED, | |
239 | 'green': win32c.FOREGROUND_GREEN, |
|
239 | 'green': win32c.FOREGROUND_GREEN, | |
@@ -244,7 +244,7 try: | |||||
244 | 'white': (win32c.FOREGROUND_RED | win32c.FOREGROUND_GREEN | |
|
244 | 'white': (win32c.FOREGROUND_RED | win32c.FOREGROUND_GREEN | | |
245 | win32c.FOREGROUND_BLUE), |
|
245 | win32c.FOREGROUND_BLUE), | |
246 | 'bold': win32c.FOREGROUND_INTENSITY, |
|
246 | 'bold': win32c.FOREGROUND_INTENSITY, | |
247 | 'black_background': 0, |
|
247 | 'black_background': 0x100, # unused value > 0x0f | |
248 | 'red_background': win32c.BACKGROUND_RED, |
|
248 | 'red_background': win32c.BACKGROUND_RED, | |
249 | 'green_background': win32c.BACKGROUND_GREEN, |
|
249 | 'green_background': win32c.BACKGROUND_GREEN, | |
250 | 'yellow_background': win32c.BACKGROUND_RED | win32c.BACKGROUND_GREEN, |
|
250 | 'yellow_background': win32c.BACKGROUND_RED | win32c.BACKGROUND_GREEN, | |
@@ -258,6 +258,11 try: | |||||
258 | 'inverse': win32c.COMMON_LVB_REVERSE_VIDEO, # double-byte charsets only |
|
258 | 'inverse': win32c.COMMON_LVB_REVERSE_VIDEO, # double-byte charsets only | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
|
261 | passthrough = set([win32c.FOREGROUND_INTENSITY, | |||
|
262 | win32c.BACKGROUND_INTENSITY, | |||
|
263 | win32c.COMMON_LVB_UNDERSCORE, | |||
|
264 | win32c.COMMON_LVB_REVERSE_VIDEO]) | |||
|
265 | ||||
261 | try: |
|
266 | try: | |
262 | stdout = win32c.GetStdHandle(win32c.STD_OUTPUT_HANDLE) |
|
267 | stdout = win32c.GetStdHandle(win32c.STD_OUTPUT_HANDLE) | |
263 | if stdout is None: |
|
268 | if stdout is None: | |
@@ -272,13 +277,23 try: | |||||
272 |
|
277 | |||
273 | def win32print(text, orig, **opts): |
|
278 | def win32print(text, orig, **opts): | |
274 | label = opts.get('label', '') |
|
279 | label = opts.get('label', '') | |
275 |
attr = |
|
280 | attr = origattr | |
|
281 | ||||
|
282 | def mapcolor(val, attr): | |||
|
283 | if val == -1: | |||
|
284 | return origattr | |||
|
285 | elif val in passthrough: | |||
|
286 | return attr | val | |||
|
287 | elif val > 0x0f: | |||
|
288 | return (val & 0x70) | (attr & 0x8f) | |||
|
289 | else: | |||
|
290 | return (val & 0x07) | (attr & 0xf8) | |||
276 |
|
291 | |||
277 | # determine console attributes based on labels |
|
292 | # determine console attributes based on labels | |
278 | for l in label.split(): |
|
293 | for l in label.split(): | |
279 | style = _styles.get(l, '') |
|
294 | style = _styles.get(l, '') | |
280 | for effect in style.split(): |
|
295 | for effect in style.split(): | |
281 |
attr |
|
296 | attr = mapcolor(w32effects[effect], attr) | |
282 |
|
297 | |||
283 | # hack to ensure regexp finds data |
|
298 | # hack to ensure regexp finds data | |
284 | if not text.startswith('\033['): |
|
299 | if not text.startswith('\033['): | |
@@ -289,9 +304,8 try: | |||||
289 | while m: |
|
304 | while m: | |
290 | for sattr in m.group(1).split(';'): |
|
305 | for sattr in m.group(1).split(';'): | |
291 | if sattr: |
|
306 | if sattr: | |
292 |
|
|
307 | attr = mapcolor(int(sattr), attr) | |
293 | attr = val and attr|val or 0 |
|
308 | stdout.SetConsoleTextAttribute(attr) | |
294 | stdout.SetConsoleTextAttribute(attr or origattr) |
|
|||
295 | orig(m.group(2), **opts) |
|
309 | orig(m.group(2), **opts) | |
296 | m = re.match(ansire, m.group(3)) |
|
310 | m = re.match(ansire, m.group(3)) | |
297 |
|
311 |
General Comments 0
You need to be logged in to leave comments.
Login now