Library for creating beautiful terminal interfaces in Nim.
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
nimble install prettyterm
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)
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
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
)
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>"
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!"
""")
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)
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
- Nim >= 1.6.0
- Modern terminal with ANSI escape-codes and unicode support
MIT License - see LICENSE file
We welcome contributions to the project! Please create an issue or pull request for improvement suggestions.