Skip to content

Commit

Permalink
Tweak the way the terminal widget ends scrolling
Browse files Browse the repository at this point in the history
Thanks to @Peter2121 for this implementation!

Prior to this change, if the user hit the terminal hot-key and scrolled
back up then back down to the prompt again, a further keypress - q or Q
- would still be required to end scroll-mode. This brings the terminal
widget more in-line with other terminal implementations in that
scroll-mode is now ended automatically if the user scrolls back to the
prompt; no extra keypress needed by default.

I have added a new option to the terminal Options struct to preserve the
legacy behavior, if you need it - KeyPressToEndScrollMode (default
false).
  • Loading branch information
gcla committed Jul 9, 2022
1 parent 06abc4f commit 35e5bf4
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions widgets/terminal/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,16 @@ type title struct{}
type hotkey struct{}

type Options struct {
Command []string
Env []string
HotKey IHotKeyProvider
HotKeyPersistence IHotKeyPersistence // the period of time a hotKey sticks after the first post-hotKey keypress
Scrollback int
Scrollbar bool // disabled regardless of setting if there is no scrollback
HotKeyFns []HotKeyInputFn // allow custom behavior after pressing the hotkey
EnableBracketedPaste bool
Command []string
Env []string
HotKey IHotKeyProvider
HotKeyPersistence IHotKeyPersistence // the period of time a hotKey sticks after the first post-hotKey keypress
Scrollback int
Scrollbar bool // disabled regardless of setting if there is no scrollback
HotKeyFns []HotKeyInputFn // allow custom behavior after pressing the hotkey
EnableBracketedPaste bool
KeyPressToEndScrollMode bool // set to true to enable legacy behavior - when the user has scrolled
// back to the prompt, still require a keypress (q or Q) to end scroll-mode.
}

// Widget is a widget that hosts a terminal-based application. The user provides the
Expand Down Expand Up @@ -379,9 +381,18 @@ func (w *Widget) Scroll(dir ScrollDir, page bool, lines int) {
} else {
lines = w.canvas.ScrollBuffer(dir, false, gwutil.SomeInt(lines))
}
// Scrolling is now true if it (a) was previously, or (b) wasn't, but we
// scrolled more than one line
w.isScrolling = w.isScrolling || lines != 0

wasScrolling := w.isScrolling
if lines != 0 {
w.isScrolling = true
} else if !w.params.KeyPressToEndScrollMode && dir == ScrollDown {
// Disable scroll if we are at the bottom and we tried to scroll down
// Thanks @Peter2121 !
w.isScrolling = false
}
if wasScrolling && !w.isScrolling {
w.ResetScroll()
}
}

func (w *Widget) ResetScroll() {
Expand Down

0 comments on commit 35e5bf4

Please sign in to comment.