A lightweight Swift package for creating beautiful ASCII and emoji boxes around text content. Perfect for CLI applications, logging, or anywhere you want to make text output more visually appealing.
- Create ASCII-style boxes around text
- Create emoji-style boxes for a more playful look
- Support for multi-line content
- Optional centered first line
- Customizable box width
- Smart width calculation based on content
- Proper handling of visual string lengths
- Customizable box styles
Add the following to your Package.swift file:
dependencies: [
.package(url: "https://github.com/yourusername/Boxed.git", from: "1.0.0")
]import Boxed
Boxed.ascii("Hello, World!")Output:
┌──────────────────────┐
│ │
│ Hello, World! │
│ │
└──────────────────────┘
import Boxed
Boxed.emoji("Welcome!\nTo my app")Output:
🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦
⬜️ ⬜️
⬜️ Welcome! ⬜️
⬜️ To my app ⬜️
⬜️ ⬜️
🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦
Boxed.ascii(
"Custom Width Example",
width: 40,
centerFirstLine: true
)
Boxed.emoji(
"Multiple\nLines\nOf\nText",
width: 30,
centerFirstLine: false
)public static func ascii(
_ message: String,
width: Int = 120,
centerFirstLine: Bool = true,
boxStyle: BoxCharactersProvider = BoxStyle.ascii
)public static func emoji(
_ message: String,
width: Int = 120,
centerFirstLine: Bool = true,
boxStyle: BoxCharactersProvider = BoxStyle.ascii
)message: The text content to be boxed (supports multiple lines using \n)width: The minimum width of the box (default: 120)centerFirstLine: Whether to center the first line of text (default: true)boxStyle: The style provider for box characters (default: BoxStyle.ascii)
You can create custom box styles by implementing the BoxCharactersProvider protocol:
public protocol BoxCharactersProvider {
var topLeft: Character { get }
var topRight: Character { get }
var bottomLeft: Character { get }
var bottomRight: Character { get }
var horizontal: Character { get }
var vertical: Character { get }
}Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
