mirror of
https://gitea.com/gitea/tea.git
synced 2024-11-23 19:11:38 +01:00
89e93d90b3
Merge branch 'master' into use-glamour select Glamour Theme based on BackgroundColor Merge branch 'master' into use-glamour Merge branch 'master' into use-glamour update termev update go.mod label color colorate use glamour for issue content Vendor: Add glamour Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/181 Reviewed-by: techknowlogick <techknowlogick@gitea.io> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
package termenv
|
|
|
|
import (
|
|
"text/template"
|
|
)
|
|
|
|
// TemplateFuncs contains a few useful template helpers.
|
|
func TemplateFuncs(p Profile) template.FuncMap {
|
|
return template.FuncMap{
|
|
"Color": func(values ...interface{}) string {
|
|
s := String(values[len(values)-1].(string))
|
|
switch len(values) {
|
|
case 2:
|
|
s = s.Foreground(p.Color(values[0].(string)))
|
|
case 3:
|
|
s = s.
|
|
Foreground(p.Color(values[0].(string))).
|
|
Background(p.Color(values[1].(string)))
|
|
}
|
|
|
|
return s.String()
|
|
},
|
|
"Foreground": func(values ...interface{}) string {
|
|
s := String(values[len(values)-1].(string))
|
|
if len(values) == 2 {
|
|
s = s.Foreground(p.Color(values[0].(string)))
|
|
}
|
|
|
|
return s.String()
|
|
},
|
|
"Background": func(values ...interface{}) string {
|
|
s := String(values[len(values)-1].(string))
|
|
if len(values) == 2 {
|
|
s = s.Background(p.Color(values[0].(string)))
|
|
}
|
|
|
|
return s.String()
|
|
},
|
|
"Bold": styleFunc(Style.Bold),
|
|
"Faint": styleFunc(Style.Faint),
|
|
"Italic": styleFunc(Style.Italic),
|
|
"Underline": styleFunc(Style.Underline),
|
|
"Overline": styleFunc(Style.Overline),
|
|
"Blink": styleFunc(Style.Blink),
|
|
"Reverse": styleFunc(Style.Reverse),
|
|
"CrossOut": styleFunc(Style.CrossOut),
|
|
}
|
|
}
|
|
|
|
func styleFunc(f func(Style) Style) func(...interface{}) string {
|
|
return func(values ...interface{}) string {
|
|
s := String(values[0].(string))
|
|
return f(s).String()
|
|
}
|
|
}
|