mirror of
https://github.com/walles/moar.git
synced 2024-11-30 02:34:13 +03:00
Add support for handling keypresses
This commit is contained in:
parent
95132357b1
commit
6436cce8f6
15
m/pager.go
15
m/pager.go
@ -25,7 +25,7 @@ func NewPager(r _Reader) *_Pager {
|
||||
func (p *_Pager) _AddFooter() {
|
||||
_, height := p.screen.Size()
|
||||
|
||||
for pos, char := range "Press ESC / Return to exit" {
|
||||
for pos, char := range "Press ESC / Return / q to exit" {
|
||||
p.screen.SetContent(pos, height-1, char, nil, tcell.StyleDefault)
|
||||
}
|
||||
}
|
||||
@ -50,6 +50,13 @@ func (p *_Pager) _OnKey(key tcell.Key) {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *_Pager) _OnRune(char rune) {
|
||||
switch char {
|
||||
case 'q':
|
||||
p._Quit()
|
||||
}
|
||||
}
|
||||
|
||||
// StartPaging brings up the pager on screen
|
||||
func (p *_Pager) StartPaging() {
|
||||
// This function initially inspired by
|
||||
@ -77,7 +84,11 @@ func (p *_Pager) StartPaging() {
|
||||
ev := s.PollEvent()
|
||||
switch ev := ev.(type) {
|
||||
case *tcell.EventKey:
|
||||
p._OnKey(ev.Key())
|
||||
if ev.Key() == tcell.KeyRune {
|
||||
p._OnRune(ev.Rune())
|
||||
} else {
|
||||
p._OnKey(ev.Key())
|
||||
}
|
||||
|
||||
case *tcell.EventResize:
|
||||
// We'll be implicitly redrawn just by taking another lap in the loop
|
||||
|
Loading…
Reference in New Issue
Block a user