jangada.display.Displayable#
- class jangada.display.Displayable#
Bases:
ABCAbstract base for objects with Rich terminal display.
Displayable provides a framework for beautiful terminal output via Rich panels. Subclasses define content through abstract methods _title() and _content(), while the framework handles formatting, styling, and rendering.
Integrates with Rich’s protocol (__rich__) and provides string output (__str__), making objects displayable in both Rich-aware and standard contexts.
- Attributes:
- display_settingsDisplaySettings
Configuration for display formatting. Auto-created per instance via factory, allowing independent customization.
See also
DisplaySettingsConfiguration class
format_as_formHelper for key-value displays
format_as_tableHelper for DataFrame displays
Notes
Uses template method pattern: framework provides structure, subclasses provide content. This ensures consistent styling across all displays.
Examples
Simple implementation:
class Sensor(Displayable): def __init__(self, name, temp): self.name = name self.temp = temp def _title(self): return Text(f"Sensor: {self.name}") def _content(self): return f"Temperature: {self.temp}°C"
With table:
class Report(Displayable): def __init__(self, df): self.df = df def _title(self): return Text("Data Report") def _content(self): return self.format_as_table(self.df)
Custom styling:
obj = Sensor("Temp-01", 23.5) obj.display_settings.panel_border_style = 'green' print(obj)
- __init__(*args, **kwargs)#
Methods
__delattr__(name, /)Implement delattr(self, name).
__dir__(/)Default dir() implementation.
__eq__(value, /)Return self==value.
__format__(format_spec, /)Default object formatter.
__ge__(value, /)Return self>=value.
__getattribute__(name, /)Return getattr(self, name).
__getstate__(/)Helper for pickle.
__gt__(value, /)Return self>value.
__hash__(/)Return hash(self).
__init__(*args, **kwargs)__init_subclass__This method is called when a class is subclassed.
__le__(value, /)Return self<=value.
__lt__(value, /)Return self<value.
__ne__(value, /)Return self!=value.
__reduce__(/)Helper for pickle.
__reduce_ex__(protocol, /)Helper for pickle.
__repr__(/)Return repr(self).
__rich__()Rich protocol for direct rendering.
__sizeof__(/)Size of object in memory, in bytes.
__str__()String representation with Rich formatting.
__subclasshook__Abstract classes can override this to customize issubclass().
_content()Generate panel body content.
_display_panel()Create formatted panel with current settings.
_title()Generate panel title.
format_as_form(data)Format data as key-value form.
format_as_table(frame[, show_index, ...])Format DataFrame as Rich table.
to_html([width])Export display as HTML.
to_svg([width])Export display as SVG.
Attributes
__abstractmethods____annotations____slots___abc_implConfiguration for display formatting and styling.