Skip to content

Conversation

meowgorithm
Copy link
Member

This replaces CursorView (and potentially ViewModel) with a simpler, more extensible API.

type Viewable interface {
    View() View
}

In practice, it looks like:

// A simple case where the view is just a string.
func (m Model) View() tea.View {
    // ...
    return tea.NewView(str)
}

// A more complex case where the view is a string with
// cursor and background color metadata.
func (m Model) View() tea.View {
    // ...
    v := tea.NewView(str)
    v.SetCursor(cur)
    v.SetBackgroundColor(c)
    return v
}

Properties like the cursor and background color are optional, and View could be extended down the road to include other metadata, like lipgloss.Canvas. Note that the background color should be attached to the view to avoid race conditions like we saw with tea.SetCursorPosition.

It would be my suggestion not to merge Viewable with Model in order to eventually support view alternatives like the following:

func (m Model) View(b *screen.Buffer)

@meowgorithm meowgorithm changed the title V2 viewable (v2) A Unified View Interface May 26, 2025
@meowgorithm meowgorithm changed the title (v2) A Unified View Interface (v2) A unified view interface May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants