mirror of
https://github.com/walles/moar.git
synced 2024-11-22 21:50:43 +03:00
Make pager.go compile again
This commit is contained in:
parent
05f8c2674b
commit
5d4201b151
@ -17,6 +17,7 @@ func (l LineNumber) AsOneBased() int {
|
||||
return l.number + 1
|
||||
}
|
||||
|
||||
// FIXME: Maybe drop this in favor of some array access method(s)?
|
||||
func (l LineNumber) AsZeroBased() int {
|
||||
return l.number
|
||||
}
|
||||
@ -35,6 +36,11 @@ func LineNumberFromZeroBased(zeroBased int) LineNumber {
|
||||
return LineNumber{number: zeroBased}
|
||||
}
|
||||
|
||||
// The highest possible line number
|
||||
func LineNumberMax() LineNumber {
|
||||
return LineNumber{number: math.MaxInt}
|
||||
}
|
||||
|
||||
// Set the line number to the last line of a file with the given number of lines
|
||||
// in it. Or nil if the line count is 0.
|
||||
func LineNumberFromLength(length int) *LineNumber {
|
||||
|
@ -2,7 +2,6 @@ package m
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
@ -58,7 +57,7 @@ type Pager struct {
|
||||
gotoLineString string
|
||||
|
||||
// We used to have a "Following" field here. If you want to follow, set
|
||||
// TargetLineNumberOneBased to math.MaxInt instead, see below.
|
||||
// TargetLineNumber to LineNumberMax() instead, see below.
|
||||
|
||||
isShowingHelp bool
|
||||
preHelpState *_PreHelpState
|
||||
@ -83,7 +82,7 @@ type Pager struct {
|
||||
SideScrollAmount int // Should be positive
|
||||
|
||||
// If non-nil, scroll to this line number as soon as possible. Set this
|
||||
// value to math.MaxInt to follow the end of the input (tail).
|
||||
// value to LineNumberMax() to follow the end of the input (tail).
|
||||
TargetLineNumber *linenumbers.LineNumber
|
||||
|
||||
// If true, pager will clear the screen on return. If false, pager will
|
||||
@ -255,7 +254,7 @@ func (p *Pager) handleScrolledUp() {
|
||||
|
||||
func (p *Pager) handleScrolledDown() {
|
||||
if p.isScrolledToEnd() {
|
||||
reallyHigh := linenumbers.LineNumberFromZeroBased(math.MaxInt)
|
||||
reallyHigh := linenumbers.LineNumberMax()
|
||||
p.TargetLineNumber = &reallyHigh
|
||||
} else {
|
||||
p.TargetLineNumber = &linenumbers.LineNumber{}
|
||||
|
@ -2,7 +2,6 @@ package m
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"github.com/walles/moar/m/linenumbers"
|
||||
)
|
||||
@ -305,12 +304,13 @@ func (p *Pager) scrollToEnd() {
|
||||
// lines than the number of characters it contains.
|
||||
p.scrollPosition.internalDontTouch.deltaScreenLines = len(lastInputLine.raw)
|
||||
|
||||
if p.TargetLineNumber == 0 {
|
||||
if p.TargetLineNumber == nil {
|
||||
// Start following the end of the file
|
||||
//
|
||||
// Otherwise, if we're already aiming for some place, don't overwrite
|
||||
// that.
|
||||
p.TargetLineNumber = math.MaxInt
|
||||
maxLineNumber := linenumbers.LineNumberMax()
|
||||
p.TargetLineNumber = &maxLineNumber
|
||||
}
|
||||
}
|
||||
|
||||
|
4
moar.go
4
moar.go
@ -4,7 +4,6 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@ -21,6 +20,7 @@ import (
|
||||
"golang.org/x/term"
|
||||
|
||||
"github.com/walles/moar/m"
|
||||
"github.com/walles/moar/m/linenumbers"
|
||||
"github.com/walles/moar/m/textstyles"
|
||||
"github.com/walles/moar/twin"
|
||||
)
|
||||
@ -570,7 +570,7 @@ func main() {
|
||||
|
||||
pager.TargetLineNumber = targetLineNumberOneBased
|
||||
if *follow && pager.TargetLineNumber == 0 {
|
||||
pager.TargetLineNumber = math.MaxInt
|
||||
pager.TargetLineNumber = linenumbers.LineNumberMax()
|
||||
}
|
||||
|
||||
startPaging(pager, screen, style, &formatter)
|
||||
|
Loading…
Reference in New Issue
Block a user