123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package style
- import (
- "fmt"
- "strings"
- )
- func Background(text string, r uint8, g uint8, b uint8) string {
- setter := fmt.Sprintf("\x1b[48;2;%d;%d;%dm", r, g, b)
- resetter := "\x1b[49m"
- text = strings.ReplaceAll(text, resetter, setter)
- return fmt.Sprintf("%s%s%s", setter, text, resetter)
- }
- func ExtendBackground(text string) string {
- return strings.ReplaceAll(text, "\n", "\x1b[K\n")
- }
- func Foreground(text string, r uint8, g uint8, b uint8) string {
- setter := fmt.Sprintf("\x1b[38;2;%d;%d;%dm", r, g, b)
- resetter := "\x1b[39m"
- newText := strings.ReplaceAll(text, resetter, setter)
- return fmt.Sprintf("%s%s%s", setter, newText, resetter)
- }
- func Display(text string, prependCode int, appendCode int) string {
- return fmt.Sprintf("\x1b[%dm%s\x1b[%dm", prependCode, text, appendCode)
- }
- func Bold(text string) string {
- return Display(text, 1, 22)
- }
- func Strikethrough(text string) string {
- return Display(text, 9, 29)
- }
- func Underline(text string) string {
- return Display(text, 4, 24)
- }
- func Italic(text string) string {
- return Display(text, 3, 23)
- }
- func Code(text string) string {
- return Background(text, 75, 75, 75)
- }
- func CodeBlock(text string) string {
- return ExtendBackground(Code(text))
- }
- func Highlight(text string) string {
- return Background(text, 13, 125, 0)
- }
- func Color(text string) string {
- return Foreground(text, 164, 245, 155)
- }
- func Linkify(text string) string {
- return Underline(Color(text))
- }
|