Add predefined styling rules

pull/6/head
Mickaël Menu 3 years ago
parent c61a6995a2
commit aee1d0c781
No known key found for this signature in database
GPG Key ID: 53D73664CD359895

@ -59,51 +59,50 @@ func expandThemeAliases(rules []style.Rule) []style.Rule {
} }
var attrsMapping = map[style.Rule]color.Attribute{ var attrsMapping = map[style.Rule]color.Attribute{
"reset": color.Reset, style.RuleBold: color.Bold,
"bold": color.Bold, style.RuleFaint: color.Faint,
"faint": color.Faint, style.RuleItalic: color.Italic,
"italic": color.Italic, style.RuleUnderline: color.Underline,
"underline": color.Underline, style.RuleBlink: color.BlinkSlow,
"blink-slow": color.BlinkSlow, style.RuleReverse: color.ReverseVideo,
"blink-fast": color.BlinkRapid, style.RuleHidden: color.Concealed,
"hidden": color.Concealed, style.RuleStrikethrough: color.CrossedOut,
"strikethrough": color.CrossedOut,
style.RuleBlack: color.FgBlack,
"black": color.FgBlack, style.RuleRed: color.FgRed,
"red": color.FgRed, style.RuleGreen: color.FgGreen,
"green": color.FgGreen, style.RuleYellow: color.FgYellow,
"yellow": color.FgYellow, style.RuleBlue: color.FgBlue,
"blue": color.FgBlue, style.RuleMagenta: color.FgMagenta,
"magenta": color.FgMagenta, style.RuleCyan: color.FgCyan,
"cyan": color.FgCyan, style.RuleWhite: color.FgWhite,
"white": color.FgWhite,
style.RuleBlackBg: color.BgBlack,
"black-bg": color.BgBlack, style.RuleRedBg: color.BgRed,
"red-bg": color.BgRed, style.RuleGreenBg: color.BgGreen,
"green-bg": color.BgGreen, style.RuleYellowBg: color.BgYellow,
"yellow-bg": color.BgYellow, style.RuleBlueBg: color.BgBlue,
"blue-bg": color.BgBlue, style.RuleMagentaBg: color.BgMagenta,
"magenta-bg": color.BgMagenta, style.RuleCyanBg: color.BgCyan,
"cyan-bg": color.BgCyan, style.RuleWhiteBg: color.BgWhite,
"white-bg": color.BgWhite,
style.RuleBrightBlack: color.FgHiBlack,
"bright-black": color.FgHiBlack, style.RuleBrightRed: color.FgHiRed,
"bright-red": color.FgHiRed, style.RuleBrightGreen: color.FgHiGreen,
"bright-green": color.FgHiGreen, style.RuleBrightYellow: color.FgHiYellow,
"bright-yellow": color.FgHiYellow, style.RuleBrightBlue: color.FgHiBlue,
"bright-blue": color.FgHiBlue, style.RuleBrightMagenta: color.FgHiMagenta,
"bright-magenta": color.FgHiMagenta, style.RuleBrightCyan: color.FgHiCyan,
"bright-cyan": color.FgHiCyan, style.RuleBrightWhite: color.FgHiWhite,
"bright-white": color.FgHiWhite,
style.RuleBrightBlackBg: color.BgHiBlack,
"bright-black-bg": color.BgHiBlack, style.RuleBrightRedBg: color.BgHiRed,
"bright-red-bg": color.BgHiRed, style.RuleBrightGreenBg: color.BgHiGreen,
"bright-green-bg": color.BgHiGreen, style.RuleBrightYellowBg: color.BgHiYellow,
"bright-yellow-bg": color.BgHiYellow, style.RuleBrightBlueBg: color.BgHiBlue,
"bright-blue-bg": color.BgHiBlue, style.RuleBrightMagentaBg: color.BgHiMagenta,
"bright-magenta-bg": color.BgHiMagenta, style.RuleBrightCyanBg: color.BgHiCyan,
"bright-cyan-bg": color.BgHiCyan, style.RuleBrightWhiteBg: color.BgHiWhite,
"bright-white-bg": color.BgHiWhite,
} }
func (s *Styler) attributes(rules []style.Rule) ([]color.Attribute, error) { func (s *Styler) attributes(rules []style.Rule) ([]color.Attribute, error) {

@ -48,13 +48,12 @@ func TestStyleAllRules(t *testing.T) {
test("path", "4;36m") test("path", "4;36m")
test("match", "31m") test("match", "31m")
test("reset", "0m")
test("bold", "1m") test("bold", "1m")
test("faint", "2m") test("faint", "2m")
test("italic", "3m") test("italic", "3m")
test("underline", "4m") test("underline", "4m")
test("blink-slow", "5m") test("blink", "5m")
test("blink-fast", "6m") test("reverse", "7m")
test("hidden", "8m") test("hidden", "8m")
test("strikethrough", "9m") test("strikethrough", "9m")

@ -19,7 +19,7 @@ func WithMatchFilter(callback func(func(Match) error)) ([]string, error) {
fmt.Fprintf(w, "%v\x01 %v %v\n", fmt.Fprintf(w, "%v\x01 %v %v\n",
m.Path, m.Path,
styler.MustStyle(m.Title, style.Rule("yellow")), styler.MustStyle(m.Title, style.Rule("yellow")),
styler.MustStyle(strings.JoinLines(m.Body), style.Rule("black")), styler.MustStyle(strings.JoinLines(m.Body), style.Rule("faint")),
) )
return nil return nil
}) })

@ -10,6 +10,54 @@ type Styler interface {
// Rule is a key representing a single styling rule. // Rule is a key representing a single styling rule.
type Rule string type Rule string
// Predefined styling rules.
var (
RuleBold = Rule("bold")
RuleItalic = Rule("italic")
RuleFaint = Rule("faint")
RuleUnderline = Rule("underline")
RuleStrikethrough = Rule("strikethrough")
RuleBlink = Rule("blink")
RuleReverse = Rule("reverse")
RuleHidden = Rule("hidden")
RuleBlack = Rule("black")
RuleRed = Rule("red")
RuleGreen = Rule("green")
RuleYellow = Rule("yellow")
RuleBlue = Rule("blue")
RuleMagenta = Rule("magenta")
RuleCyan = Rule("cyan")
RuleWhite = Rule("white")
RuleBlackBg = Rule("black-bg")
RuleRedBg = Rule("red-bg")
RuleGreenBg = Rule("green-bg")
RuleYellowBg = Rule("yellow-bg")
RuleBlueBg = Rule("blue-bg")
RuleMagentaBg = Rule("magenta-bg")
RuleCyanBg = Rule("cyan-bg")
RuleWhiteBg = Rule("white-bg")
RuleBrightBlack = Rule("bright-black")
RuleBrightRed = Rule("bright-red")
RuleBrightGreen = Rule("bright-green")
RuleBrightYellow = Rule("bright-yellow")
RuleBrightBlue = Rule("bright-blue")
RuleBrightMagenta = Rule("bright-magenta")
RuleBrightCyan = Rule("bright-cyan")
RuleBrightWhite = Rule("bright-white")
RuleBrightBlackBg = Rule("bright-black-bg")
RuleBrightRedBg = Rule("bright-red-bg")
RuleBrightGreenBg = Rule("bright-green-bg")
RuleBrightYellowBg = Rule("bright-yellow-bg")
RuleBrightBlueBg = Rule("bright-blue-bg")
RuleBrightMagentaBg = Rule("bright-magenta-bg")
RuleBrightCyanBg = Rule("bright-cyan-bg")
RuleBrightWhiteBg = Rule("bright-white-bg")
)
// NullStyler is a Styler with no styling rules. // NullStyler is a Styler with no styling rules.
var NullStyler = nullStyler{} var NullStyler = nullStyler{}

Loading…
Cancel
Save