1 | """ |
||
2 | Enarksh |
||
3 | |||
4 | Copyright 2013-2016 Set Based IT Consultancy |
||
5 | |||
6 | Licence MIT |
||
7 | """ |
||
8 | from cleo import Output |
||
9 | from cleo import OutputFormatterStyle |
||
10 | from cleo.styles import CleoStyle |
||
11 | |||
12 | |||
13 | class EnarkshStyle(CleoStyle): |
||
14 | """ |
||
15 | Output style for Enarksh. |
||
16 | """ |
||
17 | |||
18 | # ------------------------------------------------------------------------------------------------------------------ |
||
19 | def __init__(self, input, output): |
||
0 ignored issues
–
show
|
|||
20 | """ |
||
21 | Object constructor. |
||
22 | |||
23 | :param cleo.inputs.input.Input input: The input object. |
||
24 | :param cleo.outputs.output.Output output: The output object. |
||
25 | """ |
||
26 | CleoStyle.__init__(self, input, output) |
||
27 | |||
28 | # Style for file system objects (e.g. file and directory names). |
||
29 | style = OutputFormatterStyle('green', None, ['bold']) |
||
30 | output.get_formatter().set_style('fso', style) |
||
31 | |||
32 | # Style for errors. |
||
33 | style = OutputFormatterStyle('red', None, ['bold']) |
||
34 | output.get_formatter().set_style('err', style) |
||
35 | |||
36 | # Style for warnings. |
||
37 | style = OutputFormatterStyle('yellow', None, ['bold']) |
||
38 | output.get_formatter().set_style('warn', style) |
||
39 | |||
40 | # Style for Enarksh notices. |
||
41 | style = OutputFormatterStyle('yellow') |
||
42 | output.get_formatter().set_style('notice', style) |
||
43 | |||
44 | # ------------------------------------------------------------------------------------------------------------------ |
||
45 | def log_verbose(self, message): |
||
46 | """ |
||
47 | Logs a message only when logging level is verbose. |
||
48 | |||
49 | :param str|list[str] message: The message. |
||
50 | """ |
||
51 | if self.get_verbosity() >= Output.VERBOSITY_VERBOSE: |
||
52 | self.writeln(message) |
||
53 | |||
54 | # ------------------------------------------------------------------------------------------------------------------ |
||
55 | def log_very_verbose(self, message): |
||
56 | """ |
||
57 | Logs a message only when logging level is very verbose. |
||
58 | |||
59 | :param str|list[str] message: The message. |
||
60 | """ |
||
61 | if self.get_verbosity() >= Output.VERBOSITY_VERY_VERBOSE: |
||
62 | self.writeln(message) |
||
63 | |||
64 | # ---------------------------------------------------------------------------------------------------------------------- |
||
65 |
It is generally discouraged to redefine built-ins as this makes code very hard to read.