github.com/iamlucasvieira/ComTemplate@v0.0.0-20231228160247-43229117158f/pkg/cli/styles.go (about)

     1  package cli
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/charmbracelet/lipgloss"
     7  )
     8  
     9  const (
    10  	marginLeft   = 2
    11  	marginTop    = 1
    12  	marginBottom = 1
    13  )
    14  
    15  var (
    16  	subtle    = lipgloss.AdaptiveColor{Light: "#D9DCCF", Dark: "#383838"}
    17  	highlight = lipgloss.AdaptiveColor{Light: "#874BFD", Dark: "#7D56F4"}
    18  	special   = lipgloss.AdaptiveColor{Light: "#43BF6D", Dark: "#73F59F"}
    19  
    20  	Shell = lipgloss.NewStyle().
    21  		MarginLeft(marginLeft).
    22  		Render
    23  
    24  	ShellMargin = lipgloss.NewStyle().
    25  			MarginTop(marginTop).
    26  			MarginBottom(marginBottom).
    27  			MarginLeft(marginLeft).
    28  			Render
    29  
    30  	List = lipgloss.NewStyle().
    31  		BorderForeground(subtle)
    32  
    33  	Header = lipgloss.NewStyle().
    34  		Foreground(special).
    35  		Bold(true).
    36  		BorderStyle(lipgloss.NormalBorder()).
    37  		BorderBottom(true).
    38  		BorderForeground(subtle).
    39  		Render
    40  
    41  	ListItem = lipgloss.NewStyle().PaddingLeft(2).Render
    42  
    43  	tick = lipgloss.NewStyle().SetString("-").
    44  		Foreground(highlight).
    45  		PaddingRight(1).
    46  		String()
    47  
    48  	ListItemTick = func(s string) string {
    49  		return tick + lipgloss.NewStyle().
    50  			Render(s)
    51  	}
    52  
    53  	TextHighlight = lipgloss.NewStyle().
    54  			Foreground(highlight).
    55  			Render
    56  )
    57  
    58  // RenderList renders a list of strings
    59  func RenderList(title string, items []string) string {
    60  	// Transform []string into []ListItemTick
    61  	parts := make([]string, 0, len(items)+1)
    62  	parts = append(parts, Header(title))
    63  
    64  	// Add each item, transformed by ListItemTick, to the slice
    65  	for _, item := range items {
    66  		parts = append(parts, ListItemTick(item))
    67  	}
    68  
    69  	l := lipgloss.JoinVertical(
    70  		lipgloss.Top,
    71  		parts...,
    72  	)
    73  
    74  	return ShellMargin(List.Render(l))
    75  }
    76  
    77  // Write prints a list of strings to the terminal
    78  func Write(items ...string) {
    79  	vertical := lipgloss.JoinVertical(lipgloss.Top, items...)
    80  	fmt.Println(ShellMargin(vertical))
    81  }
    82  
    83  // WriteNoMargin prints a list of strings to the terminal
    84  func WriteNoMargin(items ...string) {
    85  	vertical := lipgloss.JoinVertical(lipgloss.Top, items...)
    86  	fmt.Println(Shell(vertical))
    87  }