1
1
mirror of https://github.com/walles/moar.git synced 2024-09-17 15:07:11 +03:00

Get line number style from Chroma theme

This commit is contained in:
Johan Walles 2023-12-17 08:51:41 +01:00
parent 21afb4f2ef
commit c88c460776
2 changed files with 18 additions and 3 deletions

View File

@ -116,9 +116,9 @@ func twinStyleFromChroma(chromaStyle *chroma.Style, chromaFormatter *chroma.Form
return &cells[0].Style
}
// ConsumeLessTermcapEnvs parses LESS_TERMCAP_xx environment variables and
// consumeLessTermcapEnvs parses LESS_TERMCAP_xx environment variables and
// adapts the moar output accordingly.
func ConsumeLessTermcapEnvs(chromaStyle *chroma.Style, chromaFormatter *chroma.Formatter) {
func consumeLessTermcapEnvs(chromaStyle *chroma.Style, chromaFormatter *chroma.Formatter) {
// Requested here: https://github.com/walles/moar/issues/14
setStyle(&manPageBold, "LESS_TERMCAP_md", twinStyleFromChroma(chromaStyle, chromaFormatter, chroma.GenericStrong))
@ -126,6 +126,20 @@ func ConsumeLessTermcapEnvs(chromaStyle *chroma.Style, chromaFormatter *chroma.F
setStyle(standoutStyle, "LESS_TERMCAP_so", nil)
}
func styleUi(chromaStyle *chroma.Style, chromaFormatter *chroma.Formatter) {
if chromaStyle == nil || chromaFormatter == nil {
return
}
lineNumberStyle := twinStyleFromChroma(chromaStyle, chromaFormatter, chroma.LineNumbers)
if lineNumberStyle != nil {
// If somebody can provide an example where not-dimmed line numbers
// looks good I'll change this, but until then they will be dimmed no
// matter what the theme authors think.
_numberStyle = lineNumberStyle.WithAttr(twin.AttrDim)
}
}
func termcapToStyle(termcap string) twin.Style {
// Add a character to be sure we have one to take the format from
cells := cellsFromString(termcap+"x", nil).Cells

View File

@ -477,7 +477,8 @@ func (p *Pager) StartPaging(screen twin.Screen, chromaStyle *chroma.Style, chrom
}()
unprintableStyle = p.UnprintableStyle
ConsumeLessTermcapEnvs(chromaStyle, chromaFormatter)
consumeLessTermcapEnvs(chromaStyle, chromaFormatter)
styleUi(chromaStyle, chromaFormatter)
p.screen = screen
p.linePrefix = getLineColorPrefix(chromaStyle, chromaFormatter)