ansi

package module
v0.0.0-...-a6ffff3 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2017 License: MIT Imports: 3 Imported by: 2

README

ansi

ANSI utilities

Install

To get started, you need a working Go environment. Once available, grab the package here:

$ go get github.com/vutran/ansi

Usage

Cursor

To be documented.

Display

To be documented.

Style

Simple functions to apply a style to a string of text.

package main

import (
	"github.com/vutran/ansi/styles"
)

func main() {
	msg: = styles.Bold("Hello, world")
	fmt.Print(msg)
}
Colors

Simple functions to apply a foreground or background color to a string of text.

package main

import (
	"github.com/vutran/ansi/colors"
)

func main() {
	msg := colors.Blue("Hello, world")
	fmt.Print(msg)
}
Loaders

Display an animated progress loader.

loader

package main

import (
	"github.com/vutran/ansi"
	"github.com/vutran/ansi/loaders"
	"time"
)

func main() {
	s := ansi.Loader(loaders.Dots, 100)
	s.SetValue("Loading")
	s.Start()
	time.Sleep(2 * time.Second)
	s.SetValue("Finalizing...")
	time.Sleep(2 * time.Second)
	s.Stop()
}
Available Loaders
  • Circle
  • Clock
  • Dots
  • Lines
  • Moon
  • Triangle
Mix and Match

You can mix and decorate your text however you prefer.

package main

import (
	"github.com/vutran/ansi/colors"
	"github.com/vutran/ansi/styles"
)

func main() {
	// bold, blue text
	msg := styles.Bold(colors.Blue("Hello, world"))
	fmt.Print(msg)
}

License

MIT © Vu Tran

Documentation

Overview

Package ansi provides ANSI escape utilities for rendering styled text to the output.

Index

Constants

View Source
const Esc = "\u001B"

Esc is the default ANSI escape prefix

Variables

This section is empty.

Functions

func Black

func Black() string

Black sets the font color to black.

func BlackBg

func BlackBg() string

BlackBg sets the background color to black.

func BlinkFast

func BlinkFast() string

BlinkFast applies fast blinking effects.

func BlinkOff

func BlinkOff() string

BlinkOff removes all blinking effects.

func BlinkSlow

func BlinkSlow() string

BlinkSlow applies slow blinking effects.

func Blue

func Blue() string

Blue sets the font color to blue.

func BlueBg

func BlueBg() string

BlueBg sets the background color to blue.

func Bold

func Bold() string

Bold increases font intensity

func BoldOff

func BoldOff() string

BoldOff turns off bold effects

func Conceal

func Conceal() string

Conceal is not widely supported.

func CrossedOut

func CrossedOut() string

CrossedOut applies a strike-through to the text.

func CrossedOutOff

func CrossedOutOff() string

CrossedOutOff removes the strike-through from the text.

func CursorBackward

func CursorBackward(n int) string

CursorBackward moves the cursor backwards by `n` columns

func CursorDown

func CursorDown(n int) string

CursorDown moves the cursor down by `n` lines

func CursorForward

func CursorForward(n int) string

CursorForward moves the cursor forward by `n` columns

func CursorStart

func CursorStart(n int) string

CursorStart moves the cursor to column `n`

func CursorUp

func CursorUp(n int) string

CursorUp moves the cursor up by `n` lines

func Cyan

func Cyan() string

Cyan sets the font color to cyan.

func CyanBg

func CyanBg() string

CyanBg sets the background color to cyan.

func DefaultBg

func DefaultBg() string

DefaultBg resets the background color.

func DefaultColor

func DefaultColor() string

DefaultColor resets the font color.

func EraseDisplay

func EraseDisplay(code int) string

EraseDisplay clears the screen

func EraseLine

func EraseLine(code int) string

EraseLine clears part of the line. If `n` is zero, clears the cursor to the end of the line. If `n` is one, clear from cursor to beginning of the line. If `n` is two, clear entire line. Cursor position does not change

func Faint

func Faint() string

Faint decreases font intensity

func FaintOff

func FaintOff() string

FaintOff turns off faint effects

func GetCursorPosition

func GetCursorPosition() string

GetCursorPosition retrieves the cursor position

func Green

func Green() string

Green sets the font color to green.

func GreenBg

func GreenBg() string

GreenBg sets the background color to green.

func HideCursor

func HideCursor() string

HideCursor hides the cursor

func ImageNegative

func ImageNegative() string

ImageNegative applies a negative image effect.

func ImagePositive

func ImagePositive() string

ImagePosition removes the negative image effect.

func Italic

func Italic() string

Italic makes the font italicized. Sometimes treated as inverse. (Not widely supported)

func ItalicOff

func ItalicOff() string

ItalicOff turns off italicized effect.

func Magenta

func Magenta() string

Magenta sets the font color to magenta.

func MagentaBg

func MagentaBg() string

MagentaBg sets the background color to magenta.

func Red

func Red() string

Red sets the font color to red.

func RedBg

func RedBg() string

RedBg sets the background color to red.

func Reset

func Reset() string

Reset turns off all SGR attributes

func RestoreCursorPosition

func RestoreCursorPosition() string

RestoreCursorPosition restores the cursor position

func Reveal

func Reveal() string

Reveal turns off conceal mode.

func SaveCursorPosition

func SaveCursorPosition() string

SaveCursorPosition saves the current cursor position

func SelectGraphicsRendition

func SelectGraphicsRendition(code int) string

SelectGraphicsRendition sets the SGR parameters.

func ShowCursor

func ShowCursor() string

ShowCursor shows the cursor

func Underline

func Underline() string

Underline adds an underline to the text.

func UnderlineOff

func UnderlineOff() string

UnderlineOff removes the underline from the text.

func White

func White() string

White sets the font color to white.

func WhiteBg

func WhiteBg() string

WhiteBg sets the background color to white.

func Yellow

func Yellow() string

Yellow sets the font color to yellow.

func YellowBg

func YellowBg() string

YellowBg sets the background color to yellow.

Types

type LoaderControl

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

LoaderControl holds internal data for the loader

func Loader

func Loader(anim []string, speed int) *LoaderControl

Loader creates a new loader with the given `anim` that animates at the specified `speed`

func (*LoaderControl) SetValue

func (loader *LoaderControl) SetValue(value string)

SetValue will set a new value for the label

func (*LoaderControl) Start

func (loader *LoaderControl) Start()

Start will start the loader

func (*LoaderControl) Stop

func (loader *LoaderControl) Stop()

Stop will stop the loader

Directories

Path Synopsis
Apply custom color to your string
Apply custom color to your string
Collection of custom loaders
Collection of custom loaders
Apply custom font treatment to your strings
Apply custom font treatment to your strings

Jump to

Keyboard shortcuts

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