Skip to content

PrettyTerm - This is a set of utilities and modules for the Nim and Ryton programming languages that help create a user-friendly terminal interface.

License

Notifications You must be signed in to change notification settings

CodeLibraty/prettyterm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PrettyTerm - Pretty Terminal Printers

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

About

PrettyTerm - This is a set of utilities and modules for the Nim and Ryton programming languages that help create a user-friendly terminal interface.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages