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