Skip to main content

Termalign

Termalign is a lightweight Python module for advanced text formatting and alignment in terminals, logs, CLI output, and simple plain-text reports.

It provides intuitive functions and classes to align, format, wrap, colorize, and decorate text with optional borders and multi-column layouts.


Features

  • Align text: left, right, center, justify
  • Wrap and indent multiline text
  • Add decorative or structural ASCII/Unicode borders
  • Apply color and bold styling (ANSI-compatible)
  • Define reusable formatting styles
  • Easily create multi-column text layouts
  • Simple API (format_table) for quick use
  • Advanced API (TextFormatter, ColumnBuilder) for full control

Installation

# Clone or copy this module into your project
# or install manually via pip (in development)
pip install -e .

Usage Examples

Align a single line

from termalign import align_line

print(align_line("Hello", width=20, align="center"))
# --> "       Hello        "

Format a block of text

from termalign import format_block

text = "Python is a powerful, readable, and versatile programming language."
print(format_block(text, width=40, align="justify"))
#Python  is  a  powerful,  readable,  and
#versatile      programming     language.

Use a reusable formatter

from termalign import TextFormatter

fmt = TextFormatter(width=50, align="center", indent=4, border=True)
print(fmt.format("Centered and bordered text"))
#    +------------------------------------------------+
#    |           Centered and bordered text           |
#    +------------------------------------------------+

Add a border (ASCII, Unicode, Double, Dashed, DoubleDashed)

from termalign.utils import add_border

print(add_border("Hello World", style="unicode"))
#┌─────────────┐
#│ Hello World │
#└─────────────┘

Apply color

from termalign.utils import colorize

print(colorize("Success!", "green", bold=True))
print(colorize("Warning!", "yellow"))
print(colorize("Error!", "red"))

Format a Table (the easiest way!)

from termalign import format_table

print(format_table(
    texts=[
        "Full name of the participant",
        "Subject age",
        "Current city of residence"
    ],
    widths=[30, 20, 40],
    aligns=["left", "center", "right"],
    borders=True
))
#+--------------------------------+  +----------------------+  +------------------------------------------+
#| Full name of the participant   |  |     Subject age      |  |                Current city of residence |
#+--------------------------------+  +----------------------+  +------------------------------------------+

Advanced Usage with ColumnBuilder

from termalign import ColumnBuilder, ColumnLayout

layout = ColumnLayout.from_builders(
    ColumnBuilder("Left Column").width(30).align("left").border(),
    ColumnBuilder("Center Column").width(20).align("center").border(),
    ColumnBuilder("Right Column").width(40).align("right").indent(2).border()
)

print(layout.format())
#+--------------------------------+  +----------------------+    +----------------------------------------+
#| Left Column                    |  |    Center Column     |    |                           Right Column |
#+--------------------------------+  +----------------------+    +----------------------------------------+

Tools Reference

Core Functions

  • align_line(text, width, align): Align a single line.
  • format_block(text, width, align): Wrap and align multiple lines.
  • wrap_and_indent(text, width, indent): Wrap text with paragraph-style indentation.
  • format_columns(blocks, widths, align): Combine pre-formatted blocks into columns.

Formatting Utilities

  • pad_line(text, width): Manually pad a string.
  • indent_lines(text, indent): Add indentation to each line.
  • add_border(text, style): Wrap text with a border (ascii, unicode, double, dashed, DoubleDashed).
  • colorize(text, color, bold=False): Apply terminal ANSI color and bold style.

High-Level Interfaces

  • TextFormatter(width, align, indent, border): Object for reusable formatting config.
  • format_table(...): Quick function to build table with one-liners.
  • ColumnBuilder(text): Fluent builder for defining a column.
  • ColumnLayout.from_builders(...): Combine columns with full control.

License

MIT License

Metadata

Release files for termalign 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for termalign 0.1.1
File Size Uploaded
termalign-0.1.1.tar.gz 9.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for termalign 0.1.1
File Interpreter ABI Platform
termalign-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.8 kB

Release files / termalign-0.1.1.tar.gz

Download URL termalign-0.1.1.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
282507629d520b8021a9a7445e548ec40759afbf005d665791e2cf0f8934fc98
BLAKE2b-256 checksum
How to use checksums
db21e41d26e2912aa48d81a1fa0b9402a6f5acc1b12755f33145a072a11d1b26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / termalign-0.1.1-py3-none-any.whl

Download URL termalign-0.1.1-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d132b8f19074363605398cda25d9b77f9dc6d222d1fee6f52e18b79741d8d759
BLAKE2b-256 checksum
How to use checksums
17153fbde7baf3d2e36845ff9076acbd95001f93036036fb414209714c53145b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page