-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add renders utility, fix tests & bench
- Loading branch information
Vic Shóstak
committed
May 26, 2023
1 parent
57d3bfa
commit b9ce07c
Showing
12 changed files
with
163 additions
and
27 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
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
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
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,31 @@ | ||
package gosl | ||
|
||
import "github.com/charmbracelet/lipgloss" | ||
|
||
// RenderStyled render a styled string with a given lipgloss.Style template | ||
// using "charmbracelet/lipgloss" package. | ||
// | ||
// If s have an "" (empty) value returns zero-value for a string. | ||
// | ||
// Example: | ||
// | ||
// package main | ||
// | ||
// import ( | ||
// "fmt" | ||
// "log" | ||
// | ||
// "github.com/charmbracelet/lipgloss" | ||
// "github.com/koddr/gosl" | ||
// ) | ||
// | ||
// func main() { | ||
// t := lipgloss.NewStyle().Foreground(lipgloss.Color("42")).Margin(1) | ||
// | ||
// s := gosl.RenderStyled("This is a styled text", t) | ||
// | ||
// fmt.Println(s) | ||
// } | ||
func RenderStyled(str string, template lipgloss.Style) string { | ||
return template.Render(str) | ||
} |
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,34 @@ | ||
package gosl | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/charmbracelet/lipgloss" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var resultPrinters string | ||
|
||
func BenchmarkRenderStyled(b *testing.B) { | ||
var r string | ||
for i := 0; i < b.N; i++ { | ||
r = RenderStyled("Hello, World!", lipgloss.NewStyle().Foreground(lipgloss.Color("42"))) | ||
} | ||
resultGenerators = r | ||
} | ||
|
||
func TestRenderStyled(t *testing.T) { | ||
r := RenderStyled("", lipgloss.Style{}) | ||
assert.EqualValues(t, "", r) | ||
|
||
r = RenderStyled("Hello, World!", lipgloss.NewStyle().Foreground(lipgloss.Color("42"))) | ||
assert.EqualValues(t, "Hello, World!", r) | ||
|
||
g := Utility{} // tests for method | ||
|
||
r = g.RenderStyled("", lipgloss.Style{}) | ||
assert.EqualValues(t, "", r) | ||
|
||
r = g.RenderStyled("Hello, World!", lipgloss.NewStyle().Foreground(lipgloss.Color("42"))) | ||
assert.EqualValues(t, "Hello, World!", r) | ||
} |
Oops, something went wrong.