mirror of
https://github.com/walles/moar.git
synced 2024-11-27 01:05:23 +03:00
Modify input lines rendering API
Make the rendering function return both the lines and the clipped first-line-number value.
This commit is contained in:
parent
c4e8562c7c
commit
002d4e40af
10
m/pager.go
10
m/pager.go
@ -164,14 +164,10 @@ func (p *Pager) _Redraw(spinner string) {
|
||||
wrapLongLines: p.WrapLongLines,
|
||||
}
|
||||
|
||||
// If we're asking for past-the-end lines, the Reader will clip for us,
|
||||
// and we should adapt to that. Otherwise if you scroll 100 lines past
|
||||
// the end, you'll then have to scroll 100 lines up again before the
|
||||
// display starts scrolling visibly.
|
||||
p.firstLineOneBased = screenLines.firstLineOneBased()
|
||||
|
||||
var screenLineNumber int
|
||||
for lineNumber, row := range screenLines.getScreenLines(p.searchPattern) {
|
||||
var renderedScreenLines [][]twin.Cell
|
||||
renderedScreenLines, p.firstLineOneBased = screenLines.renderScreenLines(p.searchPattern)
|
||||
for lineNumber, row := range renderedScreenLines {
|
||||
screenLineNumber = lineNumber
|
||||
for column, cell := range row {
|
||||
p.screen.SetCell(column, screenLineNumber, cell)
|
||||
|
@ -19,7 +19,11 @@ type ScreenLines struct {
|
||||
wrapLongLines bool
|
||||
}
|
||||
|
||||
func (sl *ScreenLines) getScreenLines(searchPattern *regexp.Regexp) [][]twin.Cell {
|
||||
// Render screen lines into an array of lines consisting of Cells.
|
||||
//
|
||||
// The second return value is the same as firstInputLineOneBased, but clipped if
|
||||
// needed so that the end of the input is visible.
|
||||
func (sl *ScreenLines) renderScreenLines(searchPattern *regexp.Regexp) ([][]twin.Cell, int) {
|
||||
// Count the length of the last line number
|
||||
//
|
||||
// Offsets figured out through trial-and-error...
|
||||
@ -39,7 +43,7 @@ func (sl *ScreenLines) getScreenLines(searchPattern *regexp.Regexp) [][]twin.Cel
|
||||
returnLines := make([][]twin.Cell, 0, sl.height)
|
||||
screenFull := false
|
||||
for lineIndex, line := range sl.inputLines.lines {
|
||||
lineNumber := sl.firstLineOneBased() + lineIndex
|
||||
lineNumber := sl.inputLines.firstLineOneBased + lineIndex
|
||||
|
||||
highlighted := line.HighlightedTokens(searchPattern)
|
||||
var wrapped [][]twin.Cell
|
||||
@ -71,7 +75,9 @@ func (sl *ScreenLines) getScreenLines(searchPattern *regexp.Regexp) [][]twin.Cel
|
||||
}
|
||||
}
|
||||
|
||||
return returnLines
|
||||
// FIXME: We can't just use firstInputLineOneBased, in the presence of
|
||||
// wrapped lines that number can be too low.
|
||||
return returnLines, sl.firstInputLineOneBased
|
||||
}
|
||||
|
||||
func (sl *ScreenLines) createScreenLine(lineNumberToShow *int, numberPrefixLength int, contents []twin.Cell) []twin.Cell {
|
||||
@ -145,8 +151,3 @@ func createLineNumberPrefix(fileLineNumber *int, numberPrefixLength int) []twin.
|
||||
|
||||
return lineNumberPrefix
|
||||
}
|
||||
|
||||
func (sl *ScreenLines) firstLineOneBased() int {
|
||||
// FIXME: This is wrong when wrapping is enabled
|
||||
return sl.inputLines.firstLineOneBased
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user