當前位置: 首頁>>代碼示例>>Golang>>正文


Golang termbox-go.PollEvent函數代碼示例

本文整理匯總了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:
		}
	}
}
開發者ID:henesy,項目名稱:NetRogue,代碼行數:32,代碼來源:main.go

示例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

}
開發者ID:nickaubert,項目名稱:grin,代碼行數:7,代碼來源:grin.go

示例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
}
開發者ID:telyn,項目名稱:form,代碼行數:28,代碼來源:form.go

示例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)
		}
	}
}
開發者ID:hoffoo,項目名稱:termboxutil,代碼行數:27,代碼來源:screen.go

示例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)
		}
	}
}
開發者ID:GiantToast,項目名稱:ngrok,代碼行數:27,代碼來源:view.go

示例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")
	}
}
開發者ID:telyn,項目名稱:form,代碼行數:27,代碼來源:main.go

示例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
		}
	}
}
開發者ID:rwcarlsen,項目名稱:editor,代碼行數:34,代碼來源:session.go

示例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
				}
			}
		}
	}
}
開發者ID:sjmarshy,項目名稱:go_game_jam,代碼行數:31,代碼來源:main.go

示例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)
		}
	}
}
開發者ID:rbonvall,項目名稱:ejemplos-go,代碼行數:26,代碼來源:termbox.go

示例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()
	}
}
開發者ID:nmuth,項目名稱:dastardly-go,代碼行數:35,代碼來源:game.go

示例11: keys_in

func keys_in(ck chan string) {

	key := tb.PollEvent()

	operation := get_key(key)
	ck <- operation

}
開發者ID:nickaubert,項目名稱:grin,代碼行數:8,代碼來源:grin.go

示例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
}
開發者ID:nickaubert,項目名稱:grin,代碼行數:8,代碼來源:grin.go

示例13: pause

func pause() {
	fmt.Println("請按任意鍵繼續...")
Loop:
	for {
		switch ev := termbox.PollEvent(); ev.Type {
		case termbox.EventKey:
			break Loop
		}
	}
}
開發者ID:CodyGuo,項目名稱:Go-Cody,代碼行數:10,代碼來源:main.go

示例14: StartEventPolling

func StartEventPolling() {
	go func() {
		for {
			select {
			case <-stopPolling:
				return
			case internalEvents <- termbox.PollEvent():
			}
		}
	}()
}
開發者ID:sgeb,項目名稱:go-tuikit,代碼行數:11,代碼來源:tuikit.go

示例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)
		}
	}
}
開發者ID:CasualSuperman,項目名稱:dfc,代碼行數:15,代碼來源:test_input.go


注:本文中的github.com/nsf/termbox-go.PollEvent函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。