lipgloss-convert
String conversion functions for lipgloss Styles.
This library defines the following two functions:
type Style = lipgloss.Style
// Import reads style specifications from the input string
// and sets the corresponding properties in the dst style.
func Import(dst Style, input string) (Style, error)
// Export emits style specifications that represent
// the given style.
func Export(s Style) string
For example:
import (
"fmt"
"github.com/charmbracelet/lipgloss"
lipglossc "github.com/knz/lipgloss-convert"
)
func main() {
style := lipgloss.NewStyle().
Bold(true).
Align(lipgloss.Center).
Foreground(lipgloss.Color("#FAFAFA")).
Background(lipgloss.AdaptiveColor{"#7D56F4", "#112233"})).
BorderTopForeground(lipgloss.Color("12")).
BorderStyle(lipgloss.RoundedBorder()).
PaddingTop(2).
PaddingLeft(4).
Width(22)
fmt.Println(lipglossc.Export(s))
}
Displays:
align: 0.5;
background: adaptive(#7D56F4,#112233);
bold: true;
border-style: border("─","─","│","│","╭","╮","╯","╰");
border-top-foreground: 12;
foreground: #FAFAFA;
padding-left: 4;
padding-top: 2;
width: 22;
Then using the Import()
function on the result will recover the original lipgloss.Style
.
See the lipgloss documentation for details. This library automatically supports all the lipgloss properties, as follows:
Foreground
in lipgloss becomesforeground
in the textual syntax.UnderlineSpaces
becomesunderline-spaces
.- etc.
It also supports the following special values:
-
For colors:
foreground: #abc; foreground: #aabbcc; foreground: 123; foreground: adaptive(<color>,<color>);
-
Padding, margin etc which can take multiple values at once:
margin: 10 margin: 10 20 margin: 10 20 10 20
-
Border styles:
border-style: rounded; border-style: hidden; border-style: normal; border-style: thick; border-style: double;
-
Border styles with top/bottom or left/right selection (see the doc for
lipgloss.Style
‘sBorder()
method):border-style: normal true false; border-style: normal true false false true;