mirror of
https://github.com/walles/moar.git
synced 2024-08-16 15:30:34 +03:00
Compare commits
2 Commits
b835e9a23d
...
19b54159a3
Author | SHA1 | Date | |
---|---|---|---|
|
19b54159a3 | ||
|
779f1717aa |
2
build.sh
2
build.sh
@ -28,4 +28,6 @@ fi
|
||||
go build -trimpath -ldflags="-s -w -X main.versionString=${VERSION}" -o "${BINARY}"
|
||||
|
||||
# Alternative build line, if you want to attach to the running process in the Go debugger:
|
||||
#
|
||||
# -gcflags='-N -l' disables optimizations and inlining, which makes debugging easier.
|
||||
# go build -ldflags="-X main.versionString=${VERSION}" -gcflags='-N -l' -o "${BINARY}"
|
||||
|
@ -27,12 +27,12 @@ type PagerModeSearch struct {
|
||||
|
||||
pattern *regexp.Regexp
|
||||
startLine linenumbers.LineNumber
|
||||
lock *sync.Mutex
|
||||
lock sync.Mutex
|
||||
|
||||
searcher chan searchCommand
|
||||
}
|
||||
|
||||
func (m PagerModeSearch) drawFooter(_ string, _ string) {
|
||||
func (m *PagerModeSearch) drawFooter(_ string, _ string) {
|
||||
width, height := m.pager.screen.Size()
|
||||
|
||||
pos := 0
|
||||
@ -52,7 +52,7 @@ func (m PagerModeSearch) drawFooter(_ string, _ string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (m PagerModeSearch) searcherSearch() *linenumbers.LineNumber {
|
||||
func (m *PagerModeSearch) searcherSearch() *linenumbers.LineNumber {
|
||||
// Search to the end
|
||||
for position := m.startLine; ; position = position.NonWrappingAdd(1) {
|
||||
line := m.pager.reader.GetLine(position)
|
||||
@ -78,7 +78,6 @@ func (m PagerModeSearch) searcherSearch() *linenumbers.LineNumber {
|
||||
}
|
||||
|
||||
func (m *PagerModeSearch) initSearcher() {
|
||||
m.lock = &sync.Mutex{}
|
||||
m.searcher = make(chan searchCommand, 1)
|
||||
|
||||
go func() {
|
||||
@ -177,9 +176,12 @@ func removeLastChar(s string) string {
|
||||
return s[:len(s)-size]
|
||||
}
|
||||
|
||||
func (m PagerModeSearch) onKey(key twin.KeyCode) {
|
||||
func (m *PagerModeSearch) onKey(key twin.KeyCode) {
|
||||
switch key {
|
||||
case twin.KeyEscape, twin.KeyEnter:
|
||||
if m.searcher != nil {
|
||||
m.searcher <- searchCommandDone
|
||||
}
|
||||
//nolint:gosimple // The linter's advice is just wrong here
|
||||
m.pager.mode = PagerModeViewing{pager: m.pager}
|
||||
|
||||
@ -192,6 +194,9 @@ func (m PagerModeSearch) onKey(key twin.KeyCode) {
|
||||
m.updateSearchPattern()
|
||||
|
||||
case twin.KeyUp, twin.KeyDown, twin.KeyPgUp, twin.KeyPgDown:
|
||||
if m.searcher != nil {
|
||||
m.searcher <- searchCommandDone
|
||||
}
|
||||
//nolint:gosimple // The linter's advice is just wrong here
|
||||
m.pager.mode = PagerModeViewing{pager: m.pager}
|
||||
m.pager.mode.onKey(key)
|
||||
@ -201,7 +206,7 @@ func (m PagerModeSearch) onKey(key twin.KeyCode) {
|
||||
}
|
||||
}
|
||||
|
||||
func (m PagerModeSearch) onRune(char rune) {
|
||||
func (m *PagerModeSearch) onRune(char rune) {
|
||||
m.pager.searchString = m.pager.searchString + string(char)
|
||||
m.updateSearchPattern()
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ func (m PagerModeViewing) onRune(char rune) {
|
||||
p.handleScrolledDown()
|
||||
|
||||
case '/':
|
||||
p.mode = PagerModeSearch{pager: p}
|
||||
p.mode = &PagerModeSearch{pager: p}
|
||||
p.TargetLineNumber = nil
|
||||
p.searchString = ""
|
||||
p.searchPattern = nil
|
||||
|
@ -13,7 +13,7 @@ func modeName(pager *Pager) string {
|
||||
return "Viewing"
|
||||
case PagerModeNotFound:
|
||||
return "NotFound"
|
||||
case PagerModeSearch:
|
||||
case *PagerModeSearch:
|
||||
return "Search"
|
||||
case *PagerModeGotoLine:
|
||||
return "GotoLine"
|
||||
@ -116,7 +116,7 @@ func Test152(t *testing.T) {
|
||||
|
||||
// Search for the first not-visible hit
|
||||
pager.searchString = "abcde"
|
||||
searchMode := PagerModeSearch{pager: pager}
|
||||
searchMode := &PagerModeSearch{pager: pager}
|
||||
pager.mode = searchMode
|
||||
|
||||
// Scroll to the next search hit
|
||||
|
Loading…
Reference in New Issue
Block a user