Skip to content

Commit

Permalink
Proposal: provide tea.Context through a function
Browse files Browse the repository at this point in the history
This pre-initializes a lipgloss.Renderer on the appropriate output,
which should be used by all Bubbles and components to correctly render
taking the terminal capabilities into account. The renderer is stored
in a tea.Context, which can get accessed through tea.Program.
This could also hold other properties like the initial dimensions of
the output or settings like alt-screen or bracketed paste being
supported.

This is a breaking API change as it changes tea.Program's API.
  • Loading branch information
muesli committed Feb 21, 2024
1 parent eed309f commit 9e15991
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions textarea/textarea.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,12 @@ type Model struct {
}

// New creates a new model with default settings.
func New() Model {
func New(r *lipgloss.Renderer) Model {
vp := viewport.New(0, 0)
vp.KeyMap = viewport.KeyMap{}
cur := cursor.New()

focusedStyle, blurredStyle := DefaultStyles()
focusedStyle, blurredStyle := DefaultStyles(r)

m := Model{
CharLimit: defaultCharLimit,
Expand Down Expand Up @@ -282,26 +282,26 @@ func New() Model {

// DefaultStyles returns the default styles for focused and blurred states for
// the textarea.
func DefaultStyles() (Style, Style) {
func DefaultStyles(r *lipgloss.Renderer) (Style, Style) {
focused := Style{
Base: lipgloss.NewStyle(),
CursorLine: lipgloss.NewStyle().Background(lipgloss.AdaptiveColor{Light: "255", Dark: "0"}),
CursorLineNumber: lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "240"}),
EndOfBuffer: lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "254", Dark: "0"}),
LineNumber: lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "249", Dark: "7"}),
Placeholder: lipgloss.NewStyle().Foreground(lipgloss.Color("240")),
Prompt: lipgloss.NewStyle().Foreground(lipgloss.Color("7")),
Text: lipgloss.NewStyle(),
Base: r.NewStyle(),
CursorLine: r.NewStyle().Background(lipgloss.AdaptiveColor{Light: "255", Dark: "0"}),
CursorLineNumber: r.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "240"}),
EndOfBuffer: r.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "254", Dark: "0"}),
LineNumber: r.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "249", Dark: "7"}),
Placeholder: r.NewStyle().Foreground(lipgloss.Color("240")),
Prompt: r.NewStyle().Foreground(lipgloss.Color("7")),
Text: r.NewStyle(),
}
blurred := Style{
Base: lipgloss.NewStyle(),
CursorLine: lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "245", Dark: "7"}),
CursorLineNumber: lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "249", Dark: "7"}),
EndOfBuffer: lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "254", Dark: "0"}),
LineNumber: lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "249", Dark: "7"}),
Placeholder: lipgloss.NewStyle().Foreground(lipgloss.Color("240")),
Prompt: lipgloss.NewStyle().Foreground(lipgloss.Color("7")),
Text: lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "245", Dark: "7"}),
Base: r.NewStyle(),
CursorLine: r.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "245", Dark: "7"}),
CursorLineNumber: r.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "249", Dark: "7"}),
EndOfBuffer: r.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "254", Dark: "0"}),
LineNumber: r.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "249", Dark: "7"}),
Placeholder: r.NewStyle().Foreground(lipgloss.Color("240")),
Prompt: r.NewStyle().Foreground(lipgloss.Color("7")),
Text: r.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "245", Dark: "7"}),
}

return focused, blurred
Expand Down

0 comments on commit 9e15991

Please sign in to comment.