本文整理汇总了Golang中github.com/gizak/termui.EventCh函数的典型用法代码示例。如果您正苦于以下问题:Golang EventCh函数的具体用法?Golang EventCh怎么用?Golang EventCh使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EventCh函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: init
func init() {
err := termui.Init()
if err != nil {
panic(err)
}
termui.UseTheme("default")
ui = NewUi()
refreshTicker := time.NewTicker(time.Millisecond * 50)
evt := termui.EventCh()
ui.refresh()
go func() {
for {
select {
case e := <-evt:
if e.Type == termui.EventKey && e.Ch == 'q' {
os.Exit(1)
}
if e.Type == termui.EventResize {
ui.gridWidth = termui.TermWidth()
ui.refresh()
}
case <-refreshTicker.C:
ui.refresh()
}
}
}()
}
开发者ID:bigwhoop,项目名称:podcastd,代码行数:32,代码来源:ui.go
示例2: main
func main() {
err := ui.Init()
if err != nil {
panic(err)
}
defer ui.Close()
w11 := ui.NewPar("Hello world")
w11.Height = 10
w11.Border.Label = "Hello"
w11.Border.LabelFgColor = ui.ColorGreen
w12 := ui.NewPar("first")
w12.Height = 20
w2 := ui.NewPar("second")
w2.Height = 20
ui.Body.AddRows(
ui.NewRow(
ui.NewCol(6, 0, w11),
ui.NewCol(6, 0, w12)),
ui.NewRow(
ui.NewCol(12, 0, w2)))
ui.Body.Align()
ui.Render(ui.Body)
<-ui.EventCh()
}
开发者ID:plumbum,项目名称:go-samples,代码行数:33,代码来源:main.go
示例3: main
func main() {
err := termui.Init()
if err != nil {
panic(err)
}
defer termui.Close()
termui.UseTheme("helloworld")
strs := []string{
"[0] github.com/gizak/termui",
"[1] 你好,世界",
"[2] こんにちは世界",
"[3] keyboard.go",
"[4] output.go",
"[5] random_out.go",
"[6] dashboard.go",
"[7] nsf/termbox-go"}
ls := termui.NewList()
ls.Items = strs
ls.ItemFgColor = termui.ColorYellow
ls.Border.Label = "List"
ls.Height = 7
ls.Width = 25
ls.Y = 0
termui.Render(ls)
<-termui.EventCh()
}
开发者ID:j4ustin,项目名称:go-ethereum,代码行数:31,代码来源:list.go
示例4: main
func main() {
err := termui.Init()
if err != nil {
panic(err)
}
defer termui.Close()
termui.UseTheme("helloworld")
bc := termui.NewBarChart()
data := []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.Data = data
bc.Width = 26
bc.Height = 10
bc.DataLabels = bclabels
bc.TextColor = termui.ColorGreen
bc.BarColor = termui.ColorRed
bc.NumColor = termui.ColorYellow
termui.Render(bc)
<-termui.EventCh()
}
开发者ID:j4ustin,项目名称:go-ethereum,代码行数:25,代码来源:barchart.go
示例5: main
func main() {
err := termui.Init()
if err != nil {
panic(err)
}
defer termui.Close()
termui.UseTheme("helloworld")
data := []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}
spl0 := termui.NewSparkline()
spl0.Data = data[3:]
spl0.Title = "Sparkline 0"
spl0.LineColor = termui.ColorGreen
// single
spls0 := termui.NewSparklines(spl0)
spls0.Height = 2
spls0.Width = 20
spls0.HasBorder = false
spl1 := termui.NewSparkline()
spl1.Data = data
spl1.Title = "Sparkline 1"
spl1.LineColor = termui.ColorRed
spl2 := termui.NewSparkline()
spl2.Data = data[5:]
spl2.Title = "Sparkline 2"
spl2.LineColor = termui.ColorMagenta
// group
spls1 := termui.NewSparklines(spl0, spl1, spl2)
spls1.Height = 8
spls1.Width = 20
spls1.Y = 3
spls1.Border.Label = "Group Sparklines"
spl3 := termui.NewSparkline()
spl3.Data = data
spl3.Title = "Enlarged Sparkline"
spl3.Height = 8
spl3.LineColor = termui.ColorYellow
spls2 := termui.NewSparklines(spl3)
spls2.Height = 11
spls2.Width = 30
spls2.Border.FgColor = termui.ColorCyan
spls2.X = 21
spls2.Border.Label = "Tweeked Sparkline"
termui.Render(spls0, spls1, spls2)
<-termui.EventCh()
}
开发者ID:j4ustin,项目名称:go-ethereum,代码行数:55,代码来源:sparklines.go
示例6: readMessage
func readMessage(message *imap.MessageInfo) {
set := new(imap.SeqSet)
set.AddNum(message.Seq)
cmd, err := imap.Wait(c.Fetch(set, BODY_PART_NAME))
panicMaybe(err)
reader, err := messageReader(cmd.Data[0].MessageInfo())
panicMaybe(err)
scanner := bufio.NewScanner(reader)
var lines []string
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
messageBodyStr := strings.Join(lines[:min(len(lines), ui.TermHeight()-2)], "\n")
if len(messageBodyStr) <= 0 {
LOG.Printf("Message body was empty or could not be retrieved: +%v\n", err)
return
}
msgBox := ui.NewPar(messageBodyStr)
msgBox.Border.Label = "Reading Message"
msgBox.Height = ui.TermHeight()
msgBox.Width = ui.TermWidth()
msgBox.Y = 0
ui.Render(msgBox)
topLineIndex := 0
redraw := make(chan bool)
for {
select {
case e := <-ui.EventCh():
switch e.Key {
case ui.KeyArrowDown:
topLineIndex = max(0, min(
len(lines)-msgBox.Height/2,
topLineIndex+1))
go func() { redraw <- true }()
case ui.KeyArrowUp:
topLineIndex = max(0, topLineIndex-1)
go func() { redraw <- true }()
case ui.KeyEsc:
// back to "list messages"
return
}
case <-redraw:
messageBodyStr = strings.Join(lines[topLineIndex+1:], "\n")
msgBox.Text = messageBodyStr
ui.Render(msgBox)
}
}
}
开发者ID:llvtt,项目名称:gomail,代码行数:55,代码来源:readmail.go
示例7: main
func main() {
err := termui.Init()
if err != nil {
panic(err)
}
defer termui.Close()
termui.UseTheme("helloworld")
sinps := (func() []float64 {
n := 220
ps := make([]float64, n)
for i := range ps {
ps[i] = 1 + math.Sin(float64(i)/5)
}
return ps
})()
lc0 := termui.NewLineChart()
lc0.Border.Label = "braille-mode Line Chart"
lc0.Data = sinps
lc0.Width = 50
lc0.Height = 12
lc0.X = 0
lc0.Y = 0
lc0.AxesColor = termui.ColorWhite
lc0.LineColor = termui.ColorGreen | termui.AttrBold
lc1 := termui.NewLineChart()
lc1.Border.Label = "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
lc2 := termui.NewLineChart()
lc2.Border.Label = "dot-mode Line Chart"
lc2.Mode = "dot"
lc2.Data = sinps[4:]
lc2.Width = 77
lc2.Height = 16
lc2.X = 0
lc2.Y = 12
lc2.AxesColor = termui.ColorWhite
lc2.LineColor = termui.ColorCyan | termui.AttrBold
termui.Render(lc0, lc1, lc2)
<-termui.EventCh()
}
开发者ID:j4ustin,项目名称:go-ethereum,代码行数:54,代码来源:linechart.go
示例8: main
func main() {
err := ui.Init()
if err != nil {
panic(err)
}
defer ui.Close()
initial()
ech := ui.EventCh()
for screen := intro; screen != nil; {
screen = screen(ech)
}
}
开发者ID:NHOrus,项目名称:rirs,代码行数:12,代码来源:main.go
示例9: main
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()
}
开发者ID:j4ustin,项目名称:go-ethereum,代码行数:52,代码来源:gauge.go
示例10: showSubreddit
func showSubreddit(subredditName string) error {
r := geddit.NewSession("r by /u/bnadland")
submissions, err := r.SubredditSubmissions(subredditName, geddit.HotSubmissions, geddit.ListingOptions{})
if err != nil {
return err
}
isActive := true
cursor := 3
for isActive {
entries := []string{}
for i, submission := range submissions {
entries = append(entries, fmt.Sprintf("%s %s", isActiveCursor(cursor, i), submission.Title))
}
ls := termui.NewList()
ls.Items = entries
ls.ItemFgColor = termui.ColorDefault
ls.Border.Label = fmt.Sprintf("Subreddit: %s", subredditName)
ls.Height = termui.TermHeight()
ls.Width = termui.TermWidth()
ls.Y = 0
termui.Render(ls)
event := <-termui.EventCh()
if event.Type == termui.EventKey {
switch event.Key {
case termui.KeyArrowLeft:
isActive = false
case termui.KeyArrowDown:
cursor = cursor + 1
if cursor > len(submissions) {
cursor = len(submissions)
}
case termui.KeyArrowUp:
cursor = cursor - 1
if cursor < 0 {
cursor = 0
}
}
}
}
return nil
}
开发者ID:bnadland,项目名称:r,代码行数:46,代码来源:main.go
示例11: main
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()
}
开发者ID:nindalf,项目名称:gotop,代码行数:43,代码来源:main.go
示例12: maintainSparkLines
func maintainSparkLines(redraw chan bool, quit chan bool) {
evt := ui.EventCh()
for {
select {
case e := <-evt:
if e.Type == ui.EventKey && e.Ch == 'q' {
quit <- true
return
}
if e.Type == ui.EventResize {
ui.Body.Width = ui.TermWidth()
ui.Body.Align()
go func() { redraw <- true }()
}
case <-redraw:
ui.Render(ui.Body)
}
}
}
开发者ID:jkoelndorfer,项目名称:cli,代码行数:19,代码来源:metrics.go
示例13: main
func main() {
// show flashscreen
views.MainView().Init()
err := termui.Init()
if err != nil {
panic(err)
}
defer termui.Close()
currentView = views.MainView().SwitchToView()
go func() {
for {
currentView.Render()
time.Sleep(1 * time.Second)
}
}()
for {
e := <-termui.EventCh()
if e.Type == termui.EventKey {
if e.Key == termui.KeyEsc {
break
} else if e.Key == termui.KeyArrowLeft {
currentView = views.EventView().SwitchToView()
currentView.Render()
} else if e.Key == termui.KeyArrowRight {
currentView = views.MainView().SwitchToView()
currentView.Render()
} else if e.Key == termui.KeyArrowUp {
currentView = views.RPSView().SwitchToView()
currentView.Render()
} else {
// FIXME: quit with any key
break
}
}
}
}
开发者ID:rzh,项目名称:montu,代码行数:42,代码来源:main.go
示例14: main
func main() {
err := termui.Init()
if err != nil {
panic(err)
}
defer termui.Close()
termui.UseTheme("helloworld")
bc := termui.NewMBarChart()
math := []int{90, 85, 90, 80}
english := []int{70, 85, 75, 60}
science := []int{75, 60, 80, 85}
compsci := []int{100, 100, 100, 100}
bc.Data[0] = math
bc.Data[1] = english
bc.Data[2] = science
bc.Data[3] = compsci
studentsName := []string{"Ken", "Rob", "Dennis", "Linus"}
bc.Border.Label = "Student's Marks X-Axis=Name Y-Axis=Marks[Math,English,Science,ComputerScience] in %"
bc.Width = 100
bc.Height = 50
bc.Y = 10
bc.BarWidth = 10
bc.DataLabels = studentsName
bc.ShowScale = true //Show y_axis scale value (min and max)
bc.SetMax(400)
bc.TextColor = termui.ColorGreen //this is color for label (x-axis)
bc.BarColor[3] = termui.ColorGreen //BarColor for computerscience
bc.BarColor[1] = termui.ColorYellow //Bar Color for english
bc.NumColor[3] = termui.ColorRed // Num color for computerscience
bc.NumColor[1] = termui.ColorRed // num color for english
//Other colors are automatically populated, btw All the students seems do well in computerscience. :p
termui.Render(bc)
<-termui.EventCh()
}
开发者ID:j4ustin,项目名称:go-ethereum,代码行数:40,代码来源:mbarchart.go
示例15: main
func main() {
err := termui.Init()
if err != nil {
panic(err)
}
defer termui.Close()
termui.UseTheme("helloworld")
par0 := termui.NewPar("Borderless Text")
par0.Height = 1
par0.Width = 20
par0.Y = 1
par0.HasBorder = false
par1 := termui.NewPar("你好,世界。")
par1.Height = 3
par1.Width = 17
par1.X = 20
par1.Border.Label = "标签"
par2 := termui.NewPar("Simple colored text\nwith label. It [can be](RED) multilined with \\n or [break automatically](GREEN, BOLD)")
par2.RendererFactory = termui.MarkdownTextRendererFactory{}
par2.Height = 5
par2.Width = 37
par2.Y = 4
par2.Border.Label = "Multiline"
par2.Border.FgColor = termui.ColorYellow
par3 := termui.NewPar("Long text with label and it is auto trimmed.")
par3.Height = 3
par3.Width = 37
par3.Y = 9
par3.Border.Label = "Auto Trim"
termui.Render(par0, par1, par2, par3)
<-termui.EventCh()
}
开发者ID:sguiheux,项目名称:termui,代码行数:39,代码来源:par.go
示例16: showMainWindow
func showMainWindow() {
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
draw := func(t int) {
ui.Render(p)
}
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)
}
}
}
开发者ID:tony,项目名称:gorpg,代码行数:38,代码来源:window.go
示例17: main
func main() {
sysmon = gtop.NewSysmon()
go sysmon.MonCPU()
err := termui.Init()
if err != nil {
panic(err)
}
defer termui.Close()
bufferer := []termui.Bufferer{}
lcpu_c, _, err := sysmon.CPUCount()
if err == nil {
cpu_bars = []*gtop.Bar{}
bar_offset := 0
for i := 0; i < lcpu_c; i++ {
b := gtop.NewBar(35, 2, 1+bar_offset, strconv.Itoa(i+1), &bufferer)
cpu_bars = append(cpu_bars, b)
bar_offset += b.Height
}
}
go render_loop(bufferer)
go update_cpu_bars()
evt := termui.EventCh()
for {
select {
case e := <-evt:
if e.Type == termui.EventKey && e.Ch == 0 {
return
}
}
}
}
开发者ID:TilmanGriesel,项目名称:gtop,代码行数:37,代码来源:gtop.go
示例18: main
func main() {
flag.Usage = Usage
flag.Parse()
// Process ports/urls
ports, _ := ParsePorts(*urls)
if *self {
port, err := StartSelfMonitor()
if err == nil {
ports = append(ports, port)
}
}
if len(ports) == 0 {
fmt.Fprintln(os.Stderr, "no ports specified. Use -ports arg to specify ports of Go apps to monitor")
Usage()
os.Exit(1)
}
if *interval <= 0 {
fmt.Fprintln(os.Stderr, "update interval is not valid. Valid examples: 5s, 1m, 1h30m")
Usage()
os.Exit(1)
}
// Process vars
vars, err := ParseVars(*varsArg)
if err != nil {
log.Fatal(err)
}
// Init UIData
data := NewUIData(vars)
for _, port := range ports {
service := NewService(port, vars)
data.Services = append(data.Services, service)
}
// Start proper UI
var ui UI
if len(data.Services) > 1 {
ui = &TermUI{}
} else {
ui = &TermUISingle{}
}
if *dummy {
ui = &DummyUI{}
}
if err := ui.Init(*data); err != nil {
log.Fatal(err)
}
defer ui.Close()
tick := time.NewTicker(*interval)
evtCh := termui.EventCh()
UpdateAll(ui, data)
for {
select {
case <-tick.C:
UpdateAll(ui, data)
case e := <-evtCh:
if e.Type == termui.EventKey && e.Ch == 'q' {
return
}
if e.Type == termui.EventResize {
ui.Update(*data)
}
}
}
}
开发者ID:hhatto,项目名称:expvarmon,代码行数:70,代码来源:main.go
示例19: monitor
// monitor starts a terminal UI based monitoring tool for the requested metrics.
func monitor(ctx *cli.Context) {
var (
client comms.EthereumClient
err error
)
// Attach to an Ethereum node over IPC or RPC
endpoint := ctx.String(monitorCommandAttachFlag.Name)
if client, err = comms.ClientFromEndpoint(endpoint, codec.JSON); err != nil {
utils.Fatalf("Unable to attach to geth node: %v", err)
}
defer client.Close()
xeth := rpc.NewXeth(client)
// Retrieve all the available metrics and resolve the user pattens
metrics, err := retrieveMetrics(xeth)
if err != nil {
utils.Fatalf("Failed to retrieve system metrics: %v", err)
}
monitored := resolveMetrics(metrics, ctx.Args())
if len(monitored) == 0 {
list := expandMetrics(metrics, "")
sort.Strings(list)
if len(list) > 0 {
utils.Fatalf("No metrics specified.\n\nAvailable:\n - %s", strings.Join(list, "\n - "))
} else {
utils.Fatalf("No metrics collected by geth (--%s).\n", utils.MetricsEnabledFlag.Name)
}
}
sort.Strings(monitored)
if cols := len(monitored) / ctx.Int(monitorCommandRowsFlag.Name); cols > 6 {
utils.Fatalf("Requested metrics (%d) spans more that 6 columns:\n - %s", len(monitored), strings.Join(monitored, "\n - "))
}
// Create and configure the chart UI defaults
if err := termui.Init(); err != nil {
utils.Fatalf("Unable to initialize terminal UI: %v", err)
}
defer termui.Close()
termui.UseTheme("helloworld")
rows := len(monitored)
if max := ctx.Int(monitorCommandRowsFlag.Name); rows > max {
rows = max
}
cols := (len(monitored) + rows - 1) / rows
for i := 0; i < rows; i++ {
termui.Body.AddRows(termui.NewRow())
}
// Create each individual data chart
footer := termui.NewPar("")
footer.HasBorder = true
footer.Height = 3
charts := make([]*termui.LineChart, len(monitored))
units := make([]int, len(monitored))
data := make([][]float64, len(monitored))
for i := 0; i < len(monitored); i++ {
charts[i] = createChart((termui.TermHeight() - footer.Height) / rows)
row := termui.Body.Rows[i%rows]
row.Cols = append(row.Cols, termui.NewCol(12/cols, 0, charts[i]))
}
termui.Body.AddRows(termui.NewRow(termui.NewCol(12, 0, footer)))
refreshCharts(xeth, monitored, data, units, charts, ctx, footer)
termui.Body.Align()
termui.Render(termui.Body)
// Watch for various system events, and periodically refresh the charts
refresh := time.Tick(time.Duration(ctx.Int(monitorCommandRefreshFlag.Name)) * time.Second)
for {
select {
case event := <-termui.EventCh():
if event.Type == termui.EventKey && event.Key == termui.KeyCtrlC {
return
}
if event.Type == termui.EventResize {
termui.Body.Width = termui.TermWidth()
for _, chart := range charts {
chart.Height = (termui.TermHeight() - footer.Height) / rows
}
termui.Body.Align()
termui.Render(termui.Body)
}
case <-refresh:
if refreshCharts(xeth, monitored, data, units, charts, ctx, footer) {
termui.Body.Align()
}
termui.Render(termui.Body)
}
}
}
开发者ID:j4ustin,项目名称:go-ethereum,代码行数:94,代码来源:monitorcmd.go
示例20: main
//.........这里部分代码省略.........
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)
}
}
}
开发者ID:arscan,项目名称:gosf,代码行数:101,代码来源:main.go
注:本文中的github.com/gizak/termui.EventCh函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论