package lipgloss

import (
	

	
)

// whitespace is a whitespace renderer.
type whitespace struct {
	chars string
	style Style
}

// newWhitespace creates a new whitespace renderer.
func ( ...WhitespaceOption) *whitespace {
	 := &whitespace{}
	for ,  := range  {
		()
	}
	return 
}

// Render whitespaces.
func ( whitespace) ( int) string {
	if .chars == "" {
		.chars = " "
	}

	 := []rune(.chars)
	 := 0
	 := strings.Builder{}

	// Cycle through runes and print them into the whitespace.
	for  := 0;  < ; {
		.WriteRune([])
		// Measure the width of the rune we just wrote, ensuring we always
		// make progress to avoid infinite loops with zero-width characters
		// like tabs.
		 := ansi.StringWidth(string([]))
		if  < 1 {
			 = 1
		}
		 += 
		++
		if  >= len() {
			 = 0
		}
	}

	// Fill any extra gaps white spaces. This might be necessary if any runes
	// are more than one cell wide, which could leave a one-rune gap.
	 :=  - ansi.StringWidth(.String())
	if  > 0 {
		.WriteString(strings.Repeat(" ", ))
	}

	return .style.Render(.String())
}

// WhitespaceOption sets a styling rule for rendering whitespace.
type WhitespaceOption func(*whitespace)

// WithWhitespaceStyle sets the style for the whitespace.
func ( Style) WhitespaceOption {
	return func( *whitespace) {
		.style = 
	}
}

// WithWhitespaceChars sets the characters to be rendered in the whitespace.
func ( string) WhitespaceOption {
	return func( *whitespace) {
		.chars = 
	}
}