Exemple #1
0
func uiDetail(detail *termui.List) *termui.Grid {
	body := termui.NewGrid()
	help := termui.NewPar("s:summary(main view) q:quit h:help")
	help.Height = 3
	help.Border.Label = "Keyboard shortcuts"
	detail.Height = 15
	body.AddRows(
		termui.NewRow(termui.NewCol(12, 0, help)),
		termui.NewRow(termui.NewCol(12, 0, detail)))
	return body
}
Exemple #2
0
func uiHelp() *termui.Grid {
	body := termui.NewGrid()
	kbHelp := termui.NewList()
	kbHelp.Items = []string{
		"h: Help",
		"s: Summary view",
		"c: processes by cpu usage",
		"C: cgroups for cpu subsystem",
		"m: processes by memory usage",
		"M: cgroups for memory subsystem",
		"i: processes by io",
		"d: disk io statistics",
		"f: filesystem statistics",
		"n: network interface statistics",
		"p: problems found",
		"q: Quit",
	}
	kbHelp.Border.Label = "Keyboard shortcuts"
	kbHelp.Height = 20
	body.AddRows(termui.NewRow(termui.NewCol(12, 0, kbHelp)))
	return body
}
Exemple #3
0
func uiSummary(widgets *osmain.DisplayWidgets) *termui.Grid {
	body := termui.NewGrid()
	help := termui.NewPar("q:quit h:help c:cpu etc")
	help.Height = 3
	body.AddRows(
		termui.NewRow(
			termui.NewCol(8, 0, widgets.Summary),
			termui.NewCol(4, 0, help)),
		termui.NewRow(
			termui.NewCol(6, 0, widgets.ProcessesByCPU),
			termui.NewCol(6, 0, widgets.ProcessesByMemory)),
		termui.NewRow(
			termui.NewCol(8, 0, widgets.ProcessesByIO),
			termui.NewCol(4, 0, widgets.DiskIOUsage)),
		termui.NewRow(
			termui.NewCol(6, 0, widgets.FileSystemUsage),
			termui.NewCol(6, 0, widgets.InterfaceUsage)),
		termui.NewRow(
			termui.NewCol(6, 0, widgets.CgroupsCPU),
			termui.NewCol(6, 0, widgets.CgroupsMem)),
		termui.NewRow(termui.NewCol(12, 0, widgets.Problems)))
	return body
}
Exemple #4
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)
		}
	}
}