readline icon indicating copy to clipboard operation
readline copied to clipboard

Delete key with empty line makes Readline to return EOF

Open hallazzang opened this issue 4 years ago • 2 comments

Steps to reproduce problem:

  1. Input aaa
  2. Press ^A(Ctrl+A) to move cursor to the beginning of the line
  3. Press Delete key 4 times

Here's the code I used:

package main

import (
	"fmt"

	"github.com/chzyer/readline"
)

func main() {
	rl, err := readline.New("> ")
	if err != nil {
		panic(err)
	}
	defer rl.Close()

	for {
		line, err := rl.Readline()
		if err != nil {
			break
		}
		println(line)
	}
}

hallazzang avatar Jun 09 '20 07:06 hallazzang

Did you use ctrl + d to deleter characters?

https://github.com/chzyer/readline/blob/master/readline.go#L119-L123

if c.EOFPrompt == "" {
	c.EOFPrompt = "^D"
} else if c.EOFPrompt == "\n" {
	c.EOFPrompt = ""
}

As you can see, if you don't EOFPrompt field in Config structure, it will default to ^D

By the way, if you don't like how it reaches EOF with ^D, the following could be a fix:

for {
	line, err := rl.Readline()
	if err != nil {
                if err == io.EOF {
                        continue
                }
		break
	}
	println(line)
}

BunnyBrewery avatar Jun 20 '20 03:06 BunnyBrewery

@hallazzang @BunnyBrewery I have the same issue and handling io.EOF solve it partially.

In my case delete key causes the same behavior as ctrl+d.

I tried to change c.EOFPrompt through config but it didn't work. Did you found any other solution?

jzyinq avatar Apr 30 '21 14:04 jzyinq