peterh / liner

Pure Go line editor with history, inspired by linenoise
MIT License
1.05k stars 132 forks source link

Multiple NewLiners swallows characters #5

Closed larzconwell closed 10 years ago

larzconwell commented 10 years ago

Each time you call NewLiner after the first time it swallows a character from input when you call Prompt.

Here's an example: https://gist.github.com/larzconwell/9624785

Actual output:

> sdf  # Input 'sdf'
s
> df   # Input 'sdf'
df

Expected output:

> sdf  # Input 'sdf'
sdf
> sdf  # Input 'sdf'
sdf
peterh commented 10 years ago

I cannot reproduce your issue. This works for me:

func main() {
        for {
                l := liner.NewLiner()
                s, err := l.Prompt("Prompt: ")
                if err != nil {
                        fmt.Println("error", err)
                        l.Close()
                        os.Exit(1)
                }
                fmt.Println("got", s)
                l.Close()
        }
}

Don't forget to l.Close() before you call NewLiner again.

Actually, try to call NewLiner only once; NewLiner leaks memory on go 1.0 (because there was no way to unregister a signal handler before Go 1.1).

larzconwell commented 10 years ago

That code doesn't work for me either. I get the same error as above.

What system are you on? I'm running Linux.

EDIT: but yeah I'll make it so only one NewLiner is allocated, but this is still an issue I think.

peterh commented 10 years ago

I can reproduce on Linux. Thanks for the bug report.