File: letters_from_string.go

package info (click to toggle)
golang-github-pterm-pterm 0.12.79-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,640 kB
  • sloc: makefile: 4
file content (44 lines) | stat: -rw-r--r-- 1,097 bytes parent folder | download
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"
)

// LettersFromString 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 LettersFromString(text string) pterm.Letters {
	return LettersFromStringWithStyle(text, &pterm.ThemeDefault.LetterStyle)
}

// LettersFromStringWithStyle creates a Letters object from a string and applies a Style to it.
func LettersFromStringWithStyle(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
}

// LettersFromStringWithRGB creates a Letters object from a string and applies an RGB color to it (overwrites style).
func LettersFromStringWithRGB(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
}