diff --git a/bigtext_printer.go b/bigtext_printer.go index db8ad7dc9..9548438fc 100644 --- a/bigtext_printer.go +++ b/bigtext_printer.go @@ -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{} @@ -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 diff --git a/bigtext_printer_test.go b/bigtext_printer_test.go index 76c642d77..405e361d1 100644 --- a/bigtext_printer_test.go +++ b/bigtext_printer_test.go @@ -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) { @@ -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{ @@ -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 diff --git a/testdata/snapshots/TestBarChartPrinter_NilStylePrint.testza b/testdata/snapshots/TestBarChartPrinter_NilStylePrint.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestBarChartPrinter_Render.testza b/testdata/snapshots/TestBarChartPrinter_Render.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestBarChartPrinter_RenderExample.testza b/testdata/snapshots/TestBarChartPrinter_RenderExample.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestBarChartPrinter_RenderExampleHorizontal.testza b/testdata/snapshots/TestBarChartPrinter_RenderExampleHorizontal.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestBarChartPrinter_RenderExampleRawOutput.testza b/testdata/snapshots/TestBarChartPrinter_RenderExampleRawOutput.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestBarChartPrinter_RenderLowBarValues.testza b/testdata/snapshots/TestBarChartPrinter_RenderLowBarValues.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestBarChartPrinter_RenderMultipleLineLabel.testza b/testdata/snapshots/TestBarChartPrinter_RenderMultipleLineLabel.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestBarChartPrinter_RenderNegativeBarValues.testza b/testdata/snapshots/TestBarChartPrinter_RenderNegativeBarValues.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestBarChartPrinter_RenderNegativeBarValuesHorizontal.testza b/testdata/snapshots/TestBarChartPrinter_RenderNegativeBarValuesHorizontal.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestBarChartPrinter_RenderPositiveBarValues.testza b/testdata/snapshots/TestBarChartPrinter_RenderPositiveBarValues.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestBarChartPrinter_RenderPositiveBarValuesHorizontal.testza b/testdata/snapshots/TestBarChartPrinter_RenderPositiveBarValuesHorizontal.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestBarChartPrinter_RenderZeroBarValues.testza b/testdata/snapshots/TestBarChartPrinter_RenderZeroBarValues.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestBarChartPrinter_RenderZeroBarValuesHorizontal.testza b/testdata/snapshots/TestBarChartPrinter_RenderZeroBarValuesHorizontal.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestBigTextPrinter_Render.testza b/testdata/snapshots/TestBigTextPrinter_Render.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestBigTextPrinter_RenderNoStyling.testza b/testdata/snapshots/TestBigTextPrinter_RenderNoStyling.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestBigTextPrinter_RenderRGB.testza b/testdata/snapshots/TestBigTextPrinter_RenderRGB.testza new file mode 100644 index 000000000..371c038f3 --- /dev/null +++ b/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" diff --git a/testdata/snapshots/TestBigTextPrinter_RenderRGBNoStyling.testza b/testdata/snapshots/TestBigTextPrinter_RenderRGBNoStyling.testza new file mode 100644 index 000000000..59fcf4f78 --- /dev/null +++ b/testdata/snapshots/TestBigTextPrinter_RenderRGBNoStyling.testza @@ -0,0 +1 @@ +(string) (len=6) "Hello\n" diff --git a/testdata/snapshots/TestBigTextPrinter_RenderRawOutput.testza b/testdata/snapshots/TestBigTextPrinter_RenderRawOutput.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestBigTextPrinter_RenderRawOutputNoStyling.testza b/testdata/snapshots/TestBigTextPrinter_RenderRawOutputNoStyling.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestDemo0.testza b/testdata/snapshots/TestDemo0.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestDemo1.testza b/testdata/snapshots/TestDemo1.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestDemo2.testza b/testdata/snapshots/TestDemo2.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestDemo3.testza b/testdata/snapshots/TestDemo3.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestDemo4.testza b/testdata/snapshots/TestDemo4.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestDemo5.testza b/testdata/snapshots/TestDemo5.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestDemo6.testza b/testdata/snapshots/TestDemo6.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestDemo7.testza b/testdata/snapshots/TestDemo7.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestTablePrinterWithRowSeparators_Render_1_linux.testza b/testdata/snapshots/TestTablePrinterWithRowSeparators_Render_1_windows.testza old mode 100755 new mode 100644 similarity index 100% rename from testdata/snapshots/TestTablePrinterWithRowSeparators_Render_1_linux.testza rename to testdata/snapshots/TestTablePrinterWithRowSeparators_Render_1_windows.testza diff --git a/testdata/snapshots/TestTablePrinterWithRowSeparators_Render_2_linux.testza b/testdata/snapshots/TestTablePrinterWithRowSeparators_Render_2_windows.testza old mode 100755 new mode 100644 similarity index 100% rename from testdata/snapshots/TestTablePrinterWithRowSeparators_Render_2_linux.testza rename to testdata/snapshots/TestTablePrinterWithRowSeparators_Render_2_windows.testza diff --git a/testdata/snapshots/TestTablePrinterWithRowSeparators_Render_3_linux.testza b/testdata/snapshots/TestTablePrinterWithRowSeparators_Render_3_windows.testza old mode 100755 new mode 100644 similarity index 100% rename from testdata/snapshots/TestTablePrinterWithRowSeparators_Render_3_linux.testza rename to testdata/snapshots/TestTablePrinterWithRowSeparators_Render_3_windows.testza diff --git a/testdata/snapshots/TestTablePrinter_Render_1_linux.testza b/testdata/snapshots/TestTablePrinter_Render_1_windows.testza old mode 100755 new mode 100644 similarity index 100% rename from testdata/snapshots/TestTablePrinter_Render_1_linux.testza rename to testdata/snapshots/TestTablePrinter_Render_1_windows.testza diff --git a/testdata/snapshots/TestTablePrinter_Render_2_linux.testza b/testdata/snapshots/TestTablePrinter_Render_2_windows.testza old mode 100755 new mode 100644 similarity index 100% rename from testdata/snapshots/TestTablePrinter_Render_2_linux.testza rename to testdata/snapshots/TestTablePrinter_Render_2_windows.testza diff --git a/testdata/snapshots/TestTablePrinter_WithCSVReader.testza b/testdata/snapshots/TestTablePrinter_WithCSVReader.testza old mode 100755 new mode 100644 diff --git a/testdata/snapshots/TestTreePrinterNilPrint_linux.testza b/testdata/snapshots/TestTreePrinterNilPrint_windows.testza old mode 100755 new mode 100644 similarity index 100% rename from testdata/snapshots/TestTreePrinterNilPrint_linux.testza rename to testdata/snapshots/TestTreePrinterNilPrint_windows.testza diff --git a/testdata/snapshots/TestTreePrinter_Render_linux.testza b/testdata/snapshots/TestTreePrinter_Render_windows.testza old mode 100755 new mode 100644 similarity index 100% rename from testdata/snapshots/TestTreePrinter_Render_linux.testza rename to testdata/snapshots/TestTreePrinter_Render_windows.testza