本文整理匯總了Golang中github.com/nsf/termbox-go.PollEvent函數的典型用法代碼示例。如果您正苦於以下問題:Golang PollEvent函數的具體用法?Golang PollEvent怎麽用?Golang PollEvent使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了PollEvent函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
/* A multiplayer rogue-like in the spirit of TOAG, but implemented in termbox-go */
func main() {
//flag.Parse()
/* start network handling and channels */
max_dimensions := 80 * 24
screen := make([]nr.Sprite, max_dimensions)
world := loadWorld()
/* initialize termbox interface */
err := tb.Init()
check(err)
tb.SetInputMode(tb.InputAlt)
w, h := tb.Size()
tb.Clear(tb.ColorBlack, tb.ColorBlack)
tb.Flush()
go draw(w, h)
for run := true; run == true; {
switch ev := tb.PollEvent(); ev.Type {
case tb.EventKey:
//key := ev.Ch
if ev.Key == tb.KeyCtrlQ {
tb.Flush()
run = false
}
default:
}
}
}
示例2: debug_stats
func debug_stats(height int, show_text string, show_val int) {
bh_status := fmt.Sprintf("%s : %d ", show_text, show_val)
print_tb(0, height, 0, 0, bh_status)
_ = tb.PollEvent().Ch
}
示例3: Run
func (f *Form) Run() error {
draw := func() bool {
termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
f.DrawInto(&box.TermBox{}, 0, 0)
termbox.Flush()
return true
}
err := termbox.Init()
defer termbox.Close()
if err != nil {
return err
}
if draw() {
f.running = true
for f.running {
ev := termbox.PollEvent()
if !f.HandleEvent(&ev) {
f.running = false
}
draw()
}
} else {
return errors.New("fail sadness")
}
return nil
}
示例4: Loop
func (s *Screen) Loop() {
for {
e := termbox.PollEvent()
// handle error
if e.Type == termbox.EventError {
panic(e.Err)
}
w := curWindow // TODO rename w to curWindow
// handle resize
if w.autoResize && e.Type == termbox.EventResize {
err := w.Redraw()
if err != nil {
panic(err) // TODO dont panic here
}
termbox.Flush()
continue
}
if w.CatchEvent != nil {
w.CatchEvent(e)
}
}
}
示例5: input
func (v *TermView) input() {
for {
ev := termbox.PollEvent()
switch ev.Type {
case termbox.EventKey:
switch ev.Key {
case termbox.KeyCtrlC:
v.Info("Got quit command")
v.ctl.Cmds <- ui.CmdQuit{}
}
case termbox.EventResize:
v.Info("Resize event, redrawing")
// send nil to update channel to force re-rendering
v.updates <- nil
for _, sv := range v.subviews {
sv.Render()
}
case termbox.EventError:
if v.ctl.IsShuttingDown() {
return
}
panic(ev.Err)
}
}
}
示例6: main
func main() {
dot = termbox.Cell{Ch: '.', Fg: termbox.ColorDefault, Bg: termbox.ColorDefault}
greenPlus = termbox.Cell{Ch: '+', Fg: termbox.ColorGreen, Bg: termbox.ColorDefault}
err := termbox.Init()
if err != nil {
panic(err)
}
if draw() {
fmt.Fprintf(os.Stderr, "drew ok\r\n")
loop:
for {
switch ev := termbox.PollEvent(); ev.Type {
case termbox.EventKey:
switch ev.Key {
case termbox.KeyEsc:
break loop
}
case termbox.EventResize:
draw()
}
}
termbox.Close()
} else {
fmt.Printf("Didn't draw correctly\r\n")
}
}
示例7: Run
func (s *Session) Run() error {
s.mode = &ModeEdit{}
data, err := ioutil.ReadFile(s.File)
if err != nil {
return err
}
s.Buf = util.NewBuffer(data)
s.W, s.H = termbox.Size()
s.H--
s.View.SetBuf(s.Buf)
s.View.SetSize(s.W, s.H)
s.View.SetTabwidth(s.Tabwidth)
for {
s.Draw()
termbox.Flush()
termbox.Clear(0, 0)
ev := termbox.PollEvent()
switch ev.Type {
case termbox.EventKey:
s.mode, err = s.mode.HandleKey(s, ev)
if err != nil {
return err
}
case termbox.EventResize:
s.W, s.H = ev.Width, ev.Height-1
s.View.SetSize(s.W, s.H)
case termbox.EventMouse:
case termbox.EventError:
return ev.Err
}
}
}
示例8: loop
func loop(s state) {
for {
render(s)
switch ev := tb.PollEvent(); ev.Type {
case tb.EventKey:
switch ev.Key {
case tb.KeyEsc:
os.Exit(0)
break
case tb.KeySpace:
s = turn(s)
break
default:
switch ev.Ch {
case keyq:
os.Exit(0)
break
case keyh:
s.message = helpMessage
render(s)
break
default:
s.nextTurnEvent = ev
break
}
}
}
}
}
示例9: main
func main() {
err := tb.Init()
if err != nil {
panic(err)
}
defer tb.Close()
tb.SetInputMode(tb.InputEsc)
tb.Clear(tb.ColorCyan, tb.ColorBlue)
tb.Flush()
loop:
for i := 0; ; i++ {
ev := tb.PollEvent()
switch ev.Type {
case tb.EventKey:
if ev.Key == tb.KeyCtrlC {
break loop
}
tb.SetCell(i, i, ev.Ch, tb.ColorGreen, tb.ColorBlack)
tb.Flush()
case tb.EventError:
panic(ev.Err)
}
}
}
示例10: Run
func (this *Game) Run() {
err := tb.Init()
if err != nil {
panic(err)
}
defer tb.Close()
tb.HideCursor()
this.Draw()
loop:
for {
switch ev := tb.PollEvent(); ev.Type {
case tb.EventKey:
switch ev.Key {
case tb.KeyEsc:
break loop
}
switch ev.Ch {
case 'h':
this.Player.Move(-1, 0)
case 'j':
this.Player.Move(0, 1)
case 'k':
this.Player.Move(0, -1)
case 'l':
this.Player.Move(1, 0)
}
}
this.Draw()
}
}
示例11: keys_in
func keys_in(ck chan string) {
key := tb.PollEvent()
operation := get_key(key)
ck <- operation
}
示例12: debug_tb
func debug_tb(x, y int, fg, bg tb.Attribute, msg string) {
for _, c := range msg {
tb.SetCell(x, y, c, fg, bg)
x++
}
tb.Flush()
_ = tb.PollEvent().Ch
}
示例13: pause
func pause() {
fmt.Println("請按任意鍵繼續...")
Loop:
for {
switch ev := termbox.PollEvent(); ev.Type {
case termbox.EventKey:
break Loop
}
}
}
示例14: StartEventPolling
func StartEventPolling() {
go func() {
for {
select {
case <-stopPolling:
return
case internalEvents <- termbox.PollEvent():
}
}
}()
}
示例15: main
func main() {
termbox.Init()
defer termbox.Close()
termbox.SetInputMode(termbox.InputEsc)
termbox.Flush()
for i := 0; i < 7; i++ {
switch ev := termbox.PollEvent(); ev.Type {
case termbox.EventKey:
fmt.Println(ev)
}
}
}