/
pagermode-viewing.go
178 lines (139 loc) · 4.12 KB
/
pagermode-viewing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package m
import (
log "github.com/sirupsen/logrus"
"github.com/walles/moar/twin"
)
type PagerModeViewing struct {
pager *Pager
}
func (m PagerModeViewing) drawFooter(statusText string, spinner string) {
helpText := "Press 'ESC' / 'q' to exit, '/' to search, '?' for help"
if m.pager.isShowingHelp {
helpText = "Press 'ESC' / 'q' to exit help, '/' to search"
}
if m.pager.ShowStatusBar {
m.pager.setFooter(statusText + spinner + " " + helpText)
}
}
func (m PagerModeViewing) onKey(keyCode twin.KeyCode) {
p := m.pager
switch keyCode {
case twin.KeyEscape:
p.Quit()
case twin.KeyUp:
// Clipping is done in _Redraw()
p.scrollPosition = p.scrollPosition.PreviousLine(1)
p.handleScrolledUp()
case twin.KeyDown, twin.KeyEnter:
// Clipping is done in _Redraw()
p.scrollPosition = p.scrollPosition.NextLine(1)
p.handleScrolledDown()
case twin.KeyRight:
p.moveRight(p.SideScrollAmount)
case twin.KeyLeft:
p.moveRight(-p.SideScrollAmount)
case twin.KeyAltRight:
p.moveRight(1)
case twin.KeyAltLeft:
p.moveRight(-1)
case twin.KeyHome:
p.scrollPosition = newScrollPosition("Pager scroll position")
p.handleScrolledUp()
case twin.KeyEnd:
p.scrollToEnd()
case twin.KeyPgUp:
p.scrollPosition = p.scrollPosition.PreviousLine(p.visibleHeight())
p.handleScrolledUp()
case twin.KeyPgDown:
p.scrollPosition = p.scrollPosition.NextLine(p.visibleHeight())
p.handleScrolledDown()
default:
log.Debugf("Unhandled key event %v", keyCode)
}
}
func (m PagerModeViewing) onRune(char rune) {
p := m.pager
switch char {
case 'q':
p.Quit()
case '?':
if !p.isShowingHelp {
p.preHelpState = &_PreHelpState{
reader: p.reader,
scrollPosition: p.scrollPosition,
leftColumnZeroBased: p.leftColumnZeroBased,
targetLineNumber: p.TargetLineNumber,
}
p.reader = _HelpReader
p.scrollPosition = newScrollPosition("Pager scroll position")
p.leftColumnZeroBased = 0
p.TargetLineNumber = nil
p.isShowingHelp = true
}
case '=':
p.ShowStatusBar = !p.ShowStatusBar
// '\x10' = CTRL-p, should scroll up one line.
// Ref: https://github.com/walles/moar/issues/107#issuecomment-1328354080
case 'k', 'y', '\x10':
// Clipping is done in _Redraw()
p.scrollPosition = p.scrollPosition.PreviousLine(1)
p.handleScrolledUp()
// '\x0e' = CTRL-n, should scroll down one line.
// Ref: https://github.com/walles/moar/issues/107#issuecomment-1328354080
case 'j', 'e', '\x0e':
// Clipping is done in _Redraw()
p.scrollPosition = p.scrollPosition.NextLine(1)
p.handleScrolledDown()
case 'l':
// vim right
p.moveRight(p.SideScrollAmount)
case 'h':
// vim left
p.moveRight(-p.SideScrollAmount)
case '<':
p.scrollPosition = newScrollPosition("Pager scroll position")
p.handleScrolledUp()
case '>', 'G':
p.scrollToEnd()
case 'f', ' ':
p.scrollPosition = p.scrollPosition.NextLine(p.visibleHeight())
p.handleScrolledDown()
case 'b':
p.scrollPosition = p.scrollPosition.PreviousLine(p.visibleHeight())
p.handleScrolledUp()
// '\x15' = CTRL-u, should work like just 'u'.
// Ref: https://github.com/walles/moar/issues/90
case 'u', '\x15':
p.scrollPosition = p.scrollPosition.PreviousLine(p.visibleHeight() / 2)
p.handleScrolledUp()
// '\x04' = CTRL-d, should work like just 'd'.
// Ref: https://github.com/walles/moar/issues/90
case 'd', '\x04':
p.scrollPosition = p.scrollPosition.NextLine(p.visibleHeight() / 2)
p.handleScrolledDown()
case '/':
p.mode = PagerModeSearch{pager: p}
p.TargetLineNumber = nil
p.searchString = ""
p.searchPattern = nil
case 'g':
p.mode = &PagerModeGotoLine{pager: p}
p.TargetLineNumber = nil
// Should match the pagermode-not-found.go previous-search-hit bindings
case 'n':
p.scrollToNextSearchHit()
// Should match the pagermode-not-found.go next-search-hit bindings
case 'p', 'N':
p.scrollToPreviousSearchHit()
case 'm':
p.mode = PagerModeMark{pager: p}
p.TargetLineNumber = nil
case '\'':
p.mode = PagerModeJumpToMark{pager: p}
p.TargetLineNumber = nil
case 'w':
p.WrapLongLines = !p.WrapLongLines
default:
log.Debugf("Unhandled rune keypress '%s'/0x%08x", string(char), int32(char))
}
}