Skip to content

Commit

Permalink
Allow ^D (EOF) to terminate the session.
Browse files Browse the repository at this point in the history
  • Loading branch information
burke committed Nov 13, 2014
1 parent 2110cf4 commit 6b1d1c0
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions cmd/dlv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"flag"
"fmt"
"io"
"os"
"os/exec"

Expand Down Expand Up @@ -101,15 +102,18 @@ func main() {
for {
cmdstr, err := t.promptForInput()
if err != nil {
if err == io.EOF {
handleExit(t, dbgproc, 0)
return
}
die(1, "Prompt for input failed.\n")
}

cmdstr, args := parseCommand(cmdstr)

if cmdstr == "exit" {
err := goreadline.WriteHistoryToFile(historyFile)
fmt.Println("readline:", err)
handleExit(t, dbgproc, 0)
return
}

cmd := cmds.Find(cmdstr)
Expand All @@ -119,8 +123,10 @@ func main() {
}
}
}

func handleExit(t *term, dbp *proctl.DebuggedProcess, status int) {
errno := goreadline.WriteHistoryToFile(historyFile)
fmt.Println("readline:", errno)

fmt.Println("Would you like to kill the process? [y/n]")
answer, err := t.stdin.ReadString('\n')
if err != nil {
Expand Down Expand Up @@ -164,8 +170,11 @@ func parseCommand(cmdstr string) (string, []string) {

func (t *term) promptForInput() (string, error) {
prompt := "dlv> "
line := *goreadline.ReadLine(&prompt)
line = strings.TrimSuffix(line, "\n")
linep := goreadline.ReadLine(&prompt)
if linep == nil {
return "", io.EOF
}
line = strings.TrimSuffix(*linep, "\n")
if line != "" {
goreadline.AddHistory(line)
}
Expand Down

0 comments on commit 6b1d1c0

Please sign in to comment.