Пример #1
0
Файл: e.go Проект: bgrundmann/e
func main() {
	args := parseCommandLine()
	cleanup := initTermbox()
	defer cleanup()
	nextEvent, cleanup := initEventSource(args)
	defer cleanup()
	var v view.View
	cleanup = initBufferAndView(&v, args)
	defer cleanup()
	// not that interested in startup and tear down cost
	// so let's start profiling only now
	cleanup = initProfiling(args)
	defer cleanup()

mainloop:
	for {
		v.Display()
		switch ev := nextEvent(); ev.Type {
		case termbox.EventKey:
			switch ev.Key {
			case termbox.KeyEsc:
				break mainloop
			case termbox.KeyPgdn:
				v.PageDown()
			case termbox.KeyPgup:
				v.PageUp()
			default:
				switch ev.Ch {
				case 'l':
					v.MoveCursor(motion.RuneForward)
				case 'h':
					v.MoveCursor(motion.RuneBackward)
				case 'j':
					v.MoveCursor(motion.LineForward)
				case 'k':
					v.MoveCursor(motion.LineBackward)
				}
			}
		case termbox.EventError:
			panic(ev.Err)
		}
	}
}