Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unexpected history behavior #1

Open
emicklei opened this issue Feb 14, 2014 · 3 comments
Open

unexpected history behavior #1

emicklei opened this issue Feb 14, 2014 · 3 comments

Comments

@emicklei
Copy link

I am working on a small example that uses the readline package

When I enter each number 1,2,3 and use the arrow keys to navigate the history, I get the sequence 2,3,2,1

$ go run cli.go
>1
1
>2
2
>3
3
1

When I restart the program and enter A then this entry is not showing in the history. I was expecting this.

Maybe I setup the program wrong. (what is the role of the ps2 argument in NewLine?)

package main

import (
    "fmt"
    "log"
    "os"
    "path"

    "github.com/kless/term"
    "github.com/kless/term/readline"
)

var historyFile = path.Join(os.TempDir(), "test_history")

func main() {
    hist, err := readline.NewHistoryOfSize(historyFile, 10)
    if err != nil {
        log.Fatal("could not create history", err)
    }
    ter, _ := term.New()
    defer func() {
        if err := ter.Restore(); err != nil {
            log.Print(err)
        }
    }()
    l, err := readline.NewLine(ter, ">", "?", 1, hist)
    if err != nil {
        log.Fatal("NewLine failed", err)
    }
    for {
        entry, err := l.Read()
        if err != nil {
            log.Fatal("Read failed", err)
        }
        if entry == "exit" || entry == "quit" {
            break
        }
        fmt.Println(entry)
    }

}
@tredoe
Copy link
Owner

tredoe commented Mar 4, 2014

Yes, there is an issue in the history. But I have no time to fix it. Sorry!
Anyway, I accept code that could fix it.

@ElPincheTopo
Copy link

I will try to fix this problem as well as adding the search in history with Ctrl+r as in GNU Readline.

@kless would you accept this changes?

@tredoe
Copy link
Owner

tredoe commented Apr 14, 2014

@ElPincheTopo Yes, I'd accept them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants