Skip to content

Commit

Permalink
LESS_TERMCAP_so highlighting of search hits
Browse files Browse the repository at this point in the history
Relates to #114.
  • Loading branch information
walles committed Dec 31, 2022
1 parent 871ac3b commit 460071f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions m/ansiTokenizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const BACKSPACE = '\b'

var manPageBold = twin.StyleDefault.WithAttr(twin.AttrBold)
var manPageUnderline = twin.StyleDefault.WithAttr(twin.AttrUnderline)
var standoutStyle *twin.Style = nil
var unprintableStyle UnprintableStyle = UNPRINTABLE_STYLE_HIGHLIGHT

// A Line represents a line of text that can / will be paged
Expand All @@ -40,7 +41,7 @@ func NewLine(raw string) Line {
}

// Returns a representation of the string split into styled tokens. Any regexp
// matches are highlighted in inverse video. A nil regexp means no highlighting.
// matches are highlighted. A nil regexp means no highlighting.
func (line *Line) HighlightedTokens(search *regexp.Regexp) cellsWithTrailer {
plain := line.Plain()
matchRanges := getMatchRanges(&plain, search)
Expand All @@ -50,8 +51,11 @@ func (line *Line) HighlightedTokens(search *regexp.Regexp) cellsWithTrailer {
for _, token := range fromString.Cells {
style := token.Style
if matchRanges.InRange(len(returnCells)) {
// Search hits in reverse video
style = style.WithAttr(twin.AttrReverse)
if standoutStyle != nil {
style = *standoutStyle
} else {
style = style.WithAttr(twin.AttrReverse)
}
}

returnCells = append(returnCells, twin.Cell{
Expand Down Expand Up @@ -89,6 +93,12 @@ func SetManPageFormatFromEnv() {
if lessTermcapUs != "" {
manPageUnderline = termcapToStyle(lessTermcapUs)
}

lessTermcapSo := os.Getenv("LESS_TERMCAP_so")
if lessTermcapSo != "" {
_standoutStyle := termcapToStyle(lessTermcapSo)
standoutStyle = &_standoutStyle
}
}

func termcapToStyle(termcap string) twin.Style {
Expand Down

0 comments on commit 460071f

Please sign in to comment.