1
1
mirror of https://github.com/walles/moar.git synced 2024-08-16 15:30:34 +03:00

Revert "Merge branch 'johan/ui-colors-from-chroma'"

This reverts commit ed491742a1, reversing
changes made to 12f316f8c8.

Before this goes in, we should first auto detect bright vs dark terminal
background and default to different themes in those two cases: #67
This commit is contained in:
Johan Walles 2023-12-28 18:38:37 +01:00
parent 794047451e
commit e80c60439b
3 changed files with 2 additions and 103 deletions

View File

@ -55,42 +55,6 @@ func twinStyleFromChroma(chromaStyle *chroma.Style, chromaFormatter *chroma.Form
return &cells[0].Style
}
func backgroundStyleFromChroma(chromaStyle chroma.Style) twin.Style {
backgroundEntry := chromaStyle.Get(chroma.Background)
backgroundColor := twin.ColorDefault
if backgroundEntry.Background.IsSet() {
backgroundColor = twin.NewColor24Bit(
backgroundEntry.Background.Red(),
backgroundEntry.Background.Green(),
backgroundEntry.Background.Blue())
}
foregroundColor := twin.ColorDefault
if backgroundEntry.Colour.IsSet() {
foregroundColor = twin.NewColor24Bit(
backgroundEntry.Colour.Red(),
backgroundEntry.Colour.Green(),
backgroundEntry.Colour.Blue())
}
returnMe := twin.StyleDefault.
WithBackground(backgroundColor).
WithForeground(foregroundColor)
if backgroundEntry.Bold == chroma.Yes {
returnMe = returnMe.WithAttr(twin.AttrBold)
}
if backgroundEntry.Italic == chroma.Yes {
returnMe = returnMe.WithAttr(twin.AttrItalic)
}
if backgroundEntry.Underline == chroma.Yes {
returnMe = returnMe.WithAttr(twin.AttrUnderline)
}
return returnMe
}
// consumeLessTermcapEnvs parses LESS_TERMCAP_xx environment variables and
// adapts the moar output accordingly.
func consumeLessTermcapEnvs(chromaStyle *chroma.Style, chromaFormatter *chroma.Formatter) {
@ -124,11 +88,8 @@ func styleUi(chromaStyle *chroma.Style, chromaFormatter *chroma.Formatter, statu
if standoutStyle != nil {
statusbarStyle = *standoutStyle
} else if statusbarOption == STATUSBAR_STYLE_INVERSE {
if chromaStyle != nil {
statusbarStyle = backgroundStyleFromChroma(*chromaStyle).WithAttr(twin.AttrReverse)
} else {
statusbarStyle = twin.StyleDefault.WithAttr(twin.AttrReverse)
}
// FIXME: Get this from the Chroma style
statusbarStyle = twin.StyleDefault.WithAttr(twin.AttrReverse)
} else if statusbarOption == STATUSBAR_STYLE_PLAIN {
plain := twinStyleFromChroma(chromaStyle, chromaFormatter, chroma.None)
if plain != nil {

View File

@ -1,54 +0,0 @@
package m
import (
"testing"
"github.com/alecthomas/chroma/v2/styles"
"github.com/walles/moar/twin"
"gotest.tools/v3/assert"
)
func TestBackgroundStyleFromChromaGithub(t *testing.T) {
style := backgroundStyleFromChroma(*styles.Get("github"))
assert.Equal(t, style.String(), "Default color on #ffffff")
}
func TestBackgroundStyleFromChromaAverage(t *testing.T) {
// Verify we get the right values out of a style with both Text and Background.
style := backgroundStyleFromChroma(*styles.Get("average"))
assert.Equal(t, style.String(), "#757575 on #000000")
}
func TestBackgroundStyleFromChromaNative(t *testing.T) {
// Verify we get the right values out of a style where Background comes with
// both foreground and background.
style := backgroundStyleFromChroma(*styles.Get("native"))
assert.Equal(t, style.String(), "#d0d0d0 on #202020")
}
// Loop over all styles and check that the contrast we get in
// backgroundStyleFromChroma is good enough.
func TestBackgroundStyleContrast(t *testing.T) {
for _, style := range styles.Registry {
t.Run(style.Name, func(t *testing.T) {
backgroundStyle := backgroundStyleFromChroma(*style)
if backgroundStyle.Foreground().ColorType() == twin.ColorTypeDefault {
return
}
if backgroundStyle.Background().ColorType() == twin.ColorTypeDefault {
return
}
distance := backgroundStyle.Background().Distance(backgroundStyle.Foreground())
// 0.4 feels low, but as of Chroma v2.12.0 this is the distance we
// get for some styles (solarized-dark, solarized-light, average).
//
// Let's at least verify it doesn't get worse than this.
assert.Check(t, distance > 0.4, "distance=%f", distance)
})
}
}

View File

@ -117,14 +117,6 @@ func (attr AttrMask) has(attrs AttrMask) bool {
return attr&attrs != 0
}
func (style Style) Background() Color {
return style.bg
}
func (style Style) Foreground() Color {
return style.fg
}
func (style Style) WithBackground(color Color) Style {
return Style{
fg: style.fg,