• Stars
    star
    954
  • Rank 46,064 (Top 1.0 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 11 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Advanced terminal output in Go

Description

This library provides basic building blocks for building advanced console UIs.

Initially created for Gor.

Full API documentation: http://godoc.org/github.com/buger/goterm

Basic usage

Full screen console app, printing current time:

import (
    tm "github.com/buger/goterm"
    "time"
)

func main() {
    tm.Clear() // Clear current screen

    for {
        // By moving cursor to top-left position we ensure that console output
        // will be overwritten each time, instead of adding new.
        tm.MoveCursor(1,1)

        tm.Println("Current Time:", time.Now().Format(time.RFC1123))

        tm.Flush() // Call it every time at the end of rendering

        time.Sleep(time.Second)
    }
}

This can be seen in examples/time_example.go. To run it yourself, go into your $GOPATH/src/github.com/buger/goterm directory and run go run ./examples/time_example.go

Print red bold message on white background:

tm.Println(tm.Background(tm.Color(tm.Bold("Important header"), tm.RED), tm.WHITE))

Create box and move it to center of the screen:

tm.Clear()

// Create Box with 30% width of current screen, and height of 20 lines
box := tm.NewBox(30|tm.PCT, 20, 0)

// Add some content to the box
// Note that you can add ANY content, even tables
fmt.Fprint(box, "Some box content")

// Move Box to approx center of the screen
tm.Print(tm.MoveTo(box.String(), 40|tm.PCT, 40|tm.PCT))

tm.Flush()

This can be found in examples/box_example.go.

Draw table:

// Based on http://golang.org/pkg/text/tabwriter
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)
tm.Flush()

This can be found in examples/table_example.go.

Line charts

Chart example:

screen shot 2013-07-09 at 5 05 37 pm

    import (
        tm "github.com/buger/goterm"
    )

    chart := tm.NewLineChart(100, 20)
    
    data := new(tm.DataTable)
    data.AddColumn("Time")
    data.AddColumn("Sin(x)")
    data.AddColumn("Cos(x+1)")

    for i := 0.1; i < 10; i += 0.1 {
	data.AddRow(i, math.Sin(i), math.Cos(i+1))
    }
    
    tm.Println(chart.Draw(data))

This can be found in examples/chart_example.go.

Drawing 2 separate graphs in different scales. Each graph have its own Y axe.

chart.Flags = tm.DRAW_INDEPENDENT

Drawing graph with relative scale (Grapwh draw starting from min value instead of zero)

chart.Flags = tm.DRAW_RELATIVE

More Repositories

1

goreplay

GoReplay is an open-source tool for capturing and replaying live HTTP traffic into a test environment in order to continuously test your system with real data. It can be used to increase confidence in code deployments, configuration changes and infrastructure changes.
Go
18,294
star
2

jsonparser

One of the fastest alternative JSON parser for Go that does not require schema
Go
5,303
star
3

cloud-ssh

Cloud enhanced SSH client replacement with host auto-completion
Go
111
star
4

chromus

Chromus - web music player, reincarnation of Last.fm free music player https://chrome.google.com/extensions/detail/bbncpldmanoknoahidbgmkgobgmhnafh
JavaScript
78
star
5

PointOut

PointOut
JavaScript
11
star
6

budget_allocation_ui

JavaScript
7
star
7

minus-javascript

Javascript API for Min.us
JavaScript
6
star
8

vk_contest

JavaScript
3
star
9

go2service

Python
3
star
10

email_reminder

JavaScript
3
star
11

oDesk-extension

JavaScript
3
star
12

fotodep_store

PHP
3
star
13

CPP-Labs

MIEE 2009
3
star
14

flick_faver

Flickr mashup
Python
2
star
15

video-player

Video player
ActionScript
2
star
16

ff_addon_template

JavaScript
2
star
17

cursor_logger

JavaScript
2
star
18

fotodep_fmagazine

PHP
2
star
19

instant_hits

2
star
20

gmail-news-reader

Use Gmail as news reader
JavaScript
2
star
21

currency_viewer

http://habrahabr.ru/special/ostrovok/
JavaScript
2
star
22

minus-extension

Browser extension for Min.us
JavaScript
2
star
23

capistrano-fast-deploy

Capistrano v3 addon for faster deploys
2
star
24

helpdesk

Android and iPhone reviews in 1 place
JavaScript
2
star
25

SimplyRead

JavaScript
2
star
26

appengine_starter_kit

Google App Engine project template
Python
2
star
27

rentfilter

Vertical search engine for apartments rent ads with fraud detection
Python
2
star
28

business_address_finder

Finds addresses and phones by company name. Thanks to Yandex Maps API.
Python
2
star
29

sidekiq-job-manager

Manage your Sidekiq jobs
Ruby
2
star
30

simplifyjson

https://simplifyjson.com
HTML
2
star
31

avtoadfilter

avtoadfilter
Python
1
star
32

donotforgettodo

Most simple todo project
Python
1
star
33

payoneer_account_stats

Payoneer account stats
JavaScript
1
star
34

video_scrobbler

Firefox extention
JavaScript
1
star
35

minus-firefox

JavaScript
1
star
36

text-editing-extension

1
star
37

enchanced_bookmarks

http://enchmarks.blogspot.com/
1
star
38

vida_parser

Vida.ru parser
Ruby
1
star
39

master-f

Сайт строительной фирмы Мастер-Ф
JavaScript
1
star
40

calendar_api

Callendar API
Ruby
1
star
41

music_string_parser

Parses given string, and returns music info (Artist, Album, Song, etc..)
1
star
42

Audio-Viz

CoffeeScript
1
star
43

Squzy

1
star
44

minus_chrome_app

1
star
45

lars

🚨 Is a lightweight, fast and extensible zero allocation HTTP router for Go used to create customizable frameworks.
Go
1
star
46

jquery_select

1
star
47

datocms-Hugo-Portfolio-Website-demo

CSS
1
star
48

vim_config

My vimrc config
1
star
49

fontlovers

JavaScript
1
star
50

resume

JavaScript
1
star
51

dfmo

DFMO Group
Python
1
star
52

music_video_aggregator

Python
1
star
53

goreplay-docker

Docker image for goreplay
1
star