Ejemplo n.º 1
0
/* 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:
		}
	}
}
Ejemplo n.º 2
0
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)
		}
	}
}
Ejemplo n.º 3
0
Archivo: form.go Proyecto: telyn/form
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
}
Ejemplo n.º 4
0
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
				}
			}
		}
	}
}
Ejemplo n.º 5
0
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)
		}
	}
}
Ejemplo n.º 6
0
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

}
Ejemplo n.º 7
0
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()
	}
}
Ejemplo n.º 8
0
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)
		}
	}
}
Ejemplo n.º 9
0
Archivo: main.go Proyecto: telyn/form
func main() {
	field := NewTextField(12, []rune(""), func(val string) bool {
		return false
	})
	field1 := NewTextField(24, []rune(""), func(val string) bool { return true })
	field2 := NewTextField(18, []rune(""), func(val string) bool { return true })
	form = NewForm([]Field{
		Label(field, "First text field, yeah!"),
		Label(field1, "Second text field, accompanied by a whole load more words. Like at least nine words but probably more yeah. That's how many words we're going for anyway. This ought to do"),
		Label(field2, "Third text field oh boy"),
	})
	err := termbox.Init()
	defer termbox.Close()
	if err != nil {
		fmt.Println(err)
		return
	}

	if draw() {
		fmt.Fprintf(os.Stderr, "drew ok\r\n")

	loop:
		for {
			ev := termbox.PollEvent()
			if !form.HandleEvent(&ev) {
				log.Print("Exiting because HandleEvent said so")
				break loop
			}
			draw()
		}
	}

}
Ejemplo n.º 10
0
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
		}
	}
}
Ejemplo n.º 11
0
func keys_in(ck chan string) {

	key := tb.PollEvent()

	operation := get_key(key)
	ck <- operation

}
Ejemplo n.º 12
0
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
}
Ejemplo n.º 13
0
func pause() {
	fmt.Println("请按任意键继续...")
Loop:
	for {
		switch ev := termbox.PollEvent(); ev.Type {
		case termbox.EventKey:
			break Loop
		}
	}
}
Ejemplo n.º 14
0
func StartEventPolling() {
	go func() {
		for {
			select {
			case <-stopPolling:
				return
			case internalEvents <- termbox.PollEvent():
			}
		}
	}()
}
Ejemplo n.º 15
0
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)
		}
	}
}
Ejemplo n.º 16
0
func main() {
	termbox.Init()
	defer termbox.Close()
	m := panel.MainScreen()
	var p panel.Panel = newOcto()
loop:
	for {
		m.Clear().Write(help)
		panel.DrawAll(panels...)
		if len(panels) > 0 {
			p.SetBorder(termbox.Cell{'d', 2, 0})
		}
		termbox.Flush()

		switch ev := termbox.PollEvent(); ev.Type {
		case termbox.EventKey:
			switch ev.Key {
			case termbox.KeyEsc:
				break loop
			case termbox.KeyTab:
				p.SetBorder(termbox.Cell{'s', 0, 0})
				p = panels[0]
				Top(p)
			case termbox.KeyArrowDown:
				p.Move(0, 1)
			case termbox.KeyArrowUp:
				p.Move(0, -1)
			case termbox.KeyArrowLeft:
				p.Move(-1, 0)
			case termbox.KeyArrowRight:
				p.Move(1, 0)
			case termbox.KeyInsert:
				p.SetBorder(termbox.Cell{'s', 0, 0})
				p = newOcto()
				Top(p)
			case termbox.KeyDelete:
				if len(panels) > 0 {
					panels = panels[:len(panels)-1]
					if len(panels) > 0 {
						p = panels[0]
						Top(p)
					}
				}
			}
		}
	}
}
Ejemplo n.º 17
0
Archivo: main.go Proyecto: telyn/form
func main() {
	buttons = NewButtonsField([]Button{{
		Action: func() {
			log.Printf("Yeah!")
		},
		Text: "yeah!",
	}, {
		Action: func() {
			log.Printf("No!")
		},
		Text: "no!",
	}})

	buttons.Focus(true)
	err := termbox.Init()
	if err != nil {
		panic(err)
	}

	if draw() {
		log.Printf("drew ok\r\n")
	loop:
		for {
			switch ev := termbox.PollEvent(); ev.Type {
			case termbox.EventKey:
				switch ev.Key {
				case termbox.KeyEsc, termbox.KeyCtrlC:
					break loop
				default:
					if ev.Ch != '\x00' {
						buttons.ReceiveRune(ev.Ch)
					} else {
						buttons.ReceiveKey(ev.Key)
					}
					draw()
				}
			case termbox.EventResize:
				draw()
			}
		}
		termbox.Close()
	} else {
		log.Printf("Didn't draw correctly. weird\r\n")
	}

}
Ejemplo n.º 18
0
func (tb termbox) Initialize() <-chan Event {
	if err := T.Init(); err != nil {
		return nil
	}

	events := make(chan Event, 10)
	go func() {
		for {
			in_event := T.PollEvent()
			if out_event, ok := translate_event(in_event); ok {
				events <- out_event
			}
		}
	}()

	return events
}
func main() {
	defer glog.Flush()
	flag.Parse()

	err := ui.Init()
	if err != nil {
		panic(err)
	}
	defer ui.Close()

	jenkins, err := gojenkins.CreateJenkins(*jenkinsUrl).Init()
	if err != nil {
		panic(err)
	}
	ls, infobox, redbox, yellowbox, greenbox := initWidgets()

	if *filter != "" {
		filterBuildName = regexp.MustCompile(*filter)
	}

	evt := make(chan tm.Event)
	go func() {
		for {
			evt <- tm.PollEvent()
		}
	}()

	ticker := time.NewTicker(*sampleInterval).C
	for {
		select {
		case e := <-evt:
			if e.Type == tm.EventKey && e.Ch == 'q' {
				return
			}
		case <-ticker:
			// alway resize, strange behaviour with tm.EventResize
			resizeUI(ls)
			ls.Items = ls.Items[:0]
			resetBox(infobox, redbox, yellowbox, greenbox)
			jenkinsPoll(jenkins, infobox, ls, redbox, yellowbox, greenbox)
			ui.Render(ui.Body)
		}
	}
}
Ejemplo n.º 20
0
Archivo: cli.go Proyecto: jteeuwen/dcpu
// pollTermEvent waits for, and handles termbox events.
func (c *CLI) pollTermEvent() {
	for {
		evt := term.PollEvent()

		if c.cpu == nil {
			return
		}

		switch evt.Type {
		case term.EventKey:
			if !c.input.Focused() || !c.input.OnKey(evt) {
				c.kb.Poll(evt)
			}

		case term.EventResize:
			c.resize(evt.Width, evt.Height)
		}
	}
}
Ejemplo n.º 21
0
// write to server
func writer(nc net.Conn, quit chan<- bool) {
	for {
		e := termbox.PollEvent()
		if e.Ch == 0 {
			switch e.Key {
			case termbox.KeyCtrlC:
				fmt.Println("cntrl c")
				quit <- true
			case termbox.KeySpace:
				nc.Write([]byte(" "))
				fmt.Print(" ")
			}
		} else {
			// send to server
			nc.Write([]byte(string(e.Ch)))
			fmt.Print(string(e.Ch))
		}
	}
}
Ejemplo n.º 22
0
Archivo: main.go Proyecto: telyn/form
func main() {
	textField := NewTextField(12, []rune(""), func(val string) bool {
		return true
	})
	labelField = Label(textField,
		"was jean-michel jarre a fraud? discuss in one line or else. YOU MUST DISCUSS IT OR ELSE ELEVEN YEARS DUNGEON AAAAAA")
	labelField.Focus(true)

	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, termbox.KeyCtrlC:
					break loop
				default:
					if ev.Ch != '\x00' {
						textField.ReceiveRune(ev.Ch)
					} else {
						textField.ReceiveKey(ev.Key)
					}
					draw()
				}

			case termbox.EventResize:
				draw()
			}
		}
		termbox.Close()
	} else {
		fmt.Printf("Didn't draw correctly\r\n")
	}

	fmt.Printf("Hey %s\r\n", textField.GetValue())

}
Ejemplo n.º 23
0
Archivo: main.go Proyecto: telyn/form
func main() {
	textField = NewTextField(16, make([]rune, 0), func(val string) bool {
		if len(val) > 3 {
			return true
		}
		return false
	})
	textField.Focus(true)

	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, termbox.KeyCtrlC:
					break loop
				default:
					if ev.Ch != '\x00' {
						textField.ReceiveRune(ev.Ch)
					} else {
						textField.ReceiveKey(ev.Key)
					}
					draw()
				}

			case termbox.EventResize:
				draw()
			}
		}
		termbox.Close()
	} else {
		fmt.Printf("Didn't draw correctly\r\n")
	}

	fmt.Printf("Hey %s\r\n", textField.GetValue())
}
Ejemplo n.º 24
0
func main() {
	fname := os.Args[1]

	f, err := os.Open(fname)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	img, _, err := image.Decode(f)
	if err != nil {
		log.Fatal(err)
	}

	err = termbox.Init()
	if err != nil {
		panic(err)
	}
	defer termbox.Close()

	if termbox.SetOutputMode(termbox.Output256) == termbox.Output256 {
		palette = upgrade(palette)
	}

	lw, lh := termbox.Size()
	draw(img)
loop:
	for {
		ev := termbox.PollEvent()
		switch ev.Type {
		case termbox.EventKey:
			if ev.Key == termbox.KeyEsc {
				break loop
			}
		case termbox.EventResize:
			termbox.Flush()
			if w, h := termbox.Size(); lw != w || lh != h {
				lw, lh = w, h
				draw(img)
			}
		}
	}
}
Ejemplo n.º 25
0
Archivo: view.go Proyecto: 0x19/ngrok
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.Shutdown("")
			}

		case termbox.EventResize:
			v.Info("Resize event, redrawing")
			v.redraw.In() <- 1

		case termbox.EventError:
			panic(ev.Err)
		}
	}
}
Ejemplo n.º 26
0
func main() {
	termbox.Init()
	defer termbox.Close()

	et, err := gaze.AnyEyeTracker()

	if err != nil {
		log.Println(err)
		return
	}

	et.Connect()
	defer et.Close()
	termbox.Clear(0, termbox.ColorWhite) //Set bg to white.
	et.StartTracking(func(data *gaze.GazeData) {
		ts := data.TrackingStatus()
		if ts >= gaze.BothEyesTracked && ts != gaze.OneEyeTrackedUnknownWhich {
			termbox.Clear(0, termbox.ColorWhite)
			drawPoint(*data.Left().GazePointOnDisplay(), leftMarker)
			drawPoint(*data.Right().GazePointOnDisplay(), rightMarker)
			termbox.Flush()
		}
	})

	done := make(chan struct{})

	go func() {
		for {
			event := termbox.PollEvent()
			if event.Type == termbox.EventKey && event.Key == termbox.KeyEsc {
				close(done)
			}
		}
	}()

	<-done
}
Ejemplo n.º 27
0
func (w *Window) MainUIHandler() error {
	for {
		e := termbox.PollEvent()

		if e.Type == termbox.EventError {
			return (e.Err)
		}

		// handle resize
		if e.Type == termbox.EventResize {
			err := w.Repaint()
			if err != nil {
				return (err)
			}

			termbox.Flush()
			continue
		}

		if w.EventHandler != nil {
			w.EventHandler(e)
		}
	}
}
Ejemplo n.º 28
0
Archivo: ui.go Proyecto: twocool/srvdir
func ui(routes []Route) {
	termbox.Init()
	defer termbox.Close()

	width, height := termbox.Size()
	a := NewArea(0, 0, width, height)

	a.Clear()
	a.APrintf(termbox.ColorCyan|termbox.AttrBold, 0, 0, "srvdir")
	a.Printf(7, 0, "by")
	a.APrintf(termbox.ColorCyan|termbox.AttrBold, 10, 0, "@inconshreveable")
	quitMessage := "(Ctl+C to quit)"
	a.Printf(width-len(quitMessage), 0, quitMessage)

	a.APrintf(termbox.AttrBold, 0, 2, "Serving")
	for i, r := range routes {
		a.Printf(0, i+3, "%s -> %s", r.addr, r.path)
	}

	termbox.Flush()

	for {
		e := termbox.PollEvent()
		switch e.Type {
		case termbox.EventKey:
			switch e.Key {
			case termbox.KeyCtrlC:
				return
			}
		case termbox.EventError:
			return
		case termbox.EventResize:
			// XXX
		}
	}
}
Ejemplo n.º 29
0
func main() {
	flag.Parse()
	dm, err := drum.NewMachine(*sequenceDir, *sampleDir)
	if err != nil {
		fmt.Println("an error occurred loading the drum machine:", err)
		return
	}
	term.dm = dm
	defer term.dm.Close()
	term.dm.SetBeatChangeCB(beatChange)
	for name := range term.dm.Samples {
		term.sampleNames = append(term.sampleNames, name)
	}
	term.mode = cmdMode

	if err := tb.Init(); err != nil {
		fmt.Println("an error occurred initializing termbox:", err)
		return
	}
	defer tb.Close()

	drawDrumMachine()
	for { // main run loop
		ev := tb.PollEvent()
		if ev.Key == tb.KeyCtrlC {
			break
		} else if ev.Type == tb.EventResize {
			drawDrumMachine()
		} else if ev.Type == tb.EventError {
			fmt.Println("an error occurred in termbox:", err)
			return
		} else if ev.Type == tb.EventKey {
			handleEvent(ev)
		}
	}
}
Ejemplo n.º 30
-10
Archivo: main.go Proyecto: telyn/form
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")
	}
}