Block Text Generator
Generate ASCII block text with customizable borders, padding, alignment, and Unicode box-drawing characters. Create text boxes for code comments, documentation, and decorative displays.
About
Text blocks serve critical roles in source code documentation, configuration files, and plain-text communication where visual hierarchy must be achieved without rich formatting. Poorly constructed comment headers lead to misaligned characters across different editors, broken ASCII art when fonts lack monospace consistency, and maintenance headaches when block dimensions require manual recalculation. This generator computes exact character positions using the formula padLeft = floor((W โ L) รท 2) where W represents inner width and L represents line length, ensuring pixel-perfect centering regardless of content length.
The tool employs Unicode box-drawing characters from the U+2500 block, which render consistently across modern terminals, IDEs, and text editors supporting UTF-8. Edge cases include handling tabs (converted to spaces), preserving intentional trailing whitespace, and managing zero-width joiners that corrupt character counts. Output validates against the constraint totalWidth = borderLeft + paddingLeft + contentWidth + paddingRight + borderRight, preventing off-by-one errors that plague manual block construction.
Formulas
Block text generation requires precise character positioning to maintain alignment across variable-width content. The core layout follows a box model where total width equals the sum of all horizontal components.
Where bL and bR represent border character widths (typically 1), pL and pR represent padding spaces, and Wcontent is the inner text area width.
Center alignment distributes remaining space equally. The floor function ensures integer character counts, with any odd-character remainder added to the right padding.
Word wrapping employs a greedy algorithm that iterates through words, accumulating them until adding the next word would exceed the maximum width constraint.
The 1 accounts for the space character between words. Lines exceeding the maximum width with a single word are forcibly broken at the character level to prevent overflow.
Reference Data
| Character | Unicode | Name | Usage |
|---|---|---|---|
| โ | U+2500 | Box Drawings Light Horizontal | Top/bottom borders |
| โ | U+2502 | Box Drawings Light Vertical | Left/right borders |
| โ | U+250C | Box Drawings Light Down and Right | Top-left corner |
| โ | U+2510 | Box Drawings Light Down and Left | Top-right corner |
| โ | U+2514 | Box Drawings Light Up and Right | Bottom-left corner |
| โ | U+2518 | Box Drawings Light Up and Left | Bottom-right corner |
| โ | U+2550 | Box Drawings Double Horizontal | Heavy top/bottom borders |
| โ | U+2551 | Box Drawings Double Vertical | Heavy left/right borders |
| โ | U+2554 | Box Drawings Double Down and Right | Double top-left corner |
| โ | U+2557 | Box Drawings Double Down and Left | Double top-right corner |
| โ | U+255A | Box Drawings Double Up and Right | Double bottom-left corner |
| โ | U+255D | Box Drawings Double Up and Left | Double bottom-right corner |
| โญ | U+256D | Box Drawings Light Arc Down and Right | Rounded top-left corner |
| โฎ | U+256E | Box Drawings Light Arc Down and Left | Rounded top-right corner |
| โฐ | U+256F | Box Drawings Light Arc Up and Right | Rounded bottom-left corner |
| โฏ | U+2570 | Box Drawings Light Arc Up and Left | Rounded bottom-right corner |
| โ | U+2503 | Box Drawings Heavy Vertical | Bold vertical lines |
| โ | U+2501 | Box Drawings Heavy Horizontal | Bold horizontal lines |
| โ | U+250F | Box Drawings Heavy Down and Right | Bold top-left corner |
| โ | U+2513 | Box Drawings Heavy Down and Left | Bold top-right corner |
| โ | U+2517 | Box Drawings Heavy Up and Right | Bold bottom-left corner |
| โ | U+251B | Box Drawings Heavy Up and Left | Bold bottom-right corner |
| โ | U+2588 | Full Block | Solid fill patterns |
| โ | U+2593 | Dark Shade | 75% density fill |
| โ | U+2592 | Medium Shade | 50% density fill |
| โ | U+2591 | Light Shade | 25% density fill |
| โ | U+25CF | Black Circle | Bullet points |
| โ | U+25CB | White Circle | Empty bullet points |
| โ | U+25A0 | Black Square | Square markers |
| โก | U+25A1 | White Square | Empty square markers |