func New(ctl *ui.Controller, state ui.State) *TermView { // initialize terminal display termbox.Init() // make sure ngrok doesn't quit until we've cleaned up ctl.Wait.Add(1) w, _ := termbox.Size() v := &TermView{ ctl: ctl, updates: ctl.Updates.Reg(), flush: make(chan int), subviews: make([]ui.View, 0), state: state, Logger: log.NewPrefixLogger(), area: NewArea(0, 0, w, 10), } v.Logger.AddLogPrefix("view") v.Logger.AddLogPrefix("term") switch p := state.GetProtocol().(type) { case *proto.Http: v.subviews = append(v.subviews, NewHttp(p, v.flush, ctl.Shutdown, 0, 10)) default: } v.Render() go v.run() go v.input() return v }
func init() { if err := termbox.Init(); err != nil { panic(err) } termbox.SetCursor(0, 0) termbox.HideCursor() }
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() } }
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) } } }
func main() { flag.Parse() log.SetFlags(0) flog, err := os.Create("editor.log") if err != nil { log.Fatal(err) } defer flog.Close() lg = log.New(flog, "", 0) // start termbox err = termbox.Init() if err != nil { log.Print(err) return } defer termbox.Close() v := &view.LineNum{View: &view.Wrap{}} //v := &view.Wrap{} s := &session.Session{ File: flag.Arg(0), View: v, ExpandTabs: false, SmartIndent: true, Tabwidth: 4, } // run ... err = s.Run() if err != session.ErrQuit { lg.Print(err) } }
/* 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: } } }
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 }
func realMain() error { flag.Parse() if err := termbox.Init(); err != nil { return err } defer termbox.Close() termbox.SetInputMode(termbox.InputEsc | termbox.InputMouse) opts := &gameOpts{} if *p1 == "" { opts.p1type = computer opts.p1name = "8086" } else { opts.p1type = human opts.p1name = *p1 } if *p2 == "" { opts.p2type = computer opts.p2name = "hal" } else { opts.p2type = human opts.p2name = *p2 } game := newGame(opts) game.draw() game.loop() return nil }
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() } } }
func Init() error { err := termbox.Init() if err != nil { return fmt.Errorf("Could not init terminal: %v", err) } err = clearWithDefaultColors() if err != nil { return fmt.Errorf("Could not clear terminal: %v", err) } termbox.SetInputMode(termbox.InputAlt) hideCursor() internalEventProxying() StartEventPolling() fpsCounter = NewFpsCounter(time.Second) go func() { for fps := range fpsCounter.Fps { log.Debug.Printf("FPS: %v (%v frames skipped)", fps, fpsSkipped) fpsSkipped = 0 } }() go func() { for _ = range paintChan { paintThrottled() } }() return nil }
func main() { termbox.Init() termbox.HideCursor() var p Player p = *NewPlayer() p.Draw() termbox.Flush() <-time.After(2000 * time.Millisecond) termbox.Close() os.Exit(0) }
// Init initializes termui library. This function should be called before any others. // After initialization, the library must be finalized by 'Close' function. func Init() error { Body = NewGrid() Body.X = 0 Body.Y = 0 Body.BgColor = theme.BodyBg defer (func() { w, _ := tm.Size() Body.Width = w })() return tm.Init() }
func main() { projection := false if len(os.Args) > 1 { if os.Args[1] == "-p" { projection = true } } tg.Init() run(projection) tg.Close() }
func initCanvas() bool { err := term.Init() if err != nil { return false } term.SetInputMode(term.InputEsc | term.InputMouse) canvas = new(Canvas) Reset() return true }
func debug(args ...interface{}) { term.Close() for _, a := range args { fmt.Println(a) } reader := bufio.NewReader(os.Stdin) reader.ReadString('\n') err := term.Init() if err != nil { panic(err) } term.SetInputMode(term.InputAlt) }
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) } } }
func main() { if err := tb.Init(); err != nil { panic(err) } else { defer tb.Close() tb.HideCursor() } x, y := tb.Size() drawBoundingBox(0, x-1, 0, y-1) drawTypedBoundingBox(tb.ColorBlack, tb.ColorWhite)(x/3, 2*x/3, y/3, 2*y/3) fillInBox(x/3+1, 2*x/3-1, y/3+1, 2*y/3-1, tb.ColorBlack, tb.ColorWhite) tb.Flush() time.Sleep(3 * time.Second) }
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) } } } } } }
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() { 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") } }
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()) }
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()) }
func main() { termbox.Init() defer termbox.Close() m := panel.MainScreen() for _, s := range strings.Split(example, "\n") { helper.ScrollWriteUpwards(m, s) termbox.Flush() time.Sleep(time.Millisecond * 500) } for _, s := range strings.Split(example, "\n") { helper.ScrollWrite(m, s) termbox.Flush() time.Sleep(time.Millisecond * 500) } helper.ScrollWrite(m, "And that's\neverything\nfor now.") termbox.Flush() time.Sleep(time.Millisecond * 2000) }
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) } } } }
func main() { err := tb.Init() if err != nil { panic(err) } defer tb.Close() s := state{ firsts: map[string]bool{ collector.name: true, searcher.name: true, }, } loop(s) }
func main() { rand.Seed(time.Now().UnixNano()) dim := dimensions{10, 10} ships := canonicalBattleship() attackField := makeScatteredField(dim, ships, adversary) attackOrigin := coord{0, 0} defendField := makeScatteredField(dim, ships, human) defendOrigin := coord{30, 0} printOrigin := coord{0, 30} termbox.Init() defer termbox.Close() termbox.HideCursor() termbox.Clear(termbox.ColorBlack, termbox.ColorBlack) buildLabels(attackField, attackOrigin) buildLabels(defendField, defendOrigin) // game loop var msg_us, msg_them string for attackField.shipsLeft() && defendField.shipsLeft() { buildInnerField(attackField, attackOrigin) buildInnerField(defendField, defendOrigin) termbox.Flush() msg_us = move(&attackField) termbox.Flush() msg_them = counterMove(&defendField) tbprint(printOrigin, msg_us, termbox.ColorWhite, termbox.ColorBlack) tbprint(printOrigin.down(1), msg_them, termbox.ColorWhite, termbox.ColorBlack) termbox.Flush() } if defendField.shipsLeft() { fmt.Println("You've won! Congratulations.") } else if attackField.shipsLeft() { fmt.Println("You've lost!") } }
func main() { termbox.Init() defer termbox.Close() et, err := gaze.AnyEyeTracker() if err != nil { log.Println(err) return } et.Connect() defer et.Close() done := make(chan struct{}) et.StartCalibration(func(err error) { if err != nil { log.Println("Could not start calibrating:", err) close(done) return } calibratePoint(et, 0.1, 0.1) calibratePoint(et, 0.9, 0.1) calibratePoint(et, 0.9, 0.9) calibratePoint(et, 0.1, 0.9) calibratePoint(et, 0.5, 0.5) et.ComputeAndSetCalibration(func(err error) { et.StopCalibration(func(err error) { defer close(done) if err != nil { log.Println("Could not start calibrating:", err) return } }) }) }) points, err := et.CalibrationPoints() fmt.Println() <-done }
func NewTermView(ctl mvc.Controller) *TermView { // initialize terminal display termbox.Init() w, _ := termbox.Size() v := &TermView{ ctl: ctl, updates: ctl.Updates().Reg(), redraw: util.NewBroadcast(), flush: make(chan int), shutdown: make(chan int), Logger: log.NewPrefixLogger("view", "term"), area: NewArea(0, 0, w, 10), } ctl.Go(v.run) ctl.Go(v.input) return v }
func main() { args := os.Args addr := args[1] quit := make(chan bool) // connects to tcp server nc, err := net.Dial("tcp", addr) if err != nil { panic(err) } err2 := termbox.Init() if err2 != nil { panic(err2) } defer termbox.Close() go writer(nc, quit) go reader(nc) <-quit }
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") } }