|
| 1 | +from dataclasses import dataclass |
| 2 | + |
| 3 | +from textcompose.core import Value |
| 4 | + |
| 5 | + |
| 6 | +@dataclass |
| 7 | +class ProgressBarStyle: |
| 8 | + """ |
| 9 | + Configuration for customizing the appearance of a progress bar. |
| 10 | +
|
| 11 | + Attributes: |
| 12 | + left (str | Value): Character or value for the left border. |
| 13 | + fill (str | Value): Character or value for the filled portion. |
| 14 | + empty (str | Value): Character or value for the empty portion. |
| 15 | + right (str | Value): Character or value for the right border. |
| 16 | + template (str): Format string for rendering the progress bar. |
| 17 | +
|
| 18 | + Defaults to "{left}{bar}{right} {percent}". |
| 19 | +
|
| 20 | + Supported placeholders: |
| 21 | + - {left}: Left border. |
| 22 | + - {bar}: Combined filled and empty segments. |
| 23 | + - {right}: Right border. |
| 24 | + - {percent}: Progress percentage (e.g., "50%"). |
| 25 | + - {total}: Total number of steps. |
| 26 | + - {current}: Current step number. |
| 27 | +
|
| 28 | + Built-in styles: |
| 29 | + Several built-in progress bar styles are available in the `PROGRESS_BAR_STYLES` dictionary |
| 30 | + defined in this file. To use a built-in style, simply specify its name (string key). |
| 31 | + For example: |
| 32 | +
|
| 33 | + style = "symbol_square" |
| 34 | +
|
| 35 | + See the `PROGRESS_BAR_STYLES` dictionary in this file for the full list of available style names. |
| 36 | + """ |
| 37 | + |
| 38 | + left: str | Value |
| 39 | + fill: str | Value |
| 40 | + empty: str | Value |
| 41 | + right: str | Value |
| 42 | + template: str = "{left}{bar}{right} {percent}" |
| 43 | + |
| 44 | + |
| 45 | +PROGRESS_BAR_STYLES = { |
| 46 | + # Symbol styles |
| 47 | + "symbol_square": ProgressBarStyle(left="[", fill="■", empty=" ", right="]"), |
| 48 | + "symbol_simple": ProgressBarStyle(left="[", fill="=", empty=" ", right="]"), |
| 49 | + "symbol_modern": ProgressBarStyle(left="|", fill="█", empty=" ", right="|"), |
| 50 | + "symbol_classic": ProgressBarStyle(left="[", fill="#", empty="-", right="]"), |
| 51 | + "symbol_block": ProgressBarStyle(left="[", fill="█", empty="░", right="]"), |
| 52 | + "symbol_arrow": ProgressBarStyle(left="|", fill="=", empty="-", right=">"), |
| 53 | + "symbol_circle": ProgressBarStyle(left="(", fill="●", empty="○", right=")"), |
| 54 | + "symbol_bracket": ProgressBarStyle(left="<", fill="#", empty=".", right=">"), |
| 55 | + "symbol_star": ProgressBarStyle(left="[", fill="★", empty="☆", right="]"), |
| 56 | + "symbol_magic": ProgressBarStyle(left="{", fill="▓", empty="░", right="}"), |
| 57 | + "symbol_line": ProgressBarStyle(left="[", fill="=", empty=" ", right="]"), |
| 58 | + "symbol_pipe": ProgressBarStyle(left="|", fill="█", empty=" ", right="|"), |
| 59 | + # Emoji styles |
| 60 | + "emoj_square": ProgressBarStyle(left="", fill="🟩", empty="⬜", right=""), |
| 61 | + "emoji_circle": ProgressBarStyle(left="", fill="🟢", empty="⚪", right=""), |
| 62 | +} |
0 commit comments