tml

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Unlicense Imports: 6 Imported by: 50

README

tml - Terminal Markup Language

Build Status GoDoc

A Go module (and standalone binary) to make the output of coloured/formatted text in the terminal easier and more readable.

You can use it in your Go programs, and bash etc. too.

Example screenshot

Usage in Go

The output of coloured/formatted text is easy using the following syntax:

package main

import "github.com/liamg/tml"

func main() {
    tml.Printf("<red>this text is <bold>red</bold></red> and the following is <green>%s</green>\n", "not red")
}

Usage in Bash

First, install tml:

Install Go and run the following command.

# For Go 1.16+
# Make sure that `$GOPATH/bin` is in your `$PATH`, because that's where this gets installed

go install github.com/liamg/tml/tml@latest

# For Go <1.16

go get -u github.com/liamg/tml/tml

Then you can simply pipe text containing tags to tml:

#!/bin/bash

echo "<red>this text is <bold>red</bold></red> and the following is <green>not red</green>" | tml

Format

Each tag is enclosed in angle brackets, much like HTML.

You can nest tags as deeply as you like.

It's not required to close tags you've opened, though it can make for easier reading.

Available Tags
Foreground Colours
  • <red>
  • <green>
  • <yellow>
  • <blue>
  • <magenta>
  • <cyan>
  • <lightgrey>
  • <darkgrey>
  • <black>
  • <white>
  • <lightred>
  • <lightgreen>
  • <lightyellow>
  • <lightblue>
  • <lightmagenta>
  • <lightcyan>
Background Colours
  • <bg-red>
  • <bg-green>
  • <bg-yellow>
  • <bg-blue>
  • <bg-magenta>
  • <bg-cyan>
  • <bg-lightgrey>
  • <bg-darkgrey>
  • <bg-black>
  • <bg-white>
  • <bg-lightred>
  • <bg-lightgreen>
  • <bg-lightyellow>
  • <bg-lightblue>
  • <bg-lightmagenta>
  • <bg-lightcyan>
Attributes
  • <bold>
  • <dim>
  • <italic>
  • <underline>
  • <blink>
  • <reverse>
  • <hidden>
  • <strikethrough>

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisableFormatting added in v0.2.0

func DisableFormatting()

func EnableFormatting added in v0.2.0

func EnableFormatting()

func Fprintf added in v0.5.0

func Fprintf(w io.Writer, input string, a ...interface{}) error

func Fprintln added in v0.5.0

func Fprintln(w io.Writer, input string)

func NewLine added in v0.4.0

func NewLine()

NewLine prints a new line to the terminal with no content

func Parse

func Parse(input string) (string, error)

Parse converts the input string (containing TML tags) into a string containing ANSI escape code sequences for output to the terminal.

func Printf

func Printf(input string, a ...interface{}) error

Printf works like fmt.Printf, but adds the option of using tags to apply colour or text formatting to the written text. For example "<red>some red text</red>". A full list of tags is available here: https://github.com/liamg/tml

func Println

func Println(input string)

Println works like fmt.Println, but adds the option of using tags to apply colour or text formatting to the written text. For example "<red>some red text</red>". A full list of tags is available here: https://github.com/liamg/tml

func Sprintf

func Sprintf(input string, a ...interface{}) string

Sprintf works like fmt.Sprintf, but adds the option of using tags to apply colour or text formatting to the written text. For example "<red>some red text</red>". A full list of tags is available here: https://github.com/liamg/tml

Types

type Parser

type Parser struct {
	IncludeLeadingResets  bool
	IncludeTrailingResets bool
	// contains filtered or unexported fields
}

Parser is used to parse a TML string into an output string containing ANSI escape codes

func NewParser

func NewParser(w io.Writer) *Parser

NewParser creates a new parser that writes to w

func (*Parser) Parse

func (p *Parser) Parse(reader io.Reader) error

Parse takes input from the reader and converts any provided tags to the relevant ANSI escape codes for output to parser's writer.

Directories

Path Synopsis
_examples

Jump to

Keyboard shortcuts

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