Skip to content

markup

thkit.markup

Module for display-related classes and functions.

Classes:

ThangBar(*args, **kwargs)

Bases: Progress

A class to extend functions of the rich's progress bar.

The same as rich.progress.Progress, with additional methods: - hide_bar(): hide the progress bar. - show_bar(): show the progress bar. - compute_eta(): static method to compute estimated time of arrival (ETA) given number of iterations and time taken.

Methods:

  • hide_bar

    Hide all progress bars in the given Progress object.

  • show_bar

    Show all progress bars in the given Progress object.

  • align_etatext

    Align the ETA text to the given width for all tasks.

  • compute_eta

    Estimate remaining time.

hide_bar()

Hide all progress bars in the given Progress object.

show_bar()

Show all progress bars in the given Progress object.

align_etatext(width: int)

Align the ETA text to the given width for all tasks.

compute_eta(num_iters: int, iter_index: int, old_time: float | None = None, new_time: float | None = None) -> str staticmethod

Estimate remaining time.

DynamicBarColumn(**kwargs)

Bases: BarColumn

Extend BarColumn that can read per-task fields 'complete_color', 'finished_color',... to customize colors.

Parameters:

  • The same as `rich.progress.BarColumn`, and following additional arguments
  • - complete_color (str) –

    the color for completed part of the bar.

  • - finished_color (str) –

    the color for finished bar.

  • - pulse_color (str) –

    the color for pulsing bar.

Methods:

  • render

    Gets a progress bar widget for a task.

render(task) -> ProgressBar

Gets a progress bar widget for a task.

TextDecor(text: str = 'example')

A collection of text decoration utilities.

Methods:

  • fill_center

    Return the text centered within a line of the given length, filled with fill.

  • fill_left

    Return the text left-aligned within a line of the given length, with left and right fills.

  • fill_box

    Return a string centered in a box with side delimiters.

  • repeat

    Repeat the input string to a specified length.

  • mkcolor

    Return ANSI-colored text that works in terminal or Jupyter.

Attributes:

text = text instance-attribute

fill_center(fill: str = '-', length: int = 60) -> str

Return the text centered within a line of the given length, filled with fill.

fill_left(margin: int = 15, fill_left: str = '-', fill_right: str = ' ', length: int = 60) -> str

Return the text left-aligned within a line of the given length, with left and right fills.

fill_box(fill: str = ' ', sp: str = 'ǁ', length: int = 60) -> str

Return a string centered in a box with side delimiters.

Example:

TextDecor("hello").fill_box(fill="-", sp="|", length=20)
"|-------hello-------|"

Notes
  • To input unicode characters, use the unicode escape sequence (e.g., "ǁ" for a specific character). See unicode-table for more details.
    • ║ (Double vertical bar, u2551)
    • ‖ (Double vertical line, u2016)
    • ǁ (Latin letter lateral click, u01C1)

repeat(length: int) -> str

Repeat the input string to a specified length.

mkcolor(color: str = 'blue') -> str

Return ANSI-colored text that works in terminal or Jupyter.

Parameters:

  • color (str, default: 'blue' ) –

    Color name. Defaults to "blue". Supported string values include: - Color names: "black", "red", "green",...See list here - Color ANSI codes: "#ff0000",... See codes here. - RGB codes: "rgb(255,0,0)",... See codes here.

Notes
  • Refer rich's color scheme.