package goterm
import "github.com/buger/goterm"
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
- func NewBox(width, height int, flags int) *Box
- func (b *Box) String() (out string)
- func (b *Box) Write(p []byte) (int, error)
- type Chart
- type DataTable
- type LineChart
- func NewLineChart(width, height int) *LineChart
- func (c *LineChart) Draw(data *DataTable) (out string)
- func (c *LineChart) DrawAxes(maxX, minX, maxY, minY float64, index int)
- func (c *LineChart) DrawLine(x0, y0, x1, y1 int, symbol string)
- 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 Background ¶
Change background color of string:
tm.Background("string", tm.RED)
func Bold ¶
Make bold
func Clear ¶
func Clear()
Clear screen
func Color ¶
Apply given color to string:
tm.Color("RED STRING", tm.RED)
func Context ¶
func CurrentHeight ¶
func CurrentHeight() int
CurrentHeight gets current height. Line count in Screen buffer.
func Flush ¶
func Flush()
Flush buffer and ensure that it will not overflow screen
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 Height ¶
func Height() int
Height gets console height
func Highlight ¶
func HighlightRegion ¶
func MoveCursor ¶
Move cursor to given position
func MoveCursorBackward ¶
func MoveCursorBackward(bias int)
Move cursor backward relative the current position
func MoveCursorDown ¶
func MoveCursorDown(bias int)
Move cursor down relative the current position
func MoveCursorForward ¶
func MoveCursorForward(bias int)
Move cursor forward relative the current position
func MoveCursorUp ¶
func MoveCursorUp(bias int)
Move cursor up relative the current position
func MoveTo ¶
Move string to possition
func Print ¶
func Printf ¶
func Println ¶
func ResetLine ¶
ResetLine returns carrier to start of line
func Width ¶
func Width() int
Width gets console width
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 │ │ │ └--------┘
func NewBox ¶
Create new Box. Width and height can be relative:
// Create box with 50% with of current screen and 10 lines height box := tm.NewBox(50|tm.PCT, 10, 0)
func (*Box) String ¶
String renders Box
func (*Box) Write ¶
type Chart ¶
type DataTable ¶
type DataTable struct {
// contains filtered or unexported fields
}
func (*DataTable) AddColumn ¶
func (*DataTable) AddRow ¶
type LineChart ¶
type LineChart struct { Buf []string Width int Height int Flags int // contains filtered or unexported fields }
func NewLineChart ¶
func (*LineChart) Draw ¶
func (*LineChart) DrawAxes ¶
func (*LineChart) DrawLine ¶
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
func (*Table) String ¶
Source Files ¶
box.go plot.go table.go terminal.go terminal_sysioctl.go
Directories ¶
Path | Synopsis |
---|---|
examples |
- Version
- v1.0.4 (latest)
- Published
- Jan 25, 2022
- Platform
- js/wasm
- Imports
- 11 packages
- Last checked
- now –
Tools for package owners.