termwind

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 8 Imported by: 0

README

Termwind

Go Go Report Card GoDoc License

Style CLI applications with Tailwind-like syntax in Go.

Installation

go get github.com/codiume/termwind

Usage

package main

import (
    "fmt"
    "log"
    "github.com/codiume/termwind"
)

func main() {
    output, err := termwind.Render(`
        <div class="ml-2">
            <span class="px-1 mt-1 bg-green-500 text-white font-bold">Success</span>
            <span class="ml-1">Operation completed</span>
        </div>
    `)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Print(output)
}

Supported Elements

Element Description
<div> Container element
<span> Inline element
<p> Paragraph
<ul> Unordered list
<ol> Ordered list
<li> List item
<dl> Definition list
<dt> Definition term
<dd> Definition description
<a> Anchor/link
<hr> Horizontal rule
<br> Line break

Supported Classes

Spacing
Class Description
ml-{n}, mr-{n}, mt-{n}, mb-{n} Margin (left, right, top, bottom)
mx-{n}, my-{n} Margin (horizontal, vertical)
pl-{n}, pr-{n}, pt-{n}, pb-{n} Padding (left, right, top, bottom)
px-{n}, py-{n} Padding (horizontal, vertical)
Colors

Foreground: text-{color}
Background: bg-{color}

Supported color palettes:

  • Standard: black, red, green, yellow, blue, magenta, cyan, white, gray
  • Bright: bright-{color}
  • Tailwind: slate, gray, zinc, neutral, stone, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose (50-900 shades)
  • Hex: #rrggbb
Typography
Class Description
font-bold Bold text
font-italic Italic text
underline Underlined text
line-through Strike-through text
uppercase Transform to uppercase
lowercase Transform to lowercase
capitalize Capitalize words
snakecase Transform to snake_case
Layout
Class Description
truncate Truncate text
max-w-{n} Maximum width
min-w-{n} Minimum width

Acknowledgments

This package was inspired by nunomaduro/termwind.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(input string) (string, error)

Render a HTML string and returns a styled string suitable for terminal output. Supported elements and class names are documented in the README.

func RenderToString

func RenderToString(el *Element) string

Types

type Element

type Element struct {
	Tag      Tag
	Classes  []string
	Attrs    map[string]string
	Style    Style
	Children []*Element
	Content  string
	Parent   *Element
}

Element represents a single node in the parsed element tree. Tag identifies the HTML element type, Style holds the resolved visual properties, and Children contains nested elements.

func Parse

func Parse(input string) (*Element, error)

type Style

type Style struct {
	PaddingLeft     int
	PaddingRight    int
	PaddingTop      int
	PaddingBottom   int
	MarginLeft      int
	MarginRight     int
	MarginTop       int
	MarginBottom    int
	Bold            bool
	Italic          bool
	Underline       bool
	Strikethrough   bool
	TextTransform   string
	ForegroundColor string
	BackgroundColor string
	Truncate        bool
	MaxWidth        int
	MinWidth        int
}

func ParseClasses

func ParseClasses(classes []string) Style

type Tag

type Tag string
const (
	TagAnchor    Tag = "a"
	TagBreakLine Tag = "br"
	TagDd        Tag = "dd"
	TagDiv       Tag = "div"
	TagDl        Tag = "dl"
	TagDt        Tag = "dt"
	TagHr        Tag = "hr"
	TagLi        Tag = "li"
	TagOl        Tag = "ol"
	TagParagraph Tag = "p"
	TagRaw       Tag = "raw"
	TagSpan      Tag = "span"
	TagUl        Tag = "ul"
)

func (Tag) IsInline

func (t Tag) IsInline() bool

IsInline reports whether a tag is an inline-level element. Inline elements do not support vertical margins.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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