示例#1
0
文件: goat.go 项目: hotei/goat
func frameDemo(tio *termios.TermSettings) {
	// Allocate a TTY connected to standard input
	tty, region := term.NewFrameTTY(os.Stdin)
	tty.Clear()
	region.SetBorder(term.SimpleBorder)

	width, height, err := tio.GetSize()
	if err == nil && width > 0 && height > 0 {
		region.SetSize(width, height)
	}

	region.Draw()

	// Allocate the line buffer and accumulator
	linebuf := make([]byte, 128)

	for {
		// Read from the TTY
		n, err := tty.Read(linebuf)
		if err != nil {
			log.Printf("read: %s", err)
			return
		}

		// Examine the chunk
		switch str := string(linebuf[:n]); str {
		case "quit", term.Interrupt, term.EndOfFile:
			// Quit on "quit", ^C, and ^D
			tty.Clear()
			tty.SetCursor(0, 0)
			io.WriteString(tty, "Goodbye!\r\n")
			log.Printf("%dx%d\r", width, height)
			return
		}
	}

}
示例#2
0
func ResetTerm(tio *termios.TermSettings) {
	tio.Reset()
}