DEV Community

Sivaprasad Murali
Sivaprasad Murali

Posted on

Vargula: Beautiful Terminal Styling Made Simple

Bring Color Theory and Accessibility to Your Terminal Applications

As developers, we spend countless hours staring at terminal output. Yet most command-line tools remain stuck in a monochrome world, making it harder to parse information quickly and efficiently. What if styling your terminal output could be as intuitive as writing HTML, while also leveraging sophisticated color theory and accessibility features?

Enter Vargula — a Python library that transforms terminal styling from a technical chore into a creative endeavor.

The Problem with Terminal Styling

Traditional terminal styling libraries require you to juggle ANSI escape codes, remember cryptic color names, or chain multiple function calls for simple formatting. Worse yet, they offer no guidance on creating harmonious color palettes or ensuring your output is accessible to colorblind users.

# Traditional approach - verbose and unintuitive
print('\033[1m\033[91mError:\033[0m File not found')
Enter fullscreen mode Exit fullscreen mode

Vargula changes this paradigm entirely.

HTML-Like Markup for Terminal Text

Vargula introduces an intuitive tag-based syntax that feels natural to anyone familiar with HTML:

import vargula as vg

vg.write("This is <red>red</red> and <bold>bold</bold>")
vg.write("<#FF5733>Custom hex colors</#FF5733>")
vg.write("<bold><cyan>Nested <underline>styling</underline></cyan></bold>")
Enter fullscreen mode Exit fullscreen mode

The markup system supports:

  • Named colors (<red>, <bright_blue>)
  • Hex colors (<#FF5733>)
  • Background colors (<@yellow>, <@#000000>)
  • Text styles (<bold>, <italic>, <underline>)
  • Custom styles you define

Beyond Basic Styling: Color Theory Built In

What truly sets Vargula apart is its sophisticated color palette generation based on established color theory principles. Need a harmonious color scheme for your application? Generate one in a single line:

# Generate a complementary palette from a base color
colors = vg.generate_palette("#3498db", "complementary", 5)

# Create a complete theme with semantic colors
theme = vg.generate_theme_palette("analogous", "#e74c3c")
vg.apply_palette_theme(theme)

# Now use semantic tags
vg.write("<primary>Primary action</primary>")
vg.write("<error>Error message</error>")
vg.write("<success>Operation completed</success>")
Enter fullscreen mode Exit fullscreen mode

Vargula supports seven color harmony schemes:

  • Monochromatic — variations of a single hue
  • Analogous — adjacent colors on the color wheel
  • Complementary — opposite colors for maximum contrast
  • Split Complementary — a softer complementary scheme
  • Triadic — three evenly spaced hues
  • Tetradic — four colors in two complementary pairs
  • Square — four evenly spaced hues

Accessibility First

Creating beautiful terminal output means nothing if your users can't see it properly. Vargula takes accessibility seriously with built-in WCAG compliance checking and colorblind simulation.

# Ensure colors meet WCAG AA standards
theme = vg.generate_accessible_theme(
    base_color="#3498db",
    background="#ffffff",
    wcag_level="AA"
)

# Check contrast ratio between colors
ratio = vg.calculate_contrast_ratio("#FFFFFF", "#000000")

# Validate if palette is colorblind-safe
is_safe, problems = vg.validate_colorblind_safety(colors, "deuteranopia")

# Simulate how colors appear to colorblind users
simulated = vg.simulate_colorblindness("#FF0000", "protanopia")
Enter fullscreen mode Exit fullscreen mode

This means you can confidently create terminal applications that work for everyone, including the approximately 8% of men and 0.5% of women with color vision deficiencies.

Rich Tables, Effortless Progress Bars

Vargula doesn't stop at text styling. It includes powerful components for creating professional-looking tables and progress indicators:

# Create a styled table
table = vg.Table(
    title="Sales Report Q4 2024",
    border_style="blue",
    box="double"
)

table.add_column("Region", style="bold", justify="left")
table.add_column("Revenue", style="green", justify="right")
table.add_column("Growth", style="cyan", justify="center")

table.add_row("North America", "$1.2M", "+15%")
table.add_row("Europe", "$890K", "+8%")

print(table)
Enter fullscreen mode Exit fullscreen mode

Progress bars are equally straightforward:

import time

# Simple progress bar
for item in vg.progress_bar(range(100), desc="Processing"):
    time.sleep(0.01)

# Multiple concurrent progress bars
with vg.MultiProgress() as mp:
    task1 = mp.add_task("Downloading", total=100)
    task2 = mp.add_task("Processing", total=50)

    # Update tasks independently
    mp.update(task1, 1)
    mp.update(task2, 1)
Enter fullscreen mode Exit fullscreen mode

Advanced Color Manipulation

Need to adjust colors programmatically? Vargula provides a complete toolkit:

# Lighten or darken colors
lighter = vg.lighten("#3498db", 0.2)
darker = vg.darken("#3498db", 0.2)

# Adjust saturation
vivid = vg.saturate("#80a0c0", 0.3)
muted = vg.desaturate("#3498db", 0.3)

# Rotate hue
shifted = vg.shift_hue("#FF0000", 120)  # Red → Green

# Mix colors
purple = vg.mix("#FF0000", "#0000FF", 0.5)

# Invert colors
inverted = vg.invert("#FF0000")
Enter fullscreen mode Exit fullscreen mode

Custom Styles and Themes

Create reusable styles for consistent branding across your application:

# Define custom styles once
vg.create("error", color="red", look="bold")
vg.create("success", color="green", look="bold")
vg.create("highlight", bg="yellow", color="black")

# Use them throughout your code
vg.write("<error>Connection failed</error>")
vg.write("<success>Upload complete</success>")
vg.write("<highlight>Important notice</highlight>")

# Use context managers for temporary styles
with vg.temporary("debug", color="cyan", look="dim"):
    vg.write("<debug>Debug output</debug>")
# Style automatically cleaned up
Enter fullscreen mode Exit fullscreen mode

Save and Share Your Palettes

Once you've crafted the perfect color scheme, save it for reuse across projects:

# Generate and save a palette
colors = vg.generate_palette("#3498db", "analogous", 5)
vg.save_palette(colors, "ocean_theme.json", 
                metadata={"name": "Ocean Blue"})

# Load it later
colors, metadata = vg.load_palette("ocean_theme.json")

# Works with full themes too
theme = vg.generate_theme_palette("triadic", "#9b59b6")
vg.save_theme(theme, "purple_theme.json")
Enter fullscreen mode Exit fullscreen mode

Real-World Example: A Styled CLI Logger

Let's put it all together in a practical example:

import vargula as vg
from datetime import datetime

# Setup theme
theme = vg.generate_theme_palette("analogous", "#2196F3")
vg.apply_palette_theme(theme)

# Custom styles for log levels
vg.create("timestamp", color="#666666")
vg.create("debug", color="cyan", look="dim")
vg.create("info", color="blue")
vg.create("warning", color="yellow", look="bold")
vg.create("error", color="red", look="bold")
vg.create("critical", color="white", bg="red", look="bold")

def log(level, message):
    timestamp = datetime.now().strftime("%H:%M:%S")
    vg.write(f"<timestamp>[{timestamp}]</timestamp> <{level}>{level.upper()}</{level}> {message}")

# Usage
log("info", "Application started")
log("debug", "Loading configuration from config.json")
log("success", "Database connection established")
log("warning", "Cache is 90% full")
log("error", "Failed to connect to external API")
log("critical", "System out of memory!")
Enter fullscreen mode Exit fullscreen mode

This creates a professional, color-coded logging system with just a few lines of code.

Installation and Getting Started

Getting started with Vargula is simple:

pip install vargula
Enter fullscreen mode Exit fullscreen mode

The library works seamlessly across Windows, macOS, and Linux, handling platform-specific terminal quirks automatically.

Design Philosophy

Vargula's design is guided by three core principles:

  1. Intuitive API — If you can write HTML, you can style terminal text
  2. Accessibility matters — Beautiful output should be inclusive
  3. Sophisticated yet simple — Advanced color theory shouldn't require a PhD

When to Use Vargula

Vargula shines in scenarios where terminal output quality matters:

  • CLI applications that need professional, branded output
  • Build tools that report complex status information
  • Data pipelines that need clear, color-coded logging
  • Developer tools where good UX includes good terminal UX
  • System monitors that display real-time status information

The Future of Terminal Styling

Terminals aren't going away — they're evolving. Modern developers expect rich, informative output from their command-line tools. Vargula makes it possible to deliver that experience without sacrificing development speed or code readability.

Whether you're building a simple script or a complex CLI application, Vargula lets you focus on functionality while ensuring your output is beautiful, accessible, and professional.

Try It Yourself

Ready to transform your terminal output? Install Vargula today and explore what's possible:

import vargula as vg

# Generate a palette
colors = vg.generate_palette(scheme="triadic", count=5)

# Preview it
print(vg.preview_palette(colors))

# Check accessibility
is_safe, _ = vg.validate_colorblind_safety(colors)
print("Colorblind-safe!" if is_safe else "Needs adjustment")

# Apply and use
theme = vg.generate_theme_palette("complementary")
vg.apply_palette_theme(theme)
vg.write("<primary>Primary</primary> <error>Error</error> <success>Success</success>")
Enter fullscreen mode Exit fullscreen mode

Visit the GitHub repository for full documentation, examples, and to contribute to the project.


Made with 🎨 by Sivaprasad Murali

Have you tried Vargula? Share your terminal styling creations in the comments below!

Top comments (0)