1
0
mirror of https://gitea.com/Sirherobrine23/tea.git synced 2024-08-20 22:07:24 +00:00
tea/vendor/github.com/muesli/termenv/templatehelper.go
6543 89e93d90b3 Use glamour and termev to render/colorize content (#181)
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>
2020-09-19 16:00:50 +00:00

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()
}
}