Skip to content

Commit

Permalink
Merge pull request #364 from pterm/363-move-ptermnewlettersfromstring…
Browse files Browse the repository at this point in the history
…-to-putils-package
  • Loading branch information
MarvinJWendt committed Jun 14, 2022
2 parents 6bb8c6e + 6eb9db9 commit f5fe5e7
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 44 deletions.
13 changes: 8 additions & 5 deletions _examples/bigtext/demo/main.go
@@ -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()
}
5 changes: 3 additions & 2 deletions _examples/demo/demo/main.go
Expand Up @@ -9,6 +9,7 @@ import (
"time"

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

// Speed the demo up, by setting this flag.
Expand Down Expand Up @@ -215,8 +216,8 @@ func setup() {

func introScreen() {
ptermLogo, _ := pterm.DefaultBigText.WithLetters(
pterm.NewLettersFromStringWithStyle("P", pterm.NewStyle(pterm.FgLightCyan)),
pterm.NewLettersFromStringWithStyle("Term", pterm.NewStyle(pterm.FgLightMagenta))).
putils.NewLettersFromStringWithStyle("P", pterm.NewStyle(pterm.FgLightCyan)),
putils.NewLettersFromStringWithStyle("Term", pterm.NewStyle(pterm.FgLightMagenta))).
Srender()

pterm.DefaultCenter.Print(ptermLogo)
Expand Down
37 changes: 0 additions & 37 deletions bigtext_printer.go
Expand Up @@ -14,43 +14,6 @@ import (
// Letters is a slice of Letter.
type Letters []Letter

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

// NewLettersFromStringWithStyle creates a Letters object from a string and applies a Style to it.
func NewLettersFromStringWithStyle(text string, style *Style) Letters {
s := strings.Split(text, "")
l := Letters{}

for _, s2 := range s {
l = append(l, 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 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
46 changes: 46 additions & 0 deletions deprecated.go
@@ -0,0 +1,46 @@
package pterm

import "strings"

// 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.
//
// Deprecated: use putils.NewLettersFromString instead.
func NewLettersFromString(text string) Letters {
return NewLettersFromStringWithStyle(text, &ThemeDefault.LetterStyle)
}

// NewLettersFromStringWithStyle creates a Letters object from a string and applies a Style to it.
//
// Deprecated: use putils.NewLettersFromStringWithStyle instead.
func NewLettersFromStringWithStyle(text string, style *Style) Letters {
s := strings.Split(text, "")
l := Letters{}

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

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
}
44 changes: 44 additions & 0 deletions putils/new_letters_from_string.go
@@ -0,0 +1,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
}

0 comments on commit f5fe5e7

Please sign in to comment.