add the main function of this pseudo-terminal-go

This commit is contained in:
carmark
2015-04-26 14:22:18 +08:00
parent 43463fdc0c
commit 55c346b46a

29
test.go Normal file
View File

@@ -0,0 +1,29 @@
package main
import (
"io"
"fmt"
"strings"
"terminal"
)
func main() {
term, _ := terminal.NewWithStdInOut()
defer term.ReleaseFromStdInOut() // defer this
term.SetPrompt("root@hello: # ")
line, err:= term.ReadLine()
for {
if err == io.EOF {
term.Write([]byte(line))
fmt.Println()
return
}
if (err != nil && strings.Contains(err.Error(), "control-c break")) || len(line) == 0{
line, err = term.ReadLine()
} else {
term.Write([]byte(line+"\r\n"))
line, err = term.ReadLine()
}
}
term.Write([]byte(line))
}