Display¶

Generic pretty display utils.
- FORCE_COLOR¶
By default, we will not color strings in non-interactive ttys, but you can force it with
FORCE_COLOR
, ie. gitlab-ci etc
- cli2.display.diff(diff, **kwargs)[source]¶
Pretty-print a diff generated by Python’s standard difflib.unified_diff method.
# pretty print a diff cli2.diff(difflib.unified_diff(old, new))
- cli2.display.diff_data(before, after, before_label='before', after_label='after')[source]¶
YAML Dump before and after objects and return the unified diff, printable with
diff()
.- Parameters:
before – First object to compare
after – Second object to compare
before_label – Name of the first object to display in diff
after_label – Name of the second object to display in diff
- cli2.display.highlight(string, lexer)[source]¶
Use pygments to render a string with a lexer.
- Parameters:
string – String to render
lexer – Lexer name, Yaml, Diff, etc
- cli2.display.print(*args, **kwargs)[source]¶
Try to print the
render()
’ed args, pass the kwargs to actual print method.# pretty print some_object cli2.print(some_object)
- cli2.display.render(arg, highlight=True)[source]¶
Try to render arg as yaml.
If the arg has a
.json()
method, it’ll be called. If it is parseable as JSON then it’l be parsed as such. Then, it’ll be dumped as colored YAML.Set the env var FORCE_COLOR to anything to force into printing colors even if terminal is non-interactive (ie. gitlab-ci)
# pretty render some_object print(cli2.render(some_object))