Documentation ¶
Overview ¶
Provides basic bulding blocks for advanced console UI
Coordinate system:
1/1---X----> | Y | v
Documentation for ANSI codes: http://en.wikipedia.org/wiki/ANSI_escape_code#Colors
Inspired by: http://www.darkcoding.net/software/pretty-command-line-console-output-on-unix-in-python-and-go-lang/
Index ¶
- Constants
- Variables
- func Background(str string, color int) string
- func Bold(str string) string
- func Clear()
- func Color(str string, color int) string
- func Context(data string, idx, max int) string
- func CurrentHeight() int
- func Flush()
- func GetXY(x int, y int) (int, int)
- func Height() int
- func Highlight(str, substr string, color int) string
- func HighlightRegion(str string, from, to, color int) string
- func MoveCursor(x int, y int)
- func MoveCursorBackward(bias int)
- func MoveCursorDown(bias int)
- func MoveCursorForward(bias int)
- func MoveCursorUp(bias int)
- func MoveTo(str string, x int, y int) (out string)
- func Print(a ...interface{}) (n int, err error)
- func Printf(format string, a ...interface{}) (n int, err error)
- func Println(a ...interface{}) (n int, err error)
- func ResetLine(str string) (out string)
- func Width() int
- type Box
- type Chart
- type DataTable
- type LineChart
- type Table
Constants ¶
const ( AXIS_LEFT = iota AXIS_RIGHT )
const ( DRAW_INDEPENDENT = 1 << iota DRAW_RELATIVE )
const ( BLACK = iota RED GREEN YELLOW BLUE MAGENTA CYAN WHITE )
List of possible colors
const DEFAULT_BORDER = "- │ ┌ ┐ └ ┘"
const PCT = 0x8000 << shift
const RESET = "\033[0m"
Reset all custom styles
const RESET_COLOR = "\033[32m"
Reset to default color
const RESET_LINE = "\r\033[K"
Return cursor to start of line and clean it
Variables ¶
var ANSI_RE = regexp.MustCompile(`\\0\d+\[\d+(?:;\d+)?m`)
Global screen buffer Its not recommended write to buffer dirrectly, use package Print,Printf,Println fucntions instead.
Functions ¶
func CurrentHeight ¶
func CurrentHeight() int
CurrentHeight gets current height. Line count in Screen buffer.
func GetXY ¶
GetXY gets relative or absolute coordinates To get relative, set PCT flag to number:
// Get 10% of total width to `x` and 20 to y x, y = tm.GetXY(10|tm.PCT, 20)
func HighlightRegion ¶
func MoveCursorBackward ¶
func MoveCursorBackward(bias int)
Move cursor backward relative the current position
func MoveCursorForward ¶
func MoveCursorForward(bias int)
Move cursor forward relative the current position
Types ¶
type Box ¶
type Box struct { Buf *bytes.Buffer Width int Height int // To get even padding: PaddingX ~= PaddingY*4 PaddingX int PaddingY int // Should contain 6 border pieces separated by spaces // // Example border: // "- │ ┌ ┐ └ ┘" Border string Flags int // Not used now }
Box allows you to create independent parts of screen, with its own buffer and borders. Can be used for creating modal windows
Generates boxes likes this: ┌--------┐ │hello │ │world │ │ │ └--------┘
type LineChart ¶
type LineChart struct { Buf []string Width int Height int Flags int // contains filtered or unexported fields }
func NewLineChart ¶
type Table ¶
Tabwriter with own buffer:
totals := tm.NewTable(0, 10, 5, ' ', 0) fmt.Fprintf(totals, "Time\tStarted\tActive\tFinished\n") fmt.Fprintf(totals, "%s\t%d\t%d\t%d\n", "All", started, started-finished, finished) tm.Println(totals) Based on http://golang.org/pkg/text/tabwriter
func NewTable ¶
Same as here http://golang.org/pkg/text/tabwriter/#Writer.Init