This repository has been archived on 2024-07-28. You can view files and clone it, but cannot push or open issues or pull requests.
Files
cairde/internal/models/spane.go

53 lines
974 B
Go

package models
import (
"strings"
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
var viewportStyle = lipgloss.NewStyle().
BorderStyle(lipgloss.NormalBorder()).
MarginLeft(1)
type statusPaneModel struct {
viewport viewport.Model
width int
heightOffset int
height int
}
func newStatusPaneModel() statusPaneModel {
return statusPaneModel{}
}
func (m statusPaneModel) Init() tea.Cmd {
return nil
}
func (m statusPaneModel) Update(msg tea.Msg) (statusPaneModel, tea.Cmd) {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.width = msg.Width
m.height = msg.Height - m.heightOffset - 4
m.viewport = viewport.New(msg.Width, m.height)
}
return m, nil
}
func (m statusPaneModel) View() string {
body := strings.Builder{}
body.WriteString(
viewportStyle.
Width(m.width - 2).
Height(m.height).
Render(m.viewport.View()),
)
return body.String()
}