本文整理匯總了Golang中github.com/moncho/dry/ui.Screen.CursorPosition方法的典型用法代碼示例。如果您正苦於以下問題:Golang Screen.CursorPosition方法的具體用法?Golang Screen.CursorPosition怎麽用?Golang Screen.CursorPosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/moncho/dry/ui.Screen
的用法示例。
在下文中一共展示了Screen.CursorPosition方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: mainScreen
//-----------------------------------------------------------------------------
func mainScreen(dry *app.Dry, screen *ui.Screen) {
if ok, _ := dry.Ok(); !ok {
return
}
keyboardQueue, done := ui.EventChannel()
timestampQueue := time.NewTicker(1 * time.Second)
viewClosed := make(chan struct{}, 1)
keyboardQueueForView := make(chan termbox.Event)
dryOutputChan := dry.OuputChannel()
statusBar := ui.NewStatusBar(0)
defer timestampQueue.Stop()
defer close(done)
defer close(keyboardQueueForView)
defer close(viewClosed)
app.Render(dry, screen, statusBar)
//belongs outside the loop
var viewMode = false
go func(viewMode *bool) {
for {
dryMessage := <-dryOutputChan
if !*viewMode {
statusBar.StatusMessage(dryMessage, 10*time.Second)
if dry.Changed() {
screen.Clear()
app.Render(dry, screen, statusBar)
} else {
statusBar.Render()
}
screen.Flush()
}
}
}(&viewMode)
loop:
for {
//Used for refresh-forcing events happening outside dry
var refresh = false
select {
case <-timestampQueue.C:
if !viewMode {
timestamp := time.Now().Format(`15:04:05`)
screen.RenderLine(0, 0, `<right><white>`+timestamp+`</></right>`)
screen.Flush()
}
case <-viewClosed:
viewMode = false
dry.ShowContainers()
case event := <-keyboardQueue:
switch event.Type {
case termbox.EventKey:
if !viewMode {
if event.Key == termbox.KeyEsc || event.Ch == 'q' || event.Ch == 'Q' {
break loop
} else if event.Key == termbox.KeyArrowUp { //cursor up
screen.ScrollCursorUp()
refresh = true
} else if event.Key == termbox.KeyArrowDown { // cursor down
screen.ScrollCursorDown()
refresh = true
} else if event.Key == termbox.KeyF1 { //sort
dry.Sort()
} else if event.Key == termbox.KeyF2 { //show all containers
dry.ToggleShowAllContainers()
} else if event.Key == termbox.KeyF5 { // refresh
dry.Refresh()
} else if event.Key == termbox.KeyF10 { // docker info
dry.ShowInfo()
viewMode = true
go less(dry, screen, keyboardQueueForView, viewClosed)
} else if event.Ch == '?' || event.Ch == 'h' || event.Ch == 'H' { //help
viewMode = true
dry.ShowHelp()
go less(dry, screen, keyboardQueueForView, viewClosed)
} else if event.Ch == 'e' || event.Ch == 'E' { //remove
dry.Rm(screen.CursorPosition())
} else if event.Key == termbox.KeyCtrlE { //remove all stopped
dry.RemoveAllStoppedContainers()
} else if event.Ch == 'k' || event.Ch == 'K' { //kill
dry.Kill(screen.CursorPosition())
} else if event.Ch == 'l' || event.Ch == 'L' { //logs
if logs, err := dry.Logs(screen.CursorPosition()); err == nil {
viewMode = true
go stream(screen, logs, keyboardQueueForView, viewClosed)
}
} else if event.Ch == 'r' || event.Ch == 'R' { //start
dry.StartContainer(screen.CursorPosition())
} else if event.Ch == 's' || event.Ch == 'S' { //stats
done, errC, err := dry.Stats(screen.CursorPosition())
if err == nil {
viewMode = true
go autorefresh(dry, screen, keyboardQueueForView, viewClosed, done, errC)
}
} else if event.Ch == 't' || event.Ch == 'T' { //stop
//.........這裏部分代碼省略.........