Skip to content

Commit

Permalink
feat: added NewLettersFromStringWithRGB
Browse files Browse the repository at this point in the history
  • Loading branch information
floaust committed Mar 9, 2022
1 parent 442a52f commit b9c816c
Show file tree
Hide file tree
Showing 37 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bigtext_printer.go
Expand Up @@ -32,7 +32,7 @@ func NewLettersFromStringWithStyle(text string, style *Style) Letters {
return l
}

// NewLettersFromStringWithRGB creates a Letters object from a string and applies an RGB color to it.
// 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{}
Expand Down Expand Up @@ -61,7 +61,7 @@ func (l Letter) WithStyle(style *Style) *Letter {
return &l
}

// WithRGB returns a new Letter with a specific RGB color.
// WithRGB returns a new Letter with a specific RGB color (overwrites style).
func (l Letter) WithRGB(rgb RGB) *Letter {
l.RGB = rgb
return &l
Expand Down
43 changes: 43 additions & 0 deletions bigtext_printer_test.go
Expand Up @@ -32,6 +32,22 @@ func TestBigTextPrinter_Render(t *testing.T) {
pterm.EnableStyling()
}

func TestBigTextPrinter_RenderRGB(t *testing.T) {
printer := pterm.DefaultBigText.WithLetters(pterm.NewLettersFromStringWithRGB("Hello", pterm.NewRGB(255, 0, 0)))
content := captureStdout(func(w io.Writer) {
printer.Render()
})
testza.AssertNotZero(t, content)
testza.SnapshotCreateOrValidate(t, t.Name(), content)
// DisableStyling
pterm.DisableStyling()
content = captureStdout(func(w io.Writer) {
printer.Render()
})
testza.SnapshotCreateOrValidate(t, t.Name()+"NoStyling", content)
pterm.EnableStyling()
}

func TestBigTextPrinter_RenderRawOutput(t *testing.T) {
printer := pterm.DefaultBigText.WithLetters(pterm.NewLettersFromString("Hello"))
content := captureStdout(func(w io.Writer) {
Expand Down Expand Up @@ -93,6 +109,15 @@ func TestLetter_WithStyle(t *testing.T) {
testza.AssertZero(t, p.Style)
}

func TestLetter_WithRGB(t *testing.T) {
p := pterm.Letter{}
rgb := pterm.NewRGB(0, 0, 0)
p2 := p.WithRGB(rgb)

testza.AssertEqual(t, rgb, p2.RGB)
testza.AssertZero(t, p.RGB)
}

func TestNewLettersFromText(t *testing.T) {
e := pterm.Letters{
pterm.Letter{
Expand Down Expand Up @@ -125,6 +150,24 @@ func TestNewLettersFromTextWithStyle(t *testing.T) {
testza.AssertEqual(t, e, p)
}

func TestNewLettersFromTextWithRGB(t *testing.T) {
e := pterm.Letters{
pterm.Letter{
String: "a",
Style: pterm.NewStyle(),
RGB: pterm.NewRGB(0, 0, 0),
},
pterm.Letter{
String: "b",
Style: pterm.NewStyle(),
RGB: pterm.NewRGB(0, 0, 0),
},
}
p := pterm.NewLettersFromStringWithRGB("ab", pterm.NewRGB(0, 0, 0))

testza.AssertEqual(t, e, p)
}

func TestDefaultLettersMaxHeight(t *testing.T) {
maxHeight := 5
chars := pterm.DefaultBigText.BigCharacters
Expand Down
Empty file modified testdata/snapshots/TestBarChartPrinter_NilStylePrint.testza 100755 β†’ 100644
Empty file.
Empty file modified testdata/snapshots/TestBarChartPrinter_Render.testza 100755 β†’ 100644
Empty file.
Empty file modified testdata/snapshots/TestBarChartPrinter_RenderExample.testza 100755 β†’ 100644
Empty file.
Empty file.
Empty file.
Empty file modified testdata/snapshots/TestBarChartPrinter_RenderLowBarValues.testza 100755 β†’ 100644
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file modified testdata/snapshots/TestBarChartPrinter_RenderZeroBarValues.testza 100755 β†’ 100644
Empty file.
Empty file.
Empty file modified testdata/snapshots/TestBigTextPrinter_Render.testza 100755 β†’ 100644
Empty file.
Empty file modified testdata/snapshots/TestBigTextPrinter_RenderNoStyling.testza 100755 β†’ 100644
Empty file.
1 change: 1 addition & 0 deletions testdata/snapshots/TestBigTextPrinter_RenderRGB.testza
@@ -0,0 +1 @@
(string) (len=886) "\x1b[38;2;255;0;0mβ–ˆβ–ˆ β–ˆβ–ˆ \x1b[0m\x1b[38;2;255;0;0mβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ \x1b[0m\x1b[38;2;255;0;0mβ–ˆβ–ˆ \x1b[0m\x1b[38;2;255;0;0mβ–ˆβ–ˆ \x1b[0m\x1b[38;2;255;0;0m β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ \x1b[0m\n\x1b[38;2;255;0;0mβ–ˆβ–ˆ β–ˆβ–ˆ \x1b[0m\x1b[38;2;255;0;0mβ–ˆβ–ˆ \x1b[0m\x1b[38;2;255;0;0mβ–ˆβ–ˆ \x1b[0m\x1b[38;2;255;0;0mβ–ˆβ–ˆ \x1b[0m\x1b[38;2;255;0;0mβ–ˆβ–ˆ β–ˆβ–ˆ \x1b[0m\n\x1b[38;2;255;0;0mβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ \x1b[0m\x1b[38;2;255;0;0mβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ \x1b[0m\x1b[38;2;255;0;0mβ–ˆβ–ˆ \x1b[0m\x1b[38;2;255;0;0mβ–ˆβ–ˆ \x1b[0m\x1b[38;2;255;0;0mβ–ˆβ–ˆ β–ˆβ–ˆ \x1b[0m\n\x1b[38;2;255;0;0mβ–ˆβ–ˆ β–ˆβ–ˆ \x1b[0m\x1b[38;2;255;0;0mβ–ˆβ–ˆ \x1b[0m\x1b[38;2;255;0;0mβ–ˆβ–ˆ \x1b[0m\x1b[38;2;255;0;0mβ–ˆβ–ˆ \x1b[0m\x1b[38;2;255;0;0mβ–ˆβ–ˆ β–ˆβ–ˆ \x1b[0m\n\x1b[38;2;255;0;0mβ–ˆβ–ˆ β–ˆβ–ˆ \x1b[0m\x1b[38;2;255;0;0mβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ \x1b[0m\x1b[38;2;255;0;0mβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ \x1b[0m\x1b[38;2;255;0;0mβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ \x1b[0m\x1b[38;2;255;0;0m β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ \x1b[0m\n\n"
@@ -0,0 +1 @@
(string) (len=6) "Hello\n"
Empty file modified testdata/snapshots/TestBigTextPrinter_RenderRawOutput.testza 100755 β†’ 100644
Empty file.
Empty file.
Empty file modified testdata/snapshots/TestDemo0.testza 100755 β†’ 100644
Empty file.
Empty file modified testdata/snapshots/TestDemo1.testza 100755 β†’ 100644
Empty file.
Empty file modified testdata/snapshots/TestDemo2.testza 100755 β†’ 100644
Empty file.
Empty file modified testdata/snapshots/TestDemo3.testza 100755 β†’ 100644
Empty file.
Empty file modified testdata/snapshots/TestDemo4.testza 100755 β†’ 100644
Empty file.
Empty file modified testdata/snapshots/TestDemo5.testza 100755 β†’ 100644
Empty file.
Empty file modified testdata/snapshots/TestDemo6.testza 100755 β†’ 100644
Empty file.
Empty file modified testdata/snapshots/TestDemo7.testza 100755 β†’ 100644
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file modified testdata/snapshots/TestTablePrinter_WithCSVReader.testza 100755 β†’ 100644
Empty file.
File renamed without changes.
File renamed without changes.

0 comments on commit b9c816c

Please sign in to comment.