String Transforms ๐
Lip Gloss v0.10.0
features a brand new Transform
function for Styles to alter strings at render time. As well as some bug fixes, like ANSI-aware table cell truncation. ๐งน
Simply define a Transform
function as func (string) string
and apply it to any style:
// Example:
s := NewStyle().Transform(strings.ToUpper)
fmt.Println(s.Render("raow!") // "RAOW!"
Or, if you prefer:
// Example:
reverse := func(s string) string {
n := 0
rune := make([]rune, len(s))
for _, r := range s {
rune[n] = r
n++
}
rune = rune[0:n]
for i := 0; i < n/2; i++ {
rune[i], rune[n-1-i] = rune[n-1-i], rune[i]
}
return string(rune)
}
s := NewStyle().Transform(reverse)
fmt.Println(s.Render("The quick brown ็ jumped over the lazy ็ฌ")
// "็ฌ yzal eht revo depmuj ็ nworb kciuq ehT",
What's Changed?
- Corrected border shorthand functions explanation by @ReidMason in #237
- Align help by @schmurfy in #239
Style.Transform
for altering strings at render time by @meowgorithm in #232- Adding right padding to empty string by @mikelorant in #253
- Refactor padding functions by @mikelorant in #254
- Fix truncate of table cells containing ANSI by @mikelorant in #256
- Improve maximum width of characters in a string by @mikelorant in #257
New Contributors
- @ReidMason made their first contribution in #237
- @schmurfy made their first contribution in #239
- @mikelorant made their first contribution in #253
Full Changelog: v0.9.1...v0.10.0
Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or Slack.