goterm: Index | Files | Directories

package goterm

import ""

Provides basic bulding blocks for advanced console UI

Coordinate system:


Documentation for ANSI codes:

Inspired by:


Package Files

box.go plot.go table.go terminal.go terminal_sysioctl.go


const (
    AXIS_LEFT = iota
const (
    DRAW_INDEPENDENT = 1 << iota
const (
    BLACK = iota

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


var Output *bufio.Writer = bufio.NewWriter(os.Stdout)
var Screen *bytes.Buffer = new(bytes.Buffer)

Global screen buffer Its not recommended write to buffer dirrectly, use package Print,Printf,Println fucntions instead.

func Background Uses

func Background(str string, color int) string

Change background color of string:

tm.Background("string", tm.RED)

func Bold Uses

func Bold(str string) string

Make bold

func Clear Uses

func Clear()

Clear screen

func Color Uses

func Color(str string, color int) string

Apply given color to string:

tm.Color("RED STRING", tm.RED)

func Context Uses

func Context(data string, idx, max int) string

func CurrentHeight Uses

func CurrentHeight() int

CurrentHeight gets current height. Line count in Screen buffer.

func Flush Uses

func Flush()

Flush buffer and ensure that it will not overflow screen

func GetXY Uses

func GetXY(x int, y int) (int, int)

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 Uses

func Height() int

Height gets console height

func Highlight Uses

func Highlight(str, substr string, color int) string

func HighlightRegion Uses

func HighlightRegion(str string, from, to, color int) string

func MoveCursor Uses

func MoveCursor(x int, y int)

Move cursor to given position

func MoveCursorBackward Uses

func MoveCursorBackward(bias int)

Move cursor backward relative the current position

func MoveCursorDown Uses

func MoveCursorDown(bias int)

Move cursor down relative the current position

func MoveCursorForward Uses

func MoveCursorForward(bias int)

Move cursor forward relative the current position

func MoveCursorUp Uses

func MoveCursorUp(bias int)

Move cursor up relative the current position

func MoveTo Uses

func MoveTo(str string, x int, y int) (out string)

Move string to possition

func Print Uses

func Print(a ...interface{}) (n int, err error)

func Printf Uses

func Printf(format string, a ...interface{}) (n int, err error)

func Println Uses

func Println(a ...interface{}) (n int, err error)

func ResetLine Uses

func ResetLine(str string) (out string)

ResetLine returns carrier to start of line

func Width Uses

func Width() int

Width gets console width

type Box Uses

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 Uses

func NewBox(width, height int, flags int) *Box

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 Uses

func (b *Box) String() (out string)

String renders Box

func (*Box) Write Uses

func (b *Box) Write(p []byte) (int, error)

type Chart Uses

type Chart interface {
    Draw(data DataTable, flags int) string

type DataTable Uses

type DataTable struct {
    // contains filtered or unexported fields

func (*DataTable) AddColumn Uses

func (d *DataTable) AddColumn(name string)

func (*DataTable) AddRow Uses

func (d *DataTable) AddRow(elms ...float64)

type LineChart Uses

type LineChart struct {
    Buf []string

    Width  int
    Height int

    Flags int
    // contains filtered or unexported fields

func NewLineChart Uses

func NewLineChart(width, height int) *LineChart

func (*LineChart) Draw Uses

func (c *LineChart) Draw(data *DataTable) (out string)

func (*LineChart) DrawAxes Uses

func (c *LineChart) DrawAxes(maxX, minX, maxY, minY float64, index int)

func (*LineChart) DrawLine Uses

func (c *LineChart) DrawLine(x0, y0, x1, y1 int, symbol string)

type Table Uses

type Table struct {

    Buf *bytes.Buffer

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)

 Based on

func NewTable Uses

func NewTable(minwidth, tabwidth, padding int, padchar byte, flags uint) *Table

Same as here

func (*Table) String Uses

func (t *Table) String() string



Package goterm imports 8 packages (graph) and is imported by 83 packages. Updated 2020-07-12. Refresh now. Tools for package owners.