-
-
Notifications
You must be signed in to change notification settings - Fork 187
/
new_letters_from_string.go
44 lines (35 loc) · 1.09 KB
/
new_letters_from_string.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package putils
import (
"strings"
"github.com/pterm/pterm"
)
// NewLettersFromString creates a Letters object from a string, which is prefilled with the LetterStyle from ThemeDefault.
// You can override the ThemeDefault LetterStyle if you want to.
func NewLettersFromString(text string) pterm.Letters {
return NewLettersFromStringWithStyle(text, &pterm.ThemeDefault.LetterStyle)
}
// NewLettersFromStringWithStyle creates a Letters object from a string and applies a Style to it.
func NewLettersFromStringWithStyle(text string, style *pterm.Style) pterm.Letters {
s := strings.Split(text, "")
l := pterm.Letters{}
for _, s2 := range s {
l = append(l, pterm.Letter{
String: s2,
Style: style,
})
}
return l
}
// NewLettersFromStringWithRGB creates a Letters object from a string and applies an RGB color to it (overwrites style).
func NewLettersFromStringWithRGB(text string, rgb pterm.RGB) pterm.Letters {
s := strings.Split(text, "")
l := pterm.Letters{}
for _, s2 := range s {
l = append(l, pterm.Letter{
String: s2,
Style: &pterm.Style{},
RGB: rgb,
})
}
return l
}