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

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

@ -19,7 +19,7 @@ func WithMatchFilter(callback func(func(Match) error)) ([]string, error) {
fmt.Fprintf(w, "%v\x01 %v %v\n",
m.Path,
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
})

@ -10,6 +10,54 @@ type Styler interface {
// Rule is a key representing a single styling rule.
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.
var NullStyler = nullStyler{}

Loading…
Cancel
Save