superdsm.output
- class superdsm.output.ConsoleOutput(muted=False, parent=None, margin=0)
Bases:
OutputImplements the
Outputclass for terminal-based applications.- derive(muted=False, margin=0)
Derives an output.
- Parameters:
muted –
Trueif the derived output should be muted andFalseotherwise.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 –
Trueif the output should be displayed immediately andFalseotherwise.
- 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:
OutputImplements the
Outputclass 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 –
Trueif this output should be muted andFalseotherwise.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 –
Trueif the derived output should be muted andFalseotherwise.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 –
Trueif the output should be displayed immediately andFalseotherwise.
- 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:
objectAbstract base class of
JupyterOutputandConsoleOutput.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=Trueto the constructor of the output, or itsderive()method.- Parameters:
parent – The parent output (or
None).muted –
Trueif this output should be muted andFalseotherwise.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 –
Trueif the derived output should be muted andFalseotherwise.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 –
Trueif the output should be displayed immediately andFalseotherwise.
- property muted
Trueif the output has been muted andFalseotherwise.
- 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
Outputimplementation.If
outis None or set to'muted', then aJupyterOutputobject is retruned if code is being executed in a Jupyter notebook and aConsoleOutputobject otherwise, and the returned object is set to muted in the latter case. In all other cases,outitself 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:
Trueif code is being executed in a Jupyter notebook andFalseotherwise.