PrettyTerm - Pretty Terminal Printers

August 13, 2025 ยท View on GitHub

License: MIT Nim Version Version

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

CodeLibraty Foundation

Contributing

We welcome contributions to the project! Please create an issue or pull request for improvement suggestions.

Russion Version