Skip to main content

Provides utilities for drawing fancy text boxes and tables using the Unicode Box Drawings block.

Project description

boxxy

Provides utilities for drawing fancy text boxes and tables using the Unicode Box Drawings block.


Some example code can be found in example.py:

from boxxy import *

# Create a canvas we can draw boxes and text to.
canvas = BoxCanvas()

# Draw a simple box at (0, 0) with size (10, 10).
canvas.draw_box(0, 0, 10, 10)

# Draw another, overlapping, box with double-line borders.
canvas.draw_box(5, 5, 10, 10, double_all=True)

# Draw another one but only double the left and right borders.
canvas.draw_box(3, 3, 20, 8, double_left=True, double_right=True)

# Draw a box with filled inside.
canvas.draw_box(8, 1, 5, 4, fill=True)

# Draw a simple text box.
canvas.text_box(12, 9, 'Hello world!')

# Draw a text box with multiple lines and extra padding.
canvas.text_box(17, 1, 'Big multi-\nline box.', padding=Padding(3, 1))

# Create a table and give it a title.
table = Table(title="Example")

# Set a background character that will show inside the table where we don't have any cells.
table.background = '·'

# Add row headers.
# Negative rows and columns are treated as headers during layout, but are generally the same as any other cell.
table.add(0, -1, 'Row 1')
table.add(2, -1, 'Row 3')

# Add column headers using one of the utility functions.
table.add_row('Col 1', 'Col 2', 'Col 3', None, 'Col 5', row=-1)

# Add a cell with some text.
table.add(0, 0, 'Hello world!')

# Add cells spanning rows and columns.
table.add(1, 0, 'Span\nrows', row_span=2)
table.add(1, 1, 'Span columns', col_span=4)

# Add cells with different horizontal alignment.
table.add(2, 1, 'Align Right', col_span=4, h_align=HAlign.Right)
table.add(3, 0, 'Align Left', col_span=2, h_align=HAlign.Left)
table.add(3, 2, 'Center', col_span=3, h_align=HAlign.Center)

# Draw the table to the canvas, with optional offset.
table.draw(canvas, 8, 12)
# It is also possible to just print the table with a default canvas:
# print(table)

# Finally, print the canvas.
print(canvas)

Output (sadly not displaying correctly on PyPI):

┌────────┐                                                
│       ┌┴──┐    ┌────────────────┐                       
│       │   │    │                │                       
│  ╓────┤   ├────┤   Big multi-   │                       
│  ║    └┬──┘    │   line box.    │                       
│  ║ ╔═══╪════╗  │                │                       
│  ║ ║   │    ║  └────╥───────────┘                       
│  ║ ║   │    ║       ║                                   
│  ║ ║   │    ║       ║                                   
└──╫─╫───┘  ┌─╨───────╨────┐                              
   ╙─╫──────┤ Hello world! │                              
     ║      └─╥────────────┘                              
     ║        ║ ┌─────────┐                               
     ║        ║ │ Example │                               
     ╚════════╝ ├─────────┴────┬───────┬───────┐ ┌───────┐
                │    Col 1     │ Col 2 │ Col 3 │ │ Col 5 │
        ┌───────┼──────────────┼───────┴───────┴─┴───────┤
        │ Row 1 │ Hello world! │·························│
        └───────┼──────────────┼─────────────────────────┤
                │     Span     │       Span columns      │
        ┌───────┤     rows     ├─────────────────────────┤
        │ Row 3 │              │             Align Right │
        └───────┼──────────────┴───────┬─────────────────┤
                │ Align Left           │      Center     │
                └──────────────────────┴─────────────────┘

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

boxxy-1.2.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

boxxy-1.2-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file boxxy-1.2.tar.gz.

File metadata

  • Download URL: boxxy-1.2.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for boxxy-1.2.tar.gz
Algorithm Hash digest
SHA256 d77cfe726ac8b6f21b22ec21b4a24e0d691054f8cf97d917f8f1916b817f11f5
MD5 776781d1003ca14c07859890f84d5b83
BLAKE2b-256 cb9bd87163ca2b81242042c0865d334ee49c02c5bed3050cb915422faf70c438

See more details on using hashes here.

File details

Details for the file boxxy-1.2-py3-none-any.whl.

File metadata

  • Download URL: boxxy-1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for boxxy-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4f1239828292cd7cbc1c71c9c35ef6870b511d755a23c69c74032802025cdfd1
MD5 e6bb36bd6ca3d27564be6fa6be143516
BLAKE2b-256 2686fb008d4e0f7e4c98f997948933855ee4f1d122d29d77ce8cf5bdb7fac850

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page