Skip to content

Commit

Permalink
moved NewLettersFromStringWithRGB to putils
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinJWendt committed Jun 14, 2022
1 parent c29360d commit d107216
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 21 deletions.
13 changes: 8 additions & 5 deletions _examples/bigtext/demo/main.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package main

import "github.com/pterm/pterm"
import (
"github.com/pterm/pterm"
"github.com/pterm/pterm/putils"
)

func main() {
// Print a large text with the LetterStyle from the standard theme.
// Useful for title screens.
pterm.DefaultBigText.WithLetters(pterm.NewLettersFromString("PTerm")).Render()
pterm.DefaultBigText.WithLetters(putils.NewLettersFromString("PTerm")).Render()

// Print a large text with differently colored letters.
pterm.DefaultBigText.WithLetters(
pterm.NewLettersFromStringWithStyle("P", pterm.NewStyle(pterm.FgCyan)),
pterm.NewLettersFromStringWithStyle("Term", pterm.NewStyle(pterm.FgLightMagenta))).
putils.NewLettersFromStringWithStyle("P", pterm.NewStyle(pterm.FgCyan)),
putils.NewLettersFromStringWithStyle("Term", pterm.NewStyle(pterm.FgLightMagenta))).
Render()

// NewLettersFromStringWithRGB can be used to create a large text with a specific RGB color.
pterm.DefaultBigText.WithLetters(
pterm.NewLettersFromStringWithRGB("PTerm", pterm.NewRGB(255, 215, 0))).
putils.NewLettersFromStringWithRGB("PTerm", pterm.NewRGB(255, 215, 0))).
Render()
}
16 changes: 0 additions & 16 deletions bigtext_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,6 @@ import (
// Letters is a slice of Letter.
type Letters []Letter

// NewLettersFromStringWithRGB creates a Letters object from a string and applies an RGB color to it (overwrites style).
func NewLettersFromStringWithRGB(text string, rgb RGB) Letters {
s := strings.Split(text, "")
l := Letters{}

for _, s2 := range s {
l = append(l, Letter{
String: s2,
Style: &Style{},
RGB: rgb,
})
}

return l
}

// Letter is an object, which holds a string and a specific Style for it.
type Letter struct {
String string
Expand Down
18 changes: 18 additions & 0 deletions deprecated.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,21 @@ func NewLettersFromStringWithStyle(text string, style *Style) Letters {

return l
}

// NewLettersFromStringWithRGB creates a Letters object from a string and applies an RGB color to it (overwrites style).
//
// Deprecated: use putils.NewLettersFromStringWithRGB instead.
func NewLettersFromStringWithRGB(text string, rgb RGB) Letters {
s := strings.Split(text, "")
l := Letters{}

for _, s2 := range s {
l = append(l, Letter{
String: s2,
Style: &Style{},
RGB: rgb,
})
}

return l
}
16 changes: 16 additions & 0 deletions putils/new_letters_from_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,19 @@ func NewLettersFromStringWithStyle(text string, style *pterm.Style) pterm.Letter

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
}

0 comments on commit d107216

Please sign in to comment.