nyaosorg/go-readline-ny

Feature Request: Disable history cycling

Closed this issue · 4 comments

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?

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.

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

Ok. I would merge. Thank you !

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