mirror of
https://github.com/charmbracelet/gum.git
synced 2024-11-05 05:46:36 +03:00
09feddcc61
Style provides a shell script interface for Lip Gloss. It allows you to use Lip Gloss to style text without needing to use Go. All of the styling options are available as flags. Let's make some text glamorous using bash: ``` gum style \ --foreground "#FF06B7" --border "double" \ --margin 2 --padding "2 4" --width 50 \ "And oh gosh, how delicious the fabulous frizzy frobscottle" \ "was! It was sweet and refreshing. It tasted of vanilla and" \ "cream, with just the faintest trace of raspberries on the" \ "edge of the flavour. And the bubbles were wonderful." ``` Output: ``` ╔══════════════════════════════════════════════════╗ ║ ║ ║ ║ ║ And oh gosh, how delicious the fabulous ║ ║ frizzy frobscottle was It was sweet and ║ ║ refreshing. It tasted of vanilla and ║ ║ cream, with just the faintest trace of ║ ║ raspberries on the edge of the flavour. ║ ║ And the bubbles were wonderful. ║ ║ ║ ║ ║ ╚══════════════════════════════════════════════════╝ ```
42 lines
865 B
Go
42 lines
865 B
Go
package style
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// parsePadding parses 1 - 4 integers from a string and returns them in a top,
|
|
// right, bottom, left order for use in the lipgloss.Padding() method
|
|
func parsePadding(s string) (int, int, int, int) {
|
|
var ints []int
|
|
|
|
tokens := strings.Split(s, " ")
|
|
|
|
// All tokens must be an integer
|
|
for _, token := range tokens {
|
|
parsed, err := strconv.Atoi(token)
|
|
if err != nil {
|
|
return 0, 0, 0, 0
|
|
}
|
|
ints = append(ints, parsed)
|
|
}
|
|
|
|
if len(tokens) == 1 {
|
|
return ints[0], ints[0], ints[0], ints[0]
|
|
}
|
|
|
|
if len(tokens) == 2 {
|
|
return ints[0], ints[1], ints[0], ints[1]
|
|
}
|
|
|
|
if len(tokens) == 4 {
|
|
return ints[0], ints[1], ints[2], ints[3]
|
|
}
|
|
|
|
return 0, 0, 0, 0
|
|
}
|
|
|
|
// parseMargin is an alias for parsePadding since they involve the same logic
|
|
// to parse integers to the same format.
|
|
var parseMargin = parsePadding
|