superdsm.output
- class superdsm.output.ConsoleOutput(muted=False, parent=None, margin=0)
Bases:
Output
Implements the
Output
class for terminal-based applications.- derive(muted=False, margin=0)
Derives an output.
- Parameters:
muted –
True
if the derived output should be muted andFalse
otherwise.maxlen – Maximum number of lines of the derived output.
margin – The left indentation of the derived output (in number of whitespaces, with respect to the indentation of this output).
- Returns:
The derived output.
- intermediate(line)
Display an intermediate line of text.
Intermediate output is overwritten by the next invocation of the
intermediate()
andwrite()
methods.- Parameters:
line – Line of text to be displayed.
flush –
True
if the output should be displayed immediately andFalse
otherwise.
- write(line)
Outputs a line of text permantently (as opposed to intermediate output).
Previous intermiedate output is overwritten.
- Parameters:
line – Line of text to be displayed.
- class superdsm.output.JupyterOutput(parent=None, maxlen=inf, muted=False, margin=0)
Bases:
Output
Implements the
Output
class for Jupyter-based applications.- Parameters:
parent – The parent output (or
None
).maxlen – Maximum number of allowed lines (older lines of text will be dropped if this number is exceeded).
muted –
True
if this output should be muted andFalse
otherwise.margin – The left indentation of this derived output (in number of whitespaces, with respect to the indentation of the parent output).
- clear(flush=False)
Removes all intermediate output.
- derive(muted=False, maxlen=inf, margin=0)
Derives an output.
- Parameters:
muted –
True
if the derived output should be muted andFalse
otherwise.maxlen – Maximum number of lines of the derived output.
margin – The left indentation of the derived output (in number of whitespaces, with respect to the indentation of this output).
- Returns:
The derived output.
- intermediate(line, flush=True)
Display an intermediate line of text.
Intermediate output is overwritten by the next invocation of the
intermediate()
andwrite()
methods.- Parameters:
line – Line of text to be displayed.
flush –
True
if the output should be displayed immediately andFalse
otherwise.
- truncate(offset=0)
Truncates output so that maximum number of lines is respected.
Older lines of text are dropped, so that
\[\text{number of retained lines} + \text{offset} \leq \text{maximum number of lines allowed}.\]
- write(line, keep_current=False)
Outputs a line of text permantently (as opposed to intermediate output).
Previous intermiedate output is overwritten.
- Parameters:
line – Line of text to be displayed.
- class superdsm.output.Output(parent=None, muted=False, margin=0)
Bases:
object
Abstract base class of
JupyterOutput
andConsoleOutput
.Outputs are organized hierarchically, in the sense that each output has one or none parent ouput. To indicate this relationship, we say that an output is derived from its parent. If an output is muted, all its direct and indirect derivations will be muted too. To create a muted output, pass
muted=True
to the constructor of the output, or itsderive()
method.- Parameters:
parent – The parent output (or
None
).muted –
True
if this output should be muted andFalse
otherwise.margin – The left indentation of this derived output (in number of whitespaces, with respect to the indentation of the parent output).
- derive(muted=False, maxlen=inf, margin=0)
Derives an output.
- Parameters:
muted –
True
if the derived output should be muted andFalse
otherwise.maxlen – Maximum number of lines of the derived output.
margin – The left indentation of the derived output (in number of whitespaces, with respect to the indentation of this output).
- Returns:
The derived output.
- intermediate(line, flush=True)
Display an intermediate line of text.
Intermediate output is overwritten by the next invocation of the
intermediate()
andwrite()
methods.- Parameters:
line – Line of text to be displayed.
flush –
True
if the output should be displayed immediately andFalse
otherwise.
- property muted
True
if the output has been muted andFalse
otherwise.
- write(line)
Outputs a line of text permantently (as opposed to intermediate output).
Previous intermiedate output is overwritten.
- Parameters:
line – Line of text to be displayed.
- class superdsm.output.Text
Bases:
object
- BLUE = '\x1b[94m'
- BOLD = '\x1b[1m'
- CYAN = '\x1b[96m'
- DARKCYAN = '\x1b[36m'
- END = '\x1b[0m'
- GREEN = '\x1b[92m'
- PURPLE = '\x1b[95m'
- RED = '\x1b[91m'
- UNDERLINE = '\x1b[4m'
- YELLOW = '\x1b[93m'
- static style(text, style)
- superdsm.output.get_output(out=None)
Returns a suitable
Output
implementation.If
out
is None or set to'muted'
, then aJupyterOutput
object is retruned if code is being executed in a Jupyter notebook and aConsoleOutput
object otherwise, and the returned object is set to muted in the latter case. In all other cases,out
itself will be returned.>>> import superdsm.output >>> out1 = superdsm.output.get_output(None) >>> out1.muted False >>> type(out1) <class 'superdsm.output.ConsoleOutput'> >>> out2 = superdsm.output.get_output(out1) >>> out1 is out2 True >>> out3 = superdsm.output.get_output('muted') >>> type(out3) <class 'superdsm.output.ConsoleOutput'> >>> out3.muted True
- superdsm.output.is_jupyter_notebook()
Checks whether code is being executed in a Jupyter notebook.
- Returns:
True
if code is being executed in a Jupyter notebook andFalse
otherwise.