tinge

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2025 License: MIT Imports: 4 Imported by: 3

README

Tinge

A lightweight Go library for creating beautifully styled terminal text output with an intuitive fluent API.

Features

  • 🎨 Rich Text Styling: Support for colors, bold, italic, and combined styles
  • 🔤 Fluent API: Chain methods for readable and expressive code
  • 📝 Flexible Output: Write to any io.Writer or use default stdout
  • 🎯 Simple Integration: Easy to integrate into any Go project
  • 🌈 Dracula Theme: Built-in color palette inspired by Dracula theme

Installation

go get github.com/opencommand/tinge

Quick Start

package main

import "github.com/opencommand/tinge"

func main() {
    tinge.Styled().
        Bold("Hello, ").
        Green("World!").
        Newline().
        Grey("This is a ").
        Italic("styled").
        Grey(" message.").
        Write()
}

Usage

Basic Styling
// Create a new styled text instance
text := tinge.Styled()

// Add styled content
text.Bold("Bold text").
    Space().
    Italic("Italic text").
    Newline().
    Red("Red text").
    Green("Green text")
Available Colors
  • Grey() - Light grey text
  • GreyDark() - Dark grey text
  • Red() - Red text
  • Green() - Bright green text
  • GreenLight() - Light green text
  • GreenDark() - Dark green text
  • Pink() - Pink text
  • Yellow() - Yellow text
  • Blue() - Light blue text
  • BlueDark() - Dark blue text
Text Formatting
  • Bold() - Bold text
  • Italic() - Italic text
  • BoldItalic() - Bold and italic text
Layout Control
tinge.Styled().
    Text("First line").
    Newline().
    Indent(4).
    Text("Indented line").
    Newline().
    Space(8).
    Text("Spaced text")
Custom Styling

Use the With() method to apply custom styles:

customStyle := lipgloss.NewStyle().Underline(true)
tinge.Styled().
    With(customStyle).
    Text("Custom styled text")
Output Control
// Write to stdout (default)
text.Write()

// Write to a specific writer
var buf strings.Builder
text.Write(&buf)

// Set default output writer
tinge.SetWriter(os.Stderr)
Complete Example
package main

import (
    "github.com/opencommand/tinge"
)

func main() {
    tinge.Styled().
        Bold("Welcome to ").
        Blue("Tinge").
        Bold("!").
        Newline().
        Newline().
        Grey("This library provides:").
        Newline().
        Indent(2).
        Green("✓ ").
        Text("Beautiful terminal output").
        Newline().
        Indent(2).
        Green("✓ ").
        Text("Fluent API design").
        Newline().
        Indent(2).
        Green("✓ ").
        Text("Easy integration").
        Newline().
        Newline().
        Yellow("Get started today!").
        Write()
}

API Reference

Core Methods
  • Styled() - Create a new styled text instance
  • Text(string) - Add plain text
  • Space(int?) - Add spaces (default: 1)
  • Newline() - Add a newline
  • Indent(int) - Set indentation for subsequent lines
  • Write(...io.Writer) - Output the styled text
Color Methods
  • Grey(string) - Light grey text
  • GreyDark(string) - Dark grey text
  • Red(string) - Red text
  • Green(string) - Bright green text
  • GreenLight(string) - Light green text
  • GreenDark(string) - Dark green text
  • Pink(string) - Pink text
  • Yellow(string) - Yellow text
  • Blue(string) - Light blue text
  • BlueDark(string) - Dark blue text
Formatting Methods
  • Bold(string) - Bold text
  • Italic(string) - Italic text
  • BoldItalic(string) - Bold and italic text
Advanced Methods
  • With(...TextStyle) - Apply custom styles
  • String() - Get the rendered string
  • SetWriter(io.Writer) - Set default output writer

Dependencies

Requirements

  • Go 1.23.5 or later

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Examples

Check out the examples in the repository for more usage patterns and advanced features.

Documentation

Overview

Copyright 2025 The Tinge Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

View Source
var (
	Grey       = lipgloss.NewStyle().Foreground(lipgloss.Color("#909194"))
	GreyDark   = lipgloss.NewStyle().Foreground(lipgloss.Color("#454e6d"))
	Green      = lipgloss.NewStyle().Foreground(lipgloss.Color("#50FA7B"))
	GreenLight = lipgloss.NewStyle().Foreground(lipgloss.Color("#3fed7b"))
	GreenDark  = lipgloss.NewStyle().Foreground(lipgloss.Color("#3C9258"))
	Red        = lipgloss.NewStyle().Foreground(lipgloss.Color("#ff5555"))
	Pink       = lipgloss.NewStyle().Foreground(lipgloss.Color("#ff79c6"))
	Yellow     = lipgloss.NewStyle().Foreground(lipgloss.Color("#f1fa8c"))
	Blue       = lipgloss.NewStyle().Foreground(lipgloss.Color("#a4ffff"))
	BlueDark   = lipgloss.NewStyle().Foreground(lipgloss.Color("#8be9fd"))

	Bold   = lipgloss.NewStyle().Bold(true)
	Italic = lipgloss.NewStyle().Italic(true)
)

Functions

func SetWriter added in v0.1.0

func SetWriter(output io.Writer)

Types

type StyledText

type StyledText struct {
	// contains filtered or unexported fields
}

func Styled

func Styled() *StyledText

func (*StyledText) Blue

func (s *StyledText) Blue(text string) *StyledText

func (*StyledText) BlueDark

func (s *StyledText) BlueDark(text string) *StyledText

func (*StyledText) Bold

func (s *StyledText) Bold(text string) *StyledText

func (*StyledText) BoldItalic

func (s *StyledText) BoldItalic(text string) *StyledText

func (*StyledText) Green

func (s *StyledText) Green(text string) *StyledText

func (*StyledText) GreenDark

func (s *StyledText) GreenDark(text string) *StyledText

func (*StyledText) GreenLight

func (s *StyledText) GreenLight(text string) *StyledText

func (*StyledText) Grey

func (s *StyledText) Grey(text string) *StyledText

func (*StyledText) GreyDark

func (s *StyledText) GreyDark(text string) *StyledText

func (*StyledText) Indent

func (s *StyledText) Indent(spaces int) *StyledText

func (*StyledText) Italic

func (s *StyledText) Italic(text string) *StyledText

func (*StyledText) Newline

func (s *StyledText) Newline() *StyledText

func (*StyledText) Pink

func (s *StyledText) Pink(text string) *StyledText

func (*StyledText) Red

func (s *StyledText) Red(text string) *StyledText

func (*StyledText) Space

func (s *StyledText) Space(n ...int) *StyledText

func (*StyledText) String

func (s *StyledText) String() string

func (*StyledText) Text

func (s *StyledText) Text(text string) *StyledText

func (*StyledText) With

func (s *StyledText) With(styles ...TextStyle) *StyledTextBuilder

func (*StyledText) Write added in v0.1.0

func (s *StyledText) Write(output ...io.Writer)

func (*StyledText) Yellow

func (s *StyledText) Yellow(text string) *StyledText

type StyledTextBuilder

type StyledTextBuilder struct {
	// contains filtered or unexported fields
}

func (*StyledTextBuilder) Text

func (b *StyledTextBuilder) Text(content string) *StyledText

type TextStyle

type TextStyle = lipgloss.Style

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL