mirror of
https://github.com/walles/moar.git
synced 2024-10-26 13:00:40 +03:00
Fixups after testing
This commit is contained in:
parent
4867b2c2ed
commit
a9fbc3f681
@ -184,6 +184,7 @@ func NewPager(r *Reader) *Pager {
|
||||
ScrollLeftHint: twin.NewCell('<', twin.StyleDefault.WithAttr(twin.AttrReverse)),
|
||||
ScrollRightHint: twin.NewCell('>', twin.StyleDefault.WithAttr(twin.AttrReverse)),
|
||||
scrollPosition: newScrollPosition(name),
|
||||
marks: make(map[rune]scrollPosition),
|
||||
}
|
||||
|
||||
pager.mode = PagerModeViewing{pager: &pager}
|
||||
@ -316,6 +317,7 @@ func (p *Pager) StartPaging(screen twin.Screen, chromaStyle *chroma.Style, chrom
|
||||
p.screen = screen
|
||||
p.linePrefix = getLineColorPrefix(chromaStyle, chromaFormatter)
|
||||
p.mode = PagerModeViewing{pager: p}
|
||||
p.marks = make(map[rune]scrollPosition)
|
||||
|
||||
go func() {
|
||||
for range p.reader.moreLinesAdded {
|
||||
|
@ -21,20 +21,17 @@ func (m PagerModeJumpToMark) drawFooter(_ string, _ string) {
|
||||
p.screen.SetCell(pos, height-1, twin.NewCell(token, twin.StyleDefault))
|
||||
pos++
|
||||
}
|
||||
|
||||
// Add a cursor
|
||||
p.screen.SetCell(pos, height-1, twin.NewCell(' ', twin.StyleDefault.WithAttr(twin.AttrReverse)))
|
||||
}
|
||||
|
||||
func (m PagerModeJumpToMark) getMarkPrompt() string {
|
||||
// Special case having zero, one or multiple marks
|
||||
if len(m.pager.marks) == 0 {
|
||||
return "Press \"m\" to set your first mark!"
|
||||
return "No marks set, press 'm' to set one!"
|
||||
}
|
||||
|
||||
if len(m.pager.marks) == 1 {
|
||||
for key := range m.pager.marks {
|
||||
return "Press \"" + string(key) + "\" to jump to your mark!"
|
||||
return "Jump to your mark: " + string(key)
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,7 +41,7 @@ func (m PagerModeJumpToMark) getMarkPrompt() string {
|
||||
return marks[i] < marks[j]
|
||||
})
|
||||
|
||||
prompt := "Press a key to jump to your mark: "
|
||||
prompt := "Jump to one of these marks: "
|
||||
for i, mark := range marks {
|
||||
if i > 0 {
|
||||
prompt += ", "
|
||||
@ -71,6 +68,12 @@ func (m PagerModeJumpToMark) onKey(key twin.KeyCode) {
|
||||
}
|
||||
|
||||
func (m PagerModeJumpToMark) onRune(char rune) {
|
||||
if len(m.pager.marks) == 0 && char == 'm' {
|
||||
//nolint:gosimple // The linter's advice is just wrong here
|
||||
m.pager.mode = PagerModeMark{pager: m.pager}
|
||||
return
|
||||
}
|
||||
|
||||
destination, ok := m.pager.marks[char]
|
||||
if ok {
|
||||
m.pager.scrollPosition = destination
|
||||
|
Loading…
Reference in New Issue
Block a user