nyaosorg / go-readline-ny

Readline library for golang , used in nyagos
https://pkg.go.dev/github.com/nyaosorg/go-readline-ny
MIT License
21 stars 3 forks source link

Feature Request: Disable history cycling #2

Closed ram-on closed 2 years ago

ram-on commented 2 years ago

Thank you for this project.

Feature request: assume that a user has inputted the following through editor.ReadLine() function:

  1. Hello
  2. There
  3. Morning

If the user presses the UP arrow key for 4 times, than "Morning" will be redisplayed.

Most probably this is due to the following code within history.go

    if this.historyPointer <= 0 {
        this.historyPointer = this.History.Len()
    }

Would it be possible to implement a flag such that, when enabled, if the user presses the UP key >= 4, then only the first input (i.e. "Hello") is displayed?

hymkor commented 2 years ago

Thank you for good suggestion.

I implemented the test version as the issue2 branch. To test the new feature, please execute go get github.com/nyaosorg/go-readline-ny@issue2, modify and rebuild your application.

editor := readline.Editor{
        Prompt:         func() (int, error) { return fmt.Print("$ ") },
        Writer:         colorable.NewColorableStdout(),
        History:        history,
        Coloring:       &coloring.VimBatch{},
        HistoryCycling: true, // [New flag]
}

When the field .HistoryCycling is false (zero value), the history cycling is disabled (default). When it is true, the history cycling is enabled.

If you consider the specification OK, and no ones refused, then I will merge it into the default branch and make a new release.

ram-on commented 2 years ago

Hello, I've just tested out the issue2 branch and it's working brilliantly. Many thanks!

hymkor commented 2 years ago

Ok. I would merge. Thank you !

hymkor commented 2 years ago

I have merged the branch issue2 into the default branch and released as v0.6.3