| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- package issho
- import (
- "fmt"
- "github.com/charmbracelet/bubbles/viewport"
- tea "github.com/charmbracelet/bubbletea"
- "github.com/charmbracelet/lipgloss"
- )
- // The main bubbletea Model
- type Model struct {
- Issue Issue
- 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 [issue.Issue]
- func (m Model) renderIssue() string {
- var output string
- // title
- output = output + titleStyle.Render(m.Issue.Title)
- // status
- output = output + fmt.Sprintf("\n%s", statusStyle.Render(m.Issue.Status.Data))
- // variadics
- var tags string
- for _, field := range m.Issue.Tags.Fields {
- tags = tags + field.Path + ", "
- }
- var blockedby string
- for _, field := range m.Issue.Blockedby.Fields {
- blockedby = blockedby + field.Path + ", "
- }
- if len(m.Issue.Tags.Fields) > 0 {
- output = output + variadicTitleStyle.Render("\nTags:")
- output = output + fmt.Sprintf("\n%s", variadicDataStyle.Render(tags))
- }
- if len(m.Issue.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.Issue.Description.Data)
- return borderStyle.Render(output)
- }
- // Wraps [issue.Model.renderIssue] in a viewport
- func (m Model) View() string {
- return m.renderIssue()
- }
|