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