-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
proposal: x/term: expose history #68780
Comments
Implementation golang/term#15 demo of use/benefit fortio/terminal@77eee7b |
Change https://go.dev/cl/603957 mentions this issue: |
I don't know if this is a good proposal or not, but if you add |
Thanks for looking. If you look at the code you'll see it creates a copy while holding the lock. An iterator wouldn't be helpful as the copy (snapshot) is needed. |
Hey Laurent! I was about to push for review my patches for almost the same thing, hence would rather not waste everyone's time again and join you here. I also did a And what would you think is the best approach to achieve that? A modification to // Pop the last element from the history.
func (s *stRingBuffer) Pop() (string, bool) {
if s.size == 0 {
return "", false
}
value := s.entries[s.head]
s.head--
if s.head < 0 {
s.head += s.max
}
if s.size > 0 {
s.size--
}
return value, true
}
func (t *Terminal) PopHistory() (string, bool) {
t.lock.Lock()
defer t.lock.Unlock()
return t.history.Pop()
} Or I guess also using Would you care to include this too, or you'd rather prefer that I'll push a PR after the current code is merged? Cheers, |
Thanks, yes I ended up mostly turning auto history off for real cases and adding depending on conditions, the on behavior is for backward compatibility with current behavior. I was using replace until I hit writing a "history" (and !nn repeat) which shifts the history by one making auto not useable, maybe for minimalism I should remove replace? Edit: I wouldn't mind replacing Replace by Pop btw if that works better |
I was buying though your explanation for what So the question probably is: would IMHO the usage pattern of these APIs is:
tl;dr - I'm thinking neither And remember that once an API is added, there will always be some using it forever, along with all it's undocumented or unintended side-effects 😛. |
So I use replace in the example but it's true I just set auto to false instead in my real code. I can drop it from the proposal. I just want to say though that I wanted to avoid people clearing the whole history and re-adding to change last entry as even with a relatively small 99 entry slice it'd be wasteful lastly there is one other reason for replace which is to let users use up arrow and find the last bad entry and correct it |
ping, anyone? |
Proposal Details
x/term is very nice, it includes a 100 slot history ring buffer, unfortunately entirely private
https://github.com/golang/term/blob/master/terminal.go#L89
it would be nice to let people
and
and resize
and allow replacement of last command in history (for instance to replace invalid by validated or canonical variant)
and control whether lines are automatically added to history (defaults remains true)
if acceptable I'd be happy to make a PRedit: made a PRThe text was updated successfully, but these errors were encountered: