Skip to content

xnano.core.content

xnano.core.content

xnano.core.content


Compose interface-neutral text, layout, chart, table, canvas, and native data.

Classes:

  • Run

    One styled text run.

  • TextBlock

    Wrapped plain text or lines of styled runs.

  • Stack

    Lay out child content in one direction.

  • Panel

    Decorate child content with a frame and padding.

  • Gauge

    Render a filled progress gauge.

  • LineGauge

    Render progress as a single horizontal line.

  • Bar

    One value in a bar chart.

  • BarGroup

    A labeled group of chart bars.

  • Bars

    Render grouped bars.

  • PlotDataset

    One named data series in a plot.

  • PlotAxis

    Labels and bounds for one plot axis.

  • Plot

    Render one or more numeric data series.

  • SparklineBar

    One individually styled sparkline sample.

  • Sparkline

    Render a compact sequence of vertical samples.

  • TableCell

    Styled content in one table column.

  • TableRow

    One styled table row.

  • TableGrid

    Render tabular rows with optional selection.

  • Items

    Render a selectable list of text items.

  • CanvasLine

    A straight line on a numeric canvas.

  • CanvasPoints

    A set of points on a numeric canvas.

  • CanvasRectangle

    A rectangle on a numeric canvas.

  • CanvasCircle

    A circle on a numeric canvas.

  • CanvasPrint

    Text positioned on a numeric canvas.

  • Canvas

    Render geometric shapes in numeric coordinate space.

  • Scrollbar

    Render scroll position and viewport proportion.

  • Clear

    Clear the assigned render area.

  • CellSpan

    A styled run inside a cell canvas row.

  • CellCanvas

    A rectangular sequence of styled cell rows.

  • Native

    Content already lowered for a named interface.

Attributes:

CanvasShape module-attribute

Shape accepted by Canvas.

Content module-attribute

Any content primitive.

ContentBase dataclass

ContentBase(
    *,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True
)

Shared visibility and stacking state for composed content.

Attributes:

  • style (Style | None) –

    Optional shared style.

  • z (int) –

    Sibling-local paint order.

  • visible (bool) –

    Whether this content paints.

style class-attribute instance-attribute

style: Style | None = None

Optional shared style.

z class-attribute instance-attribute

z: int = 0

Sibling-local paint order.

visible class-attribute instance-attribute

visible: bool = True

Whether this content paints.

Run dataclass

Run(
    *,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True,
    text: str,
    foreground: ColorLike | None = None,
    background: ColorLike | None = None,
    modifiers: tuple[CharacterModifier, ...] = (),
    color: InitVar[Any] = _ALIAS_UNSET
)

Bases: ContentBase

One styled text run.

Example

Run(text="Ready", foreground="green", modifiers=("bold",))

Attributes:

Methods:

  • __post_init__

    Apply the deprecated constructor alias.

  • plain

    Create a plain styled run.

text instance-attribute

text: str

Text displayed by the run.

foreground class-attribute instance-attribute

foreground: ColorLike | None = None

Foreground color.

background class-attribute instance-attribute

background: ColorLike | None = None

Background color.

modifiers class-attribute instance-attribute

modifiers: tuple[CharacterModifier, ...] = ()

Character modifiers.

style class-attribute instance-attribute

style: Style | None = None

Optional shared style.

z class-attribute instance-attribute

z: int = 0

Sibling-local paint order.

visible class-attribute instance-attribute

visible: bool = True

Whether this content paints.

__post_init__

__post_init__(color: Any) -> None

Apply the deprecated constructor alias.

Source code in xnano/core/content.py
def __post_init__(self, color: Any) -> None:
    """Apply the deprecated constructor alias."""
    resolve_init_alias(self, color, old="color", new="foreground")

plain classmethod

plain(
    text: str,
    *,
    foreground: ColorLike | None = None,
    background: ColorLike | None = None,
    modifiers: Sequence[CharacterModifier] | None = None,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True,
    color: ColorLike | None = None
) -> "Run"

Create a plain styled run.

Parameters:

  • text (str) –

    Text displayed by the run.

  • foreground (ColorLike | None, default: None ) –

    Foreground color.

  • background (ColorLike | None, default: None ) –

    Background color.

  • modifiers (Sequence[CharacterModifier] | None, default: None ) –

    Character modifiers.

  • style (Style | None, default: None ) –

    Optional shared style.

  • z (int, default: 0 ) –

    Sibling-local paint order.

  • visible (bool, default: True ) –

    Whether the run paints.

  • color (ColorLike | None, default: None ) –

    Deprecated alias for foreground.

Returns:

  • 'Run'

    A run containing text.

Source code in xnano/core/content.py
@classmethod
def plain(
    cls,
    text: str,
    *,
    foreground: ColorLike | None = None,
    background: ColorLike | None = None,
    modifiers: Sequence[CharacterModifier] | None = None,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True,
    color: ColorLike | None = None,
) -> "Run":
    """Create a plain styled run.

    Args:
        text: Text displayed by the run.
        foreground: Foreground color.
        background: Background color.
        modifiers: Character modifiers.
        style: Optional shared style.
        z: Sibling-local paint order.
        visible: Whether the run paints.
        color: Deprecated alias for ``foreground``.

    Returns:
        A run containing ``text``.
    """
    foreground = resolve_color_alias(foreground, color, stacklevel=3)
    return cls(
        text=text,
        foreground=foreground,
        background=background,
        modifiers=tuple(modifiers or ()),
        style=style,
        z=z,
        visible=visible,
    )

TextBlock dataclass

TextBlock(
    *,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True,
    text: str = "",
    lines: tuple[tuple[Run, ...], ...] = (),
    foreground: ColorLike | None = None,
    background: ColorLike | None = None,
    modifiers: tuple[CharacterModifier, ...] = (),
    horizontal_align: Alignment | None = None,
    vertical_align: VerticalAlignment | None = None,
    wrap: bool = True,
    color: InitVar[Any] = _ALIAS_UNSET,
    align: InitVar[Any] = _ALIAS_UNSET
)

Bases: ContentBase

Wrapped plain text or lines of styled runs.

Example

TextBlock(text="Hello", horizontal_align="center")

Attributes:

Methods:

  • __post_init__

    Apply deprecated constructor aliases.

  • from_plain

    Create a block from plain text and explicit style values.

  • from_lines

    Create a block from styled line sequences.

text class-attribute instance-attribute

text: str = ''

Plain text content.

lines class-attribute instance-attribute

lines: tuple[tuple[Run, ...], ...] = ()

Styled text lines.

foreground class-attribute instance-attribute

foreground: ColorLike | None = None

Default foreground color.

background class-attribute instance-attribute

background: ColorLike | None = None

Default background color.

modifiers class-attribute instance-attribute

modifiers: tuple[CharacterModifier, ...] = ()

Default character modifiers.

horizontal_align class-attribute instance-attribute

horizontal_align: Alignment | None = None

Horizontal alignment.

vertical_align class-attribute instance-attribute

vertical_align: VerticalAlignment | None = None

Vertical alignment within the painted area.

wrap class-attribute instance-attribute

wrap: bool = True

Whether long lines wrap.

style class-attribute instance-attribute

style: Style | None = None

Optional shared style.

z class-attribute instance-attribute

z: int = 0

Sibling-local paint order.

visible class-attribute instance-attribute

visible: bool = True

Whether this content paints.

__post_init__

__post_init__(color: Any, align: Any) -> None

Apply deprecated constructor aliases.

Source code in xnano/core/content.py
def __post_init__(self, color: Any, align: Any) -> None:
    """Apply deprecated constructor aliases."""
    resolve_init_alias(self, color, old="color", new="foreground")
    resolve_init_alias(self, align, old="align", new="horizontal_align")

from_plain classmethod

from_plain(
    text: str,
    *,
    foreground: ColorLike | None = None,
    background: ColorLike | None = None,
    modifiers: Sequence[CharacterModifier] | None = None,
    horizontal_align: Alignment | None = None,
    vertical_align: VerticalAlignment | None = None,
    wrap: bool = True,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True,
    color: ColorLike | None = None
) -> "TextBlock"

Create a block from plain text and explicit style values.

color is a deprecated alias for foreground.

Source code in xnano/core/content.py
@classmethod
def from_plain(
    cls,
    text: str,
    *,
    foreground: ColorLike | None = None,
    background: ColorLike | None = None,
    modifiers: Sequence[CharacterModifier] | None = None,
    horizontal_align: Alignment | None = None,
    vertical_align: VerticalAlignment | None = None,
    wrap: bool = True,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True,
    color: ColorLike | None = None,
) -> "TextBlock":
    """Create a block from plain text and explicit style values.

    ``color`` is a deprecated alias for ``foreground``.
    """
    foreground = resolve_color_alias(foreground, color, stacklevel=3)
    return cls(
        text=text,
        foreground=foreground,
        background=background,
        modifiers=tuple(modifiers or ()),
        horizontal_align=horizontal_align,
        vertical_align=vertical_align,
        wrap=wrap,
        style=style,
        z=z,
        visible=visible,
    )

from_lines classmethod

from_lines(
    lines: Sequence[Sequence[Run] | Run | str],
    *,
    foreground: ColorLike | None = None,
    background: ColorLike | None = None,
    modifiers: Sequence[CharacterModifier] | None = None,
    horizontal_align: Alignment | None = None,
    vertical_align: VerticalAlignment | None = None,
    wrap: bool = True,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True,
    color: ColorLike | None = None
) -> "TextBlock"

Create a block from styled line sequences.

color is a deprecated alias for foreground.

Source code in xnano/core/content.py
@classmethod
def from_lines(
    cls,
    lines: Sequence[Sequence[Run] | Run | str],
    *,
    foreground: ColorLike | None = None,
    background: ColorLike | None = None,
    modifiers: Sequence[CharacterModifier] | None = None,
    horizontal_align: Alignment | None = None,
    vertical_align: VerticalAlignment | None = None,
    wrap: bool = True,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True,
    color: ColorLike | None = None,
) -> "TextBlock":
    """Create a block from styled line sequences.

    ``color`` is a deprecated alias for ``foreground``.
    """
    foreground = resolve_color_alias(foreground, color, stacklevel=3)
    normalized: list[tuple[Run, ...]] = []
    for line in lines:
        if isinstance(line, str):
            normalized.append((Run(text=line),))
        elif isinstance(line, Run):
            normalized.append((line,))
        else:
            normalized.append(tuple(line))
    return cls(
        lines=tuple(normalized),
        foreground=foreground,
        background=background,
        modifiers=tuple(modifiers or ()),
        horizontal_align=horizontal_align,
        vertical_align=vertical_align,
        wrap=wrap,
        style=style,
        z=z,
        visible=visible,
    )

Stack dataclass

Stack(
    *,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True,
    children: tuple[ContentBase, ...] = (),
    direction: Direction = "vertical",
    gap: int = 0
)

Bases: ContentBase

Lay out child content in one direction.

Example

Stack(children=(TextBlock(text="One"), TextBlock(text="Two")))

Attributes:

children class-attribute instance-attribute

children: tuple[ContentBase, ...] = ()

Child content.

direction class-attribute instance-attribute

direction: Direction = 'vertical'

Layout direction.

gap class-attribute instance-attribute

gap: int = 0

Cells between children.

style class-attribute instance-attribute

style: Style | None = None

Optional shared style.

z class-attribute instance-attribute

z: int = 0

Sibling-local paint order.

visible class-attribute instance-attribute

visible: bool = True

Whether this content paints.

Panel dataclass

Panel(
    *,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True,
    child: ContentBase,
    title: str | None = None,
    title_position: FrameTitlePosition | None = None,
    border: Border | None = None,
    border_color: ColorLike | None = None,
    border_sides: tuple[Side, ...] | None = None,
    background: ColorLike | None = None,
    padding: PaddingLike | None = None
)

Bases: ContentBase

Decorate child content with a frame and padding.

Example

Panel(child=TextBlock(text="Status"), title="Service")

Attributes:

child instance-attribute

child: ContentBase

Content inside the panel.

title class-attribute instance-attribute

title: str | None = None

Optional frame title.

title_position class-attribute instance-attribute

title_position: FrameTitlePosition | None = None

Frame title alignment.

border class-attribute instance-attribute

border: Border | None = None

Border style.

border_color class-attribute instance-attribute

border_color: ColorLike | None = None

Border foreground color.

border_sides class-attribute instance-attribute

border_sides: tuple[Side, ...] | None = None

Visible border sides.

background class-attribute instance-attribute

background: ColorLike | None = None

Panel background color.

padding class-attribute instance-attribute

padding: PaddingLike | None = None

Space between border and child.

style class-attribute instance-attribute

style: Style | None = None

Optional shared style.

z class-attribute instance-attribute

z: int = 0

Sibling-local paint order.

visible class-attribute instance-attribute

visible: bool = True

Whether this content paints.

Gauge dataclass

Gauge(
    *,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True,
    progress: float = 0.0,
    label: str | None = None,
    foreground: ColorLike = "green",
    background: ColorLike | None = None
)

Bases: ContentBase

Render a filled progress gauge.

Example

Gauge(progress=0.75, label="75%")

Attributes:

progress class-attribute instance-attribute

progress: float = 0.0

Completion ratio from zero to one.

label class-attribute instance-attribute

label: str | None = None

Text displayed inside the gauge.

foreground class-attribute instance-attribute

foreground: ColorLike = 'green'

Filled-region color.

background class-attribute instance-attribute

background: ColorLike | None = None

Gauge background color.

style class-attribute instance-attribute

style: Style | None = None

Optional shared style.

z class-attribute instance-attribute

z: int = 0

Sibling-local paint order.

visible class-attribute instance-attribute

visible: bool = True

Whether this content paints.

LineGauge dataclass

LineGauge(
    *,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True,
    progress: float = 0.0,
    label: str | None = None,
    foreground: ColorLike | None = None,
    filled_color: ColorLike | None = None,
    unfilled_color: ColorLike | None = None,
    background: ColorLike | None = None
)

Bases: ContentBase

Render progress as a single horizontal line.

Attributes:

progress class-attribute instance-attribute

progress: float = 0.0

Completion ratio from zero to one.

label class-attribute instance-attribute

label: str | None = None

Text displayed with the line.

foreground class-attribute instance-attribute

foreground: ColorLike | None = None

Default foreground color.

filled_color class-attribute instance-attribute

filled_color: ColorLike | None = None

Completed-region color.

unfilled_color class-attribute instance-attribute

unfilled_color: ColorLike | None = None

Remaining-region color.

background class-attribute instance-attribute

background: ColorLike | None = None

Line background color.

style class-attribute instance-attribute

style: Style | None = None

Optional shared style.

z class-attribute instance-attribute

z: int = 0

Sibling-local paint order.

visible class-attribute instance-attribute

visible: bool = True

Whether this content paints.

Bar dataclass

Bar(
    *,
    value: int,
    label: str = "",
    text_value: str | None = None,
    color: ColorLike | None = None,
    value_color: ColorLike | None = None
)

One value in a bar chart.

Attributes:

value instance-attribute

value: int

Numeric bar value.

label class-attribute instance-attribute

label: str = ''

Label beneath the bar.

text_value class-attribute instance-attribute

text_value: str | None = None

Displayed value override.

color class-attribute instance-attribute

color: ColorLike | None = None

Bar color.

value_color class-attribute instance-attribute

value_color: ColorLike | None = None

Value-label color.

BarGroup dataclass

BarGroup(
    *, bars: tuple[Bar, ...] = (), label: str | None = None
)

A labeled group of chart bars.

Attributes:

bars class-attribute instance-attribute

bars: tuple[Bar, ...] = ()

Bars in this group.

label class-attribute instance-attribute

label: str | None = None

Group label.

Bars dataclass

Bars(
    *,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True,
    groups: tuple[BarGroup, ...] = (),
    bar_width: int = 1,
    bar_gap: int = 1,
    group_gap: int = 0,
    max_value: int | None = None,
    direction: Direction = "vertical",
    color: ColorLike | None = None,
    value_color: ColorLike | None = None,
    label_color: ColorLike | None = None
)

Bases: ContentBase

Render grouped bars.

Example

Bars(groups=(BarGroup(bars=(Bar(value=8, label="A"),)),))

Attributes:

groups class-attribute instance-attribute

groups: tuple[BarGroup, ...] = ()

Bar groups.

bar_width class-attribute instance-attribute

bar_width: int = 1

Width of each bar in cells.

bar_gap class-attribute instance-attribute

bar_gap: int = 1

Cells between bars.

group_gap class-attribute instance-attribute

group_gap: int = 0

Cells between groups.

max_value class-attribute instance-attribute

max_value: int | None = None

Explicit value ceiling.

direction class-attribute instance-attribute

direction: Direction = 'vertical'

Bar growth direction.

color class-attribute instance-attribute

color: ColorLike | None = None

Default bar color.

value_color class-attribute instance-attribute

value_color: ColorLike | None = None

Default value-label color.

label_color class-attribute instance-attribute

label_color: ColorLike | None = None

Bar-label color.

style class-attribute instance-attribute

style: Style | None = None

Optional shared style.

z class-attribute instance-attribute

z: int = 0

Sibling-local paint order.

visible class-attribute instance-attribute

visible: bool = True

Whether this content paints.

PlotDataset dataclass

PlotDataset(
    *,
    data: tuple[tuple[float, float], ...] = (),
    name: str | None = None,
    color: ColorLike | None = None,
    marker: CanvasMarkerLike | None = None,
    graph_type: GraphTypeLike = "line"
)

One named data series in a plot.

Attributes:

data class-attribute instance-attribute

data: tuple[tuple[float, float], ...] = ()

Plot coordinates.

name class-attribute instance-attribute

name: str | None = None

Legend label.

color class-attribute instance-attribute

color: ColorLike | None = None

Series color.

marker class-attribute instance-attribute

marker: CanvasMarkerLike | None = None

Point marker.

graph_type class-attribute instance-attribute

graph_type: GraphTypeLike = 'line'

Line, bar, or scatter representation.

PlotAxis dataclass

PlotAxis(
    *,
    title: str | None = None,
    bounds: tuple[float, float] | None = None,
    labels: tuple[str, ...] | None = None,
    color: ColorLike | None = None
)

Labels and bounds for one plot axis.

Attributes:

title class-attribute instance-attribute

title: str | None = None

Axis title.

bounds class-attribute instance-attribute

bounds: tuple[float, float] | None = None

Minimum and maximum values.

labels class-attribute instance-attribute

labels: tuple[str, ...] | None = None

Tick labels.

color class-attribute instance-attribute

color: ColorLike | None = None

Axis color.

Plot dataclass

Plot(
    *,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True,
    datasets: tuple[PlotDataset, ...] = (),
    x_axis: PlotAxis | None = None,
    y_axis: PlotAxis | None = None,
    color: ColorLike | None = None,
    legend: bool = True,
    legend_position: LegendPositionLike | None = "top_right"
)

Bases: ContentBase

Render one or more numeric data series.

Example

Plot(datasets=(PlotDataset(data=((0, 1), (1, 3))),))

Attributes:

datasets class-attribute instance-attribute

datasets: tuple[PlotDataset, ...] = ()

Data series.

x_axis class-attribute instance-attribute

x_axis: PlotAxis | None = None

Horizontal axis.

y_axis class-attribute instance-attribute

y_axis: PlotAxis | None = None

Vertical axis.

color class-attribute instance-attribute

color: ColorLike | None = None

Default plot color.

legend class-attribute instance-attribute

legend: bool = True

Whether to show the legend.

legend_position class-attribute instance-attribute

legend_position: LegendPositionLike | None = 'top_right'

Legend placement.

style class-attribute instance-attribute

style: Style | None = None

Optional shared style.

z class-attribute instance-attribute

z: int = 0

Sibling-local paint order.

visible class-attribute instance-attribute

visible: bool = True

Whether this content paints.

SparklineBar dataclass

SparklineBar(*, value: int, color: ColorLike | None = None)

One individually styled sparkline sample.

Attributes:

value instance-attribute

value: int

Sample value.

color class-attribute instance-attribute

color: ColorLike | None = None

Sample color.

Sparkline dataclass

Sparkline(
    *,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True,
    data: tuple[int, ...] = (),
    bars: tuple[SparklineBar, ...] | None = None,
    max_value: int | None = None,
    foreground: ColorLike | None = None,
    background: ColorLike | None = None,
    absent_value_color: ColorLike | None = None,
    absent_value_symbol: str | None = None
)

Bases: ContentBase

Render a compact sequence of vertical samples.

Example

Sparkline(data=(2, 5, 3, 8), foreground="cyan")

Attributes:

data class-attribute instance-attribute

data: tuple[int, ...] = ()

Sample values.

bars class-attribute instance-attribute

bars: tuple[SparklineBar, ...] | None = None

Individually styled samples.

max_value class-attribute instance-attribute

max_value: int | None = None

Explicit sample ceiling.

foreground class-attribute instance-attribute

foreground: ColorLike | None = None

Default sample color.

background class-attribute instance-attribute

background: ColorLike | None = None

Sparkline background.

absent_value_color class-attribute instance-attribute

absent_value_color: ColorLike | None = None

Color for missing or zero samples.

absent_value_symbol class-attribute instance-attribute

absent_value_symbol: str | None = None

Symbol for missing or zero samples.

style class-attribute instance-attribute

style: Style | None = None

Optional shared style.

z class-attribute instance-attribute

z: int = 0

Sibling-local paint order.

visible class-attribute instance-attribute

visible: bool = True

Whether this content paints.

TableCell dataclass

TableCell(
    *,
    content: str | Run | TextBlock = "",
    foreground: ColorLike | None = None,
    background: ColorLike | None = None,
    modifiers: tuple[CharacterModifier, ...] = ()
)

Styled content in one table column.

Attributes:

content class-attribute instance-attribute

content: str | Run | TextBlock = ''

Cell content.

foreground class-attribute instance-attribute

foreground: ColorLike | None = None

Foreground color.

background class-attribute instance-attribute

background: ColorLike | None = None

Background color.

modifiers class-attribute instance-attribute

modifiers: tuple[CharacterModifier, ...] = ()

Character modifiers.

TableRow dataclass

TableRow(
    *,
    cells: tuple[TableCell | str, ...] = (),
    foreground: ColorLike | None = None,
    background: ColorLike | None = None,
    height: int = 1
)

One styled table row.

Attributes:

cells class-attribute instance-attribute

cells: tuple[TableCell | str, ...] = ()

Cells in column order.

foreground class-attribute instance-attribute

foreground: ColorLike | None = None

Default row foreground.

background class-attribute instance-attribute

background: ColorLike | None = None

Default row background.

height class-attribute instance-attribute

height: int = 1

Row height in cells.

TableGrid dataclass

TableGrid(
    *,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True,
    rows: tuple[TableRow, ...] = (),
    header: TableRow | None = None,
    footer: TableRow | None = None,
    column_widths: tuple[int | float, ...] | None = None,
    column_spacing: int = 1,
    selected_row: int | None = None,
    selected_column: int | None = None,
    highlight_color: ColorLike | None = None,
    highlight_background: ColorLike | None = None,
    highlight_symbol: str | None = None
)

Bases: ContentBase

Render tabular rows with optional selection.

Example

TableGrid(rows=(TableRow(cells=("Ada", "Engineer")),))

Attributes:

rows class-attribute instance-attribute

rows: tuple[TableRow, ...] = ()

Body rows.

header class-attribute instance-attribute

header: TableRow | None = None

Optional header row.

footer class-attribute instance-attribute

footer: TableRow | None = None

Optional footer row.

column_widths class-attribute instance-attribute

column_widths: tuple[int | float, ...] | None = None

Fixed cell widths or fractional widths.

column_spacing class-attribute instance-attribute

column_spacing: int = 1

Cells between columns.

selected_row class-attribute instance-attribute

selected_row: int | None = None

Selected body row.

selected_column class-attribute instance-attribute

selected_column: int | None = None

Selected column.

highlight_color class-attribute instance-attribute

highlight_color: ColorLike | None = None

Selection foreground.

highlight_background class-attribute instance-attribute

highlight_background: ColorLike | None = None

Selection background.

highlight_symbol class-attribute instance-attribute

highlight_symbol: str | None = None

Symbol prefixed to the selected row.

style class-attribute instance-attribute

style: Style | None = None

Optional shared style.

z class-attribute instance-attribute

z: int = 0

Sibling-local paint order.

visible class-attribute instance-attribute

visible: bool = True

Whether this content paints.

Items dataclass

Items(
    *,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True,
    items: tuple[str | Run | TextBlock, ...] = (),
    selected: int | None = None,
    foreground: ColorLike | None = None,
    background: ColorLike | None = None,
    highlight_color: ColorLike = "black",
    highlight_background: ColorLike = "white",
    highlight_symbol: str = "> "
)

Bases: ContentBase

Render a selectable list of text items.

Example

Items(items=("One", "Two"), selected=0)

Attributes:

items class-attribute instance-attribute

items: tuple[str | Run | TextBlock, ...] = ()

List entries.

selected class-attribute instance-attribute

selected: int | None = None

Selected entry index.

foreground class-attribute instance-attribute

foreground: ColorLike | None = None

Default foreground.

background class-attribute instance-attribute

background: ColorLike | None = None

Default background.

highlight_color class-attribute instance-attribute

highlight_color: ColorLike = 'black'

Selected-entry foreground.

highlight_background class-attribute instance-attribute

highlight_background: ColorLike = 'white'

Selected-entry background.

highlight_symbol class-attribute instance-attribute

highlight_symbol: str = '> '

Symbol prefixed to the selected entry.

style class-attribute instance-attribute

style: Style | None = None

Optional shared style.

z class-attribute instance-attribute

z: int = 0

Sibling-local paint order.

visible class-attribute instance-attribute

visible: bool = True

Whether this content paints.

CanvasLine dataclass

CanvasLine(
    *,
    x1: float,
    y1: float,
    x2: float,
    y2: float,
    color: ColorLike = "white"
)

A straight line on a numeric canvas.

Attributes:

x1 instance-attribute

x1: float

Starting x-coordinate.

y1 instance-attribute

y1: float

Starting y-coordinate.

x2 instance-attribute

x2: float

Ending x-coordinate.

y2 instance-attribute

y2: float

Ending y-coordinate.

color class-attribute instance-attribute

color: ColorLike = 'white'

Line color.

CanvasPoints dataclass

CanvasPoints(
    *,
    coords: tuple[tuple[float, float], ...] = (),
    color: ColorLike = "white"
)

A set of points on a numeric canvas.

Attributes:

coords class-attribute instance-attribute

coords: tuple[tuple[float, float], ...] = ()

Point coordinates.

color class-attribute instance-attribute

color: ColorLike = 'white'

Point color.

CanvasRectangle dataclass

CanvasRectangle(
    *,
    x: float,
    y: float,
    width: float,
    height: float,
    color: ColorLike = "white"
)

A rectangle on a numeric canvas.

Attributes:

x instance-attribute

x: float

Left coordinate.

y instance-attribute

y: float

Top coordinate.

width instance-attribute

width: float

Rectangle width.

height instance-attribute

height: float

Rectangle height.

color class-attribute instance-attribute

color: ColorLike = 'white'

Rectangle color.

CanvasCircle dataclass

CanvasCircle(
    *,
    x: float,
    y: float,
    radius: float,
    color: ColorLike = "white"
)

A circle on a numeric canvas.

Attributes:

x instance-attribute

x: float

Center x-coordinate.

y instance-attribute

y: float

Center y-coordinate.

radius instance-attribute

radius: float

Circle radius.

color class-attribute instance-attribute

color: ColorLike = 'white'

Circle color.

CanvasPrint dataclass

CanvasPrint(
    *,
    x: float,
    y: float,
    content: str | Run | TextBlock = ""
)

Text positioned on a numeric canvas.

Attributes:

x instance-attribute

x: float

Text x-coordinate.

y instance-attribute

y: float

Text y-coordinate.

content class-attribute instance-attribute

content: str | Run | TextBlock = ''

Displayed text.

Canvas dataclass

Canvas(
    *,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True,
    shapes: tuple[CanvasShape, ...] = (),
    x_bounds: tuple[float, float] = (0.0, 1.0),
    y_bounds: tuple[float, float] = (0.0, 1.0),
    marker: CanvasMarkerLike = "braille",
    background: ColorLike | None = None
)

Bases: ContentBase

Render geometric shapes in numeric coordinate space.

Example

Canvas(shapes=(CanvasCircle(x=0.5, y=0.5, radius=0.25),))

Attributes:

shapes class-attribute instance-attribute

shapes: tuple[CanvasShape, ...] = ()

Shapes painted in declaration order.

x_bounds class-attribute instance-attribute

x_bounds: tuple[float, float] = (0.0, 1.0)

Horizontal coordinate bounds.

y_bounds class-attribute instance-attribute

y_bounds: tuple[float, float] = (0.0, 1.0)

Vertical coordinate bounds.

marker class-attribute instance-attribute

marker: CanvasMarkerLike = 'braille'

Canvas point marker.

background class-attribute instance-attribute

background: ColorLike | None = None

Canvas background.

style class-attribute instance-attribute

style: Style | None = None

Optional shared style.

z class-attribute instance-attribute

z: int = 0

Sibling-local paint order.

visible class-attribute instance-attribute

visible: bool = True

Whether this content paints.

Scrollbar dataclass

Scrollbar(
    *,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True,
    content_length: int = 0,
    position: int = 0,
    viewport_length: int = 0,
    orientation: ScrollbarOrientationLike = "vertical_right",
    thumb_symbol: str | None = None,
    track_symbol: str | None = None,
    begin_symbol: str | None = None,
    end_symbol: str | None = None,
    color: ColorLike | None = None,
    thumb_color: ColorLike | None = None,
    track_color: ColorLike | None = None
)

Bases: ContentBase

Render scroll position and viewport proportion.

Example

Scrollbar(content_length=100, viewport_length=20, position=10)

Attributes:

content_length class-attribute instance-attribute

content_length: int = 0

Total scrollable length.

position class-attribute instance-attribute

position: int = 0

Current scroll offset.

viewport_length class-attribute instance-attribute

viewport_length: int = 0

Visible length.

orientation class-attribute instance-attribute

orientation: ScrollbarOrientationLike = 'vertical_right'

Scrollbar edge and direction.

thumb_symbol class-attribute instance-attribute

thumb_symbol: str | None = None

Custom thumb symbol.

track_symbol class-attribute instance-attribute

track_symbol: str | None = None

Custom track symbol.

begin_symbol class-attribute instance-attribute

begin_symbol: str | None = None

Symbol at the beginning.

end_symbol class-attribute instance-attribute

end_symbol: str | None = None

Symbol at the end.

color class-attribute instance-attribute

color: ColorLike | None = None

Default scrollbar color.

thumb_color class-attribute instance-attribute

thumb_color: ColorLike | None = None

Thumb color.

track_color class-attribute instance-attribute

track_color: ColorLike | None = None

Track color.

style class-attribute instance-attribute

style: Style | None = None

Optional shared style.

z class-attribute instance-attribute

z: int = 0

Sibling-local paint order.

visible class-attribute instance-attribute

visible: bool = True

Whether this content paints.

Clear dataclass

Clear(
    *,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True
)

Bases: ContentBase

Clear the assigned render area.

Attributes:

  • style (Style | None) –

    Optional shared style.

  • z (int) –

    Sibling-local paint order.

  • visible (bool) –

    Whether this content paints.

style class-attribute instance-attribute

style: Style | None = None

Optional shared style.

z class-attribute instance-attribute

z: int = 0

Sibling-local paint order.

visible class-attribute instance-attribute

visible: bool = True

Whether this content paints.

CellSpan dataclass

CellSpan(
    text: str = " ",
    foreground: ColorLike | None = None,
    background: ColorLike | None = None,
    modifiers: tuple[CharacterModifier, ...] = (),
)

A styled run inside a cell canvas row.

Attributes:

text class-attribute instance-attribute

text: str = ' '

Characters covered by the span.

foreground class-attribute instance-attribute

foreground: ColorLike | None = None

Foreground color.

background class-attribute instance-attribute

background: ColorLike | None = None

Background color.

modifiers class-attribute instance-attribute

modifiers: tuple[CharacterModifier, ...] = ()

Character modifiers.

CellCanvas dataclass

CellCanvas(
    *,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True,
    rows: tuple[tuple[CellSpan, ...], ...] = (),
    width: int = 0,
    height: int = 0
)

Bases: ContentBase

A rectangular sequence of styled cell rows.

Example

CellCanvas.from_rows(((CellSpan("OK", color="green"),),))

Attributes:

Methods:

  • from_rows

    Create a cell canvas from styled span rows.

rows class-attribute instance-attribute

rows: tuple[tuple[CellSpan, ...], ...] = ()

Rows of styled spans.

width class-attribute instance-attribute

width: int = 0

Canvas width in cells.

height class-attribute instance-attribute

height: int = 0

Canvas height in cells.

style class-attribute instance-attribute

style: Style | None = None

Optional shared style.

z class-attribute instance-attribute

z: int = 0

Sibling-local paint order.

visible class-attribute instance-attribute

visible: bool = True

Whether this content paints.

from_rows classmethod

from_rows(
    rows: Sequence[Sequence[CellSpan | str]],
    *,
    width: int | None = None,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True
) -> "CellCanvas"

Create a cell canvas from styled span rows.

Source code in xnano/core/content.py
@classmethod
def from_rows(
    cls,
    rows: Sequence[Sequence[CellSpan | str]],
    *,
    width: int | None = None,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True,
) -> "CellCanvas":
    """Create a cell canvas from styled span rows."""
    normalized = tuple(
        tuple(
            span if isinstance(span, CellSpan) else CellSpan(text=span)
            for span in row
        )
        for row in rows
    )
    measured_width = max(
        (sum(len(span.text) for span in row) for row in normalized),
        default=0,
    )
    return cls(
        rows=normalized,
        width=measured_width if width is None else width,
        height=len(normalized),
        style=style,
        z=z,
        visible=visible,
    )

Native dataclass

Native(
    *,
    style: Style | None = None,
    z: int = 0,
    visible: bool = True,
    interface_kind: str,
    payload: Any = None
)

Bases: ContentBase

Content already lowered for a named interface.

Example

Native(interface_kind="terminal", payload=widget)

Attributes:

interface_kind instance-attribute

interface_kind: str

Target interface name.

payload class-attribute instance-attribute

payload: Any = None

Interface-specific payload.

style class-attribute instance-attribute

style: Style | None = None

Optional shared style.

z class-attribute instance-attribute

z: int = 0

Sibling-local paint order.

visible class-attribute instance-attribute

visible: bool = True

Whether this content paints.