diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 73d392dd9..6491ad209 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,6 +3,14 @@ > This document explains how to participate in the development of PTerm.\ If your goal is to report a bug instead of programming PTerm, you can do so [here](https://github.com/pterm/pterm/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc). +## Best practise + +We enforce some best practises, especially made for PTerm, to provide a clean and consistent user experience. + +### Styles + +Styles should always be consumed as pointers. That way, the user can change the style of printers globally. + ## Creating a new printer > In this chapter we will show you how to create a new printer. diff --git a/color.go b/color.go index 3626ee475..5f7eeef3a 100644 --- a/color.go +++ b/color.go @@ -246,6 +246,11 @@ func (c Color) String() string { return fmt.Sprintf("%d", c) } +// ToStyle converts the color to a style. +func (c Color) ToStyle() *Style { + return &Style{c} +} + // Style is a collection of colors. // Can include foreground, background and styling (eg. Bold, Underscore, etc.) colors. type Style []Color diff --git a/color_test.go b/color_test.go index f41a17b80..2b0909a83 100644 --- a/color_test.go +++ b/color_test.go @@ -152,7 +152,13 @@ func TestColorPrinterPrintMethods(t *testing.T) { } func TestNewStyle(t *testing.T) { + s := pterm.NewStyle(pterm.FgRed, pterm.BgBlue, pterm.Bold) + testza.AssertEqual(t, s, &pterm.Style{pterm.FgRed, pterm.BgBlue, pterm.Bold}) +} +func TestColor_ToStyle(t *testing.T) { + s := pterm.FgCyan.ToStyle() + testza.AssertEqual(t, s, &pterm.Style{pterm.FgCyan}) } func TestStyle_Add(t *testing.T) {