Show More
@@ -0,0 +1,390 b'' | |||||
|
1 | """ | |||
|
2 | ``astyle`` provides classes for adding style (foreground and background color; | |||
|
3 | bold; blink; etc.) to terminal and curses output. | |||
|
4 | """ | |||
|
5 | ||||
|
6 | ||||
|
7 | import os | |||
|
8 | ||||
|
9 | try: | |||
|
10 | import curses | |||
|
11 | except ImportError: | |||
|
12 | curses = None | |||
|
13 | ||||
|
14 | ||||
|
15 | COLOR_BLACK = 0 | |||
|
16 | COLOR_RED = 1 | |||
|
17 | COLOR_GREEN = 2 | |||
|
18 | COLOR_YELLOW = 3 | |||
|
19 | COLOR_BLUE = 4 | |||
|
20 | COLOR_MAGENTA = 5 | |||
|
21 | COLOR_CYAN = 6 | |||
|
22 | COLOR_WHITE = 7 | |||
|
23 | ||||
|
24 | A_BLINK = 1<<0 # Blinking text | |||
|
25 | A_BOLD = 1<<1 # Extra bright or bold text | |||
|
26 | A_DIM = 1<<2 # Half bright text | |||
|
27 | A_REVERSE = 1<<3 # Reverse-video text | |||
|
28 | A_STANDOUT = 1<<4 # The best highlighting mode available | |||
|
29 | A_UNDERLINE = 1<<5 # Underlined text | |||
|
30 | ||||
|
31 | ||||
|
32 | class Style(object): | |||
|
33 | """ | |||
|
34 | Store foreground color, background color and attribute (bold, underlined | |||
|
35 | etc.). | |||
|
36 | """ | |||
|
37 | __slots__ = ("fg", "bg", "attrs") | |||
|
38 | ||||
|
39 | COLORNAMES = { | |||
|
40 | "black": COLOR_BLACK, | |||
|
41 | "red": COLOR_RED, | |||
|
42 | "green": COLOR_GREEN, | |||
|
43 | "yellow": COLOR_YELLOW, | |||
|
44 | "blue": COLOR_BLUE, | |||
|
45 | "magenta": COLOR_MAGENTA, | |||
|
46 | "cyan": COLOR_CYAN, | |||
|
47 | "white": COLOR_WHITE, | |||
|
48 | } | |||
|
49 | ATTRNAMES = { | |||
|
50 | "blink": A_BLINK, | |||
|
51 | "bold": A_BOLD, | |||
|
52 | "dim": A_DIM, | |||
|
53 | "reverse": A_REVERSE, | |||
|
54 | "standout": A_STANDOUT, | |||
|
55 | "underline": A_UNDERLINE, | |||
|
56 | } | |||
|
57 | ||||
|
58 | def __init__(self, fg, bg, attrs=0): | |||
|
59 | """ | |||
|
60 | Create a ``Style`` object with ``fg`` as the foreground color, | |||
|
61 | ``bg`` as the background color and ``attrs`` as the attributes. | |||
|
62 | ||||
|
63 | Examples: | |||
|
64 | ||||
|
65 | >>> Style(COLOR_RED, COLOR_BLACK) | |||
|
66 | >>> Style(COLOR_YELLOW, COLOR_BLUE, A_BOLD|A_UNDERLINE) | |||
|
67 | """ | |||
|
68 | self.fg = fg | |||
|
69 | self.bg = bg | |||
|
70 | self.attrs = attrs | |||
|
71 | ||||
|
72 | def __call__(self, *args): | |||
|
73 | text = Text() | |||
|
74 | for arg in args: | |||
|
75 | if isinstance(arg, Text): | |||
|
76 | text.extend(arg) | |||
|
77 | else: | |||
|
78 | text.append((self, arg)) | |||
|
79 | return text | |||
|
80 | ||||
|
81 | def __eq__(self, other): | |||
|
82 | return self.fg == other.fg and self.bg == other.bg and self.attrs == other.attrs | |||
|
83 | ||||
|
84 | def __neq__(self, other): | |||
|
85 | return self.fg != other.fg or self.bg != other.bg or self.attrs != other.attrs | |||
|
86 | ||||
|
87 | def __repr__(self): | |||
|
88 | color2name = ("black", "red", "green", "yellow", "blue", "magenta", "cyan", "white") | |||
|
89 | attrs2name = ("blink", "bold", "dim", "reverse", "standout", "underline") | |||
|
90 | ||||
|
91 | return "<%s fg=%s bg=%s attrs=%s>" % ( | |||
|
92 | self.__class__.__name__, color2name[self.fg], color2name[self.bg], | |||
|
93 | "|".join([attrs2name[b] for b in xrange(6) if self.attrs&(1<<b)]) or 0) | |||
|
94 | ||||
|
95 | def fromstr(cls, value): | |||
|
96 | """ | |||
|
97 | Create a ``Style`` object from a string. The format looks like this: | |||
|
98 | ``"red:black:bold|blink"``. | |||
|
99 | """ | |||
|
100 | # defaults | |||
|
101 | fg = COLOR_WHITE | |||
|
102 | bg = COLOR_BLACK | |||
|
103 | attrs = 0 | |||
|
104 | ||||
|
105 | parts = value.split(":") | |||
|
106 | if len(parts) > 0: | |||
|
107 | fg = cls.COLORNAMES[parts[0].lower()] | |||
|
108 | if len(parts) > 1: | |||
|
109 | bg = cls.COLORNAMES[parts[1].lower()] | |||
|
110 | if len(parts) > 2: | |||
|
111 | for strattr in parts[2].split("|"): | |||
|
112 | attrs |= cls.ATTRNAMES[strattr.lower()] | |||
|
113 | return cls(fg, bg, attrs) | |||
|
114 | fromstr = classmethod(fromstr) | |||
|
115 | ||||
|
116 | def fromenv(cls, name, default): | |||
|
117 | """ | |||
|
118 | Create a ``Style`` from an environment variable named ``name`` | |||
|
119 | (using ``default`` if the environment variable doesn't exist). | |||
|
120 | """ | |||
|
121 | return cls.fromstr(os.environ.get(name, default)) | |||
|
122 | fromenv = classmethod(fromenv) | |||
|
123 | ||||
|
124 | ||||
|
125 | def switchstyle(s1, s2): | |||
|
126 | """ | |||
|
127 | Return the ANSI escape sequence needed to switch from style ``s1`` to | |||
|
128 | style ``s2``. | |||
|
129 | """ | |||
|
130 | attrmask = (A_BLINK|A_BOLD|A_UNDERLINE|A_REVERSE) | |||
|
131 | a1 = s1.attrs & attrmask | |||
|
132 | a2 = s2.attrs & attrmask | |||
|
133 | ||||
|
134 | args = [] | |||
|
135 | if s1 != s2: | |||
|
136 | # do we have to get rid of the bold/underline/blink bit? | |||
|
137 | # (can only be done by a reset) | |||
|
138 | # use reset when our target color is the default color | |||
|
139 | # (this is shorter than 37;40) | |||
|
140 | if (a1 & ~a2 or s2==style_default): | |||
|
141 | args.append("0") | |||
|
142 | s1 = style_default | |||
|
143 | a1 = 0 | |||
|
144 | ||||
|
145 | # now we know that old and new color have the same boldness, | |||
|
146 | # or the new color is bold and the old isn't, | |||
|
147 | # i.e. we only might have to switch bold on, not off | |||
|
148 | if not (a1 & A_BOLD) and (a2 & A_BOLD): | |||
|
149 | args.append("1") | |||
|
150 | ||||
|
151 | # Fix underline | |||
|
152 | if not (a1 & A_UNDERLINE) and (a2 & A_UNDERLINE): | |||
|
153 | args.append("4") | |||
|
154 | ||||
|
155 | # Fix blink | |||
|
156 | if not (a1 & A_BLINK) and (a2 & A_BLINK): | |||
|
157 | args.append("5") | |||
|
158 | ||||
|
159 | # Fix reverse | |||
|
160 | if not (a1 & A_REVERSE) and (a2 & A_REVERSE): | |||
|
161 | args.append("7") | |||
|
162 | ||||
|
163 | # Fix foreground color | |||
|
164 | if s1.fg != s2.fg: | |||
|
165 | args.append("3%d" % s2.fg) | |||
|
166 | ||||
|
167 | # Finally fix the background color | |||
|
168 | if s1.bg != s2.bg: | |||
|
169 | args.append("4%d" % s2.bg) | |||
|
170 | ||||
|
171 | if args: | |||
|
172 | return "\033[%sm" % ";".join(args) | |||
|
173 | return "" | |||
|
174 | ||||
|
175 | ||||
|
176 | class Text(list): | |||
|
177 | """ | |||
|
178 | A colored string. A ``Text`` object is a sequence, the sequence | |||
|
179 | items will be ``(style, string)`` tuples. | |||
|
180 | """ | |||
|
181 | ||||
|
182 | def __init__(self, *args): | |||
|
183 | list.__init__(self) | |||
|
184 | self.append(*args) | |||
|
185 | ||||
|
186 | def __repr__(self): | |||
|
187 | return "%s.%s(%s)" % ( | |||
|
188 | self.__class__.__module__, self.__class__.__name__, | |||
|
189 | list.__repr__(self)[1:-1]) | |||
|
190 | ||||
|
191 | def append(self, *args): | |||
|
192 | for arg in args: | |||
|
193 | if isinstance(arg, Text): | |||
|
194 | self.extend(arg) | |||
|
195 | elif isinstance(arg, tuple): # must be (style, string) | |||
|
196 | list.append(self, arg) | |||
|
197 | elif isinstance(arg, unicode): | |||
|
198 | list.append(self, (style_default, arg)) | |||
|
199 | else: | |||
|
200 | list.append(self, (style_default, str(arg))) | |||
|
201 | ||||
|
202 | def insert(self, index, *args): | |||
|
203 | self[index:index] = Text(*args) | |||
|
204 | ||||
|
205 | def __add__(self, other): | |||
|
206 | new = Text() | |||
|
207 | new.append(self) | |||
|
208 | new.append(other) | |||
|
209 | return new | |||
|
210 | ||||
|
211 | def __iadd__(self, other): | |||
|
212 | self.append(other) | |||
|
213 | return self | |||
|
214 | ||||
|
215 | def format(self, styled=True): | |||
|
216 | """ | |||
|
217 | This generator yields the strings that will make up the final | |||
|
218 | colorized string. | |||
|
219 | """ | |||
|
220 | if styled: | |||
|
221 | oldstyle = style_default | |||
|
222 | for (style, string) in self: | |||
|
223 | if not isinstance(style, (int, long)): | |||
|
224 | switch = switchstyle(oldstyle, style) | |||
|
225 | if switch: | |||
|
226 | yield switch | |||
|
227 | if string: | |||
|
228 | yield string | |||
|
229 | oldstyle = style | |||
|
230 | switch = switchstyle(oldstyle, style_default) | |||
|
231 | if switch: | |||
|
232 | yield switch | |||
|
233 | else: | |||
|
234 | for (style, string) in self: | |||
|
235 | if not isinstance(style, (int, long)): | |||
|
236 | yield string | |||
|
237 | ||||
|
238 | def string(self, styled=True): | |||
|
239 | """ | |||
|
240 | Return the resulting string (with escape sequences, if ``styled`` | |||
|
241 | is true). | |||
|
242 | """ | |||
|
243 | return "".join(self.format(styled)) | |||
|
244 | ||||
|
245 | def __str__(self): | |||
|
246 | """ | |||
|
247 | Return ``self`` as a string (without ANSI escape sequences). | |||
|
248 | """ | |||
|
249 | return self.string(False) | |||
|
250 | ||||
|
251 | def write(self, stream, styled=True): | |||
|
252 | """ | |||
|
253 | Write ``self`` to the output stream ``stream`` (with escape sequences, | |||
|
254 | if ``styled`` is true). | |||
|
255 | """ | |||
|
256 | for part in self.format(styled): | |||
|
257 | stream.write(part) | |||
|
258 | ||||
|
259 | def __xrepr__(self, mode="default"): | |||
|
260 | yield (-1, True) | |||
|
261 | for info in self: | |||
|
262 | yield info | |||
|
263 | ||||
|
264 | ||||
|
265 | def streamstyle(stream, styled=None): | |||
|
266 | """ | |||
|
267 | If ``styled`` is ``None``, return whether ``stream`` refers to a terminal. | |||
|
268 | If this can't be determined (either because ``stream`` doesn't refer to a | |||
|
269 | real OS file, or because you're on Windows) return ``False``. If ``styled`` | |||
|
270 | is not ``None`` ``styled`` will be returned unchanged. | |||
|
271 | """ | |||
|
272 | if styled is None: | |||
|
273 | try: | |||
|
274 | styled = os.isatty(stream.fileno()) | |||
|
275 | except (KeyboardInterrupt, SystemExit): | |||
|
276 | raise | |||
|
277 | except Exception: | |||
|
278 | styled = False | |||
|
279 | return styled | |||
|
280 | ||||
|
281 | ||||
|
282 | def write(stream, styled, *texts): | |||
|
283 | """ | |||
|
284 | Write ``texts`` to ``stream``. | |||
|
285 | """ | |||
|
286 | text = Text(*texts) | |||
|
287 | text.write(stream, streamstyle(stream, styled)) | |||
|
288 | ||||
|
289 | ||||
|
290 | def writeln(stream, styled, *texts): | |||
|
291 | """ | |||
|
292 | Write ``texts`` to ``stream`` and finish with a line feed. | |||
|
293 | """ | |||
|
294 | write(stream, styled, *texts) | |||
|
295 | stream.write("\n") | |||
|
296 | ||||
|
297 | ||||
|
298 | class Stream(object): | |||
|
299 | """ | |||
|
300 | Stream wrapper that adds color output. | |||
|
301 | """ | |||
|
302 | def __init__(self, stream, styled=None): | |||
|
303 | self.stream = stream | |||
|
304 | self.styled = streamstyle(stream, styled) | |||
|
305 | ||||
|
306 | def write(self, *texts): | |||
|
307 | write(self.stream, self.styled, *texts) | |||
|
308 | ||||
|
309 | def writeln(self, *texts): | |||
|
310 | writeln(self.stream, self.styled, *texts) | |||
|
311 | ||||
|
312 | def __getattr__(self, name): | |||
|
313 | return getattr(self.stream, name) | |||
|
314 | ||||
|
315 | ||||
|
316 | class stdout(object): | |||
|
317 | """ | |||
|
318 | Stream wrapper for ``sys.stdout`` that adds color output. | |||
|
319 | """ | |||
|
320 | def write(self, *texts): | |||
|
321 | write(sys.stdout, None, *texts) | |||
|
322 | ||||
|
323 | def writeln(self, *texts): | |||
|
324 | writeln(sys.stdout, None, *texts) | |||
|
325 | ||||
|
326 | def __getattr__(self, name): | |||
|
327 | return getattr(sys.stdout, name) | |||
|
328 | stdout = stdout() | |||
|
329 | ||||
|
330 | ||||
|
331 | class stderr(object): | |||
|
332 | """ | |||
|
333 | Stream wrapper for ``sys.stderr`` that adds color output. | |||
|
334 | """ | |||
|
335 | def write(self, *texts): | |||
|
336 | write(sys.stderr, None, *texts) | |||
|
337 | ||||
|
338 | def writeln(self, *texts): | |||
|
339 | writeln(sys.stderr, None, *texts) | |||
|
340 | ||||
|
341 | def __getattr__(self, name): | |||
|
342 | return getattr(sys.stdout, name) | |||
|
343 | stderr = stderr() | |||
|
344 | ||||
|
345 | ||||
|
346 | if curses is not None: | |||
|
347 | # This is probably just range(8) | |||
|
348 | COLOR2CURSES = [ | |||
|
349 | COLOR_BLACK, | |||
|
350 | COLOR_RED, | |||
|
351 | COLOR_GREEN, | |||
|
352 | COLOR_YELLOW, | |||
|
353 | COLOR_BLUE, | |||
|
354 | COLOR_MAGENTA, | |||
|
355 | COLOR_CYAN, | |||
|
356 | COLOR_WHITE, | |||
|
357 | ] | |||
|
358 | ||||
|
359 | A2CURSES = { | |||
|
360 | A_BLINK: curses.A_BLINK, | |||
|
361 | A_BOLD: curses.A_BOLD, | |||
|
362 | A_DIM: curses.A_DIM, | |||
|
363 | A_REVERSE: curses.A_REVERSE, | |||
|
364 | A_STANDOUT: curses.A_STANDOUT, | |||
|
365 | A_UNDERLINE: curses.A_UNDERLINE, | |||
|
366 | } | |||
|
367 | ||||
|
368 | ||||
|
369 | # default style | |||
|
370 | style_default = Style.fromstr("white:black") | |||
|
371 | ||||
|
372 | # Styles for datatypes | |||
|
373 | style_type_none = Style.fromstr("magenta:black") | |||
|
374 | style_type_bool = Style.fromstr("magenta:black") | |||
|
375 | style_type_number = Style.fromstr("yellow:black") | |||
|
376 | style_type_datetime = Style.fromstr("magenta:black") | |||
|
377 | ||||
|
378 | # Style for URLs and file/directory names | |||
|
379 | style_url = Style.fromstr("green:black") | |||
|
380 | style_dir = Style.fromstr("cyan:black") | |||
|
381 | style_file = Style.fromstr("green:black") | |||
|
382 | ||||
|
383 | # Style for ellipsis (when an output has been shortened | |||
|
384 | style_ellisis = Style.fromstr("red:black") | |||
|
385 | ||||
|
386 | # Style for displaying exceptions | |||
|
387 | style_error = Style.fromstr("red:black") | |||
|
388 | ||||
|
389 | # Style for displaying non-existing attributes | |||
|
390 | style_nodata = Style.fromstr("red:black") |
This diff has been collapsed as it changes many lines, (562 lines changed) Show them Hide them | |||||
@@ -57,11 +57,11 b' three extensions points (all of them optional):' | |||||
57 | line would use ``True``, but for a large data structure (i.e. a nested list, |
|
57 | line would use ``True``, but for a large data structure (i.e. a nested list, | |
58 | tuple or dictionary) ``False`` would be used). The other output ``__xrepr__()`` |
|
58 | tuple or dictionary) ``False`` would be used). The other output ``__xrepr__()`` | |
59 | may produce is tuples of ``Style```objects and text (which contain the text |
|
59 | may produce is tuples of ``Style```objects and text (which contain the text | |
60 |
representation of the object). If ``__xrepr__()`` |
|
60 | representation of the object; see the ``astyle`` module). If ``__xrepr__()`` | |
61 |
structure the function ``xrepr(object, mode)`` can |
|
61 | recursively outputs a data structure the function ``xrepr(object, mode)`` can | |
62 |
must be passed as the mode in these calls. This in |
|
62 | be used and ``"default"`` must be passed as the mode in these calls. This in | |
63 |
``__xrepr__()`` method on ``object`` (or uses ``repr(object)`` |
|
63 | turn calls the ``__xrepr__()`` method on ``object`` (or uses ``repr(object)`` | |
64 | representation if ``__xrepr__()`` doesn't exist. |
|
64 | as the string representation if ``__xrepr__()`` doesn't exist). | |
65 |
|
65 | |||
66 | * Objects that can be iterated by ``Pipe``s must implement the method |
|
66 | * Objects that can be iterated by ``Pipe``s must implement the method | |
67 | ``__xiter__(self, mode)``. ``mode`` can take the following values: |
|
67 | ``__xiter__(self, mode)``. ``mode`` can take the following values: | |
@@ -163,6 +163,8 b' try:' | |||||
163 | except ImportError: |
|
163 | except ImportError: | |
164 | pass |
|
164 | pass | |
165 |
|
165 | |||
|
166 | import astyle | |||
|
167 | ||||
166 |
|
168 | |||
167 | __all__ = [ |
|
169 | __all__ = [ | |
168 | "ifile", "ils", "iglob", "iwalk", "ipwdentry", "ipwd", "igrpentry", "igrp", |
|
170 | "ifile", "ils", "iglob", "iwalk", "ipwdentry", "ipwd", "igrpentry", "igrp", | |
@@ -379,299 +381,6 b' def _attrname(name):' | |||||
379 | return str(name) |
|
381 | return str(name) | |
380 |
|
382 | |||
381 |
|
383 | |||
382 | COLOR_BLACK = 0 |
|
|||
383 | COLOR_RED = 1 |
|
|||
384 | COLOR_GREEN = 2 |
|
|||
385 | COLOR_YELLOW = 3 |
|
|||
386 | COLOR_BLUE = 4 |
|
|||
387 | COLOR_MAGENTA = 5 |
|
|||
388 | COLOR_CYAN = 6 |
|
|||
389 | COLOR_WHITE = 7 |
|
|||
390 |
|
||||
391 | A_BLINK = 1<<0 # Blinking text |
|
|||
392 | A_BOLD = 1<<1 # Extra bright or bold text |
|
|||
393 | A_DIM = 1<<2 # Half bright text |
|
|||
394 | A_REVERSE = 1<<3 # Reverse-video text |
|
|||
395 | A_STANDOUT = 1<<4 # The best highlighting mode available |
|
|||
396 | A_UNDERLINE = 1<<5 # Underlined text |
|
|||
397 |
|
||||
398 |
|
||||
399 | class Style(object): |
|
|||
400 | """ |
|
|||
401 | Store foreground color, background color and attribute (bold, underlined |
|
|||
402 | etc.). |
|
|||
403 | """ |
|
|||
404 | __slots__ = ("fg", "bg", "attrs") |
|
|||
405 |
|
||||
406 | COLORNAMES = { |
|
|||
407 | "black": COLOR_BLACK, |
|
|||
408 | "red": COLOR_RED, |
|
|||
409 | "green": COLOR_GREEN, |
|
|||
410 | "yellow": COLOR_YELLOW, |
|
|||
411 | "blue": COLOR_BLUE, |
|
|||
412 | "magenta": COLOR_MAGENTA, |
|
|||
413 | "cyan": COLOR_CYAN, |
|
|||
414 | "white": COLOR_WHITE, |
|
|||
415 | } |
|
|||
416 | ATTRNAMES = { |
|
|||
417 | "blink": A_BLINK, |
|
|||
418 | "bold": A_BOLD, |
|
|||
419 | "dim": A_DIM, |
|
|||
420 | "reverse": A_REVERSE, |
|
|||
421 | "standout": A_STANDOUT, |
|
|||
422 | "underline": A_UNDERLINE, |
|
|||
423 | } |
|
|||
424 |
|
||||
425 | def __init__(self, fg, bg, attrs=0): |
|
|||
426 | """ |
|
|||
427 | Create a ``Style`` object with ``fg`` as the foreground color, |
|
|||
428 | ``bg`` as the background color and ``attrs`` as the attributes. |
|
|||
429 |
|
||||
430 | Examples: |
|
|||
431 |
|
||||
432 | >>> Style(COLOR_RED, COLOR_BLACK) |
|
|||
433 | >>> Style(COLOR_YELLOW, COLOR_BLUE, A_BOLD|A_UNDERLINE) |
|
|||
434 | """ |
|
|||
435 | self.fg = fg |
|
|||
436 | self.bg = bg |
|
|||
437 | self.attrs = attrs |
|
|||
438 |
|
||||
439 | def __call__(self, *args): |
|
|||
440 | text = Text() |
|
|||
441 | for arg in args: |
|
|||
442 | if isinstance(arg, Text): |
|
|||
443 | text.extend(arg) |
|
|||
444 | else: |
|
|||
445 | text.append((self, arg)) |
|
|||
446 | return text |
|
|||
447 |
|
||||
448 | def __eq__(self, other): |
|
|||
449 | return self.fg == other.fg and self.bg == other.bg and self.attrs == other.attrs |
|
|||
450 |
|
||||
451 | def __neq__(self, other): |
|
|||
452 | return self.fg != other.fg or self.bg != other.bg or self.attrs != other.attrs |
|
|||
453 |
|
||||
454 | def __repr__(self): |
|
|||
455 | color2name = ("black", "red", "green", "yellow", "blue", "magenta", "cyan", "white") |
|
|||
456 | attrs2name = ("blink", "bold", "dim", "reverse", "standout", "underline") |
|
|||
457 |
|
||||
458 | return "<%s fg=%s bg=%s attrs=%s>" % ( |
|
|||
459 | self.__class__.__name__, color2name[self.fg], color2name[self.bg], |
|
|||
460 | "|".join([attrs2name[b] for b in xrange(6) if self.attrs&(1<<b)]) or 0) |
|
|||
461 |
|
||||
462 | def fromstr(cls, value): |
|
|||
463 | """ |
|
|||
464 | Create a ``Style`` object from a string. The format looks like this: |
|
|||
465 | ``"red:black:bold|blink"``. |
|
|||
466 | """ |
|
|||
467 | # defaults |
|
|||
468 | fg = COLOR_WHITE |
|
|||
469 | bg = COLOR_BLACK |
|
|||
470 | attrs = 0 |
|
|||
471 |
|
||||
472 | parts = value.split(":") |
|
|||
473 | if len(parts) > 0: |
|
|||
474 | fg = cls.COLORNAMES[parts[0].lower()] |
|
|||
475 | if len(parts) > 1: |
|
|||
476 | bg = cls.COLORNAMES[parts[1].lower()] |
|
|||
477 | if len(parts) > 2: |
|
|||
478 | for strattr in parts[2].split("|"): |
|
|||
479 | attrs |= cls.ATTRNAMES[strattr.lower()] |
|
|||
480 | return cls(fg, bg, attrs) |
|
|||
481 | fromstr = classmethod(fromstr) |
|
|||
482 |
|
||||
483 | def fromenv(cls, name, default): |
|
|||
484 | """ |
|
|||
485 | Create a ``Style`` from an environment variable named ``name`` |
|
|||
486 | (using ``default`` if the environment variable doesn't exist). |
|
|||
487 | """ |
|
|||
488 | return cls.fromstr(os.environ.get(name, default)) |
|
|||
489 | fromenv = classmethod(fromenv) |
|
|||
490 |
|
||||
491 |
|
||||
492 | def switchstyle(s1, s2): |
|
|||
493 | """ |
|
|||
494 | Return the ANSI escape sequence needed to switch from style ``s1`` to |
|
|||
495 | style ``s2``. |
|
|||
496 | """ |
|
|||
497 | attrmask = (A_BLINK|A_BOLD|A_UNDERLINE|A_REVERSE) |
|
|||
498 | a1 = s1.attrs & attrmask |
|
|||
499 | a2 = s2.attrs & attrmask |
|
|||
500 |
|
||||
501 | args = [] |
|
|||
502 | if s1 != s2: |
|
|||
503 | # do we have to get rid of the bold/underline/blink bit? |
|
|||
504 | # (can only be done by a reset) |
|
|||
505 | # use reset when our target color is the default color |
|
|||
506 | # (this is shorter than 37;40) |
|
|||
507 | if (a1 & ~a2 or s2==style_default): |
|
|||
508 | args.append("0") |
|
|||
509 | s1 = style_default |
|
|||
510 | a1 = 0 |
|
|||
511 |
|
||||
512 | # now we know that old and new color have the same boldness, |
|
|||
513 | # or the new color is bold and the old isn't, |
|
|||
514 | # i.e. we only might have to switch bold on, not off |
|
|||
515 | if not (a1 & A_BOLD) and (a2 & A_BOLD): |
|
|||
516 | args.append("1") |
|
|||
517 |
|
||||
518 | # Fix underline |
|
|||
519 | if not (a1 & A_UNDERLINE) and (a2 & A_UNDERLINE): |
|
|||
520 | args.append("4") |
|
|||
521 |
|
||||
522 | # Fix blink |
|
|||
523 | if not (a1 & A_BLINK) and (a2 & A_BLINK): |
|
|||
524 | args.append("5") |
|
|||
525 |
|
||||
526 | # Fix reverse |
|
|||
527 | if not (a1 & A_REVERSE) and (a2 & A_REVERSE): |
|
|||
528 | args.append("7") |
|
|||
529 |
|
||||
530 | # Fix foreground color |
|
|||
531 | if s1.fg != s2.fg: |
|
|||
532 | args.append("3%d" % s2.fg) |
|
|||
533 |
|
||||
534 | # Finally fix the background color |
|
|||
535 | if s1.bg != s2.bg: |
|
|||
536 | args.append("4%d" % s2.bg) |
|
|||
537 |
|
||||
538 | if args: |
|
|||
539 | return "\033[%sm" % ";".join(args) |
|
|||
540 | return "" |
|
|||
541 |
|
||||
542 |
|
||||
543 | class Text(list): |
|
|||
544 | """ |
|
|||
545 | A colored string. A ``Text`` object is a sequence, the sequence |
|
|||
546 | items will be ``(style, string)`` tuples. |
|
|||
547 | """ |
|
|||
548 |
|
||||
549 | def __init__(self, *args): |
|
|||
550 | list.__init__(self) |
|
|||
551 | self.append(*args) |
|
|||
552 |
|
||||
553 | def __repr__(self): |
|
|||
554 | return "%s.%s(%s)" % ( |
|
|||
555 | self.__class__.__module__, self.__class__.__name__, |
|
|||
556 | list.__repr__(self)[1:-1]) |
|
|||
557 |
|
||||
558 | def append(self, *args): |
|
|||
559 | for arg in args: |
|
|||
560 | if isinstance(arg, Text): |
|
|||
561 | self.extend(arg) |
|
|||
562 | elif isinstance(arg, tuple): # must be (style, string) |
|
|||
563 | list.append(self, arg) |
|
|||
564 | elif isinstance(arg, unicode): |
|
|||
565 | list.append(self, (style_default, arg)) |
|
|||
566 | else: |
|
|||
567 | list.append(self, (style_default, str(arg))) |
|
|||
568 |
|
||||
569 | def insert(self, index, *args): |
|
|||
570 | self[index:index] = Text(*args) |
|
|||
571 |
|
||||
572 | def __add__(self, other): |
|
|||
573 | new = Text() |
|
|||
574 | new.append(self) |
|
|||
575 | new.append(other) |
|
|||
576 | return new |
|
|||
577 |
|
||||
578 | def __iadd__(self, other): |
|
|||
579 | self.append(other) |
|
|||
580 | return self |
|
|||
581 |
|
||||
582 | def format(self, styled=True): |
|
|||
583 | """ |
|
|||
584 | This generator yields the strings that will make up the final |
|
|||
585 | colorized string. |
|
|||
586 | """ |
|
|||
587 | if styled: |
|
|||
588 | oldstyle = style_default |
|
|||
589 | for (style, string) in self: |
|
|||
590 | if not isinstance(style, (int, long)): |
|
|||
591 | switch = switchstyle(oldstyle, style) |
|
|||
592 | if switch: |
|
|||
593 | yield switch |
|
|||
594 | if string: |
|
|||
595 | yield string |
|
|||
596 | oldstyle = style |
|
|||
597 | switch = switchstyle(oldstyle, style_default) |
|
|||
598 | if switch: |
|
|||
599 | yield switch |
|
|||
600 | else: |
|
|||
601 | for (style, string) in self: |
|
|||
602 | if not isinstance(style, (int, long)): |
|
|||
603 | yield string |
|
|||
604 |
|
||||
605 | def string(self, styled=True): |
|
|||
606 | """ |
|
|||
607 | Return the resulting string (with escape sequences, if ``styled`` |
|
|||
608 | is true). |
|
|||
609 | """ |
|
|||
610 | return "".join(self.format(styled)) |
|
|||
611 |
|
||||
612 | def __str__(self): |
|
|||
613 | """ |
|
|||
614 | Return the resulting string with ANSI escape sequences. |
|
|||
615 | """ |
|
|||
616 | return self.string(False) |
|
|||
617 |
|
||||
618 | def write(self, stream, styled=True): |
|
|||
619 | for part in self.format(styled): |
|
|||
620 | stream.write(part) |
|
|||
621 |
|
||||
622 | def __xrepr__(self, mode="default"): |
|
|||
623 | yield (-1, True) |
|
|||
624 | for info in self: |
|
|||
625 | yield info |
|
|||
626 |
|
||||
627 |
|
||||
628 | if curses is not None: |
|
|||
629 | # This is probably just range(8) |
|
|||
630 | COLOR2CURSES = [ |
|
|||
631 | COLOR_BLACK, |
|
|||
632 | COLOR_RED, |
|
|||
633 | COLOR_GREEN, |
|
|||
634 | COLOR_YELLOW, |
|
|||
635 | COLOR_BLUE, |
|
|||
636 | COLOR_MAGENTA, |
|
|||
637 | COLOR_CYAN, |
|
|||
638 | COLOR_WHITE, |
|
|||
639 | ] |
|
|||
640 |
|
||||
641 | A2CURSES = { |
|
|||
642 | A_BLINK: curses.A_BLINK, |
|
|||
643 | A_BOLD: curses.A_BOLD, |
|
|||
644 | A_DIM: curses.A_DIM, |
|
|||
645 | A_REVERSE: curses.A_REVERSE, |
|
|||
646 | A_STANDOUT: curses.A_STANDOUT, |
|
|||
647 | A_UNDERLINE: curses.A_UNDERLINE, |
|
|||
648 | } |
|
|||
649 |
|
||||
650 |
|
||||
651 | # default style |
|
|||
652 | style_default = Style(COLOR_WHITE, COLOR_BLACK) |
|
|||
653 |
|
||||
654 | # Styles for datatypes |
|
|||
655 | style_type_none = Style(COLOR_MAGENTA, COLOR_BLACK) |
|
|||
656 | style_type_bool = Style(COLOR_MAGENTA, COLOR_BLACK) |
|
|||
657 | style_type_number = Style(COLOR_YELLOW, COLOR_BLACK) |
|
|||
658 | style_type_datetime = Style(COLOR_MAGENTA, COLOR_BLACK) |
|
|||
659 |
|
||||
660 | # Style for URLs and file/directory names |
|
|||
661 | style_url = Style(COLOR_GREEN, COLOR_BLACK) |
|
|||
662 | style_dir = Style(COLOR_CYAN, COLOR_BLACK) |
|
|||
663 | style_file = Style(COLOR_GREEN, COLOR_BLACK) |
|
|||
664 |
|
||||
665 | # Style for ellipsis (when an output has been shortened |
|
|||
666 | style_ellisis = Style(COLOR_RED, COLOR_BLACK) |
|
|||
667 |
|
||||
668 | # Style for displaying exceptions |
|
|||
669 | style_error = Style(COLOR_RED, COLOR_BLACK) |
|
|||
670 |
|
||||
671 | # Style for displaying non-existing attributes |
|
|||
672 | style_nodata = Style(COLOR_RED, COLOR_BLACK) |
|
|||
673 |
|
||||
674 |
|
||||
675 | def xrepr(item, mode): |
|
384 | def xrepr(item, mode): | |
676 | try: |
|
385 | try: | |
677 | func = item.__xrepr__ |
|
386 | func = item.__xrepr__ | |
@@ -685,62 +394,62 b' def xrepr(item, mode):' | |||||
685 | raise |
|
394 | raise | |
686 | except Exception: |
|
395 | except Exception: | |
687 | yield (-1, True) |
|
396 | yield (-1, True) | |
688 | yield (style_default, repr(item)) |
|
397 | yield (astyle.style_default, repr(item)) | |
689 | return |
|
398 | return | |
690 | if item is None: |
|
399 | if item is None: | |
691 | yield (-1, True) |
|
400 | yield (-1, True) | |
692 | yield (style_type_none, repr(item)) |
|
401 | yield (astyle.style_type_none, repr(item)) | |
693 | elif isinstance(item, bool): |
|
402 | elif isinstance(item, bool): | |
694 | yield (-1, True) |
|
403 | yield (-1, True) | |
695 | yield (style_type_bool, repr(item)) |
|
404 | yield (astyle.style_type_bool, repr(item)) | |
696 | elif isinstance(item, str): |
|
405 | elif isinstance(item, str): | |
697 | yield (-1, True) |
|
406 | yield (-1, True) | |
698 | if mode == "cell": |
|
407 | if mode == "cell": | |
699 | yield (style_default, repr(item.expandtabs(tab))[1:-1]) |
|
408 | yield (astyle.style_default, repr(item.expandtabs(tab))[1:-1]) | |
700 | else: |
|
409 | else: | |
701 | yield (style_default, repr(item)) |
|
410 | yield (astyle.style_default, repr(item)) | |
702 | elif isinstance(item, unicode): |
|
411 | elif isinstance(item, unicode): | |
703 | yield (-1, True) |
|
412 | yield (-1, True) | |
704 | if mode == "cell": |
|
413 | if mode == "cell": | |
705 | yield (style_default, repr(item.expandtabs(tab))[2:-1]) |
|
414 | yield (astyle.style_default, repr(item.expandtabs(tab))[2:-1]) | |
706 | else: |
|
415 | else: | |
707 | yield (style_default, repr(item)) |
|
416 | yield (astyle.style_default, repr(item)) | |
708 | elif isinstance(item, (int, long, float)): |
|
417 | elif isinstance(item, (int, long, float)): | |
709 | yield (1, True) |
|
418 | yield (1, True) | |
710 | yield (style_type_number, repr(item)) |
|
419 | yield (astyle.style_type_number, repr(item)) | |
711 | elif isinstance(item, complex): |
|
420 | elif isinstance(item, complex): | |
712 | yield (-1, True) |
|
421 | yield (-1, True) | |
713 | yield (style_type_number, repr(item)) |
|
422 | yield (astyle.style_type_number, repr(item)) | |
714 | elif isinstance(item, datetime.datetime): |
|
423 | elif isinstance(item, datetime.datetime): | |
715 | yield (-1, True) |
|
424 | yield (-1, True) | |
716 | if mode == "cell": |
|
425 | if mode == "cell": | |
717 | # Don't use strftime() here, as this requires year >= 1900 |
|
426 | # Don't use strftime() here, as this requires year >= 1900 | |
718 | yield (style_type_datetime, |
|
427 | yield (astyle.style_type_datetime, | |
719 | "%04d-%02d-%02d %02d:%02d:%02d.%06d" % \ |
|
428 | "%04d-%02d-%02d %02d:%02d:%02d.%06d" % \ | |
720 | (item.year, item.month, item.day, |
|
429 | (item.year, item.month, item.day, | |
721 | item.hour, item.minute, item.second, |
|
430 | item.hour, item.minute, item.second, | |
722 | item.microsecond), |
|
431 | item.microsecond), | |
723 | ) |
|
432 | ) | |
724 | else: |
|
433 | else: | |
725 | yield (style_type_datetime, repr(item)) |
|
434 | yield (astyle.style_type_datetime, repr(item)) | |
726 | elif isinstance(item, datetime.date): |
|
435 | elif isinstance(item, datetime.date): | |
727 | yield (-1, True) |
|
436 | yield (-1, True) | |
728 | if mode == "cell": |
|
437 | if mode == "cell": | |
729 | yield (style_type_datetime, |
|
438 | yield (astyle.style_type_datetime, | |
730 | "%04d-%02d-%02d" % (item.year, item.month, item.day)) |
|
439 | "%04d-%02d-%02d" % (item.year, item.month, item.day)) | |
731 | else: |
|
440 | else: | |
732 | yield (style_type_datetime, repr(item)) |
|
441 | yield (astyle.style_type_datetime, repr(item)) | |
733 | elif isinstance(item, datetime.time): |
|
442 | elif isinstance(item, datetime.time): | |
734 | yield (-1, True) |
|
443 | yield (-1, True) | |
735 | if mode == "cell": |
|
444 | if mode == "cell": | |
736 | yield (style_type_datetime, |
|
445 | yield (astyle.style_type_datetime, | |
737 | "%02d:%02d:%02d.%06d" % \ |
|
446 | "%02d:%02d:%02d.%06d" % \ | |
738 | (item.hour, item.minute, item.second, item.microsecond)) |
|
447 | (item.hour, item.minute, item.second, item.microsecond)) | |
739 | else: |
|
448 | else: | |
740 | yield (style_type_datetime, repr(item)) |
|
449 | yield (astyle.style_type_datetime, repr(item)) | |
741 | elif isinstance(item, datetime.timedelta): |
|
450 | elif isinstance(item, datetime.timedelta): | |
742 | yield (-1, True) |
|
451 | yield (-1, True) | |
743 | yield (style_type_datetime, repr(item)) |
|
452 | yield (astyle.style_type_datetime, repr(item)) | |
744 | elif isinstance(item, Exception): |
|
453 | elif isinstance(item, Exception): | |
745 | yield (-1, True) |
|
454 | yield (-1, True) | |
746 | if item.__class__.__module__ == "exceptions": |
|
455 | if item.__class__.__module__ == "exceptions": | |
@@ -749,9 +458,9 b' def xrepr(item, mode):' | |||||
749 | classname = "%s.%s" % \ |
|
458 | classname = "%s.%s" % \ | |
750 | (item.__class__.__module__, item.__class__.__name__) |
|
459 | (item.__class__.__module__, item.__class__.__name__) | |
751 | if mode == "header" or mode == "footer": |
|
460 | if mode == "header" or mode == "footer": | |
752 | yield (style_error, "%s: %s" % (classname, item)) |
|
461 | yield (astyle.style_error, "%s: %s" % (classname, item)) | |
753 | else: |
|
462 | else: | |
754 | yield (style_error, classname) |
|
463 | yield (astyle.style_error, classname) | |
755 | elif isinstance(item, (list, tuple)): |
|
464 | elif isinstance(item, (list, tuple)): | |
756 | yield (-1, False) |
|
465 | yield (-1, False) | |
757 | if mode == "header" or mode == "footer": |
|
466 | if mode == "header" or mode == "footer": | |
@@ -760,22 +469,22 b' def xrepr(item, mode):' | |||||
760 | else: |
|
469 | else: | |
761 | classname = "%s.%s" % \ |
|
470 | classname = "%s.%s" % \ | |
762 | (item.__class__.__module__,item.__class__.__name__) |
|
471 | (item.__class__.__module__,item.__class__.__name__) | |
763 | yield (style_default, |
|
472 | yield (astyle.style_default, | |
764 | "<%s object with %d items at 0x%x>" % \ |
|
473 | "<%s object with %d items at 0x%x>" % \ | |
765 | (classname, len(item), id(item))) |
|
474 | (classname, len(item), id(item))) | |
766 | else: |
|
475 | else: | |
767 | if isinstance(item, list): |
|
476 | if isinstance(item, list): | |
768 | yield (style_default, "[") |
|
477 | yield (astyle.style_default, "[") | |
769 | end = "]" |
|
478 | end = "]" | |
770 | else: |
|
479 | else: | |
771 | yield (style_default, "(") |
|
480 | yield (astyle.style_default, "(") | |
772 | end = ")" |
|
481 | end = ")" | |
773 | for (i, subitem) in enumerate(item): |
|
482 | for (i, subitem) in enumerate(item): | |
774 | if i: |
|
483 | if i: | |
775 | yield (style_default, ", ") |
|
484 | yield (astyle.style_default, ", ") | |
776 | for part in xrepr(subitem, "default"): |
|
485 | for part in xrepr(subitem, "default"): | |
777 | yield part |
|
486 | yield part | |
778 | yield (style_default, end) |
|
487 | yield (astyle.style_default, end) | |
779 | elif isinstance(item, (dict, types.DictProxyType)): |
|
488 | elif isinstance(item, (dict, types.DictProxyType)): | |
780 | yield (-1, False) |
|
489 | yield (-1, False) | |
781 | if mode == "header" or mode == "footer": |
|
490 | if mode == "header" or mode == "footer": | |
@@ -784,28 +493,28 b' def xrepr(item, mode):' | |||||
784 | else: |
|
493 | else: | |
785 | classname = "%s.%s" % \ |
|
494 | classname = "%s.%s" % \ | |
786 | (item.__class__.__module__,item.__class__.__name__) |
|
495 | (item.__class__.__module__,item.__class__.__name__) | |
787 | yield (style_default, |
|
496 | yield (astyle.style_default, | |
788 | "<%s object with %d items at 0x%x>" % \ |
|
497 | "<%s object with %d items at 0x%x>" % \ | |
789 | (classname, len(item), id(item))) |
|
498 | (classname, len(item), id(item))) | |
790 | else: |
|
499 | else: | |
791 | if isinstance(item, dict): |
|
500 | if isinstance(item, dict): | |
792 | yield (style_default, "{") |
|
501 | yield (astyle.style_default, "{") | |
793 | end = "}" |
|
502 | end = "}" | |
794 | else: |
|
503 | else: | |
795 | yield (style_default, "dictproxy((") |
|
504 | yield (astyle.style_default, "dictproxy((") | |
796 | end = "})" |
|
505 | end = "})" | |
797 | for (i, (key, value)) in enumerate(item.iteritems()): |
|
506 | for (i, (key, value)) in enumerate(item.iteritems()): | |
798 | if i: |
|
507 | if i: | |
799 | yield (style_default, ", ") |
|
508 | yield (astyle.style_default, ", ") | |
800 | for part in xrepr(key, "default"): |
|
509 | for part in xrepr(key, "default"): | |
801 | yield part |
|
510 | yield part | |
802 | yield (style_default, ": ") |
|
511 | yield (astyle.style_default, ": ") | |
803 | for part in xrepr(value, "default"): |
|
512 | for part in xrepr(value, "default"): | |
804 | yield part |
|
513 | yield part | |
805 | yield (style_default, end) |
|
514 | yield (astyle.style_default, end) | |
806 | else: |
|
515 | else: | |
807 | yield (-1, True) |
|
516 | yield (-1, True) | |
808 | yield (style_default, repr(item)) |
|
517 | yield (astyle.style_default, repr(item)) | |
809 |
|
518 | |||
810 |
|
519 | |||
811 | def xattrs(item, mode): |
|
520 | def xattrs(item, mode): | |
@@ -874,15 +583,15 b' class ichain(Pipe):' | |||||
874 | if mode == "header" or mode == "footer": |
|
583 | if mode == "header" or mode == "footer": | |
875 | for (i, item) in enumerate(self.iters): |
|
584 | for (i, item) in enumerate(self.iters): | |
876 | if i: |
|
585 | if i: | |
877 | yield (style_default, "+") |
|
586 | yield (astyle.style_default, "+") | |
878 | if isinstance(item, Pipe): |
|
587 | if isinstance(item, Pipe): | |
879 | yield (style_default, "(") |
|
588 | yield (astyle.style_default, "(") | |
880 | for part in xrepr(item, mode): |
|
589 | for part in xrepr(item, mode): | |
881 | yield part |
|
590 | yield part | |
882 | if isinstance(item, Pipe): |
|
591 | if isinstance(item, Pipe): | |
883 | yield (style_default, ")") |
|
592 | yield (astyle.style_default, ")") | |
884 | else: |
|
593 | else: | |
885 | yield (style_default, repr(self)) |
|
594 | yield (astyle.style_default, repr(self)) | |
886 |
|
595 | |||
887 | def __repr__(self): |
|
596 | def __repr__(self): | |
888 | args = ", ".join([repr(it) for it in self.iters]) |
|
597 | args = ", ".join([repr(it) for it in self.iters]) | |
@@ -1124,13 +833,13 b' class ifile(path.path):' | |||||
1124 | try: |
|
833 | try: | |
1125 | if self.isdir(): |
|
834 | if self.isdir(): | |
1126 | name = "idir" |
|
835 | name = "idir" | |
1127 | style = style_dir |
|
836 | style = astyle.style_dir | |
1128 | else: |
|
837 | else: | |
1129 | name = "ifile" |
|
838 | name = "ifile" | |
1130 | style = style_file |
|
839 | style = astyle.style_file | |
1131 | except IOError: |
|
840 | except IOError: | |
1132 | name = "ifile" |
|
841 | name = "ifile" | |
1133 | style = style_default |
|
842 | style = astyle.style_default | |
1134 | if mode == "cell" or mode in "header" or mode == "footer": |
|
843 | if mode == "cell" or mode in "header" or mode == "footer": | |
1135 | abspath = repr(path._base(self.normpath())) |
|
844 | abspath = repr(path._base(self.normpath())) | |
1136 | if abspath.startswith("u"): |
|
845 | if abspath.startswith("u"): | |
@@ -1160,7 +869,7 b' class iparentdir(ifile):' | |||||
1160 | def __xrepr__(self, mode): |
|
869 | def __xrepr__(self, mode): | |
1161 | yield (-1, True) |
|
870 | yield (-1, True) | |
1162 | if mode == "cell": |
|
871 | if mode == "cell": | |
1163 | yield (style_dir, os.pardir) |
|
872 | yield (astyle.style_dir, os.pardir) | |
1164 | else: |
|
873 | else: | |
1165 | for part in ifile.__xrepr__(self, mode): |
|
874 | for part in ifile.__xrepr__(self, mode): | |
1166 | yield part |
|
875 | yield part | |
@@ -1209,9 +918,10 b' class iglob(Table):' | |||||
1209 | def __xrepr__(self, mode): |
|
918 | def __xrepr__(self, mode): | |
1210 | yield (-1, True) |
|
919 | yield (-1, True) | |
1211 | if mode == "header" or mode == "footer" or mode == "cell": |
|
920 | if mode == "header" or mode == "footer" or mode == "cell": | |
1212 | yield (style_default, "%s(%r)" % (self.__class__.__name__, self.glob)) |
|
921 | yield (astyle.style_default, | |
|
922 | "%s(%r)" % (self.__class__.__name__, self.glob)) | |||
1213 | else: |
|
923 | else: | |
1214 | yield (style_default, repr(self)) |
|
924 | yield (astyle.style_default, repr(self)) | |
1215 |
|
925 | |||
1216 | def __repr__(self): |
|
926 | def __repr__(self): | |
1217 | return "%s.%s(%r)" % \ |
|
927 | return "%s.%s(%r)" % \ | |
@@ -1243,9 +953,10 b' class iwalk(Table):' | |||||
1243 | def __xrepr__(self, mode): |
|
953 | def __xrepr__(self, mode): | |
1244 | yield (-1, True) |
|
954 | yield (-1, True) | |
1245 | if mode == "header" or mode == "footer" or mode == "cell": |
|
955 | if mode == "header" or mode == "footer" or mode == "cell": | |
1246 | yield (style_default, "%s(%r)" % (self.__class__.__name__, self.base)) |
|
956 | yield (astyle.style_default, | |
|
957 | "%s(%r)" % (self.__class__.__name__, self.base)) | |||
1247 | else: |
|
958 | else: | |
1248 | yield (style_default, repr(self)) |
|
959 | yield (astyle.style_default, repr(self)) | |
1249 |
|
960 | |||
1250 | def __repr__(self): |
|
961 | def __repr__(self): | |
1251 | return "%s.%s(%r)" % \ |
|
962 | return "%s.%s(%r)" % \ | |
@@ -1330,9 +1041,9 b' class ipwd(Table):' | |||||
1330 | def __xrepr__(self, mode): |
|
1041 | def __xrepr__(self, mode): | |
1331 | yield (-1, True) |
|
1042 | yield (-1, True) | |
1332 | if mode == "header" or mode == "footer" or mode == "cell": |
|
1043 | if mode == "header" or mode == "footer" or mode == "cell": | |
1333 | yield (style_default, "%s()" % self.__class__.__name__) |
|
1044 | yield (astyle.style_default, "%s()" % self.__class__.__name__) | |
1334 | else: |
|
1045 | else: | |
1335 | yield (style_default, repr(self)) |
|
1046 | yield (astyle.style_default, repr(self)) | |
1336 |
|
1047 | |||
1337 |
|
1048 | |||
1338 | class igrpentry(object): |
|
1049 | class igrpentry(object): | |
@@ -1379,16 +1090,16 b' class igrpentry(object):' | |||||
1379 | def __xrepr__(self, mode): |
|
1090 | def __xrepr__(self, mode): | |
1380 | yield (-1, True) |
|
1091 | yield (-1, True) | |
1381 | if mode == "header" or mode == "footer" or mode == "cell": |
|
1092 | if mode == "header" or mode == "footer" or mode == "cell": | |
1382 | yield (style_default, "group ") |
|
1093 | yield (astyle.style_default, "group ") | |
1383 | try: |
|
1094 | try: | |
1384 | yield (style_default, self.name) |
|
1095 | yield (astyle.style_default, self.name) | |
1385 | except KeyError: |
|
1096 | except KeyError: | |
1386 | if isinstance(self._id, basestring): |
|
1097 | if isinstance(self._id, basestring): | |
1387 | yield (style_default, self.name_id) |
|
1098 | yield (astyle.style_default, self.name_id) | |
1388 | else: |
|
1099 | else: | |
1389 | yield (style_type_number, str(self._id)) |
|
1100 | yield (astyle.style_type_number, str(self._id)) | |
1390 | else: |
|
1101 | else: | |
1391 | yield (style_default, repr(self)) |
|
1102 | yield (astyle.style_default, repr(self)) | |
1392 |
|
1103 | |||
1393 | def __xiter__(self, mode): |
|
1104 | def __xiter__(self, mode): | |
1394 | for member in self.mem: |
|
1105 | for member in self.mem: | |
@@ -1410,9 +1121,9 b' class igrp(Table):' | |||||
1410 | def __xrepr__(self, mode): |
|
1121 | def __xrepr__(self, mode): | |
1411 | yield (-1, False) |
|
1122 | yield (-1, False) | |
1412 | if mode == "header" or mode == "footer": |
|
1123 | if mode == "header" or mode == "footer": | |
1413 | yield (style_default, "%s()" % self.__class__.__name__) |
|
1124 | yield (astyle.style_default, "%s()" % self.__class__.__name__) | |
1414 | else: |
|
1125 | else: | |
1415 | yield (style_default, repr(self)) |
|
1126 | yield (astyle.style_default, repr(self)) | |
1416 |
|
1127 | |||
1417 |
|
1128 | |||
1418 | class Fields(object): |
|
1129 | class Fields(object): | |
@@ -1427,26 +1138,26 b' class Fields(object):' | |||||
1427 | def __xrepr__(self, mode): |
|
1138 | def __xrepr__(self, mode): | |
1428 | yield (-1, False) |
|
1139 | yield (-1, False) | |
1429 | if mode == "header" or mode == "cell": |
|
1140 | if mode == "header" or mode == "cell": | |
1430 | yield (style_default, self.__class__.__name__) |
|
1141 | yield (astyle.style_default, self.__class__.__name__) | |
1431 | yield (style_default, "(") |
|
1142 | yield (astyle.style_default, "(") | |
1432 | for (i, f) in enumerate(self.__fieldnames): |
|
1143 | for (i, f) in enumerate(self.__fieldnames): | |
1433 | if i: |
|
1144 | if i: | |
1434 | yield (style_default, ", ") |
|
1145 | yield (astyle.style_default, ", ") | |
1435 | yield (style_default, f) |
|
1146 | yield (astyle.style_default, f) | |
1436 | yield (style_default, "=") |
|
1147 | yield (astyle.style_default, "=") | |
1437 | for part in xrepr(getattr(self, f), "default"): |
|
1148 | for part in xrepr(getattr(self, f), "default"): | |
1438 | yield part |
|
1149 | yield part | |
1439 | yield (style_default, ")") |
|
1150 | yield (astyle.style_default, ")") | |
1440 | elif mode == "footer": |
|
1151 | elif mode == "footer": | |
1441 | yield (style_default, self.__class__.__name__) |
|
1152 | yield (astyle.style_default, self.__class__.__name__) | |
1442 | yield (style_default, "(") |
|
1153 | yield (astyle.style_default, "(") | |
1443 | for (i, f) in enumerate(self.__fieldnames): |
|
1154 | for (i, f) in enumerate(self.__fieldnames): | |
1444 | if i: |
|
1155 | if i: | |
1445 | yield (style_default, ", ") |
|
1156 | yield (astyle.style_default, ", ") | |
1446 | yield (style_default, f) |
|
1157 | yield (astyle.style_default, f) | |
1447 | yield (style_default, ")") |
|
1158 | yield (astyle.style_default, ")") | |
1448 | else: |
|
1159 | else: | |
1449 | yield (style_default, repr(self)) |
|
1160 | yield (astyle.style_default, repr(self)) | |
1450 |
|
1161 | |||
1451 |
|
1162 | |||
1452 | class FieldTable(Table, list): |
|
1163 | class FieldTable(Table, list): | |
@@ -1464,15 +1175,15 b' class FieldTable(Table, list):' | |||||
1464 | def __xrepr__(self, mode): |
|
1175 | def __xrepr__(self, mode): | |
1465 | yield (-1, False) |
|
1176 | yield (-1, False) | |
1466 | if mode == "header" or mode == "footer": |
|
1177 | if mode == "header" or mode == "footer": | |
1467 | yield (style_default, self.__class__.__name__) |
|
1178 | yield (astyle.style_default, self.__class__.__name__) | |
1468 | yield (style_default, "(") |
|
1179 | yield (astyle.style_default, "(") | |
1469 | for (i, f) in enumerate(self.__fieldnames): |
|
1180 | for (i, f) in enumerate(self.__fieldnames): | |
1470 | if i: |
|
1181 | if i: | |
1471 | yield (style_default, ", ") |
|
1182 | yield (astyle.style_default, ", ") | |
1472 | yield (style_default, f) |
|
1183 | yield (astyle.style_default, f) | |
1473 | yield (style_default, ")") |
|
1184 | yield (astyle.style_default, ")") | |
1474 | else: |
|
1185 | else: | |
1475 | yield (style_default, repr(self)) |
|
1186 | yield (astyle.style_default, repr(self)) | |
1476 |
|
1187 | |||
1477 | def __repr__(self): |
|
1188 | def __repr__(self): | |
1478 | return "<%s.%s object with fields=%r at 0x%x>" % \ |
|
1189 | return "<%s.%s object with fields=%r at 0x%x>" % \ | |
@@ -1487,16 +1198,16 b' class List(list):' | |||||
1487 | def __xrepr__(self, mode): |
|
1198 | def __xrepr__(self, mode): | |
1488 | yield (-1, False) |
|
1199 | yield (-1, False) | |
1489 | if mode == "header" or mode == "cell" or mode == "footer" or mode == "default": |
|
1200 | if mode == "header" or mode == "cell" or mode == "footer" or mode == "default": | |
1490 | yield (style_default, self.__class__.__name__) |
|
1201 | yield (astyle.style_default, self.__class__.__name__) | |
1491 | yield (style_default, "(") |
|
1202 | yield (astyle.style_default, "(") | |
1492 | for (i, item) in enumerate(self): |
|
1203 | for (i, item) in enumerate(self): | |
1493 | if i: |
|
1204 | if i: | |
1494 | yield (style_default, ", ") |
|
1205 | yield (astyle.style_default, ", ") | |
1495 | for part in xrepr(item, "default"): |
|
1206 | for part in xrepr(item, "default"): | |
1496 | yield part |
|
1207 | yield part | |
1497 | yield (style_default, ")") |
|
1208 | yield (astyle.style_default, ")") | |
1498 | else: |
|
1209 | else: | |
1499 | yield (style_default, repr(self)) |
|
1210 | yield (astyle.style_default, repr(self)) | |
1500 |
|
1211 | |||
1501 |
|
1212 | |||
1502 | class ienv(Table): |
|
1213 | class ienv(Table): | |
@@ -1516,9 +1227,9 b' class ienv(Table):' | |||||
1516 | def __xrepr__(self, mode): |
|
1227 | def __xrepr__(self, mode): | |
1517 | yield (-1, True) |
|
1228 | yield (-1, True) | |
1518 | if mode == "header" or mode == "cell": |
|
1229 | if mode == "header" or mode == "cell": | |
1519 | yield (style_default, "%s()" % self.__class__.__name__) |
|
1230 | yield (astyle.style_default, "%s()" % self.__class__.__name__) | |
1520 | else: |
|
1231 | else: | |
1521 | yield (style_default, repr(self)) |
|
1232 | yield (astyle.style_default, repr(self)) | |
1522 |
|
1233 | |||
1523 |
|
1234 | |||
1524 | class icsv(Pipe): |
|
1235 | class icsv(Pipe): | |
@@ -1548,18 +1259,18 b' class icsv(Pipe):' | |||||
1548 | if input is not None: |
|
1259 | if input is not None: | |
1549 | for part in xrepr(input, mode): |
|
1260 | for part in xrepr(input, mode): | |
1550 | yield part |
|
1261 | yield part | |
1551 | yield (style_default, " | ") |
|
1262 | yield (astyle.style_default, " | ") | |
1552 | yield (style_default, "%s(" % self.__class__.__name__) |
|
1263 | yield (astyle.style_default, "%s(" % self.__class__.__name__) | |
1553 | for (i, (name, value)) in enumerate(self.csvargs.iteritems()): |
|
1264 | for (i, (name, value)) in enumerate(self.csvargs.iteritems()): | |
1554 | if i: |
|
1265 | if i: | |
1555 | yield (style_default, ", ") |
|
1266 | yield (astyle.style_default, ", ") | |
1556 | yield (style_default, name) |
|
1267 | yield (astyle.style_default, name) | |
1557 | yield (style_default, "=") |
|
1268 | yield (astyle.style_default, "=") | |
1558 | for part in xrepr(value, "default"): |
|
1269 | for part in xrepr(value, "default"): | |
1559 | yield part |
|
1270 | yield part | |
1560 | yield (style_default, ")") |
|
1271 | yield (astyle.style_default, ")") | |
1561 | else: |
|
1272 | else: | |
1562 | yield (style_default, repr(self)) |
|
1273 | yield (astyle.style_default, repr(self)) | |
1563 |
|
1274 | |||
1564 | def __repr__(self): |
|
1275 | def __repr__(self): | |
1565 | args = ", ".join(["%s=%r" % item for item in self.csvargs.iteritems()]) |
|
1276 | args = ", ".join(["%s=%r" % item for item in self.csvargs.iteritems()]) | |
@@ -1596,9 +1307,10 b' class ix(Table):' | |||||
1596 | def __xrepr__(self, mode): |
|
1307 | def __xrepr__(self, mode): | |
1597 | yield (-1, True) |
|
1308 | yield (-1, True) | |
1598 | if mode == "header" or mode == "footer": |
|
1309 | if mode == "header" or mode == "footer": | |
1599 | yield (style_default, "%s(%r)" % (self.__class__.__name__, self.cmd)) |
|
1310 | yield (astyle.style_default, | |
|
1311 | "%s(%r)" % (self.__class__.__name__, self.cmd)) | |||
1600 | else: |
|
1312 | else: | |
1601 | yield (style_default, repr(self)) |
|
1313 | yield (astyle.style_default, repr(self)) | |
1602 |
|
1314 | |||
1603 | def __repr__(self): |
|
1315 | def __repr__(self): | |
1604 | return "%s.%s(%r)" % \ |
|
1316 | return "%s.%s(%r)" % \ | |
@@ -1676,13 +1388,13 b' class ifilter(Pipe):' | |||||
1676 | if input is not None: |
|
1388 | if input is not None: | |
1677 | for part in xrepr(input, mode): |
|
1389 | for part in xrepr(input, mode): | |
1678 | yield part |
|
1390 | yield part | |
1679 | yield (style_default, " | ") |
|
1391 | yield (astyle.style_default, " | ") | |
1680 | yield (style_default, "%s(" % self.__class__.__name__) |
|
1392 | yield (astyle.style_default, "%s(" % self.__class__.__name__) | |
1681 | for part in xrepr(self.expr, "default"): |
|
1393 | for part in xrepr(self.expr, "default"): | |
1682 | yield part |
|
1394 | yield part | |
1683 | yield (style_default, ")") |
|
1395 | yield (astyle.style_default, ")") | |
1684 | else: |
|
1396 | else: | |
1685 | yield (style_default, repr(self)) |
|
1397 | yield (astyle.style_default, repr(self)) | |
1686 |
|
1398 | |||
1687 | def __repr__(self): |
|
1399 | def __repr__(self): | |
1688 | return "<%s.%s expr=%r at 0x%x>" % \ |
|
1400 | return "<%s.%s expr=%r at 0x%x>" % \ | |
@@ -1745,13 +1457,13 b' class ieval(Pipe):' | |||||
1745 | if input is not None: |
|
1457 | if input is not None: | |
1746 | for part in xrepr(input, mode): |
|
1458 | for part in xrepr(input, mode): | |
1747 | yield part |
|
1459 | yield part | |
1748 | yield (style_default, " | ") |
|
1460 | yield (astyle.style_default, " | ") | |
1749 | yield (style_default, "%s(" % self.__class__.__name__) |
|
1461 | yield (astyle.style_default, "%s(" % self.__class__.__name__) | |
1750 | for part in xrepr(self.expr, "default"): |
|
1462 | for part in xrepr(self.expr, "default"): | |
1751 | yield part |
|
1463 | yield part | |
1752 | yield (style_default, ")") |
|
1464 | yield (astyle.style_default, ")") | |
1753 | else: |
|
1465 | else: | |
1754 | yield (style_default, repr(self)) |
|
1466 | yield (astyle.style_default, repr(self)) | |
1755 |
|
1467 | |||
1756 | def __repr__(self): |
|
1468 | def __repr__(self): | |
1757 | return "<%s.%s expr=%r at 0x%x>" % \ |
|
1469 | return "<%s.%s expr=%r at 0x%x>" % \ | |
@@ -1818,17 +1530,17 b' class isort(Pipe):' | |||||
1818 | if input is not None: |
|
1530 | if input is not None: | |
1819 | for part in xrepr(input, mode): |
|
1531 | for part in xrepr(input, mode): | |
1820 | yield part |
|
1532 | yield part | |
1821 | yield (style_default, " | ") |
|
1533 | yield (astyle.style_default, " | ") | |
1822 | yield (style_default, "%s(" % self.__class__.__name__) |
|
1534 | yield (astyle.style_default, "%s(" % self.__class__.__name__) | |
1823 | for part in xrepr(self.key, "default"): |
|
1535 | for part in xrepr(self.key, "default"): | |
1824 | yield part |
|
1536 | yield part | |
1825 | if self.reverse: |
|
1537 | if self.reverse: | |
1826 | yield (style_default, ", ") |
|
1538 | yield (astyle.style_default, ", ") | |
1827 | for part in xrepr(True, "default"): |
|
1539 | for part in xrepr(True, "default"): | |
1828 | yield part |
|
1540 | yield part | |
1829 | yield (style_default, ")") |
|
1541 | yield (astyle.style_default, ")") | |
1830 | else: |
|
1542 | else: | |
1831 | yield (style_default, repr(self)) |
|
1543 | yield (astyle.style_default, repr(self)) | |
1832 |
|
1544 | |||
1833 | def __repr__(self): |
|
1545 | def __repr__(self): | |
1834 | return "<%s.%s key=%r reverse=%r at 0x%x>" % \ |
|
1546 | return "<%s.%s key=%r reverse=%r at 0x%x>" % \ | |
@@ -1890,7 +1602,7 b' def xformat(value, mode, maxlength):' | |||||
1890 | align = None |
|
1602 | align = None | |
1891 | full = False |
|
1603 | full = False | |
1892 | width = 0 |
|
1604 | width = 0 | |
1893 | text = Text() |
|
1605 | text = astyle.Text() | |
1894 | for part in xrepr(value, mode): |
|
1606 | for part in xrepr(value, mode): | |
1895 | # part is (alignment, stop) |
|
1607 | # part is (alignment, stop) | |
1896 | if isinstance(part[0], int): |
|
1608 | if isinstance(part[0], int): | |
@@ -1903,7 +1615,7 b' def xformat(value, mode, maxlength):' | |||||
1903 | text.append(part) |
|
1615 | text.append(part) | |
1904 | width += len(part[1]) |
|
1616 | width += len(part[1]) | |
1905 | if width >= maxlength and not full: |
|
1617 | if width >= maxlength and not full: | |
1906 | text.append((style_ellisis, "...")) |
|
1618 | text.append((astyle.style_ellisis, "...")) | |
1907 | width += 3 |
|
1619 | width += 3 | |
1908 | break |
|
1620 | break | |
1909 | if align is None: # default to left alignment |
|
1621 | if align is None: # default to left alignment | |
@@ -1916,7 +1628,7 b' class idump(Display):' | |||||
1916 | maxattrlength = 200 |
|
1628 | maxattrlength = 200 | |
1917 |
|
1629 | |||
1918 | # Style for column names |
|
1630 | # Style for column names | |
1919 | style_header = Style(COLOR_WHITE, COLOR_BLACK, A_BOLD) |
|
1631 | style_header = astyle.Style.fromstr("white:black:bold") | |
1920 |
|
1632 | |||
1921 | def __init__(self, *attrs): |
|
1633 | def __init__(self, *attrs): | |
1922 | self.attrs = attrs |
|
1634 | self.attrs = attrs | |
@@ -2010,9 +1722,9 b' class XMode(object):' | |||||
2010 | def __xrepr__(self, mode): |
|
1722 | def __xrepr__(self, mode): | |
2011 | yield (-1, True) |
|
1723 | yield (-1, True) | |
2012 | if mode == "header" or mode == "footer": |
|
1724 | if mode == "header" or mode == "footer": | |
2013 | yield (style_default, self.title) |
|
1725 | yield (astyle.style_default, self.title) | |
2014 | else: |
|
1726 | else: | |
2015 | yield (style_default, repr(self)) |
|
1727 | yield (astyle.style_default, repr(self)) | |
2016 |
|
1728 | |||
2017 | def __xattrs__(self, mode): |
|
1729 | def __xattrs__(self, mode): | |
2018 | if mode == "detail": |
|
1730 | if mode == "detail": | |
@@ -2205,7 +1917,7 b' if curses is not None:' | |||||
2205 |
|
1917 | |||
2206 |
|
1918 | |||
2207 | class _BrowserHelp(object): |
|
1919 | class _BrowserHelp(object): | |
2208 | style_header = Style(COLOR_RED, COLOR_BLACK) |
|
1920 | style_header = astyle.Style.fromstr("red:blacK") | |
2209 | # This is used internally by ``ibrowse`` for displaying the help screen. |
|
1921 | # This is used internally by ``ibrowse`` for displaying the help screen. | |
2210 | def __init__(self, browser): |
|
1922 | def __init__(self, browser): | |
2211 | self.browser = browser |
|
1923 | self.browser = browser | |
@@ -2213,9 +1925,9 b' if curses is not None:' | |||||
2213 | def __xrepr__(self, mode): |
|
1925 | def __xrepr__(self, mode): | |
2214 | yield (-1, True) |
|
1926 | yield (-1, True) | |
2215 | if mode == "header" or mode == "footer": |
|
1927 | if mode == "header" or mode == "footer": | |
2216 | yield (style_default, "ibrowse help screen") |
|
1928 | yield (astyle.style_default, "ibrowse help screen") | |
2217 | else: |
|
1929 | else: | |
2218 | yield (style_default, repr(self)) |
|
1930 | yield (astyle.style_default, repr(self)) | |
2219 |
|
1931 | |||
2220 | def __xiter__(self, mode): |
|
1932 | def __xiter__(self, mode): | |
2221 | # Get reverse key mapping |
|
1933 | # Get reverse key mapping | |
@@ -2233,7 +1945,7 b' if curses is not None:' | |||||
2233 | keys = allkeys.get(name, []) |
|
1945 | keys = allkeys.get(name, []) | |
2234 | lines = textwrap.wrap(description, 60) |
|
1946 | lines = textwrap.wrap(description, 60) | |
2235 |
|
1947 | |||
2236 | yield Fields(fields, description=Text((self.style_header, name))) |
|
1948 | yield Fields(fields, description=astyle.Text((self.style_header, name))) | |
2237 | for i in xrange(max(len(keys), len(lines))): |
|
1949 | for i in xrange(max(len(keys), len(lines))): | |
2238 | try: |
|
1950 | try: | |
2239 | key = self.browser.keylabel(keys[i]) |
|
1951 | key = self.browser.keylabel(keys[i]) | |
@@ -2371,7 +2083,7 b' if curses is not None:' | |||||
2371 | parts.append(part) |
|
2083 | parts.append(part) | |
2372 | totallength += len(part[1]) |
|
2084 | totallength += len(part[1]) | |
2373 | if totallength >= self.browser.maxattrlength and not full: |
|
2085 | if totallength >= self.browser.maxattrlength and not full: | |
2374 | parts.append((style_ellisis, "...")) |
|
2086 | parts.append((astyle.style_ellisis, "...")) | |
2375 | totallength += 3 |
|
2087 | totallength += 3 | |
2376 | break |
|
2088 | break | |
2377 | # remember alignment, length and colored parts |
|
2089 | # remember alignment, length and colored parts | |
@@ -2566,19 +2278,19 b' if curses is not None:' | |||||
2566 | maxattrlength = 200 |
|
2278 | maxattrlength = 200 | |
2567 |
|
2279 | |||
2568 | # Styles for various parts of the GUI |
|
2280 | # Styles for various parts of the GUI | |
2569 | style_objheadertext = Style(COLOR_WHITE, COLOR_BLACK, A_BOLD|A_REVERSE) |
|
2281 | style_objheadertext = astyle.Style.fromstr("white:black:bold|reverse") | |
2570 | style_objheadernumber = Style(COLOR_WHITE, COLOR_BLUE, A_BOLD|A_REVERSE) |
|
2282 | style_objheadernumber = astyle.Style.fromstr("white:blue:bold|reverse") | |
2571 | style_objheaderobject = Style(COLOR_WHITE, COLOR_BLACK, A_REVERSE) |
|
2283 | style_objheaderobject = astyle.Style.fromstr("white:black:reverse") | |
2572 | style_colheader = Style(COLOR_BLUE, COLOR_WHITE, A_REVERSE) |
|
2284 | style_colheader = astyle.Style.fromstr("blue:white:reverse") | |
2573 | style_colheaderhere = Style(COLOR_GREEN, COLOR_BLACK, A_BOLD|A_REVERSE) |
|
2285 | style_colheaderhere = astyle.Style.fromstr("green:black:bold|reverse") | |
2574 | style_colheadersep = Style(COLOR_BLUE, COLOR_BLACK, A_REVERSE) |
|
2286 | style_colheadersep = astyle.Style.fromstr("blue:black:reverse") | |
2575 | style_number = Style(COLOR_BLUE, COLOR_WHITE, A_REVERSE) |
|
2287 | style_number = astyle.Style.fromstr("blue:white:reverse") | |
2576 | style_numberhere = Style(COLOR_GREEN, COLOR_BLACK, A_BOLD|A_REVERSE) |
|
2288 | style_numberhere = astyle.Style.fromstr("green:black:bold|reverse") | |
2577 | style_sep = Style(COLOR_BLUE, COLOR_BLACK) |
|
2289 | style_sep = astyle.Style.fromstr("blue:black") | |
2578 | style_data = Style(COLOR_WHITE, COLOR_BLACK) |
|
2290 | style_data = astyle.Style.fromstr("white:black") | |
2579 | style_datapad = Style(COLOR_BLUE, COLOR_BLACK, A_BOLD) |
|
2291 | style_datapad = astyle.Style.fromstr("blue:black:bold") | |
2580 | style_footer = Style(COLOR_BLACK, COLOR_WHITE) |
|
2292 | style_footer = astyle.Style.fromstr("black:white") | |
2581 | style_report = Style(COLOR_WHITE, COLOR_BLACK) |
|
2293 | style_report = astyle.Style.fromstr("white:black") | |
2582 |
|
2294 | |||
2583 | # Column separator in header |
|
2295 | # Column separator in header | |
2584 | headersepchar = "|" |
|
2296 | headersepchar = "|" | |
@@ -2710,16 +2422,16 b' if curses is not None:' | |||||
2710 | return self._styles[style.fg, style.bg, style.attrs] |
|
2422 | return self._styles[style.fg, style.bg, style.attrs] | |
2711 | except KeyError: |
|
2423 | except KeyError: | |
2712 | attrs = 0 |
|
2424 | attrs = 0 | |
2713 | for b in A2CURSES: |
|
2425 | for b in astyle.A2CURSES: | |
2714 | if style.attrs & b: |
|
2426 | if style.attrs & b: | |
2715 | attrs |= A2CURSES[b] |
|
2427 | attrs |= astyle.A2CURSES[b] | |
2716 | try: |
|
2428 | try: | |
2717 | color = self._colors[style.fg, style.bg] |
|
2429 | color = self._colors[style.fg, style.bg] | |
2718 | except KeyError: |
|
2430 | except KeyError: | |
2719 | curses.init_pair( |
|
2431 | curses.init_pair( | |
2720 | self._maxcolor, |
|
2432 | self._maxcolor, | |
2721 | COLOR2CURSES[style.fg], |
|
2433 | astyle.COLOR2CURSES[style.fg], | |
2722 | COLOR2CURSES[style.bg] |
|
2434 | astyle.COLOR2CURSES[style.bg] | |
2723 | ) |
|
2435 | ) | |
2724 | color = curses.color_pair(self._maxcolor) |
|
2436 | color = curses.color_pair(self._maxcolor) | |
2725 | self._colors[style.fg, style.bg] = color |
|
2437 | self._colors[style.fg, style.bg] = color | |
@@ -2758,7 +2470,7 b' if curses is not None:' | |||||
2758 | Return a style for displaying the original style ``style`` |
|
2470 | Return a style for displaying the original style ``style`` | |
2759 | in the row the cursor is on. |
|
2471 | in the row the cursor is on. | |
2760 | """ |
|
2472 | """ | |
2761 | return Style(style.fg, style.bg, style.attrs | A_BOLD) |
|
2473 | return astyle.Style(style.fg, style.bg, style.attrs | astyle.A_BOLD) | |
2762 |
|
2474 | |||
2763 | def report(self, msg): |
|
2475 | def report(self, msg): | |
2764 | """ |
|
2476 | """ | |
@@ -3337,7 +3049,7 b' if curses is not None:' | |||||
3337 | if posx >= endx: |
|
3049 | if posx >= endx: | |
3338 | break |
|
3050 | break | |
3339 |
|
3051 | |||
3340 | attrstyle = [(style_default, "no attribute")] |
|
3052 | attrstyle = [(astyle.style_default, "no attribute")] | |
3341 | attrname = level.displayattr[1] |
|
3053 | attrname = level.displayattr[1] | |
3342 | if attrname is not _default and attrname is not None: |
|
3054 | if attrname is not _default and attrname is not None: | |
3343 | posx += self.addstr(posy, posx, 0, endx, " | ", self.style_footer) |
|
3055 | posx += self.addstr(posy, posx, 0, endx, " | ", self.style_footer) |
General Comments 0
You need to be logged in to leave comments.
Login now