^D interrupt does the same as ^C

This commit is contained in:
zs 2019-01-30 13:35:10 +01:00
commit 84b300d396
2 changed files with 11 additions and 9 deletions

18
main.go
View file

@ -93,14 +93,8 @@ func main() {
for sess.Active {
line, err := sess.ReadLine()
if err != nil {
if err == io.EOF {
continue
} else if err.Error() == "Interrupt" {
var ans string
fmt.Printf("Are you sure you want to quit this session? y/n ")
fmt.Scan(&ans)
if strings.ToLower(ans) == "y" {
if err == io.EOF || err.Error() == "Interrupt" {
if exitPrompt() {
sess.Run("exit")
os.Exit(0)
}
@ -117,3 +111,11 @@ func main() {
}
}
}
func exitPrompt() bool {
var ans string
fmt.Printf("Are you sure you want to quit this session? y/n ")
fmt.Scan(&ans)
return strings.ToLower(ans) == "y"
}

View file

@ -74,7 +74,7 @@ func (s *Session) setupReadline() (err error) {
cfg := readline.Config{
HistoryFile: history,
InterruptPrompt: "^C",
EOFPrompt: "exit",
EOFPrompt: "^D",
AutoComplete: readline.NewPrefixCompleter(prefixCompleters...),
}