PrettyTerm - Pretty Terminal Printers
August 13, 2025 ยท View on GitHub
Library for creating beautiful terminal interfaces in Nim.
Description
PrettyTerm is a powerful Nim library that provides tools for creating styled and beautiful terminal interfaces. The library includes:
- ๐จ ANSI colors and styles support
- ๐ญ Theming system with customizable colors and icons
- ๐ Tag system for simple text styling
- ๐ณ Tree printer for structured output
- ๐ Advanced logging system
Installation
nimble install prettyterm
Quick Start
import prettyterm
# Using styled strings
echo sty"<red>Red text</red> and <green|bold>bold green</green|bold>"
# Theme configuration
let config = newDisplayConfig()
# ... using configuration
# Logging
let logger = newLogger(newLogTime())
let component = newComponent("myfile.nim", "myFunction", "/path")
discard logger.addLog("Test message", component, Ok)
Main Features
๐จ Colors and Styles
The library provides a complete set of ANSI colors and styles:
# Text colors
echo FgRed & "Red text" & ResetColor
echo FgGreen & "Green text" & ResetColor
echo FgBlue & "Blue text" & ResetColor
# Background colors
echo BgYellow & "Text on yellow background" & ResetColor
# Text styles
echo styleBold & "Bold text" & ResetColor
echo styleItalic & "Italic text" & ResetColor
echo styleUnderline & "Underlined text" & ResetColor
๐ญ Theming
Customizable theme system for consistent styling:
# Creating color theme
let customTheme = newColorTheme(
hintColor = clrBlue,
errorColor = clrRed,
successColor = clrGreen,
warningColor = clrYellow
)
# Creating icon theme
let customIcons = newIconsTheme(
hintIcon = "๐ก",
errorIcon = "โ",
successIcon = "โ
",
warningIcon = "โ ๏ธ"
)
# Creating display configuration
let config = newDisplayConfig(
colorTheme = customTheme,
iconsTheme = customIcons
)
๐ Text Styling
Simple and intuitive syntax with tags:
# Simple tags
echo sty"<red>Red text</red>"
echo sty"<green|bold>Bold green</green|bold>"
# Style combination
echo sty"<blue|underline|bg-yellow>Blue underlined on yellow background</blue|underline|bg-yellow>"
# Variable interpolation
let name = "World"
let value = 42
echo sty"Hello, <green>{name}</green>! Value: <yellow|bold>{value}</yellow|bold>"
๐ณ Tree Output
Structured data output with branching support:
# Creating root branch
let root = newBranch("Project analysis")
# Adding sub-branches
let lex = root.enterBranch("Lexical analysis")
echo lex.formatBranchLine("Tokenization completed")
let syntax = lex.enterBranch("Syntax analysis")
echo syntax.formatBranchLine("Building AST")
# Output tables
echo syntax.formatTableHeader("Results")
echo syntax.formatTableLine("Success: 100%")
echo syntax.formatTableFooter()
# Output code with line numbering
echo syntax.formatTableCodeMultiLine(1, """
proc hello() =
echo "Hello, World!"
""")
๐ Logging
Powerful logging system with various output styles:
# Creating logger
let logger = newLogger(
creationTime = newLogTime(),
printableInTerminal = true
)
# Creating component
let component = newComponent(
fileName = "main.nim",
funcName = "main",
dirPath = "/src"
)
# Adding logs
logger.style = loggerStyleTiny
discard logger.addLog("Application started", component, Ok)
logger.style = loggerStyleFull
discard logger.addLog("Database connection error", component, Error)
# Shutdown with file saving
logger.destroyLogger("./app.log", writeToFile = true)
Project Structure
prettyterm/
โโโ prettyterm.nimble # Nimble package file
โโโ src/ # package source
โ โโโ prettyterm.nim # Main module
โ โ source/ # All source files
โ โ โโโ colors.nim # ANSI colors and styles
โ โ โโโ commonTypes.nim # Basic types
โ โ โโโ themeConfig.nim # Theme configuration
โ โ โโโ stylish.nim # Text styling
โ โ โโโ treePrinter.nim # Tree printer
โ โ โโโ prettyLogger.nim # Logging system
โโโ LICENSE # MIT license
โโโ README.md # Documentation
โโโ README.ru.md # Russion version Documentation
Requirements
- Nim >= 1.6.0
- Modern terminal with ANSI escape-codes and unicode support
License
MIT License - see LICENSE file
Author
Contributing
We welcome contributions to the project! Please create an issue or pull request for improvement suggestions.