i3-blocks-go/rendering/text.go
2022-08-28 14:59:15 +02:00

35 lines
694 B
Go

package rendering
import (
"fmt"
)
type FB struct {
Foreground string
Background string
}
func Text(text string, fb FB) string {
if fb.Foreground == "" {
fb.Foreground = Color("default_foreground")
}
if fb.Background == "" {
fb.Background = Color("default_background")
}
return fmt.Sprintf("<span background='%s' foreground='%s'>%s</span>", fb.Background, fb.Foreground, text)
}
func TextWithPadding(text string, fb FB) string {
return Text(fmt.Sprintf(" %s ", text), fb)
}
func TextWithLeftPadding(text string, fb FB) string {
return Text(fmt.Sprintf(" %s", text), fb)
}
func TextWithRightPadding(text string, fb FB) string {
return Text(fmt.Sprintf("%s ", text), fb)
}