| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- // TODO Implement Bubbletea
- // TODO Replace bug.go implementation of [Bug.View]
- package buggo
- import (
- "fmt"
- "github.com/charmbracelet/bubbles/viewport"
- tea "github.com/charmbracelet/bubbletea"
- "github.com/charmbracelet/lipgloss"
- )
- // The main bubbletea Model
- type Model struct {
- Bug Bug
- Path string
- viewport viewport.Model
- }
- func (m Model) Init() tea.Cmd { return nil }
- // Handles quit logic and viewport scroll and size updates
- func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
- switch msg.(type) {
- case tea.KeyMsg:
- return m, tea.Quit
- }
- return m, nil
- }
- // [lipgloss] style definitions
- var (
- titleStyle = lipgloss.NewStyle().
- Bold(true).
- Underline(true)
- statusStyle = lipgloss.NewStyle().
- Faint(true).
- Italic(true)
- variadicTitleStyle = lipgloss.NewStyle().
- Align(lipgloss.Left).
- Italic(true)
- variadicDataStyle = lipgloss.NewStyle().
- Width(40).
- BorderStyle(lipgloss.ASCIIBorder())
- borderStyle = lipgloss.NewStyle().
- Padding(2).
- Margin(1).
- BorderStyle(lipgloss.NormalBorder())
- )
- // Handles all view logic for [buggo.Bug]
- func (m Model) renderBug() string {
- var output string
- // title
- output = output + titleStyle.Render(m.Bug.Title)
- // status
- output = output + fmt.Sprintf("\n%s", statusStyle.Render(m.Bug.Status.Data))
- // variadics
- var tags string
- for _, field := range m.Bug.Tags.Fields {
- tags = tags + field.Path + ", "
- }
- var blockedby string
- for _, field := range m.Bug.Blockedby.Fields {
- blockedby = blockedby + field.Path + ", "
- }
- if len(m.Bug.Tags.Fields) > 0 {
- output = output + variadicTitleStyle.Render("\nTags:")
- output = output + fmt.Sprintf("\n%s", variadicDataStyle.Render(tags))
- }
- if len(m.Bug.Blockedby.Fields) > 0 {
- output = output + variadicTitleStyle.Render("\n\nBlockedby:")
- output = output + fmt.Sprintf("\n%s", variadicDataStyle.Render(blockedby))
- }
- // description
- output = output + "\n---"
- output = output + titleStyle.Render("\nDescription:")
- output = output + fmt.Sprintf("\n%s", m.Bug.Description.Data)
- return borderStyle.Render(output)
- }
- // Wraps [buggo.Model.renderBug] in a viewport
- func (m Model) View() string {
- return m.renderBug()
- }
|