Refactor error-handling for line input

This commit is contained in:
Hedy Li 2022-01-01 21:54:48 +08:00
parent 419356b5cd
commit b84e6d6bd0
Signed by: hedy
GPG Key ID: B51B5A8D1B176372
1 changed files with 7 additions and 6 deletions

View File

@ -152,17 +152,18 @@ func main() {
color.Unset()
if err != nil {
if err != ln.ErrPromptAborted && err != io.EOF {
c.style.ErrorMsg("error reading line input: " + err.Error())
}
fmt.Println()
if err == io.EOF {
// Exit by CTRL-D.
if err == ln.ErrPromptAborted || err == io.EOF {
// Exit by ^C or ^D
c.QuitClient(0)
if err == io.EOF {
fmt.Println()
}
}
c.style.ErrorMsg("Error reading input: " + err.Error())
// Exiting because it will cause an infinite loop of error if used 'continue' here
c.QuitClient(1)
}
rl.AppendHistory(line)
line = strings.TrimSpace(line)
if line == "" {