diff --git a/m/line.go b/m/line.go index 99ab8d6..a20a143 100644 --- a/m/line.go +++ b/m/line.go @@ -24,11 +24,11 @@ func NewLine(raw string) Line { // Returns a representation of the string split into styled tokens. Any regexp // matches are highlighted. A nil regexp means no highlighting. -func (line *Line) HighlightedTokens(linePrefix string, search *regexp.Regexp, lineNumberOneBased *int) textstyles.CellsWithTrailer { - plain := line.Plain(lineNumberOneBased) +func (line *Line) HighlightedTokens(linePrefix string, search *regexp.Regexp, lineNumber *linenumbers.LineNumber) textstyles.CellsWithTrailer { + plain := line.Plain(lineNumber) matchRanges := getMatchRanges(&plain, search) - fromString := textstyles.CellsFromString(linePrefix+line.raw, lineNumberOneBased) + fromString := textstyles.CellsFromString(linePrefix+line.raw, lineNumber) returnCells := make([]twin.Cell, 0, len(fromString.Cells)) for _, token := range fromString.Cells { style := token.Style diff --git a/m/reader.go b/m/reader.go index d314c5d..84c0f37 100644 --- a/m/reader.go +++ b/m/reader.go @@ -639,7 +639,7 @@ func (reader *Reader) getLinesUnlocked(firstLine linenumbers.LineNumber, wantedL lastLine := firstLine.NonWrappingAdd(wantedLineCount - 1) if lastLine.AsZeroBased() >= len(reader.lines) { - lastLine = linenumbers.LineNumberFromLength(len(reader.lines)) + lastLine = *linenumbers.LineNumberFromLength(len(reader.lines)) } // Prevent reading past the end of the available lines diff --git a/m/textstyles/ansiTokenizer.go b/m/textstyles/ansiTokenizer.go index 300b8af..838e127 100644 --- a/m/textstyles/ansiTokenizer.go +++ b/m/textstyles/ansiTokenizer.go @@ -8,6 +8,7 @@ import ( "strconv" "strings" + "github.com/walles/moar/m/linenumbers" "github.com/walles/moar/twin" ) @@ -47,7 +48,7 @@ func isPlain(s string) bool { return true } -func WithoutFormatting(s string, lineNumberOneBased *int) string { +func WithoutFormatting(s string, lineNumber *linenumbers.LineNumber) string { if isPlain(s) { return s } @@ -60,7 +61,7 @@ func WithoutFormatting(s string, lineNumberOneBased *int) string { // runes. stripped.Grow(len(s) * 2) - styledStringsFromString(s, lineNumberOneBased, func(str string, style twin.Style) { + styledStringsFromString(s, lineNumber, func(str string, style twin.Style) { for _, runeValue := range runesFromStyledString(_StyledString{String: str, Style: style}) { switch runeValue { @@ -105,13 +106,13 @@ func WithoutFormatting(s string, lineNumberOneBased *int) string { } // Turn a (formatted) string into a series of screen cells -func CellsFromString(s string, lineNumberOneBased *int) CellsWithTrailer { +func CellsFromString(s string, lineNumber *linenumbers.LineNumber) CellsWithTrailer { var cells []twin.Cell // Specs: https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit styleUnprintable := twin.StyleDefault.WithBackground(twin.NewColor16(1)).WithForeground(twin.NewColor16(7)) - trailer := styledStringsFromString(s, lineNumberOneBased, func(str string, style twin.Style) { + trailer := styledStringsFromString(s, lineNumber, func(str string, style twin.Style) { for _, token := range tokensFromStyledString(_StyledString{String: str, Style: style}) { switch token.Rune {