示例#1
0
文件: e.go 项目: bgrundmann/e
func initBufferAndView(v *view.View, args commandLineArgs) func() {
	var b buf.Buf
	b.Init()
	v.Init(&b)
	if len(args.initialFiles) > 0 {
		if err := AppendFile(&b, args.initialFiles[0]); err != nil {
			log.Fatal(err)
		}
	}
	return func() {}
}
示例#2
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)
		}
	}
}