Allow ^D (EOF) to terminate the session.
This commit is contained in:
parent
9bb601bbf6
commit
9c2ab6b749
@ -4,6 +4,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
@ -101,15 +102,18 @@ func main() {
|
|||||||
for {
|
for {
|
||||||
cmdstr, err := t.promptForInput()
|
cmdstr, err := t.promptForInput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if err == io.EOF {
|
||||||
|
handleExit(t, dbgproc, 0)
|
||||||
|
return
|
||||||
|
}
|
||||||
die(1, "Prompt for input failed.\n")
|
die(1, "Prompt for input failed.\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdstr, args := parseCommand(cmdstr)
|
cmdstr, args := parseCommand(cmdstr)
|
||||||
|
|
||||||
if cmdstr == "exit" {
|
if cmdstr == "exit" {
|
||||||
err := goreadline.WriteHistoryToFile(historyFile)
|
|
||||||
fmt.Println("readline:", err)
|
|
||||||
handleExit(t, dbgproc, 0)
|
handleExit(t, dbgproc, 0)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := cmds.Find(cmdstr)
|
cmd := cmds.Find(cmdstr)
|
||||||
@ -119,8 +123,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleExit(t *term, dbp *proctl.DebuggedProcess, status int) {
|
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]")
|
fmt.Println("Would you like to kill the process? [y/n]")
|
||||||
answer, err := t.stdin.ReadString('\n')
|
answer, err := t.stdin.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -170,8 +176,11 @@ func parseCommand(cmdstr string) (string, []string) {
|
|||||||
|
|
||||||
func (t *term) promptForInput() (string, error) {
|
func (t *term) promptForInput() (string, error) {
|
||||||
prompt := "dlv> "
|
prompt := "dlv> "
|
||||||
line := *goreadline.ReadLine(&prompt)
|
linep := goreadline.ReadLine(&prompt)
|
||||||
line = strings.TrimSuffix(line, "\n")
|
if linep == nil {
|
||||||
|
return "", io.EOF
|
||||||
|
}
|
||||||
|
line := strings.TrimSuffix(*linep, "\n")
|
||||||
if line != "" {
|
if line != "" {
|
||||||
goreadline.AddHistory(line)
|
goreadline.AddHistory(line)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user