Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #364 from pterm/363-move-ptermnewlettersfromstring…
…-to-putils-package
- Loading branch information
Showing
5 changed files
with
101 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |