lipgloss icon indicating copy to clipboard operation
lipgloss copied to clipboard

Fixed UnderlineSpaces and StrikethroughSpaces

Open Taz03 opened this issue 1 year ago • 2 comments

fixes #113

Fixed:

  • [x] UnderlineSpaces and StrikethroughSpaces don't show up without Underline and Strikethrough respectively
  • [x] UnderlineSpaces and StrikethroughSpaces show up when explicitly set to false, while Underline and Strikethrough are set to true respectively

Taz03 avatar May 20 '24 20:05 Taz03

I can verify this works correctly.

Code:

package main

// This example demonstrates various Lip Gloss style and layout features.

import (
	"fmt"
	"os"
	"strings"

	"github.com/charmbracelet/lipgloss"
	"golang.org/x/term"
)

const (
	// In real life situations we'd adjust the document to fit the width we've
	// detected. In the case of this example we're hardcoding the width, and
	// later using the detected width only to truncate in order to avoid jaggy
	// wrapping.
	width = 96
)

// Style definitions.
var (

	// General.

	subtle = lipgloss.AdaptiveColor{Light: "#D9DCCF", Dark: "#383838"}

	// Dialog.

	dialogBoxStyle = lipgloss.NewStyle().
			Border(lipgloss.RoundedBorder()).
			BorderForeground(lipgloss.Color("#874BFD")).
			Padding(1, 0).
			BorderTop(true).
			BorderLeft(true).
			BorderRight(true).
			BorderBottom(true)

	buttonStyle = lipgloss.NewStyle().
			Foreground(lipgloss.Color("#FFF7DB")).
			Background(lipgloss.Color("#888B7E")).
			Padding(0, 3).
			MarginTop(1)

	activeButtonStyle = buttonStyle.
				Foreground(lipgloss.Color("#FFF7DB")).
				Background(lipgloss.Color("#F25D94")).
				MarginRight(2).
				Underline(true).UnderlineSpaces(false)

	docStyle = lipgloss.NewStyle().Padding(1, 2, 1, 2)
)

func main() {
	physicalWidth, _, _ := term.GetSize(int(os.Stdout.Fd()))
	doc := strings.Builder{}

	// Dialog
	{
		okButton := activeButtonStyle.Render("Yes Please")
		cancelButton := buttonStyle.Render("Maybe")

		question := lipgloss.NewStyle().Width(50).Align(lipgloss.Center).Render("Are you sure you want to eat marmalade?")
		buttons := lipgloss.JoinHorizontal(lipgloss.Top, okButton, cancelButton)
		ui := lipgloss.JoinVertical(lipgloss.Center, question, buttons)

		dialog := lipgloss.Place(width, 9,
			lipgloss.Center, lipgloss.Center,
			dialogBoxStyle.Render(ui),
			lipgloss.WithWhitespaceChars("猫咪"),
			lipgloss.WithWhitespaceForeground(subtle),
		)

		doc.WriteString(dialog + "\n\n")
	}

	if physicalWidth > 0 {
		docStyle = docStyle.MaxWidth(physicalWidth)
	}

	// Okay, let's print it
	fmt.Println(docStyle.Render(doc.String()))
}

Screenshot: image

Delta456 avatar May 21 '24 09:05 Delta456

Thank you so much @Taz03! Could you provide a test case for these cases?

aymanbagabas avatar May 21 '24 16:05 aymanbagabas