lipglossc

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2022 License: Apache-2.0 Imports: 7 Imported by: 1

README

lipgloss-convert

Latest Release GoDoc Build Status Go ReportCard Coverage Status

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

Exporting styles to text

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;

Importing styles from text

The Import function applies the text directives specified in its input argument to the style also provided as argument. Other properties already in the style remain unchanged.

Which properties are supported? See the lipgloss documentation for details. Import automatically supports all the lipgloss properties, as follows:

  • Foreground in lipgloss becomes foreground in the textual syntax.
  • UnderlineSpaces becomes underline-spaces.
  • etc.

Import also supports the following special cases:

  • For colors:

    foreground: #abc;
    foreground: #aabbcc;
    foreground: 123;
    foreground: adaptive(<color>,<color>);
    foreground: complete(<truecolor>,<ansi256color>,<ansicolor>);
    foreground: adaptive(<color>,<color>);
    foreground: adaptive(complete(<truecolor>,<ansi256color>,<ansicolor>),complete(<truecolor>,<ansi256color>,<ansicolor>));
    
  • Padding, margin, align 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's Border() method):

    border: normal true false;
    border: normal true false false true;
    
  • Resetting a style with clear: this erases all the properties in the style, to start with a fresh style.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Export

func Export(s S, opts ...ExportOption) string

Export emits style specifications that represent the given style. If includeDefaults is set, all the fields set to default values are also included in the output.

Types

type ExportOption

type ExportOption func(*options)

func WithExportDefaults

func WithExportDefaults() ExportOption

WithExportDefaults includes the fields that are set to default values.

func WithSeparator

func WithSeparator(sep string) ExportOption

WithSeparator sets the separator between directives.

type S

type S = lipgloss.Style

S is a handy alias to simplify declarations in this library.

func Import

func Import(dst S, input string) (S, error)

Import reads style specifications from the input string and sets the corresponding properties in the dst style.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL