mirror of
				https://github.com/Maks1mS/bubbles.git
				synced 2025-10-30 21:37:13 +03:00 
			
		
		
		
	Add color settings to spinner
This commit is contained in:
		| @@ -5,6 +5,7 @@ import ( | |||||||
| 	"time" | 	"time" | ||||||
|  |  | ||||||
| 	"github.com/charmbracelet/tea" | 	"github.com/charmbracelet/tea" | ||||||
|  | 	"github.com/muesli/termenv" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // Spinner denotes a type of spinner | // Spinner denotes a type of spinner | ||||||
| @@ -24,6 +25,8 @@ var ( | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	assertionErr = errors.New("could not perform assertion on model to what the spinner expects. are you sure you passed the right value?") | 	assertionErr = errors.New("could not perform assertion on model to what the spinner expects. are you sure you passed the right value?") | ||||||
|  |  | ||||||
|  | 	color = termenv.ColorProfile().Color | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // Model contains the state for the spinner. Use NewModel to create new models | // Model contains the state for the spinner. Use NewModel to create new models | ||||||
| @@ -31,6 +34,9 @@ var ( | |||||||
| type Model struct { | type Model struct { | ||||||
| 	Type            Spinner | 	Type            Spinner | ||||||
| 	FPS             int | 	FPS             int | ||||||
|  | 	ForegroundColor string | ||||||
|  | 	BackgroundColor string | ||||||
|  |  | ||||||
| 	frame int | 	frame int | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -66,7 +72,18 @@ func View(model Model) string { | |||||||
| 	if model.frame >= len(s) { | 	if model.frame >= len(s) { | ||||||
| 		return "[error]" | 		return "[error]" | ||||||
| 	} | 	} | ||||||
| 	return s[model.frame] |  | ||||||
|  | 	str := s[model.frame] | ||||||
|  |  | ||||||
|  | 	if model.ForegroundColor != "" || model.BackgroundColor != "" { | ||||||
|  | 		return termenv. | ||||||
|  | 			String(str). | ||||||
|  | 			Foreground(color(model.ForegroundColor)). | ||||||
|  | 			Background(color(model.BackgroundColor)). | ||||||
|  | 			String() | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	return str | ||||||
| } | } | ||||||
|  |  | ||||||
| // Sub is the subscription that allows the spinner to spin | // Sub is the subscription that allows the spinner to spin | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user