### Install all dependencies at once with pip Source: https://github.com/denvercoder1/table2ascii/blob/main/CONTRIBUTING.md Installs the package with both 'dev' and 'docs' extras, covering all development and documentation dependencies. ```bash pip install -e ".[dev,docs]" ``` -------------------------------- ### Install documentation dependencies with pip Source: https://github.com/denvercoder1/table2ascii/blob/main/CONTRIBUTING.md Installs the package with the 'docs' extra to build or serve documentation locally. ```bash pip install -e ".[docs]" ``` -------------------------------- ### Install table2ascii with pip Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/index.rst Install the library using pip. Requires Python 3.8 or higher. ```bash pip install -U table2ascii ``` -------------------------------- ### Usage example with PresetStyle.ascii_box Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/PresetStyle.md Shows how to generate a table with a preset style using table2ascii. The example uses PresetStyle.ascii_box and prints the resulting table with borders. ```python from table2ascii import table2ascii, PresetStyle output = table2ascii( header=["First", "Second", "Third", "Fourth"], body=[["10", "30", "40", "35"], ["20", "10", "20", "5"]], column_widths=[10, 10, 10, 10], style=PresetStyle.ascii_box, # any preset style ) print(output) # +----------+----------+----------+----------+ # | First | Second | Third | Fourth | # +----------+----------+----------+----------+ # | 10 | 30 | 40 | 35 | # +----------+----------+----------+----------+ # | 20 | 10 | 20 | 5 | # +----------+----------+----------+----------+ ``` -------------------------------- ### Usage example for Options Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/Options.md Demonstrates constructing an Options instance with explicit values, including PresetStyle.double_thin_compact and use_wcwidth=True. Prints options.cell_padding which outputs 1. ```python from table2ascii.options import Options from table2ascii import PresetStyle options = Options( first_col_heading=False, last_col_heading=False, column_widths=None, alignments=None, number_alignments=None, cell_padding=1, style=PresetStyle.double_thin_compact, use_wcwidth=True, ) print(options.cell_padding) # 1 ``` -------------------------------- ### Usage Example with Custom Price Class Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/SupportsStr.md Shows how to use SupportsStr with a custom class that implements __str__, and demonstrates a runtime isinstance check. ```python from table2ascii import table2ascii, SupportsStr # A custom value type that supports str() class Price: def __init__(self, amount: str) -> None: self.amount = amount def __str__(self) -> str: return f"${self.amount}" output = table2ascii( header=["Item", "Price"], body=[["Milk", Price("2.99")], ["Cheese", Price("10.99")]], number_alignments=[None, ...], # values support str() ) print(output) # Structural check: assert isinstance(Price("1.00"), SupportsStr) # runtime_checkable ``` -------------------------------- ### Usage example for to_ascii() Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/TableToAscii.md Shows how to create a TableToAscii instance with options and print the resulting ASCII table. The output is shown in the comments. ```python from table2ascii.table_to_ascii import TableToAscii from table2ascii import PresetStyle from table2ascii.options import Options options = Options( first_col_heading=False, last_col_heading=False, column_widths=None, alignments=None, number_alignments=None, cell_padding=1, style=PresetStyle.double_thin_compact, use_wcwidth=True, ) table = TableToAscii( header=["A", "B"], body=[["1", "2"]], footer=None, options=options, ).to_ascii() print(table) # ╔═══╤═══╗ # ║ A │ B ║ # ╟───┼───╢ # ║ 1 │ 2 ║ # ╚═══╧═══╝ ``` -------------------------------- ### Install runtime dependencies with pip Source: https://github.com/denvercoder1/table2ascii/blob/main/CONTRIBUTING.md Installs the package in editable mode without extra dependencies, suitable for runtime use. ```bash pip install -e . ``` -------------------------------- ### Install development dependencies with pip Source: https://github.com/denvercoder1/table2ascii/blob/main/CONTRIBUTING.md Installs the package with the 'dev' extra to set up the development environment. Requires Python 3.8+. ```bash pip install -e ".[dev]" ``` -------------------------------- ### Usage example with per-column alignment Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/Alignment.md Shows how to use table2ascii with a list of Alignment values for per-column alignment. The output demonstrates the alignment of each column. ```python from table2ascii import table2ascii, Alignment output = table2ascii( header=["Product", "Category", "Price", "Rating"], body=[ ["Milk", "Dairy", "$2.99", "6.28318"], ["Cheese", "Dairy", "$10.99", "8.2"], ], # per-column alignment: LEFT, CENTER, RIGHT, DECIMAL alignments=[Alignment.LEFT, Alignment.CENTER, Alignment.RIGHT, Alignment.DECIMAL], ) print(output) # ╔══════════════════════════════════════╗ # ║ Product Category Price Rating ║ # ╟──────────────────────────────────────╢ # ║ Milk Dairy $2.99 6.28318 ║ # ║ Cheese Dairy $10.99 8.2 ║ # ╚══════════════════════════════════════╝ ``` -------------------------------- ### Fully-configured table2ascii call with all options Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/configuration.md Shows a complete table2ascii invocation with header, body, footer, column widths, alignments, cell padding, style, and wcwidth. Use this as a reference for configuring all available options. The example prints the resulting ASCII table. ```python from table2ascii import table2ascii, Alignment, PresetStyle output = table2ascii( header=["Product", "Category", "Price", "Rating"], body=[ ["Milk", "Dairy", "$2.99", "6.28318"], ["Cheese", "Dairy", "$10.99", "8.2"], ["Apples", "Produce", "$0.99", "10.00"], ], footer=["Total", "—", "$14.97", "24.48"], first_col_heading=True, last_col_heading=False, column_widths=[10, 10, None, None], # auto-size price/rating alignments=[Alignment.LEFT, Alignment.CENTER, Alignment.RIGHT, Alignment.DECIMAL], number_alignments=Alignment.RIGHT, # right-align numeric values cell_padding=1, style=PresetStyle.double_box, use_wcwidth=True, ) print(output) ``` -------------------------------- ### PresetStyle Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/PresetStyle.md Documentation for the PresetStyle enumeration, including usage examples and customization. ```APIDOC ## PresetStyle ### Description PresetStyle is an enumeration of predefined table styles for use with the `table2ascii` function. Each attribute is a mutable `TableStyle` object, allowing customization via the `set()` method. ### Usage ```python from table2ascii import table2ascii, PresetStyle output = table2ascii( header=["First", "Second", "Third", "Fourth"], body=[["10", "30", "40", "35"], ["20", "10", "20", "5"]], column_widths=[10, 10, 10, 10], style=PresetStyle.ascii_box, # any preset style ) print(output) # +----------+----------+----------+----------+ # | First | Second | Third | Fourth | # +----------+----------+----------+----------+ # | 10 | 30 | 40 | 35 | # +----------+----------+----------+----------+ # | 20 | 10 | 20 | 5 | # +----------+----------+----------+----------+ ``` ### Attributes - `PresetStyle.double_thin_compact` - Default style used when no style is specified. - `PresetStyle.` - Any other preset style. ### Customization Each attribute is a mutable `TableStyle`. You can derive a custom style using `PresetStyle.plain.set(...)`. See TableStyle.md for details. ``` -------------------------------- ### Catching Errors in Consumer Code Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/exceptions.md Example of how to catch table2ascii exceptions in consumer code. ```APIDOC ## Catching Errors in Consumer Code ### Description Example demonstrating how to catch `ColumnWidthTooSmallError` and other `Table2AsciiError` subclasses. ### Code Example ```python from table2ascii import table2ascii, Table2AsciiError, ColumnWidthTooSmallError try: table2ascii(body=[["a"]], column_widths=[0]) # 0 < minimum 4 (1 char + 2 padding) except ColumnWidthTooSmallError as exc: print(exc.column_index, exc.column_width, exc.min_width) except Table2AsciiError: # catch any other table2ascii error (all inherit Table2AsciiError) ... ``` ### Notes - All table2ascii errors inherit from `Table2AsciiError`. - See [errors.md](../errors.md) for the complete trigger/location catalog. ``` -------------------------------- ### Usage Example with table2ascii Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/Merge.md Shows how to use Merge.LEFT in header, body, and footer sequences passed to table2ascii(). The output demonstrates merged cells and separator rendering. Note that when a row begins with Merge.LEFT, the leading cell renders as an empty string. ```python from table2ascii import table2ascii, Merge, PresetStyle output = table2ascii( header=["#", "G", "Merge", Merge.LEFT, "S"], body=[ [1, 5, 6, 200, Merge.LEFT], [2, "E", "Long cell", Merge.LEFT, Merge.LEFT], ], footer=["SUM", "100", "200", Merge.LEFT, "300"], style=PresetStyle.double_thin_box, first_col_heading=True, ) print(output) # ╔═════╦═════╤═══════╤═════╗ # ║ # ║ G │ Merge │ S ║ # ╠═════╬═════╪═══╤═══╧═════╣ # ║ 1 ║ 5 │ 6 │ 200 ║ # ╟─────╫─────┼───┴─────────╢ # ║ 2 ║ E │ Long cell ║ # ╠═════╦═════╤═══╧═══╪═════╣ # ║ SUM ║ 100 │ 200 │ 300 ║ # ╚═════╩═════╧═══════╧═════╝ ``` -------------------------------- ### Serve documentation locally Source: https://github.com/denvercoder1/table2ascii/blob/main/CONTRIBUTING.md Builds and serves the documentation locally at http://127.0.0.1:8888. ```bash task docs ``` -------------------------------- ### Building Options in table2ascii() Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/Options.md Shows how table2ascii() constructs an Options instance with all resolved values and passes it to TableToAscii. This is the only place Options is built; consumers should use table2ascii() directly. ```python return TableToAscii( header, body, footer, Options( first_col_heading=first_col_heading, last_col_heading=last_col_heading, column_widths=column_widths, alignments=alignments, number_alignments=number_alignments, cell_padding=cell_padding, style=style, use_wcwidth=use_wcwidth, ), ).to_ascii() ``` -------------------------------- ### Alignment Enum Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/Alignment.md Documentation for the Alignment enum, including its definition, members, behavior notes, and usage examples. ```APIDOC ## `Alignment` Enum ### Description An `enum.IntEnum` describing how cell text is aligned within a column. Each member compares equal to its integer value. ### Definition ```python class Alignment(IntEnum): """Enum for text alignment types within a table cell""" LEFT = 0 CENTER = 1 RIGHT = 2 DECIMAL = 3 ``` ### Members | Member | Value | Description | |--------|-------|-------------| | `Alignment.LEFT` | `0` | Text is left-aligned (padded with spaces at the end). | | `Alignment.CENTER` | `1` | Text is centered (padding split evenly, extra space on the right when odd). | | `Alignment.RIGHT` | `2` | Text is right-aligned (padded with spaces at the beginning). | | `Alignment.DECIMAL` | `3` | Decimal numbers are aligned so the decimal point lines up across the column. | ### Usage Notes - The default alignment for all columns is `Alignment.CENTER` (applied by `table2ascii()` when `alignments` is `None`). - **DECIMAL semantics**: - If `DECIMAL` is used in `number_alignments`, all *non-numeric* values are aligned according to the `alignments` argument. - If `DECIMAL` is used in `alignments` (i.e. as the base column alignment), non-numeric values are centered. - Numeric values are integers, floats, and strings containing only decimal characters (`str.isdecimal`) and at most one decimal point. - DECIMAL alignment geometry is precomputed in `TableToAscii` via `__calculate_decimal_widths_and_positions()`: for each DECIMAL column it finds the max digits before the decimal point (`decimal_positions`) and the total width (`decimal_widths`), then pads each number so its decimal point lands at that position (`__pad()`). - `DECIMAL` was added in version 1.1.0. - `alignments`/`number_alignments` may each be a single `Alignment` (applied to every column) or a `Sequence[Alignment]` of per-column values (added in 1.1.0). ### Usage Example ```python from table2ascii import table2ascii, Alignment output = table2ascii( header=["Product", "Category", "Price", "Rating"], body=[ ["Milk", "Dairy", "$2.99", "6.28318"], ["Cheese", "Dairy", "$10.99", "8.2"], ], # per-column alignment: LEFT, CENTER, RIGHT, DECIMAL alignments=[Alignment.LEFT, Alignment.CENTER, Alignment.RIGHT, Alignment.DECIMAL], ) print(output) # ╔══════════════════════════════════════╗ # ║ Product Category Price Rating ║ # ╟──────────────────────────────────────╢ # ║ Milk Dairy $2.99 6.28318 ║ # ║ Cheese Dairy $10.99 8.2 ║ # ╚══════════════════════════════════════╝ ``` Single-value usage with a numeric override: ```python from table2ascii import table2ascii, Alignment output = table2ascii( header=["Name", "Age"], body=[["John", 30], ["Jane", 28]], alignments=Alignment.LEFT, # left-align all columns number_alignments=Alignment.RIGHT, # but right-align numeric values ) ``` ``` -------------------------------- ### Catch option-validation errors with TableOptionError Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/errors.md Catches option-validation errors, which are also ValueError. The example triggers an InvalidCellPaddingError by using a negative cell_padding. ```python from table2ascii import table2ascii, TableOptionError try: table2ascii(body=[["x"]], cell_padding=-1) # InvalidCellPaddingError except TableOptionError as exc: # also caught by `except ValueError` print(exc) ``` -------------------------------- ### PresetStyle.simple Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/PresetStyle.md A pre-built TableStyle instance for a simple border style. ```APIDOC ## PresetStyle.simple ### Description A pre-built TableStyle instance for a simple border style. ### Usage Pass this style to `table2ascii(style=PresetStyle.simple)`. ### Definition ```python simple = TableStyle.from_string(" ═ ║ ═ ══ ╦╩") ``` ``` -------------------------------- ### Set column widths and alignments with column_widths and alignments Source: https://github.com/denvercoder1/table2ascii/blob/main/README.md Demonstrates setting column widths and per-column alignments using the Alignment enum (LEFT, CENTER, RIGHT, DECIMAL). ```python from table2ascii import table2ascii, Alignment output = table2ascii( header=["Product", "Category", "Price", "Rating"], body=[ ["Milk", "Dairy", "$2.99", "6.283"], ["Cheese", "Dairy", "$10.99", "8.2"], ["Apples", "Produce", "$0.99", "10.00"], ], column_widths=[12, 12, 12, 12], alignments=[Alignment.LEFT, Alignment.CENTER, Alignment.RIGHT, Alignment.DECIMAL], ) print(output) """ ╔═══════════════════════════════════════════════════╗ ║ Product Category Price Rating ║ ╟───────────────────────────────────────────────────╢ ║ Milk Dairy $2.99 6.283 ║ ║ Cheese Dairy $10.99 8.2 ║ ║ Apples Produce $0.99 10.00 ║ ╚═══════════════════════════════════════════════════╝ """ ``` -------------------------------- ### Catch all table2ascii errors with Table2AsciiError Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/errors.md A broad exception handler that catches any error derived from Table2AsciiError. The example triggers a BodyColumnCountMismatchError by passing a row with fewer columns than expected. ```python from table2ascii import table2ascii, Table2AsciiError from table2ascii.exceptions import NoHeaderBodyOrFooterError try: table2ascii(body=[["1", "2"], ["3"]]) # 2 columns expected, row has 1 except NoHeaderBodyOrFooterError: print("no content given") except Table2AsciiError as exc: print(type(exc).__name__, exc) # BodyColumnCountMismatchError ``` -------------------------------- ### Catching table2ascii errors in consumer code Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/exceptions.md Example of catching ColumnWidthTooSmallError and Table2AsciiError when calling table2ascii. The try block triggers ColumnWidthTooSmallError with column_widths=[0] (minimum is 4). The except clauses handle the specific error and any other table2ascii error. ```python from table2ascii import table2ascii, Table2AsciiError, ColumnWidthTooSmallError try: table2ascii(body=[["a"]], column_widths=[0]) # 0 < minimum 4 (1 char + 2 padding) except ColumnWidthTooSmallError as exc: print(exc.column_index, exc.column_width, exc.min_width) except Table2AsciiError: # catch any other table2ascii error (all inherit Table2AsciiError) ... ``` -------------------------------- ### PresetStyle.ascii_compact Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/PresetStyle.md A pre-built TableStyle instance for an ASCII compact border style. ```APIDOC ## PresetStyle.ascii_compact ### Description A pre-built TableStyle instance for an ASCII compact border style. ### Usage Pass this style to `table2ascii(style=PresetStyle.ascii_compact)`. ### Definition ```python ascii_compact = TableStyle.from_string("+-+-+|| +-+-+ ++-+ -- --") ``` ``` -------------------------------- ### Basic table2ascii call with header, body, and footer Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/table2ascii.md Creates a table with header, body, and footer. The output is a string with no trailing newline. ```python from table2ascii import table2ascii output = table2ascii( header=["#", "G", "H", "R", "S"], body=[["1", "30", "40", "35", "30"], ["2", "30", "40", "35", "30"]], footer=["SUM", "130", "140", "135", "130"], ) print(output) # ╔═════════════════════════════╗ # ║ # G H R S ║ # ╟─────────────────────────────╢ # ║ 1 30 40 35 30 ║ # ║ 2 30 40 35 30 ║ # ╟─────────────────────────────╢ # ║ SUM 130 140 135 130 ║ # ╚═════════════════════════════╝ ``` -------------------------------- ### PresetStyle.minimalist Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/PresetStyle.md A pre-built TableStyle instance for a minimalist border style. ```APIDOC ## PresetStyle.minimalist ### Description A pre-built TableStyle instance for a minimalist border style. ### Usage Pass this style to `table2ascii(style=PresetStyle.minimalist)`. ### Definition ```python minimalist = TableStyle.from_string(" ─── │ ━━━ ─── ── ──━━┬┴┯┷") ``` ``` -------------------------------- ### PresetStyle.ascii_simple Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/PresetStyle.md A pre-built TableStyle instance for an ASCII simple border style. ```APIDOC ## PresetStyle.ascii_simple ### Description A pre-built TableStyle instance for an ASCII simple border style. ### Usage Pass this style to `table2ascii(style=PresetStyle.ascii_simple)`. ### Definition ```python ascii_simple = TableStyle.from_string(" = | = == ==") ``` ``` -------------------------------- ### Basic usage of TableStyle.from_string Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/TableStyle.md Creates a TableStyle by passing a 30-character string. The string maps to the 30 fields in order. ```python # Basic usage from table2ascii import TableStyle style = TableStyle.from_string("╔═╦╤╗║║│╠═╬╪╣╟─╫┼╢╚╩╧╝┬┴╤╧╥╨╦╩") ``` -------------------------------- ### PresetStyle.markdown Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/PresetStyle.md A pre-built TableStyle instance for a Markdown-style border. ```APIDOC ## PresetStyle.markdown ### Description A pre-built TableStyle instance for a Markdown-style border. ### Usage Pass this style to `table2ascii(style=PresetStyle.markdown)`. ### Definition ```python markdown = TableStyle.from_string(" ||||-||| -- --") ``` ``` -------------------------------- ### PresetStyle.ascii Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/PresetStyle.md A pre-built TableStyle instance for an ASCII border style. ```APIDOC ## PresetStyle.ascii ### Description A pre-built TableStyle instance for an ASCII border style. ### Usage Pass this style to `table2ascii(style=PresetStyle.ascii)`. ### Definition ```python ascii = TableStyle.from_string("+-+-+|| +-+-++-+-+++-+----++++") ``` ``` -------------------------------- ### PresetStyle.ascii_borderless Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/PresetStyle.md A pre-built TableStyle instance for an ASCII borderless style. ```APIDOC ## PresetStyle.ascii_borderless ### Description A pre-built TableStyle instance for an ASCII borderless style. ### Usage Pass this style to `table2ascii(style=PresetStyle.ascii_borderless)`. ### Definition ```python ascii_borderless = TableStyle.from_string(" | - -- --") ``` ``` -------------------------------- ### PresetStyle.thin_compact Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/PresetStyle.md A pre-built TableStyle instance for a thin compact border style. ```APIDOC ## PresetStyle.thin_compact ### Description A pre-built TableStyle instance for a thin compact border style. ### Usage Pass this style to `table2ascii(style=PresetStyle.thin_compact)`. ### Definition ```python thin_compact = TableStyle.from_string("┌─┬─┐││ ├─┼─┤ └┴─┘ ── ┬┴") ``` ``` -------------------------------- ### PresetStyle.borderless Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/PresetStyle.md A pre-built TableStyle instance for a borderless style. ```APIDOC ## PresetStyle.borderless ### Description A pre-built TableStyle instance for a borderless style. ### Usage Pass this style to `table2ascii(style=PresetStyle.borderless)`. ### Definition ```python borderless = TableStyle.from_string(" ┃ ━ ━━ ━━") ``` ``` -------------------------------- ### Use preset styles with PresetStyle Source: https://github.com/denvercoder1/table2ascii/blob/main/README.md Shows two preset styles: PresetStyle.ascii_box and PresetStyle.plain. The ascii_box style uses ASCII characters, while the plain style uses no borders and can be customized with cell_padding and alignments. ```python from table2ascii import table2ascii, Alignment, PresetStyle output = table2ascii( header=["First", "Second", "Third", "Fourth"], body=[["10", "30", "40", "35"], ["20", "10", "20", "5"]], column_widths=[10, 10, 10, 10], style=PresetStyle.ascii_box ) print(output) """ +----------+----------+----------+----------+ | First | Second | Third | Fourth | +----------+----------+----------+----------+ | 10 | 30 | 40 | 35 | +----------+----------+----------+----------+ | 20 | 10 | 20 | 5 | +----------+----------+----------+----------+ """ output = table2ascii( header=["First", "Second", "Third", "Fourth"], body=[["10", "30", "40", "35"], ["20", "10", "20", "5"]], style=PresetStyle.plain, cell_padding=0, alignments=Alignment.LEFT, ) print(output) """ First Second Third Fourth 10 30 40 35 20 10 20 5 """ ``` -------------------------------- ### PresetStyle.ascii_minimalist Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/PresetStyle.md A pre-built TableStyle instance for an ASCII minimalist border style. ```APIDOC ## PresetStyle.ascii_minimalist ### Description A pre-built TableStyle instance for an ASCII minimalist border style. ### Usage Pass this style to `table2ascii(style=PresetStyle.ascii_minimalist)`. ### Definition ```python ascii_minimalist = TableStyle.from_string(" --- | === --- -- --==--==") ``` ``` -------------------------------- ### PresetStyle.plain Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/PresetStyle.md A pre-built TableStyle instance for a plain style with no borders. ```APIDOC ## PresetStyle.plain ### Description A pre-built TableStyle instance for a plain style with no borders. ### Usage Pass this style to `table2ascii(style=PresetStyle.plain)`. ### Definition ```python plain = TableStyle.from_string(" " * 30).set(left_and_right_edge="") ``` ``` -------------------------------- ### Lint and fix codebase Source: https://github.com/denvercoder1/table2ascii/blob/main/CONTRIBUTING.md Runs Black, isort, and pre-commit hooks to lint and fix the codebase. ```bash task lint ``` -------------------------------- ### PresetStyle.thin Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/PresetStyle.md A pre-built TableStyle instance for a thin border style. ```APIDOC ## PresetStyle.thin ### Description A pre-built TableStyle instance for a thin border style. ### Usage Pass this style to `table2ascii(style=PresetStyle.thin)`. ### Definition ```python thin = TableStyle.from_string("┌─┬─┐││ ├─┼─┤├─┼─┤└┴─┘────┬┴┬┴") ``` ``` -------------------------------- ### Run tests with Tox Source: https://github.com/denvercoder1/table2ascii/blob/main/CONTRIBUTING.md Runs the Tox test script to verify that the tested functionality still works. ```bash task test ``` -------------------------------- ### PresetStyle.thick_compact Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/PresetStyle.md A pre-built TableStyle instance for a thick compact border style. ```APIDOC ## PresetStyle.thick_compact ### Description A pre-built TableStyle instance for a thick compact border style. ### Usage Pass this style to `table2ascii(style=PresetStyle.thick_compact)`. ### Definition ```python thick_compact = TableStyle.from_string("┏━┳━┓┃┃ ┣━╋━┫ ┗┻━┛ ━━ ┳┻") ``` ``` -------------------------------- ### Check typing errors with Pyright Source: https://github.com/denvercoder1/table2ascii/blob/main/CONTRIBUTING.md Runs Pyright to ensure type hints are used correctly and to check for typing errors. ```bash task pyright ``` -------------------------------- ### from_string(string) Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/TableStyle.md Creates a TableStyle by mapping the first 30 characters of the string to the 30 fields, in declaration order (A–V, W–Z, 0–3). Raises TableStyleTooLongError if the string is longer than 30 characters, and emits a TableStyleTooShortWarning if shorter, padding with spaces. ```APIDOC ## from_string(string) ### Description Creates a `TableStyle` by mapping the first 30 characters of the string to the 30 fields, in declaration order (A–V, W–Z, 0–3). ### Method Class method ### Signature ```python @classmethod def from_string(cls, string: str) -> "TableStyle": ``` ### Parameters - **string** (`str`) - Required - Exactly 30 characters, one per field, in order. ### Return Type `TableStyle` ### Behavior / Throws - If `len(string) > 30` (number of dataclass fields): Raises `TableStyleTooLongError` (see errors.md). - If `len(string) < 30`: Emits `TableStyleTooShortWarning` (a `UserWarning`) and right-pads the string with spaces. - If `len(string) == 30`: Constructs normally with `cls(*string)`. The character count (30) is derived at runtime from `len(cls.__dataclass_fields__)`, so it tracks the number of fields. ### Example ```python # Basic usage from table2ascii import TableStyle style = TableStyle.from_string("╔═╦╤╗║║│╠═╬╪╣╟─╫┼╢╚╩╧╝┬┴╤╧╥╨╦╩") ``` ```python # Error handling: too many characters raises; too few warns and pads import warnings from table2ascii import TableStyle, TableStyleTooLongError try: TableStyle.from_string("~" * 31) # 31 chars > 30 fields except TableStyleTooLongError as exc: print(exc.max_characters) # 30 with warnings.catch_warnings(record=True) as caught: warnings.simplefilter("always") TableStyle.from_string("~" * 10) # 10 chars -> warning, padded to 30 print(caught[0].category.__name__) # TableStyleTooShortWarning ``` ``` -------------------------------- ### PresetStyle.thin_compact_rounded Source: https://github.com/denvercoder1/table2ascii/blob/main/_autodocs/api-reference/PresetStyle.md A pre-built TableStyle instance for a thin compact rounded border style. ```APIDOC ## PresetStyle.thin_compact_rounded ### Description A pre-built TableStyle instance for a thin compact rounded border style. ### Usage Pass this style to `table2ascii(style=PresetStyle.thin_compact_rounded)`. ### Definition ```python thin_compact_rounded = TableStyle.from_string("╭─┬─╮││ ├─┼─┤ ╰┴─╯ ── ┬┴") ``` ```