Пример #1
0
func main() {
	err := termui.Init()
	if err != nil {
		panic(err)
	}
	defer termui.Close()

	termui.UseTheme("helloworld")

	g0 := termui.NewGauge()
	g0.Percent = 40
	g0.Width = 50
	g0.Height = 3
	g0.Border.Label = "Slim Gauge"
	g0.BarColor = termui.ColorRed
	g0.Border.FgColor = termui.ColorWhite
	g0.Border.LabelFgColor = termui.ColorCyan

	g2 := termui.NewGauge()
	g2.Percent = 60
	g2.Width = 50
	g2.Height = 3
	g2.PercentColor = termui.ColorBlue
	g2.Y = 3
	g2.Border.Label = "Slim Gauge"
	g2.BarColor = termui.ColorYellow
	g2.Border.FgColor = termui.ColorWhite

	g1 := termui.NewGauge()
	g1.Percent = 30
	g1.Width = 50
	g1.Height = 5
	g1.Y = 6
	g1.Border.Label = "Big Gauge"
	g1.PercentColor = termui.ColorYellow
	g1.BarColor = termui.ColorGreen
	g1.Border.FgColor = termui.ColorWhite
	g1.Border.LabelFgColor = termui.ColorMagenta

	g3 := termui.NewGauge()
	g3.Percent = 50
	g3.Width = 50
	g3.Height = 3
	g3.Y = 11
	g3.Border.Label = "Gauge with custom label"
	g3.Label = "{{percent}}% (100MBs free)"
	g3.LabelAlign = termui.AlignRight

	termui.Render(g0, g1, g2, g3)

	<-termui.EventCh()
}
Пример #2
0
func (t *TerminalUI) AdjustMemory(stats Statistics) {
	// memory gauges
	mem := make([]*ui.Gauge, len(stats.Instances))
	for i, idx := range stats.Instances {
		// show max 8 instances
		if i > 7 {
			break
		}

		memory := uint64(stats.Data[idx].Stats.Usage.Memory)
		quota := uint64(stats.Data[idx].Stats.MemoryQuota)
		percent := int(math.Ceil((float64(memory) / float64(quota)) * 100.0))
		mem[i] = ui.NewGauge()
		mem[i].Percent = percent
		mem[i].Height = 13 - min(len(stats.Instances), 8)
		mem[i].Border.Label = fmt.Sprintf("Memory - Instance %d: %d%% (%s / %s)",
			i, percent, bytefmt.ByteSize(memory), bytefmt.ByteSize(quota))
		mem[i].Border.FgColor = ui.ColorWhite
		mem[i].Border.LabelFgColor = ui.ColorWhite
		mem[i].BarColor = colors[i%6]
		mem[i].PercentColor = ui.ColorWhite
	}
	t.Memory = mem

	// update layout
	ui.Body.Rows = []*ui.Row{
		ui.NewRow(
			ui.NewCol(3, 0, t.Usage),
			ui.NewCol(3, 0, t.Summary),
			ui.NewCol(6, 0, t.Disk)),
		ui.NewRow(
			ui.NewCol(6, 0, t.CPU),
			t.newMemCol(6, 0, t.Memory)),
	}
}
Пример #3
0
Файл: chunk.go Проект: rzh/montu
func (w *ChunkWidget) Init() {
	g := termui.NewGauge()
	g.Percent = 10
	g.Width = 50
	g.Height = 3
	g.Y = 11
	g.Border.Label = "> " + w.title + " chunks <"
	g.Label = "test"
	g.LabelAlign = termui.AlignRight
	g.BarColor = termui.ColorGreen
	// g.PercentColor = termui.ColorYellow

	w.bc = g

	go func() {
		for {
			// TODO: refresh data here via channel or something
			s := gen.MongosMonitor()

			if max3(s.GetStats().ChunkDistribution) == 0 {
				w.bc.Percent = 0
			} else {
				w.bc.Percent = w.getChunkCount(s.GetStats())
			}
			w.bc.Label = fmt.Sprintf("chunks: %d", s.GetStats().ChunkDistribution[w.shard])
			w.bc.Border.Label = "> " + w.title + " - " + w.bc.Label + " <"

			time.Sleep(1 * time.Second)
		}
	}()
}
Пример #4
0
// titleWidget Provides the title bar
func titleWidget() *termui.Gauge {
	t := termui.NewGauge()
	t.Height = 1
	t.Border = false

	return t
}
Пример #5
0
func main() {
	err := ui.Init()
	if err != nil {
		panic(err)
	}
	defer ui.Close()

	p := ui.NewPar(":PRESS q TO QUIT DEMO")
	p.Height = 3
	p.Width = 50
	p.TextFgColor = ui.ColorWhite
	p.BorderLabel = "Text Box"
	p.BorderFg = ui.ColorCyan

	g := ui.NewGauge()
	g.Percent = 50
	g.Width = 50
	g.Height = 3
	g.Y = 11
	g.BorderLabel = "Gauge"
	g.BarColor = ui.ColorRed
	g.BorderFg = ui.ColorWhite
	g.BorderLabelFg = ui.ColorCyan

	ui.Render(p, g) // feel free to call Render, it's async and non-block
}
Пример #6
0
func newTerminalUI(appName string) error {
	if err := ui.Init(); err != nil {
		return err
	}
	ui.UseTheme("helloworld")

	// usage text
	usageText := fmt.Sprintf(`Show live statistics for [%s]

:Press 'q' or 'ctrl-c' to exit
:Press 'PageUp' to increase app instances
:Press 'PageDown' to decrease app instances`, appName)
	usage := ui.NewPar(usageText)
	usage.Height = 12
	usage.TextFgColor = ui.ColorWhite
	usage.Border.Label = "Usage"
	usage.Border.FgColor = ui.ColorCyan

	// summary text
	summary := ui.NewPar("")
	summary.Height = 12
	summary.TextFgColor = ui.ColorRed
	summary.Border.Label = "Summary"
	summary.Border.FgColor = ui.ColorCyan

	// cpu sparklines
	data := [400]int{}
	line := ui.NewSparkline()
	line.Data = data[:]
	line.Height = 4
	line.LineColor = colors[0]
	cpu := ui.NewSparklines(line)
	cpu.Height = 7
	cpu.Border.Label = "CPU Usage"

	// memory gauges
	mem := make([]*ui.Gauge, 1)
	for i := range mem {
		mem[i] = ui.NewGauge()
		mem[i].Percent = 0
		mem[i].Height = 5
	}

	// disk bars
	disk := ui.NewBarChart()
	disk.Border.Label = "Disk Usage (in MB)"
	disk.Data = []int{0, 0, 0, 0, 0, 0, 0, 0}
	disk.Height = 12
	disk.BarWidth = 10
	disk.DataLabels = []string{"I: 0", "I: 1", "I: 2", "I: 3", "I: 4", "I: 5", "I: 6", "I: 7"}
	disk.TextColor = ui.ColorWhite
	disk.BarColor = ui.ColorYellow
	disk.NumColor = ui.ColorWhite

	term = &TerminalUI{ui.Body, usage, summary, cpu, mem, disk}
	return nil
}
Пример #7
0
func (cte *CpuTabElems) AddGauge(key string, Y int, width int) *termui.Gauge {
	cte.GMap[key] = termui.NewGauge()
	cte.GMap[key].Width = width
	cte.GMap[key].Height = 3
	cte.GMap[key].Y = Y
	cte.GMap[key].Border.Label = key
	cte.GMap[key].Percent = 0 //int(val.user + val.nice + val.system)
	return cte.GMap[key]
}
Пример #8
0
func main() {
	err := ui.Init()
	fmt.Println(daemon.UpSince())
	if err != nil {
		fmt.Println("Could not initialise UI")
	}
	defer ui.Close()

	ut, _ := daemon.Uptime()
	p := ui.NewPar(ut.String())
	p.Height = 3
	p.Width = 50
	p.TextFgColor = ui.ColorWhite
	p.Border.Label = "Uptime"
	p.Border.FgColor = ui.ColorCyan

	g0 := ui.NewGauge()
	g0.Percent = 40
	g0.Width = 50
	g0.Height = 3
	g0.Border.Label = "Memory"
	g0.BarColor = ui.ColorRed
	g0.Border.FgColor = ui.ColorWhite
	g0.Border.LabelFgColor = ui.ColorCyan

	g2 := ui.NewGauge()
	g2.Percent = 60
	g2.Width = 50
	g2.Height = 3
	g2.PercentColor = ui.ColorBlue
	g2.Y = 3
	g2.Border.Label = "CPU"
	g2.BarColor = ui.ColorYellow
	g2.Border.FgColor = ui.ColorWhite

	ui.Body.AddRows(ui.NewRow(ui.NewCol(6, 0, g0), ui.NewCol(6, 0, p)),
		ui.NewRow(ui.NewCol(6, 0, g2)))
	ui.Body.Align()
	ui.Render(ui.Body)
	go updateMemCPU(g2, g0)
	go updateUptime(p)
	<-ui.EventCh()
}
Пример #9
0
func main() {
	err := termui.Init()
	if err != nil {
		panic(err)
	}
	defer termui.Close()

	termui.UseTheme("helloworld")

	g0 := termui.NewGauge()
	g0.Percent = 40
	g0.Width = 50
	g0.Height = 3
	g0.Border.Label = "Slim Gauge"
	g0.BarColor = termui.ColorRed
	g0.Border.FgColor = termui.ColorWhite
	g0.Border.LabelFgColor = termui.ColorCyan

	g2 := termui.NewGauge()
	g2.Percent = 60
	g2.Width = 50
	g2.Height = 3
	g2.PercentColor = termui.ColorBlue
	g2.Y = 3
	g2.Border.Label = "Slim Gauge"
	g2.BarColor = termui.ColorYellow
	g2.Border.FgColor = termui.ColorWhite

	g1 := termui.NewGauge()
	g1.Percent = 30
	g1.Width = 50
	g1.Height = 5
	g1.Y = 6
	g1.Border.Label = "Big Gauge"
	g1.PercentColor = termui.ColorYellow
	g1.BarColor = termui.ColorGreen
	g1.Border.FgColor = termui.ColorWhite
	g1.Border.LabelFgColor = termui.ColorMagenta

	termui.Render(g0, g1, g2)

	termbox.PollEvent()
}
Пример #10
0
func main() {

	err := termui.Init()
	if err != nil {
		panic(err)
	}
	defer termui.Close()

	sinps := (func() []float64 {
		n := 220
		ps := make([]float64, n)
		for i := range ps {
			ps[i] = 1 + math.Sin(float64(i)/5)
		}
		return ps
	})()

	p := termui.NewPar(":PRESS q or Esc TO QUIT DEMO Hello World")
	p.Height = 3
	p.Width = 50
	p.TextFgColor = termui.ColorWhite
	p.BorderLabel = "Hello-World"
	p.BorderFg = termui.ColorCyan

	lc1 := termui.NewLineChart()
	lc1.BorderLabel = "dot-mode Line Chart"
	lc1.Mode = "dot"
	lc1.Data = sinps
	lc1.Width = 26
	lc1.Height = 12
	lc1.X = 51
	lc1.DotStyle = '+'
	lc1.AxesColor = termui.ColorWhite
	lc1.LineColor = termui.ColorYellow | termui.AttrBold

	g0 := termui.NewGauge()
	g0.Percent = 40
	g0.Width = 50
	g0.Height = 3
	g0.Y = 3
	g0.BorderLabel = "Slim Gauge"
	g0.BarColor = termui.ColorRed
	g0.BorderFg = termui.ColorWhite
	g0.BorderLabelFg = termui.ColorCyan

	termui.Render(p, g0, lc1)

	termui.Handle("/sys", func(e termui.Event) {
		k, ok := e.Data.(termui.EvtKbd)
		if ok && (k.KeyStr == "q" || k.KeyStr == "<escape>") {
			termui.StopLoop()
		}
	})
	termui.Loop()
}
Пример #11
0
func NewMemTabElems(width int) *MemTabElems {
	g := termui.NewGauge()
	g.Width = width
	g.Height = 3
	g.Y = 0

	sline := termui.NewSparkline()
	sline.Title = "MEM"
	sline.Height = 8

	sls := termui.NewSparklines(sline)
	sls.Width = width
	sls.Height = 12
	sls.Y = 3
	return &MemTabElems{Gauge: g, SLines: sls}
}
Пример #12
0
func (m *MsgLossChart) Init(cfUI terminal.UI) {
	m.sentByIP = make(map[string]int64)
	m.receivedByIP = make(map[string]int64)
	m.cfUI = cfUI
	m.graph = termui.NewGauge()
	m.graph.Width = 50
	m.graph.Height = 8
	m.graph.PercentColor = termui.ColorBlue
	m.graph.Y = 0
	m.graph.X = 0
	m.graph.BorderLabel = "(%)Msg Loss Between Metron and Doppler"
	m.graph.BarColor = termui.ColorYellow
	m.graph.BorderFg = termui.ColorWhite

	m.validOrigins = []string{"MetronAgent", "DopplerServer"}
	m.validMetricNames = []string{"DopplerForwarder.sentMessages", "tlsListener.receivedMessageCount", "dropsondeListener.receivedMessageCount"}

}
Пример #13
0
func (u *Ui) refreshActiveDownloadWidgets() {
	u.activeDownloadWidgets = make([]*termui.Gauge, 0, len(u.activeDownloads))

	uris := make([]string, 0, len(u.activeDownloads))
	for uri, _ := range u.activeDownloads {
		uris = append(uris, uri)
	}
	sort.Strings(uris)

	for _, uri := range uris {
		progress := u.activeDownloads[uri]

		widget := termui.NewGauge()
		widget.Height = 3
		widget.Percent = int(progress.Percent * 100)
		widget.Border.Label = "Downloading: " + uri
		widget.Label = fmt.Sprintf("{{percent}}%% (%s)", curl.PrettySpeedString(progress.Speed))

		u.activeDownloadWidgets = append(u.activeDownloadWidgets, widget)
	}
}
Пример #14
0
func NewBar(width int, x int, y int, label string, targetBufferer *[]termui.Bufferer) *Bar {
	e := &Bar{}

	e.Height = 3
	e.Width = width
	e.X = x
	e.Y = y

	e.Gauge = termui.NewGauge()
	e.Gauge.Percent = 0
	e.Gauge.Percent = 0
	e.Gauge.Width = width - 6
	e.Gauge.Height = e.Height
	e.Gauge.Border.Label = ""
	e.Gauge.BgColor = termui.ColorBlack
	e.Gauge.BarColor = termui.ColorGreen
	e.Gauge.Border.FgColor = termui.ColorWhite
	e.Gauge.Border.LabelFgColor = termui.ColorCyan
	e.Gauge.HasBorder = true
	e.Gauge.LabelAlign = termui.AlignRight

	e.Label = termui.NewPar("")
	e.Label.Width = 20
	e.Label.Height = 1
	e.Label.TextFgColor = termui.ColorWhite
	e.Label.HasBorder = false
	e.Label.Text = label

	e.Bufferer = append(e.Bufferer, e.Gauge)
	e.Bufferer = append(e.Bufferer, e.Label)
	*targetBufferer = append(*targetBufferer, e.Bufferer...)

	e.ValueChannel = make(chan int, 100)
	go e.readValueChannel()

	e.Invalidate()

	return e
}
Пример #15
0
func RunTerminalUI() {

	err := ui.Init()
	if err != nil {
		panic(err)
	}
	defer ui.Close()

	// var ps []float64
	//
	// jobrateStream := (func() []float64 {
	//
	// 	jInfo := GetInfoObj()
	// 	ps = append(ps, float64(jInfo.JobRate))
	// 	return ps
	//
	// })
	// ui.UseTheme("helloworld")
	// lc := ui.NewLineChart()
	// lc.Border.Label = "JobRate"
	// lc.Data = jobrateStream()
	// lc.Width = 100
	// lc.Height = 20
	// lc.X = 0
	// lc.Y = 0
	// lc.AxesColor = ui.ColorWhite
	// lc.LineColor = ui.ColorRed | ui.AttrBold
	// lc.Mode = "dot"
	BufferPercent := func() int {

		return int(100 * len(resultsToDispatch) / Config.DispatchBufferSize)

	}

	gspeed := ui.NewGauge()
	gspeed.Percent = 50
	gspeed.Width = 50
	gspeed.Height = 3
	gspeed.Y = 8
	gspeed.X = 0
	gspeed.Border.Label = "Job Rate"
	gspeed.BarColor = ui.ColorGreen
	gspeed.Border.FgColor = ui.ColorWhite
	gspeed.Border.LabelFgColor = ui.ColorYellow

	greq := ui.NewGauge()
	greq.Percent = 50
	greq.Width = 50
	greq.Height = 3
	greq.Y = 0
	greq.X = 0
	greq.Border.Label = "Requests Buffer"
	greq.BarColor = ui.ColorYellow
	greq.Border.FgColor = ui.ColorWhite
	greq.Border.LabelFgColor = ui.ColorCyan

	g := ui.NewGauge()
	g.Percent = 50
	g.Width = 50
	g.Height = 3
	g.Y = 4
	g.Border.Label = "Results Buffer"
	g.BarColor = ui.ColorRed
	g.Border.FgColor = ui.ColorWhite
	g.Border.LabelFgColor = ui.ColorCyan

	list_msg := ui.NewList()
	list_msg.ItemFgColor = ui.ColorYellow
	list_msg.Border.Label = "Log"
	list_msg.Height = 10
	list_msg.Y = 14
	list_msg.X = 30
	list_msg.Width = 25

	list := ui.NewList()
	list.ItemFgColor = ui.ColorYellow
	list.Border.Label = "Info"
	list.Height = 10
	list.Y = 14
	list.Width = 25

	listItems := func() (out []string) {
		inf := GetInfoObj()
		out = append(out, fmt.Sprintf(" %d Jobs/Second", inf.JobRate))
		out = append(out, fmt.Sprintf(" %d  Workers", workForce.NumWorkers))
		out = append(out, fmt.Sprintf(" %d  Jobs Processed", TotalDone))
		out = append(out, fmt.Sprintf(" %s  QueueBinary", Config.Fetch_Binkey))
		out = append(out, fmt.Sprintf(" %s", inf.Host))
		out = append(out, fmt.Sprintf(" %v", inf.IpAddresses))
		return
	}

	p := ui.NewPar("0 Jobs per second")
	p.Height = 3
	p.Width = 50
	p.TextFgColor = ui.ColorWhite
	p.Border.Label = "Text Box"
	p.Border.FgColor = ui.ColorCyan

	draw := func(t int) {
		// offset := int((len(ps) / (lc.Width / 2)) * (lc.Width / 2))
		// lc.Data = jobrateStream()[offset:]

		list.Items = listItems()
		list_msg.Items = Messages
		gspeed.Percent = GetInfoObj().JobRate
		g.Percent = BufferPercent()
		greq.Percent = int(100 * len(workForce.JobRequestQueue) / Config.RequestQueueSize)
		// p.Text = fmt.Sprintf("%d Jobs/Second | %d Workers | %d Jobs Done", GetInfoObj().JobRate, workForce.NumWorkers, TotalDone)
		ui.Render(list_msg, list, g, greq, gspeed)
	}

	evt := ui.EventCh()

	i := 0
	drawEnabled := true
	for {
		select {
		case e := <-evt:

			if e.Type == ui.EventKey {
				switch e.Ch {

				case 'd':
					drawEnabled = !drawEnabled

				}

			}

			if e.Type == ui.EventKey && e.Ch == 'J' {
				workForce.ChangeNumWorkers(workForce.NumWorkers - 10)
			}
			if e.Type == ui.EventKey && e.Ch == 'K' {
				workForce.ChangeNumWorkers(workForce.NumWorkers + 10)
			}
			if e.Type == ui.EventKey && e.Ch == 'j' {
				workForce.ChangeNumWorkers(workForce.NumWorkers - 1)
			}
			if e.Type == ui.EventKey && e.Ch == 'k' {
				workForce.ChangeNumWorkers(workForce.NumWorkers + 1)
			}
			if e.Type == ui.EventKey && e.Ch == 'q' {
				return
			}
		default:
			if drawEnabled == true {

				draw(i)
			}
			i++
			time.Sleep(time.Second / 2)
		}
	}

}
Пример #16
0
func main() {
	err := ui.Init()
	if err != nil {
		panic(err)
	}
	defer ui.Close()

	sinps := (func() []float64 {
		n := 400
		ps := make([]float64, n)
		for i := range ps {
			ps[i] = 1 + math.Sin(float64(i)/5)
		}
		return ps
	})()
	sinpsint := (func() []int {
		ps := make([]int, len(sinps))
		for i, v := range sinps {
			ps[i] = int(100*v + 10)
		}
		return ps
	})()

	// ui.UseTheme("helloworld")

	spark := ui.Sparkline{}
	spark.Height = 8
	spdata := sinpsint
	spark.Data = spdata[:100]
	spark.LineColor = ui.ColorCyan
	spark.TitleColor = ui.ColorWhite

	sp := ui.NewSparklines(spark)
	sp.Height = 11
	sp.Border.Label = "Sparkline"

	lc := ui.NewLineChart()
	lc.Border.Label = "braille-mode Line Chart"
	lc.Data = sinps
	lc.Height = 11
	lc.AxesColor = ui.ColorWhite
	lc.LineColor = ui.ColorYellow | ui.AttrBold

	gs := make([]*ui.Gauge, 3)
	for i := range gs {
		gs[i] = ui.NewGauge()
		gs[i].Height = 2
		gs[i].HasBorder = false
		gs[i].Percent = i * 10
		gs[i].PaddingBottom = 1
		gs[i].BarColor = ui.ColorRed
	}

	ls := ui.NewList()
	ls.HasBorder = false
	ls.Items = []string{
		"[1] Downloading File 1",
		"", // == \newline
		"[2] Downloading File 2",
		"",
		"[3] Uploading File 3",
	}
	ls.Height = 5

	par := ui.NewPar("<> This row has 3 columns\n<- Widgets can be stacked up like left side\n<- Stacked widgets are treated as a single widget")
	par.Height = 5
	par.Border.Label = "Demonstration"

	// build layout
	ui.Body.AddRows(
		ui.NewRow(
			ui.NewCol(6, 0, sp),
			ui.NewCol(6, 0, lc)),
		ui.NewRow(
			ui.NewCol(3, 0, ls),
			ui.NewCol(3, 0, gs[0], gs[1], gs[2]),
			ui.NewCol(6, 0, par)))

	// calculate layout
	ui.Body.Align()

	done := make(chan bool)
	redraw := make(chan bool)

	/*
		update := func() {
			for i := 0; i < 103; i++ {
				for _, g := range gs {
					g.Percent = (g.Percent + 3) % 100
				}

				sp.Lines[0].Data = spdata[:100+i]
				lc.Data = sinps[2*i:]

				time.Sleep(time.Second / 2)
				redraw <- true
			}
			done <- true
		}
	*/

	evt := ui.EventCh()

	ui.Render(ui.Body)
	// go update()

	for {
		select {
		case e := <-evt:
			if e.Type == ui.EventKey && e.Ch == 'q' {
				return
			}
			if e.Type == ui.EventResize {
				ui.Body.Width = ui.TermWidth()
				ui.Body.Align()
				go func() { redraw <- true }()
			}
		case <-done:
			return
		case <-redraw:
			ui.Render(ui.Body)
		}
	}
}
Пример #17
0
func main() {
	err := tui.Init()
	if err != nil {
		panic(err)
	}
	defer tui.Close()

	///////////
	//
	//  Create UI components
	//
	///////////

	// Header
	pr_th := 3
	pr_title := tui.NewPar("Text Console User Interfaces")
	pr_title.Width = tui.TermWidth()
	pr_title.Height = pr_th
	pr_title.BorderFg = tui.ColorBlue

	// Footer
	g_h := 5
	g := tui.NewGauge()
	g.Percent = 1
	g.Width = tui.TermWidth()
	g.Height = g_h
	g.Y = tui.TermHeight() - g_h
	g.BorderLabel = "Progress"
	g.Label = "{{percent}} - Start!"
	g.LabelAlign = tui.AlignRight
	g.BarColor = tui.ColorGreen
	g.BorderFg = tui.ColorBlue
	g.BorderLabelFg = tui.ColorWhite

	// Slide 1
	txtlst1 := "Introduction\n\no Myself\n\no Interests in Go"
	se1_1 := tui.NewPar(txtlst1)
	se1_1.Width = tui.TermWidth()
	se1_1.Height = (tui.TermHeight() / 2) - (pr_th + g_h)
	se1_1.Y = pr_th
	se1_2 := tui.NewPar("")
	se1_2.Width = tui.TermWidth()
	se1_2.Height = (tui.TermHeight() / 2) - (pr_th + g_h)
	se1_2.Y = pr_th + se1_1.Height

	// Slide 2
	txtlst2 := "The Termui Library\n\no Console library UI\n\n"
	txtlst2 += "o A widget library for dashboard building in the terminal\n\n"
	txtlst2 += "o Cross Platform\n\n  o Runs on Linux, OSX, and Windows"
	se2_1 := tui.NewPar(txtlst2)
	se2_1.Width = tui.TermWidth()
	se2_1.Height = (tui.TermHeight() / 2) - (pr_th + g_h)
	se2_1.Y = pr_th

	// Slide 3
	txtlst3 := "More Info\n\n"
	txtlst3 += "o Built on top of termbox library\n\n"
	txtlst3 += "o Inherits handlers, events, and cross platform compatibility"
	se3_1 := tui.NewPar(txtlst3)
	se3_1.Width = tui.TermWidth()
	se3_1.Height = (tui.TermHeight() / 2) - (pr_th + g_h)
	se3_1.Y = pr_th

	// Slide 4
	txtlst4 := "Features\n\n"
	txtlst4 += "o Multiple widgets available\n\n"
	txtlst4 += "o Automatic grid layout\n\n"
	txtlst4 += "o 多言語可能 (multi-lang possible)"
	se4_1 := tui.NewPar(txtlst4)
	se4_1.Width = tui.TermWidth()
	se4_1.Height = (tui.TermHeight() / 2) - (pr_th + g_h)
	se4_1.Y = pr_th

	// Slide 5
	txtlst5 := "Widget Features\n\n"
	txtlst5 += "o Can be surrounded by borders\n\n"
	txtlst5 += "o Can have labels associated with it\n\n"
	txtlst5 += "o Borders can also have labels\n\n"
	txtlst5 += "o Color"
	se5_1 := tui.NewPar(txtlst5)
	se5_1.Width = tui.TermWidth()
	se5_1.Height = (tui.TermHeight() / 2) - (pr_th + g_h)
	se5_1.Y = pr_th

	// Slide 6
	txtlst6 := "Widgets - Par\n\no Par - aka Textbox\n\n"
	txtlst6 += "o Basic textbox widget\n\n"
	txtlst6 += "   p := termui.NewPar(\"World\")\n"
	txtlst6 += "   p.BorderLabel(\"Hello\")"
	se6_1 := tui.NewPar(txtlst6)
	se6_1.Width = tui.TermWidth()
	se6_1.Height = (tui.TermHeight() / 2) - (pr_th + g_h)
	se6_1.Y = pr_th
	se6_2 := tui.NewPar("World")
	se6_2.BorderLabel = "Hello"
	se6_2.BorderFg = tui.ColorYellow
	se6_2.BorderLabelFg = tui.ColorWhite
	se6_2.Width = tui.TermWidth()
	se6_2.Height = (tui.TermHeight() / 2) - (pr_th + g_h)
	se6_2.Y = pr_th + se6_1.Height

	// Slide 7
	txtlst7 := "Widgets - Lists\n\no List - A text list\n\n"
	txtlst7 += "o Text Lists\n\n"
	txtlst7 += "   tl := termui.NewList()\n"
	txtlst7 += "   tl.Items = textlist\n"
	se7_2lst := []string{
		"* List Elems",
		"* Are Just",
		"* Lists of",
		"* Strings",
		"* [and support](fg-blue)",
		"* [colors](fg-green,bg-black)"}
	se7_1 := tui.NewPar(txtlst7)
	se7_1.Width = tui.TermWidth()
	se7_1.Height = (tui.TermHeight() / 2) - (pr_th + g_h)
	se7_1.Y = pr_th
	se7_2 := tui.NewList()
	se7_2.Items = se7_2lst
	se7_2.BorderFg = tui.ColorYellow
	se7_2.BorderLabelFg = tui.ColorWhite
	se7_2.Width = tui.TermWidth()
	se7_2.Height = (tui.TermHeight() / 2) - (pr_th + g_h)
	se7_2.Y = pr_th + se7_1.Height

	// Slide 8
	txtlst8 := "Widgets - Line Charts\n\n"
	txtlst8 += "o Draw linecharts\n\n"
	txtlst8 += "   lc := termui.NewLineChart()\n"
	txtlst8 += "   lc.Data = cosdata"
	se8_1 := tui.NewPar(txtlst8)
	se8_1.Width = tui.TermWidth()
	se8_1.Height = (tui.TermHeight() / 2) - (pr_th + g_h)
	se8_1.Y = pr_th
	se8_2 := tui.NewLineChart()
	se8_2.Data = cosData()
	se8_2.BorderFg = tui.ColorYellow
	se8_2.BorderLabelFg = tui.ColorWhite
	se8_2.Width = tui.TermWidth()
	se8_2.Height = (tui.TermHeight() / 2) - (pr_th + g_h)
	se8_2.Y = pr_th + se8_1.Height

	// Slide 9
	txtlst9 := "Widgets - Bar Charts\n\n"
	txtlst9 += "o Draw bar charts\n\n"
	txtlst9 += "   data := []int{4, 5, 6, 7, 8, 6, 5}\n"
	txtlst9 += "   bc := termui.NewBarChart()\n"
	txtlst9 += "   bc.Data = data"
	se9_1 := tui.NewPar(txtlst9)
	se9_1.Width = tui.TermWidth()
	se9_1.Height = (tui.TermHeight() / 2) - (pr_th + g_h)
	se9_1.Y = pr_th
	se9_2 := tui.NewBarChart()
	se9_2.Data = []int{4, 5, 6, 7, 8, 6, 5}
	se9_2.DataLabels = []string{"S0", "S1", "S2", "S3", "S4", "S5", "S6", "S7"}
	se9_2.BorderFg = tui.ColorYellow
	se9_2.BorderLabelFg = tui.ColorWhite
	se9_2.Width = tui.TermWidth()
	se9_2.Height = (tui.TermHeight() / 2) - (pr_th + g_h)
	se9_2.Y = pr_th + se9_1.Height

	// Slide 10
	txtlst10 := "Widgets - Sparklines\n\n"
	txtlst10 += "o Draw sparklines\n\n"
	txtlst10 += "   data := []int{4, 5, 6, 7, 8, 6, 5}\n"
	txtlst10 += "   sp := termui.NewSparkline()\n"
	txtlst10 += "   sp.Data = data\n"
	txtlst10 += "   spl := termui.NewSparklines(sp)"
	se10_1 := tui.NewPar(txtlst10)
	se10_1.Width = tui.TermWidth()
	se10_1.Height = (tui.TermHeight() / 2) - (pr_th + g_h)
	se10_1.Y = pr_th
	sp10_2 := tui.NewSparkline()
	sp10_2.Data = []int{4, 5, 6, 7, 8, 6, 5}
	sp10_2.LineColor = tui.ColorRed
	se10_2 := tui.NewSparklines(sp10_2)
	se10_2.Width = tui.TermWidth()
	se10_2.Height = (tui.TermHeight() / 2) - (pr_th + g_h)
	se10_2.Y = pr_th + se10_1.Height

	// Slide 11
	txtlst11 := "General Workflow\n\n"
	txtlst11 += "o Setup\n\no Create & Setup UI elems\n\n"
	txtlst11 += "o Setup handlers\n\nLoop"
	se11_1 := tui.NewPar(txtlst11)
	se11_1.Width = tui.TermWidth()
	se11_1.Height = (tui.TermHeight() / 2) - (pr_th + g_h)
	se11_1.Y = pr_th
	txtlst11_2 := "   termui.Init()\n"
	txtlst11_2 += "   p := termui.NewPar(\"Hello World\")\n"
	txtlst11_2 += "   termui.Render(p)\n"
	txtlst11_2 += "   termui.Handle(\"/sys/kbd/Q\", func(termui.Event) {\n"
	txtlst11_2 += "             termui.StopLoop() })\n"
	txtlst11_2 += "   termui.Loop()"
	se11_2 := tui.NewPar(txtlst11_2)
	se11_2.BorderFg = tui.ColorYellow
	se11_2.BorderLabelFg = tui.ColorWhite
	se11_2.Width = tui.TermWidth()
	se11_2.Height = (tui.TermHeight() / 2) - (pr_th + g_h)
	se11_2.Y = pr_th + se11_1.Height

	// Slide 12
	txtlst12 := "Extra Notes\n\n"
	txtlst12 += "o V1 vs V2\n\n"
	txtlst12 += "o Timers\n\n"
	se12_1 := tui.NewPar(txtlst12)
	se12_1.Width = tui.TermWidth()
	se12_1.Height = (tui.TermHeight() / 2) - (pr_th + g_h)
	se12_1.Y = pr_th
	se12_2 := tui.NewPar("")
	se12_2.Border = false
	se12_2.Width = tui.TermWidth()
	se12_2.Height = (tui.TermHeight() / 2) - (pr_th + g_h)
	se12_2.Y = pr_th + se12_1.Height

	///////////
	//
	//  Build the slideshow
	//
	///////////
	slides := NewSlideShow(pr_title, g)
	slides.AddSlide("start", []tui.Bufferer{})
	slides.AddSlide("Intro", []tui.Bufferer{se1_1})
	slides.AddSlide("Termui", []tui.Bufferer{se2_1})
	slides.AddSlide("More Info", []tui.Bufferer{se3_1})
	slides.AddSlide("Features", []tui.Bufferer{se4_1})
	slides.AddSlide("WidgetFeatures", []tui.Bufferer{se5_1})
	slides.AddSlide("Par()", []tui.Bufferer{se6_1, se6_2})
	slides.AddSlide("List()", []tui.Bufferer{se7_1, se7_2})
	slides.AddSlide("LineChart()", []tui.Bufferer{se8_1, se8_2})
	slides.AddSlide("BarChart()", []tui.Bufferer{se9_1, se9_2})
	slides.AddSlide("Sparkline()", []tui.Bufferer{se10_1, se10_2})
	slides.AddSlide("quickdemo", []tui.Bufferer{se11_1, se11_2})
	slides.AddSlide("gotchas", []tui.Bufferer{se12_1, se12_2})

	slides_num := slides.Length()
	slides_idx := 0

	maxttl := 360
	ttl := maxttl

	draw := func() {
		tui.Render(slides.At(slides_idx).Widgets...)
	}

	tui.Render(pr_title, g)

	tui.Handle("/sys/kbd/Q", func(tui.Event) {
		tui.StopLoop()
	})
	tui.Handle("/sys/kbd/<left>", func(tui.Event) {
	})
	tui.Handle("/sys/kbd/<right>", func(tui.Event) {
		ttl = maxttl
		slides_idx++
		if slides_idx > (slides_num - 1) {
			slides_idx = 0
		}
		g.Percent = calcPercent(slides_idx, slides_num)

		lbl := "Progress - " + strconv.Itoa(g.Percent) + "%" +
			" TTL: " + strconv.Itoa(ttl)

		g.BorderLabel = lbl
		g.Label = "{{percent}} - " + slides.At(slides_idx).Title
	})
	tui.Handle("/sys/kbd/<space>", func(tui.Event) {
		ttl = maxttl
		slides_idx++
		if slides_idx > (slides_num - 1) {
			slides_idx = 0
		}
		g.Percent = calcPercent(slides_idx, slides_num)

		lbl := "Progress - " + strconv.Itoa(g.Percent) + "%" +
			" TTL: " + strconv.Itoa(ttl)

		g.BorderLabel = lbl
		g.Label = "{{percent}} - " + slides.At(slides_idx).Title
	})
	tui.Handle("/timer/1s", func(e tui.Event) {
		ttl--
		if ttl <= 0 {
			if slides_idx < (slides_num - 1) {
				if slides_idx > slides.Length()-1 {
					slides_idx++
				}
			}
			g.Percent = calcPercent(slides_idx, slides_num)
			ttl = maxttl
		}
		lbl := "Progress - " + strconv.Itoa(g.Percent) + "%" +
			" TTL: " + strconv.Itoa(ttl)
		g.BorderLabel = lbl

		draw()
	})

	tui.Loop()
}
Пример #18
0
func main() {
	// Init
	err := ui.Init()
	if err != nil {
		panic(err)
	}
	defer ui.Close()

	// Theme Setting
	ui.UseTheme("helloworld")

	// Setup the CPU Gauge
	cpuGauge := ui.NewGauge()
	cpuGauge.Height = 2
	cpuGauge.BarColor = ui.ColorRed
	cpuGauge.HasBorder = false
	cpuGauge.PaddingBottom = 1
	go UpdateGenericGauge(cpuGauge, GetCPUPercentage)

	// Setup the RAM Gauge
	ramGauge := ui.NewGauge()
	ramGauge.Height = 2
	ramGauge.BarColor = ui.ColorGreen
	ramGauge.HasBorder = false
	ramGauge.PaddingBottom = 1
	go UpdateGenericGauge(ramGauge, GetRAMPercentage)

	// Setup the Label list
	ls := ui.NewList()
	ls.HasBorder = false
	ls.Items = []string{
		"CPU",
		"",
		"RAM",
	}
	ls.Height = 5

	// Setup the CPU Line Chart
	cpuLineChart := ui.NewLineChart()
	cpuLineChart.Width = 50
	cpuLineChart.Height = 11
	cpuLineChart.Border.Label = "CPU Usage"
	cpuLineChart.AxesColor = ui.ColorWhite
	cpuLineChart.LineColor = ui.ColorGreen | ui.AttrBold
	go UpdateGenericChart(cpuLineChart, GetCPUPercentage)

	// Setup the RAM Line Chart
	ramLineChart := ui.NewLineChart()
	ramLineChart.Width = 50
	ramLineChart.Height = 11
	ramLineChart.Border.Label = "RAM Usage"
	ramLineChart.AxesColor = ui.ColorWhite
	ramLineChart.LineColor = ui.ColorGreen | ui.AttrBold
	go UpdateGenericChart(ramLineChart, GetRAMPercentage)

	// Setup the layout
	ui.Body.AddRows(
		ui.NewRow(
			ui.NewCol(3, 0, cpuGauge, ramGauge),
			ui.NewCol(3, 0, ls),
		),
		ui.NewRow(
			ui.NewCol(6, 0, cpuLineChart),
			ui.NewCol(6, 0, ramLineChart),
		),
	)

	// Align
	ui.Body.Align()

	// Create the event polling system
	evt := make(chan tm.Event)
	go func() {
		for {
			evt <- tm.PollEvent()
		}
	}()

	for {
		select {
		case e := <-evt:
			if e.Type == tm.EventKey && e.Ch == 'q' {
				return
			}
			if e.Type == tm.EventResize {
				ui.Body.Width = ui.TermWidth()
				ui.Body.Align()
			}
		default:
			ui.Render(ui.Body)
			time.Sleep(time.Second / 2)
		}
	}
}
Пример #19
0
func main() {
	err := ui.Init()
	if err != nil {
		panic(err)
	}
	defer ui.Close()

	ui.UseTheme("helloworld")

	p := ui.NewPar(":PRESS q TO QUIT DEMO")
	p.Height = 3
	p.Width = 50
	p.Border.Label = "Text Box"

	strs := []string{"[0] gizak/termui", "[1] editbox.go", "[2] iterrupt.go", "[3] keyboard.go", "[4] output.go", "[5] random_out.go", "[6] dashboard.go", "[7] nsf/termbox-go"}
	list := ui.NewList()
	list.Items = strs
	list.Border.Label = "List"
	list.Height = 7
	list.Width = 25
	list.Y = 4

	g := ui.NewGauge()
	g.Percent = 50
	g.Width = 50
	g.Height = 3
	g.Y = 11
	g.Border.Label = "Gauge"

	spark := ui.NewSparkline()
	spark.Title = "srv 0:"
	spdata := []int{4, 2, 1, 6, 3, 9, 1, 4, 2, 15, 14, 9, 8, 6, 10, 13, 15, 12, 10, 5, 3, 6, 1, 7, 10, 10, 14, 13, 6}
	spark.Data = spdata

	spark1 := ui.NewSparkline()
	spark1.Title = "srv 1:"
	spark1.Data = spdata

	sp := ui.NewSparklines(spark, spark1)
	sp.Width = 25
	sp.Height = 7
	sp.Border.Label = "Sparkline"
	sp.Y = 4
	sp.X = 25

	lc := ui.NewLineChart()
	sinps := (func() []float64 {
		n := 100
		ps := make([]float64, n)
		for i := range ps {
			ps[i] = 1 + math.Sin(float64(i)/4)
		}
		return ps
	})()

	lc.Border.Label = "Line Chart"
	lc.Data = sinps
	lc.Width = 50
	lc.Height = 11
	lc.X = 0
	lc.Y = 14
	lc.Mode = "dot"

	bc := ui.NewBarChart()
	bcdata := []int{3, 2, 5, 3, 9, 5, 3, 2, 5, 8, 3, 2, 4, 5, 3, 2, 5, 7, 5, 3, 2, 6, 7, 4, 6, 3, 6, 7, 8, 3, 6, 4, 5, 3, 2, 4, 6, 4, 8, 5, 9, 4, 3, 6, 5, 3, 6}
	bclabels := []string{"S0", "S1", "S2", "S3", "S4", "S5"}
	bc.Border.Label = "Bar Chart"
	bc.Width = 26
	bc.Height = 10
	bc.X = 51
	bc.Y = 0
	bc.DataLabels = bclabels

	lc1 := ui.NewLineChart()
	lc1.Border.Label = "Line Chart"
	rndwalk := (func() []float64 {
		n := 150
		d := make([]float64, n)
		for i := 1; i < n; i++ {
			if i < 20 {
				d[i] = d[i-1] + 0.01
			}
			if i > 20 {
				d[i] = d[i-1] - 0.05
			}
		}
		return d
	})()
	lc1.Data = rndwalk
	lc1.Width = 26
	lc1.Height = 11
	lc1.X = 51
	lc1.Y = 14

	p1 := ui.NewPar("Hey!\nI am a borderless block!")
	p1.HasBorder = false
	p1.Width = 26
	p1.Height = 2
	p1.X = 52
	p1.Y = 11

	draw := func(t int) {
		g.Percent = t % 101
		list.Items = strs[t%9:]
		sp.Lines[0].Data = spdata[t%10:]
		sp.Lines[1].Data = spdata[t/2%10:]
		lc.Data = sinps[t/2:]
		lc1.Data = rndwalk[t:]
		bc.Data = bcdata[t/2%10:]
		ui.Render(p, list, g, sp, lc, bc, lc1, p1)
	}

	evt := ui.EventCh()
	i := 0
	for {
		select {
		case e := <-evt:
			if e.Type == ui.EventKey && e.Ch == 'q' {
				return
			}
		default:
			draw(i)
			i++
			if i == 102 {
				return
			}
			time.Sleep(time.Second / 2)
		}
	}
}
Пример #20
0
func main() {
	err := ui.Init()
	if err != nil {
		panic(err)
	}
	defer ui.Close()

	p := ui.NewPar(":PRESS q TO QUIT DEMO")
	p.Height = 3
	p.Width = 50
	p.TextFgColor = ui.ColorWhite
	p.Border.Label = "Text Box"
	p.Border.FgColor = ui.ColorCyan

	strs := []string{"[0] gizak/termui", "[1] editbox.go", "[2] iterrupt.go", "[3] keyboard.go", "[4] output.go", "[5] random_out.go", "[6] dashboard.go", "[7] nsf/termbox-go"}
	list := ui.NewList()
	list.Items = strs
	list.ItemFgColor = ui.ColorYellow
	list.Border.Label = "List"
	list.Height = 7
	list.Width = 25
	list.Y = 4

	g := ui.NewGauge()
	g.Percent = 50
	g.Width = 50
	g.Height = 3
	g.Y = 11
	g.Border.Label = "Gauge"
	g.BarColor = ui.ColorRed
	g.Border.FgColor = ui.ColorWhite
	g.Border.LabelFgColor = ui.ColorCyan

	spark := ui.Sparkline{}
	spark.Height = 1
	spark.Title = "srv 0:"
	spdata := []int{4, 2, 1, 6, 3, 9, 1, 4, 2, 15, 14, 9, 8, 6, 10, 13, 15, 12, 10, 5, 3, 6, 1, 7, 10, 10, 14, 13, 6}
	spark.Data = spdata
	spark.LineColor = ui.ColorCyan
	spark.TitleColor = ui.ColorWhite

	spark1 := ui.Sparkline{}
	spark1.Height = 1
	spark1.Title = "srv 1:"
	spark1.Data = spdata
	spark1.TitleColor = ui.ColorWhite
	spark1.LineColor = ui.ColorRed

	sp := ui.NewSparklines(spark, spark1)
	sp.Width = 25
	sp.Height = 7
	sp.Border.Label = "Sparkline"
	sp.Y = 4
	sp.X = 25

	sinps := (func() []float64 {
		n := 220
		ps := make([]float64, n)
		for i := range ps {
			ps[i] = 1 + math.Sin(float64(i)/5)
		}
		return ps
	})()

	lc := ui.NewLineChart()
	lc.Border.Label = "dot-mode Line Chart"
	lc.Data = sinps
	lc.Width = 50
	lc.Height = 11
	lc.X = 0
	lc.Y = 14
	lc.AxesColor = ui.ColorWhite
	lc.LineColor = ui.ColorRed | ui.AttrBold
	lc.Mode = "dot"

	bc := ui.NewBarChart()
	bcdata := []int{3, 2, 5, 3, 9, 5, 3, 2, 5, 8, 3, 2, 4, 5, 3, 2, 5, 7, 5, 3, 2, 6, 7, 4, 6, 3, 6, 7, 8, 3, 6, 4, 5, 3, 2, 4, 6, 4, 8, 5, 9, 4, 3, 6, 5, 3, 6}
	bclabels := []string{"S0", "S1", "S2", "S3", "S4", "S5"}
	bc.Border.Label = "Bar Chart"
	bc.Width = 26
	bc.Height = 10
	bc.X = 51
	bc.Y = 0
	bc.DataLabels = bclabels
	bc.BarColor = ui.ColorGreen
	bc.NumColor = ui.ColorBlack

	lc1 := ui.NewLineChart()
	lc1.Border.Label = "braille-mode Line Chart"
	lc1.Data = sinps
	lc1.Width = 26
	lc1.Height = 11
	lc1.X = 51
	lc1.Y = 14
	lc1.AxesColor = ui.ColorWhite
	lc1.LineColor = ui.ColorYellow | ui.AttrBold

	p1 := ui.NewPar("Hey!\nI am a borderless block!")
	p1.HasBorder = false
	p1.Width = 26
	p1.Height = 2
	p1.TextFgColor = ui.ColorMagenta
	p1.X = 52
	p1.Y = 11

	draw := func(t int) {
		g.Percent = t % 101
		list.Items = strs[t%9:]
		sp.Lines[0].Data = spdata[t%10:]
		sp.Lines[1].Data = spdata[t/2%10:]
		lc.Data = sinps[t/2:]
		lc1.Data = sinps[2*t:]
		bc.Data = bcdata[t/2%10:]
		ui.Render(p, list, g, sp, lc, bc, lc1, p1)
	}

	evt := ui.EventCh()

	i := 0
	for {
		select {
		case e := <-evt:
			if e.Type == ui.EventKey && e.Ch == 'q' {
				return
			}
		default:
			draw(i)
			i++
			if i == 102 {
				return
			}
			time.Sleep(time.Second / 2)
		}
	}
}
Пример #21
0
func main() {

	ui.ColorMap["fg"] = ui.ColorGreen
	ui.ColorMap["bg"] = ui.ColorBlack
	ui.ColorMap["border.fg"] = ui.ColorGreen
	ui.ColorMap["label.fg"] = ui.ColorGreen
	ui.ColorMap["par.fg"] = ui.ColorGreen
	ui.ColorMap["par.label.bg"] = ui.ColorGreen
	ui.ColorMap["par.label.fg"] = ui.ColorBlack
	ui.ColorMap["gauge.bar.bg"] = ui.ColorGreen
	err := ui.Init()
	if err != nil {
		panic(err)
	}
	defer ui.Close()

	DisplayDiscovering()

	games, _ := GoBoy.DiscoverGames()
	if len(games) == 0 {
		return
	}
	cg, err := games[0].Connect()

	if err != nil {
		fmt.Println(err)
		return
	}

	name := ui.NewPar("")
	name.Height = 3
	name.BorderLabel = "Name"

	caps := ui.NewPar("")
	caps.Height = 3
	caps.BorderLabel = "Caps"

	clock := ui.NewPar("")
	clock.Height = 3
	clock.BorderLabel = "Time"

	xp := ui.NewGauge()
	xp.Height = 3
	xp.BorderLabel = "XP"
	xp.PercentColorHighlighted = ui.ColorBlack

	hp := ui.NewGauge()
	hp.Height = 3
	hp.BorderLabel = "HP"
	hp.PercentColorHighlighted = ui.ColorBlack

	inv := ui.NewGauge()
	inv.Height = 3
	inv.BorderLabel = "Weight"
	inv.PercentColorHighlighted = ui.ColorBlack

	quests := ui.NewList()
	quests.Height = 12
	quests.BorderLabel = "Quests"

	ui.Body.AddRows(
		ui.NewRow(
			ui.NewCol(3, 0, name),
			ui.NewCol(1, 0, caps),
			ui.NewCol(2, 0, clock),
			ui.NewCol(6, 0, xp),
		),
		ui.NewRow(
			ui.NewCol(6, 0, hp),
			ui.NewCol(6, 0, inv),
		),
		ui.NewRow(
			ui.NewCol(5, 0, quests),
		),
	)

	for {
		if nameVal, ok := cg.Path("PlayerInfo.PlayerName"); ok {
			name.Text = nameVal.(string)
		}
		if capsVal, ok := cg.Path("PlayerInfo.Caps"); ok {
			caps.Text = fmt.Sprintf("%d", capsVal.(int32))
		}
		if xpVal, ok := cg.Path("PlayerInfo.XPProgressPct"); ok {
			xp.Percent = int(xpVal.(float32) * 100)
		}
		if clockVal, ok := cg.Path("PlayerInfo.TimeHour"); ok {
			hours := int(clockVal.(float32))
			minutes := int((clockVal.(float32) - float32(hours)) * 60)
			clock.Text = fmt.Sprintf("%2.0d:%2.0d", hours, minutes)
		}
		{
			maxHpVal, ok1 := cg.Path("PlayerInfo.MaxHP")
			curHpVal, ok2 := cg.Path("PlayerInfo.CurrHP")
			if ok1 && ok2 {
				maxHp := maxHpVal.(float32)
				curHp := curHpVal.(float32)

				hp.Percent = int(((curHp / maxHp) * 100))
				hp.Label = fmt.Sprintf("%.0f / %.0f", curHp, maxHp)
			}
		}
		{
			maxWVal, ok1 := cg.Path("PlayerInfo.MaxWeight")
			curWVal, ok2 := cg.Path("PlayerInfo.CurrWeight")
			if ok1 && ok2 {
				maxW := maxWVal.(float32)
				curW := curWVal.(float32)

				inv.Percent = int(((curW / maxW) * 100))
				inv.Label = fmt.Sprintf("%.0f / %.0f", curW, maxW)
				if curW > maxW {
					inv.Percent = 100
					inv.BarColor = ui.ColorRed
				} else {
					inv.BarColor = ui.ColorGreen
				}
			}
		}
		if questListVal, ok := cg.Path("Quests"); ok {
			quests.Items = []string{}
			questList := questListVal.(*GoBoy.DataArray)
			for l1 := 0; l1 < questList.Len(); l1++ {
				quest := questList.Get(l1)
				current, ok := quest.Path("enabled")
				if ok && current.(bool) {
					active, _ := quest.Path("active")
					name, _ := quest.Path("text")
					text := name.(string)
					if active.(bool) {
						text = "[" + text + "](fg-black,bg-green)"
					}
					quests.Items = append(quests.Items, text)
				}
			}
		}
		ui.Body.Width = ui.TermWidth()
		ui.Body.Align()
		ui.Render(ui.Body)
		time.Sleep(1 * time.Second)
	}

	//ui.Loop()
}
func buildUI(info info.Info) {

	urlLabel := ui.NewPar(fmt.Sprintf("%s", info.Url))
	urlLabel.Height = 3
	urlLabel.TextFgColor = ui.ColorWhite
	urlLabel.BorderLabel = "URL"
	urlLabel.BorderFg = ui.ColorCyan

	basicInfoStrings := []string{
		fmt.Sprintf("IP: %s", strings.Join(info.Ip, ",")),
		fmt.Sprintf("Host: %s", strings.Join(info.RealHost, ",")),
		fmt.Sprintf("Distribution: %s", info.Distribution),
	}

	basicInfoList := ui.NewList()
	basicInfoList.Items = basicInfoStrings
	basicInfoList.ItemFgColor = ui.ColorYellow
	basicInfoList.BorderLabel = "BasicInfo"
	basicInfoList.Height = 15
	basicInfoList.Width = 25
	basicInfoList.Y = 0

	serverLabel := ui.NewPar(fmt.Sprintf("Name: %s\nVersion: %s", info.Server.Name, info.Server.Version))
	serverLabel.Height = 4
	serverLabel.TextFgColor = ui.ColorWhite
	serverLabel.BorderLabel = "Server"
	serverLabel.BorderFg = ui.ColorCyan

	languageLabel := ui.NewPar(fmt.Sprintf("Name: %s\nVersion: %s", info.Language.Name, info.Language.Version))
	languageLabel.Height = 4
	languageLabel.TextFgColor = ui.ColorWhite
	languageLabel.BorderLabel = "Language"
	languageLabel.BorderFg = ui.ColorCyan

	frameworkLabel := ui.NewPar(fmt.Sprintf("Name: %s\nVersion: %s", info.Framework.Name, info.Framework.Version))
	frameworkLabel.Height = 4
	frameworkLabel.TextFgColor = ui.ColorWhite
	frameworkLabel.BorderLabel = "Framework"
	frameworkLabel.BorderFg = ui.ColorCyan

	packageLabel := ui.NewPar(fmt.Sprintf("Name: %s\nVersion: %s", info.Package.Name, info.Package.Version))
	packageLabel.Height = 4
	packageLabel.TextFgColor = ui.ColorWhite
	packageLabel.BorderLabel = "Package"
	packageLabel.BorderFg = ui.ColorCyan

	ispLabel := ui.NewPar(fmt.Sprintf("Name: %s\nRegion: %s", info.ISP.Name, info.ISP.Region))
	ispLabel.Height = 4
	ispLabel.TextFgColor = ui.ColorWhite
	ispLabel.BorderLabel = "ISP"
	ispLabel.BorderFg = ui.ColorCyan

	var headerStrings []string
	for key, values := range info.RawHeaders {
		headerStrings = append(headerStrings, fmt.Sprintf("%s: %s", key, strings.Join(values[:], ",")))
	}

	headerList := ui.NewList()
	headerList.Items = headerStrings
	headerList.ItemFgColor = ui.ColorYellow
	headerList.BorderLabel = "Raw Headers"
	headerList.Height = 25
	headerList.Y = 0

	var cookieStrings []string
	for key, values := range info.Cookies {
		cookieStrings = append(cookieStrings, fmt.Sprintf("%s: %s", key, values))
	}

	cookieList := ui.NewList()
	cookieList.Items = cookieStrings
	cookieList.ItemFgColor = ui.ColorYellow
	cookieList.BorderLabel = "Cookies"
	cookieList.Height = 25
	cookieList.Y = 0

	/* demo */

	sinps := (func() []float64 {
		n := 400
		ps := make([]float64, n)
		for i := range ps {
			ps[i] = 1 + math.Sin(float64(i)/5)
		}
		return ps
	})()
	sinpsint := (func() []int {
		ps := make([]int, len(sinps))
		for i, v := range sinps {
			ps[i] = int(100*v + 10)
		}
		return ps
	})()

	spark := ui.Sparkline{}
	spark.Height = 12
	spdata := sinpsint
	spark.Data = spdata[:100]
	spark.LineColor = ui.ColorCyan
	spark.TitleColor = ui.ColorWhite

	sp := ui.NewSparklines(spark)
	sp.Height = 15
	sp.BorderLabel = "Sparkline"

	g1 := ui.NewGauge()
	g1.Percent = 30
	g1.Height = 4
	g1.Y = 6
	g1.BorderLabel = "Progress"
	g1.PercentColor = ui.ColorYellow
	g1.BarColor = ui.ColorGreen
	g1.BorderFg = ui.ColorWhite
	g1.BorderLabelFg = ui.ColorMagenta

	ui.Body.AddRows(
		ui.NewRow(
			ui.NewCol(12, 0, urlLabel),
		),
		ui.NewRow(
			ui.NewCol(6, 0, basicInfoList),
			ui.NewCol(6, 0, sp),
		),
		ui.NewRow(
			ui.NewCol(4, 0, serverLabel),
			ui.NewCol(4, 0, languageLabel),
			ui.NewCol(4, 0, frameworkLabel),
		),
		ui.NewRow(
			ui.NewCol(4, 0, packageLabel),
			ui.NewCol(4, 0, ispLabel),
			ui.NewCol(4, 0, g1),
		),
		ui.NewRow(
			ui.NewCol(6, 0, headerList),
			ui.NewCol(6, 0, cookieList),
		),
	)
	ui.Body.Align()

	ui.Render(ui.Body)

	//	redraw := make(chan bool)

	ui.Handle("/sys/kbd/q", func(ui.Event) {
		// press q to quit
		ui.StopLoop()
	})

	ui.Handle("/sys/wnd/resize", func(ui.Event) {
		// press q to quit
		ui.Body.Width = ui.TermWidth()
		ui.Body.Align()
	})

	ui.Handle("/timer/1s", func(e ui.Event) {
		ui.Body.Align()
	})

	ui.Loop()
}
Пример #23
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	l := &sync.Mutex{}
	err := ui.Init()
	if err != nil {
		panic(err)
	}
	defer ui.Close()

	ui.UseTheme("helloworld")

	loadConfErr := LoadConfig()
	loadProxyErr := LoadProxies()

	LoadedProxies = len(D_PROXY_LIST)
	ProxiesLeft = LoadedProxies
	aboutUi := ui.NewPar(
		"Please report bugs @skype: newjolt\nOptimized to use " + strconv.Itoa(runtime.NumCPU()) + " cores.\nPress 'CTRL+C' to quit, 'CTRL+SPACE' to start task, 'CTRL+R' to reload settings.\nJoin us revive KryptoDEV.com")
	aboutUi.Height = 5
	aboutUi.TextFgColor = ui.ColorBlack
	aboutUi.Border.FgColor = ui.ColorMagenta
	aboutUi.TextBgColor = ui.ColorWhite
	aboutUi.BgColor = ui.ColorWhite
	aboutUi.Border.Label = "TOGNINJA: a topofgames.com auto voter v0.1 - kryptoDEV.com"
	aboutUi.Border.LabelFgColor = ui.AttrBold

	successUi := ui.NewPar("")
	successUi.Height = 3
	successUi.TextFgColor = ui.ColorWhite
	successUi.Border.Label = "Last Succeeded Vote"

	failedUi := ui.NewPar("")
	failedUi.Height = 3
	failedUi.TextFgColor = ui.ColorWhite
	failedUi.Border.Label = "Last Failed Vote"

	configUi := ui.NewPar(fmt.Sprintf("@Proxies Loaded: %d\n@Target ID: %d\n@Worker Count: %d", LoadedProxies, ConfigStruct.TargetID, ConfigStruct.WorkerCount))
	configUi.Height = 5
	configUi.TextFgColor = ui.ColorWhite
	configUi.Border.FgColor = ui.ColorWhite
	configUi.Border.Label = "Loaded Config."

	progressUi := ui.NewGauge()
	progressUi.Percent = 0
	progressUi.Height = 3
	progressUi.Border.Label = "Progress Report"
	progressUi.BarColor = ui.ColorRed
	progressUi.Border.FgColor = ui.ColorWhite
	progressUi.Border.LabelFgColor = ui.ColorCyan

	errorUi := ui.NewPar("")
	if loadConfErr != nil {
		errorUi.Text = loadConfErr.Error()
	} else if ConfigStruct.DBCUsername == "" {
		errorUi.Text = "Deathbycaptcha username not provided."
	} else if ConfigStruct.DBCPassword == "" {
		errorUi.Text = "Deathbycaptcha password not provided."
	} else if loadProxyErr != nil {
		errorUi.Text = loadProxyErr.Error()
	}
	errorUi.Height = 3
	errorUi.TextFgColor = ui.ColorRed
	errorUi.Border.FgColor = ui.ColorWhite
	errorUi.Border.Label = "Last Error"

	statsUi := ui.NewPar("")
	statsUi.Height = 3
	statsUi.TextFgColor = ui.ColorWhite
	statsUi.Border.FgColor = ui.ColorGreen
	statsUi.Border.Label = "Stats"

	// build layout
	ui.Body.AddRows(
		ui.NewRow(
			ui.NewCol(12, 0, aboutUi)),
		ui.NewRow(
			ui.NewCol(6, 0, configUi), ui.NewCol(6, 0, errorUi)),
		ui.NewRow(
			ui.NewCol(6, 0, successUi), ui.NewCol(6, 0, failedUi)),
		ui.NewRow(
			ui.NewCol(12, 0, progressUi)),
		ui.NewRow(
			ui.NewCol(12, 0, statsUi)))

	// calculate layout
	ui.Body.Align()

	done := make(chan bool)
	redraw := make(chan bool)

	evt := ui.EventCh()
	ui.Render(ui.Body)
	worker.MaxJobs = ConfigStruct.WorkerCount
	w := worker.NewWorker()

	w.On(worker.JobFinished, func(args ...interface{}) {
		l.Lock()
		ProxiesLeft--
		l.Unlock()
		pk := args[0].(*worker.Package)
		job := pk.Job().(*VoteJob)
		if job.HasError != "" {
			l.Lock()
			errorUi.Text = job.HasError
			ErrorsEncountered++
			l.Unlock()
		}
		if job.HasSuccessVoted {
			l.Lock()
			SuccessfulVotes++
			VotesAttempted++
			l.Unlock()
			if job.SuccessVoteText != "" {
				l.Lock()
				successUi.Text = job.SuccessVoteText
				l.Unlock()
			}
		}
		if job.HasFailVoted {
			l.Lock()
			FailedVotes++
			VotesAttempted++
			l.Unlock()
			if job.FailVoteText != "" {
				l.Lock()
				failedUi.Text = job.FailVoteText
				l.Unlock()
			}
		}
		if job.IsLast {
			l.Lock()
			statsUi.Text = "Bot: Finished | Proxies left: 0 | Successful Votes: " + strconv.Itoa(SuccessfulVotes) + " | Failed Votes: " + strconv.Itoa(FailedVotes) + " | Errors Encountered: " + strconv.Itoa(ErrorsEncountered)
			progressUi.Percent = 100
			progressUi.BarColor = ui.ColorGreen
			ui.Render(ui.Body)
			l.Unlock()
			return
		}
		l.Lock()
		progressUi.Percent = int(float32(100 - (100 * ProxiesLeft / LoadedProxies)))
		statsUi.Text = "Bot: Running | Proxies left: " + strconv.Itoa(ProxiesLeft) + " | Successful Votes: " + strconv.Itoa(SuccessfulVotes) + " | Failed Votes: " + strconv.Itoa(FailedVotes) + " | Errors Encountered: " + strconv.Itoa(ErrorsEncountered)
		ui.Render(ui.Body)
		l.Unlock()
	})

	for {
		select {
		case e := <-evt:
			if e.Type == ui.EventKey && e.Key == ui.KeyCtrlC {
				return
			}
			if e.Type == ui.EventKey && e.Key == ui.KeyCtrlR {
				//FetchCaptcha()
			}
			if e.Type == ui.EventKey && e.Key == ui.KeyCtrlSpace {
				for a := 0; a < LoadedProxies; a++ {
					if a == LoadedProxies {
						j := VoteJob{Name: D_PROXY_LIST[a], Proxy: D_PROXY_LIST[a], HasSuccessVoted: false, HasFailVoted: false, IsLast: true}
						w.Add(&j)
					} else {
						j := VoteJob{Name: D_PROXY_LIST[a], Proxy: D_PROXY_LIST[a], HasSuccessVoted: false, HasFailVoted: false, IsLast: false}
						w.Add(&j)
					}
				}
				w.RunUntilDone()
			}
			if e.Type == ui.EventResize {
				ui.Body.Width = ui.TermWidth()
				ui.Body.Align()
				go func() { redraw <- true }()
			}
		case <-done:
			return
		case <-redraw:
			ui.Render(ui.Body)
		}
	}
}
Пример #24
0
func (sc *sparkyClient) runTestSequence() {
	// First, we need to build the widgets on our screen.

	// Build our title box
	titleBox := termui.NewPar("──────[ sparkyfish ]────────────────────────────────────────")
	titleBox.Height = 1
	titleBox.Width = 60
	titleBox.Y = 0
	titleBox.Border = false
	titleBox.TextFgColor = termui.ColorWhite | termui.AttrBold

	// Build the server name/location banner line
	bannerBox := termui.NewPar("")
	bannerBox.Height = 1
	bannerBox.Width = 60
	bannerBox.Y = 1
	bannerBox.Border = false
	bannerBox.TextFgColor = termui.ColorRed | termui.AttrBold

	// Build a download graph widget
	dlGraph := termui.NewLineChart()
	dlGraph.BorderLabel = " Download Speed (Mbit/s)"
	dlGraph.Data = []float64{0}
	dlGraph.Width = 30
	dlGraph.Height = 12
	dlGraph.PaddingTop = 1
	dlGraph.X = 0
	dlGraph.Y = 6
	// Windows Command Prompt doesn't support our Unicode characters with the default font
	if runtime.GOOS == "windows" {
		dlGraph.Mode = "dot"
		dlGraph.DotStyle = '+'
	}
	dlGraph.AxesColor = termui.ColorWhite
	dlGraph.LineColor = termui.ColorGreen | termui.AttrBold

	// Build an upload graph widget
	ulGraph := termui.NewLineChart()
	ulGraph.BorderLabel = " Upload Speed (Mbit/s)"
	ulGraph.Data = []float64{0}
	ulGraph.Width = 30
	ulGraph.Height = 12
	ulGraph.PaddingTop = 1
	ulGraph.X = 30
	ulGraph.Y = 6
	// Windows Command Prompt doesn't support our Unicode characters with the default font
	if runtime.GOOS == "windows" {
		ulGraph.Mode = "dot"
		ulGraph.DotStyle = '+'
	}
	ulGraph.AxesColor = termui.ColorWhite
	ulGraph.LineColor = termui.ColorGreen | termui.AttrBold

	latencyGraph := termui.NewSparkline()
	latencyGraph.LineColor = termui.ColorCyan
	latencyGraph.Height = 3

	latencyGroup := termui.NewSparklines(latencyGraph)
	latencyGroup.Y = 3
	latencyGroup.Height = 3
	latencyGroup.Width = 30
	latencyGroup.Border = false
	latencyGroup.Lines[0].Data = []int{0}

	latencyTitle := termui.NewPar("Latency")
	latencyTitle.Height = 1
	latencyTitle.Width = 30
	latencyTitle.Border = false
	latencyTitle.TextFgColor = termui.ColorGreen
	latencyTitle.Y = 2

	latencyStats := termui.NewPar("")
	latencyStats.Height = 4
	latencyStats.Width = 30
	latencyStats.X = 32
	latencyStats.Y = 2
	latencyStats.Border = false
	latencyStats.TextFgColor = termui.ColorWhite | termui.AttrBold
	latencyStats.Text = "Last: 30ms\nMin: 2ms\nMax: 34ms"

	// Build a stats summary widget
	statsSummary := termui.NewPar("")
	statsSummary.Height = 7
	statsSummary.Width = 60
	statsSummary.Y = 18
	statsSummary.BorderLabel = " Throughput Summary "
	statsSummary.Text = fmt.Sprintf("DOWNLOAD \nCurrent: -- Mbit/s\tMax: --\tAvg: --\n\nUPLOAD\nCurrent: -- Mbit/s\tMax: --\tAvg: --")
	statsSummary.TextFgColor = termui.ColorWhite | termui.AttrBold

	// Build out progress gauge widget
	progress := termui.NewGauge()
	progress.Percent = 40
	progress.Width = 60
	progress.Height = 3
	progress.Y = 25
	progress.X = 0
	progress.Border = true
	progress.BorderLabel = " Test Progress "
	progress.Percent = 0
	progress.BarColor = termui.ColorRed
	progress.BorderFg = termui.ColorWhite
	progress.PercentColorHighlighted = termui.ColorWhite | termui.AttrBold
	progress.PercentColor = termui.ColorWhite | termui.AttrBold

	// Build our helpbox widget
	helpBox := termui.NewPar(" COMMANDS: [q]uit")
	helpBox.Height = 1
	helpBox.Width = 60
	helpBox.Y = 28
	helpBox.Border = false
	helpBox.TextBgColor = termui.ColorBlue
	helpBox.TextFgColor = termui.ColorYellow | termui.AttrBold
	helpBox.Bg = termui.ColorBlue

	// Add the widgets to the rendering jobs and render the screen
	sc.wr.Add("titlebox", titleBox)
	sc.wr.Add("bannerbox", bannerBox)
	sc.wr.Add("dlgraph", dlGraph)
	sc.wr.Add("ulgraph", ulGraph)
	sc.wr.Add("latency", latencyGroup)
	sc.wr.Add("latencytitle", latencyTitle)
	sc.wr.Add("latencystats", latencyStats)
	sc.wr.Add("statsSummary", statsSummary)
	sc.wr.Add("progress", progress)
	sc.wr.Add("helpbox", helpBox)
	sc.wr.Render()

	// Launch a progress bar updater
	go sc.updateProgressBar()

	// Start our ping test and block until it's complete
	sc.pingTest()

	// Start our stats generator, which receives realtime measurements from the throughput
	// reporter and generates metrics from them
	go sc.generateStats()

	// Run our download tests and block until that's done
	sc.runThroughputTest(inbound)

	// Signal to our MeasureThroughput that we're about to begin the upload test
	close(sc.changeToUpload)

	// Run an outbound (upload) throughput test and block until it's complete
	sc.runThroughputTest(outbound)

	// Signal to our generators that the upload test is complete
	close(sc.statsGeneratorDone)

	// Notify the progress bar updater to change the bar color to green
	close(sc.allTestsDone)

	return
}
Пример #25
0
func main() {
	if err := ui.Init(); err != nil {
		panic(err)
	}
	defer ui.Close()

	p := ui.NewPar(":PRESS q TO QUIT DEMO")
	p.Height = 3
	p.Width = 50
	p.TextFgColor = ui.ColorWhite
	p.BorderLabel = "Text Box"
	p.BorderFg = ui.ColorCyan
	p.Handle("/timer/1s", func(e ui.Event) {
		cnt := e.Data.(ui.EvtTimer)
		if cnt.Count%2 == 0 {
			p.TextFgColor = ui.ColorRed
		} else {
			p.TextFgColor = ui.ColorWhite
		}
	})

	strs := []string{"[0] gizak/termui", "[1] editbox.go", "[2] iterrupt.go", "[3] keyboard.go", "[4] output.go", "[5] random_out.go", "[6] dashboard.go", "[7] nsf/termbox-go"}
	list := ui.NewList()
	list.Items = strs
	list.ItemFgColor = ui.ColorYellow
	list.BorderLabel = "List"
	list.Height = 7
	list.Width = 25
	list.Y = 4

	g := ui.NewGauge()
	g.Percent = 50
	g.Width = 50
	g.Height = 3
	g.Y = 11
	g.BorderLabel = "Gauge"
	g.BarColor = ui.ColorRed
	g.BorderFg = ui.ColorWhite
	g.BorderLabelFg = ui.ColorCyan

	spark := ui.Sparkline{}
	spark.Height = 1
	spark.Title = "srv 0:"
	spdata := []int{4, 2, 1, 6, 3, 9, 1, 4, 2, 15, 14, 9, 8, 6, 10, 13, 15, 12, 10, 5, 3, 6, 1, 7, 10, 10, 14, 13, 6, 4, 2, 1, 6, 3, 9, 1, 4, 2, 15, 14, 9, 8, 6, 10, 13, 15, 12, 10, 5, 3, 6, 1, 7, 10, 10, 14, 13, 6, 4, 2, 1, 6, 3, 9, 1, 4, 2, 15, 14, 9, 8, 6, 10, 13, 15, 12, 10, 5, 3, 6, 1, 7, 10, 10, 14, 13, 6, 4, 2, 1, 6, 3, 9, 1, 4, 2, 15, 14, 9, 8, 6, 10, 13, 15, 12, 10, 5, 3, 6, 1, 7, 10, 10, 14, 13, 6}
	spark.Data = spdata
	spark.LineColor = ui.ColorCyan
	spark.TitleColor = ui.ColorWhite

	spark1 := ui.Sparkline{}
	spark1.Height = 1
	spark1.Title = "srv 1:"
	spark1.Data = spdata
	spark1.TitleColor = ui.ColorWhite
	spark1.LineColor = ui.ColorRed

	sp := ui.NewSparklines(spark, spark1)
	sp.Width = 25
	sp.Height = 7
	sp.BorderLabel = "Sparkline"
	sp.Y = 4
	sp.X = 25

	sinps := (func() []float64 {
		n := 220
		ps := make([]float64, n)
		for i := range ps {
			ps[i] = 1 + math.Sin(float64(i)/5)
		}
		return ps
	})()

	lc := ui.NewLineChart()
	lc.BorderLabel = "dot-mode Line Chart"
	lc.Data = sinps
	lc.Width = 50
	lc.Height = 11
	lc.X = 0
	lc.Y = 14
	lc.AxesColor = ui.ColorWhite
	lc.LineColor = ui.ColorRed | ui.AttrBold
	lc.Mode = "dot"

	bc := ui.NewBarChart()
	bcdata := []int{3, 2, 5, 3, 9, 5, 3, 2, 5, 8, 3, 2, 4, 5, 3, 2, 5, 7, 5, 3, 2, 6, 7, 4, 6, 3, 6, 7, 8, 3, 6, 4, 5, 3, 2, 4, 6, 4, 8, 5, 9, 4, 3, 6, 5, 3, 6}
	bclabels := []string{"S0", "S1", "S2", "S3", "S4", "S5"}
	bc.BorderLabel = "Bar Chart"
	bc.Width = 26
	bc.Height = 10
	bc.X = 51
	bc.Y = 0
	bc.DataLabels = bclabels
	bc.BarColor = ui.ColorGreen
	bc.NumColor = ui.ColorBlack

	lc1 := ui.NewLineChart()
	lc1.BorderLabel = "braille-mode Line Chart"
	lc1.Data = sinps
	lc1.Width = 26
	lc1.Height = 11
	lc1.X = 51
	lc1.Y = 14
	lc1.AxesColor = ui.ColorWhite
	lc1.LineColor = ui.ColorYellow | ui.AttrBold

	p1 := ui.NewPar("Hey!\nI am a borderless block!")
	p1.Border = false
	p1.Width = 26
	p1.Height = 2
	p1.TextFgColor = ui.ColorMagenta
	p1.X = 52
	p1.Y = 11

	draw := func(t int) {
		g.Percent = t % 101
		list.Items = strs[t%9:]
		sp.Lines[0].Data = spdata[:30+t%50]
		sp.Lines[1].Data = spdata[:35+t%50]
		lc.Data = sinps[t/2%220:]
		lc1.Data = sinps[2*t%220:]
		bc.Data = bcdata[t/2%10:]
		ui.Render(p, list, g, sp, lc, bc, lc1, p1)
	}
	ui.Handle("/sys/kbd/q", func(ui.Event) {
		ui.StopLoop()
	})
	ui.Handle("/timer/1s", func(e ui.Event) {
		t := e.Data.(ui.EvtTimer)
		draw(int(t.Count))
	})
	ui.Loop()
}
Пример #26
0
func main() {
	if err := ui.Init(); err != nil {
		panic(err)
	}
	defer ui.Close()

	sinps := (func() []float64 {
		n := 400
		ps := make([]float64, n)
		for i := range ps {
			ps[i] = 1 + math.Sin(float64(i)/5)
		}
		return ps
	})()
	sinpsint := (func() []int {
		ps := make([]int, len(sinps))
		for i, v := range sinps {
			ps[i] = int(100*v + 10)
		}
		return ps
	})()

	spark := ui.Sparkline{}
	spark.Height = 8
	spdata := sinpsint
	spark.Data = spdata[:100]
	spark.LineColor = ui.ColorCyan
	spark.TitleColor = ui.ColorWhite

	sp := ui.NewSparklines(spark)
	sp.Height = 11
	sp.BorderLabel = "Sparkline"

	lc := ui.NewLineChart()
	lc.BorderLabel = "braille-mode Line Chart"
	lc.Data = sinps
	lc.Height = 11
	lc.AxesColor = ui.ColorWhite
	lc.LineColor = ui.ColorYellow | ui.AttrBold

	gs := make([]*ui.Gauge, 3)
	for i := range gs {
		gs[i] = ui.NewGauge()
		//gs[i].LabelAlign = ui.AlignCenter
		gs[i].Height = 2
		gs[i].Border = false
		gs[i].Percent = i * 10
		gs[i].PaddingBottom = 1
		gs[i].BarColor = ui.ColorRed
	}

	ls := ui.NewList()
	ls.Border = false
	ls.Items = []string{
		"[1] Downloading File 1",
		"", // == \newline
		"[2] Downloading File 2",
		"",
		"[3] Uploading File 3",
	}
	ls.Height = 5

	par := ui.NewPar("<> This row has 3 columns\n<- Widgets can be stacked up like left side\n<- Stacked widgets are treated as a single widget")
	par.Height = 5
	par.BorderLabel = "Demonstration"

	// build layout
	ui.Body.AddRows(
		ui.NewRow(
			ui.NewCol(6, 0, sp),
			ui.NewCol(6, 0, lc)),
		ui.NewRow(
			ui.NewCol(3, 0, ls),
			ui.NewCol(3, 0, gs[0], gs[1], gs[2]),
			ui.NewCol(6, 0, par)))

	// calculate layout
	ui.Body.Align()

	ui.Render(ui.Body)

	ui.Handle("/sys/kbd/q", func(ui.Event) {
		ui.StopLoop()
	})
	ui.Handle("/timer/1s", func(e ui.Event) {
		t := e.Data.(ui.EvtTimer)
		i := t.Count
		if i > 103 {
			ui.StopLoop()
			return
		}

		for _, g := range gs {
			g.Percent = (g.Percent + 3) % 100
		}

		sp.Lines[0].Data = spdata[:100+i]
		lc.Data = sinps[2*i:]
		ui.Render(ui.Body)
	})

	ui.Handle("/sys/wnd/resize", func(e ui.Event) {
		ui.Body.Width = ui.TermWidth()
		ui.Body.Align()
		ui.Render(ui.Body)
	})

	ui.Loop()
}
Пример #27
0
func main() {
	err := termui.Init()
	if err != nil {
		panic(err)
	}
	defer termui.Close()

	//termui.UseTheme("helloworld")

	g0 := termui.NewGauge()
	g0.Percent = 40
	g0.Width = 50
	g0.Height = 3
	g0.BorderLabel = "Slim Gauge"
	g0.BarColor = termui.ColorRed
	g0.BorderFg = termui.ColorWhite
	g0.BorderLabelFg = termui.ColorCyan

	gg := termui.NewBlock()
	gg.Width = 50
	gg.Height = 5
	gg.Y = 12
	gg.BorderLabel = "TEST"
	gg.Align()

	g2 := termui.NewGauge()
	g2.Percent = 60
	g2.Width = 50
	g2.Height = 3
	g2.PercentColor = termui.ColorBlue
	g2.Y = 3
	g2.BorderLabel = "Slim Gauge"
	g2.BarColor = termui.ColorYellow
	g2.BorderFg = termui.ColorWhite

	g1 := termui.NewGauge()
	g1.Percent = 30
	g1.Width = 50
	g1.Height = 5
	g1.Y = 6
	g1.BorderLabel = "Big Gauge"
	g1.PercentColor = termui.ColorYellow
	g1.BarColor = termui.ColorGreen
	g1.BorderFg = termui.ColorWhite
	g1.BorderLabelFg = termui.ColorMagenta

	g3 := termui.NewGauge()
	g3.Percent = 50
	g3.Width = 50
	g3.Height = 3
	g3.Y = 11
	g3.BorderLabel = "Gauge with custom label"
	g3.Label = "{{percent}}% (100MBs free)"
	g3.LabelAlign = termui.AlignRight

	g4 := termui.NewGauge()
	g4.Percent = 50
	g4.Width = 50
	g4.Height = 3
	g4.Y = 14
	g4.BorderLabel = "Gauge"
	g4.Label = "Gauge with custom highlighted label"
	g4.PercentColor = termui.ColorYellow
	g4.BarColor = termui.ColorGreen
	g4.PercentColorHighlighted = termui.ColorBlack

	termui.Render(g0, g1, g2, g3, g4)

	termui.Handle("/sys/kbd/q", func(termui.Event) {
		termui.StopLoop()
	})

	termui.Loop()
}