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 prettytermimport 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" & ResetColorCustomizable 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.