cfmt

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: MIT Imports: 5 Imported by: 0

README

cfmt

ANSI colours and basic movement.

Functions

Print()

Print() takes special fmt-style parameters in the form of keywords to style text/backgrounds and move the cursor.

Example:

	cfmt.Print("%blue %bgwhite Blue%normal\tNormal\n")

Note that keywords may be followed by a space when followed by letters. This extra space won't be printed.

Printf()

Printf() takes the keywords from Print and applies its styling, then parses it through fmt.Printf().

	cfmt.Printf("%red%t%normal\n", false)
Format()

Returns a formatted string directly, allowing you to further process it.

Example:

	s := cfmt.Format("%green Green")
TermSize()

This utility function returns the width and height of the current terminal in number of characters:

	w,h,err := cfmt.TermSize()
	…
Pos()

This function sets the position in the terminal window to print from. Best combined with %cls.

Keywords

Text colours
  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • grey
  • lred
  • lgreen
  • lyellow
  • lblue
  • lmagenta
  • lcyan
  • lwhite
Background colours
  • bgblack
  • bgred
  • bggreen
  • bgyellow
  • bgblue
  • bgmagenta
  • bgcyan
  • bgwhite
  • bggrey
  • bglred
  • bglgreen
  • bglyellow
  • bglblue
  • bglmagenta
  • bglcyan
  • bglwhite
Styling and specials
  • reset: Back to normal colour and style

  • bold

  • fuzzy: May simply be grey

  • italic

  • under

  • blink: May not work (thank goodness)

  • fast: Fastblink; see blink

  • reverse: Mighr appear as black on grey.

  • conceal: May not do anything.

  • strike

  • clre: Clear to end of line

  • save: Store cursor position

  • rest: Restore cursor position; useful in progress printouts

  • cls: Clear screen

  • hide: Hide cursor

  • show: Show cursor

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(f string) string

Format returns a string with styling applied.

func Pos

func Pos(x, y int) string

Pos returns the appropriate escape code to move the cursor to the specified position in the terminal.

func Print

func Print(s string)

Print with colours, but no other formatting.

func Printf

func Printf(s string, v ...interface{})

Printf with colours uses fmt.Printf().

func TermSize

func TermSize() (width, height int, err error)

TermSize returns the width and height of the default terminal.

Types

This section is empty.

Jump to

Keyboard shortcuts

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