Esempio n. 1
0
File: main.go Progetto: telyn/form
func draw() bool {
	termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)

	dots := NewCellsBox([]termbox.Cell{dot, dot, dot, dot, dot,
		dot, dot, dot, dot, dot,
		dot, dot, dot, dot, dot,
		dot, dot, dot, dot, dot,
	}, 5)

	greenPlus := NewCellsBox([]termbox.Cell{greenPlus, greenPlus, greenPlus, greenPlus}, 2)

	if err := greenPlus.DrawInto(dots, 1, 2); err != nil {
		termbox.Close()
		fmt.Fprintf(os.Stderr, "%v1\r\n", err)
		return false
	}
	if err := dots.DrawInto(&TermBox{}, 0, 0); err != nil {
		termbox.Close()
		fmt.Fprintf(os.Stderr, "%v2\r\n", err)
		return false
	}

	termbox.SetCell(0, 0, '+', termbox.ColorRed, termbox.ColorDefault)
	termbox.SetCell(1, 0, '+', termbox.ColorRed, termbox.ColorDefault)
	termbox.SetCell(7, 0, '+', termbox.ColorRed, termbox.ColorDefault)

	termbox.Flush()
	return true
}
Esempio n. 2
0
File: main.go Progetto: 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()
		}
	}

}
Esempio n. 3
0
File: view.go Progetto: 0x19/ngrok
func (v *TermView) run() {
	defer close(v.shutdown)
	defer termbox.Close()

	redraw := v.redraw.Reg()
	defer v.redraw.UnReg(redraw)

	v.draw()
	for {
		v.Debug("Waiting for update")
		select {
		case <-v.flush:
			termbox.Flush()

		case <-v.updates:
			v.draw()

		case <-redraw:
			v.draw()

		case <-v.shutdown:
			return
		}
	}
}
Esempio n. 4
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)
		}
	}
}
Esempio n. 5
0
File: form.go Progetto: 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
}
Esempio n. 6
0
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
}
Esempio n. 7
0
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)
	}
}
Esempio n. 8
0
func error_out(message string) {

	tb.Close()
	fmt.Print(message)
	os.Exit(1)

}
Esempio n. 9
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()
	}
}
Esempio n. 10
0
func (m *ExitMode) Handle(ev term.Event) {
	if ev.Ch == 'y' {
		saveLastPosition(m.f, m.cursor.l, m.cursor.b)
		term.Close()
		os.Exit(0)
	} else if ev.Ch == 'n' || ev.Key == term.KeyCtrlK {
		m.mode.ChangeTo(m.mode.normal)
	}
}
Esempio n. 11
0
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)
}
Esempio n. 12
0
func main() {
	projection := false
	if len(os.Args) > 1 {
		if os.Args[1] == "-p" {
			projection = true
		}
	}
	tg.Init()
	run(projection)
	tg.Close()
}
Esempio n. 13
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)
		}
	}
}
Esempio n. 14
0
File: debug.go Progetto: kybin/tor
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)
}
Esempio n. 15
0
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)
}
Esempio n. 16
0
func (v *TermView) run() {
	defer v.ctl.Wait.Done()
	defer termbox.Close()

	for {
		v.Debug("Waiting for update")
		select {
		case obj := <-v.updates:
			v.state = obj.(ui.State)
			v.Render()

		case <-v.ctl.Shutdown:
			return
		}
	}
}
Esempio n. 17
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)
					}
				}
			}
		}
	}
}
Esempio n. 18
0
File: main.go Progetto: 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")
	}

}
Esempio n. 19
0
File: main.go Progetto: 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())
}
Esempio n. 20
0
File: main.go Progetto: 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())

}
Esempio n. 21
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)
			}
		}
	}
}
Esempio n. 22
0
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)
}
Esempio n. 23
0
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)
}
Esempio n. 24
0
File: cli.go Progetto: jteeuwen/dcpu
// Release unloads the CLI.
func (c *CLI) Release() {
	c.cpu = nil
	c.input = nil
	c.status = nil
	c.traceLog = nil
	c.sourceLog = nil

	if c.watchers != nil {
		c.watchers.Release()
		c.watchers = nil
	}

	if c.breakpoints != nil {
		c.breakpoints.Release()
		c.breakpoints = nil
	}

	term.Close()
}
Esempio n. 25
0
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!")
	}
}
Esempio 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()

	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
}
Esempio n. 27
0
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
}
Esempio n. 28
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
}
Esempio 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)
		}
	}
}
Esempio n. 30
-10
File: main.go Progetto: 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")
	}
}