Example #1
0
// Passthrough to termbox using termbox constants above
func SetOutputMode(mode OutputMode) {
	switch mode {
	case OutputCurrent:
		tm.SetOutputMode(tm.OutputCurrent)
	case OutputNormal:
		tm.SetOutputMode(tm.OutputNormal)
	case Output256:
		tm.SetOutputMode(tm.Output256)
	case Output216:
		tm.SetOutputMode(tm.Output216)
	case OutputGrayscale:
		tm.SetOutputMode(tm.OutputGrayscale)
	}
}
Example #2
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)
			}
		}
	}
}