tui.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // TODO Implement Bubbletea
  2. // TODO Replace bug.go implementation of [Bug.View]
  3. package buggo
  4. import (
  5. "fmt"
  6. "github.com/charmbracelet/bubbles/viewport"
  7. tea "github.com/charmbracelet/bubbletea"
  8. "github.com/charmbracelet/lipgloss"
  9. )
  10. // The main bubbletea Model
  11. type Model struct {
  12. Bug Bug
  13. Path string
  14. viewport viewport.Model
  15. }
  16. func (m Model) Init() tea.Cmd { return nil }
  17. // Handles quit logic and viewport scroll and size updates
  18. func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
  19. switch msg.(type) {
  20. case tea.KeyMsg:
  21. return m, tea.Quit
  22. }
  23. return m, nil
  24. }
  25. // [lipgloss] style definitions
  26. var (
  27. titleStyle = lipgloss.NewStyle().
  28. Bold(true).
  29. Underline(true)
  30. statusStyle = lipgloss.NewStyle().
  31. Faint(true).
  32. Italic(true)
  33. variadicTitleStyle = lipgloss.NewStyle().
  34. Align(lipgloss.Left).
  35. Italic(true)
  36. variadicDataStyle = lipgloss.NewStyle().
  37. Width(40).
  38. BorderStyle(lipgloss.ASCIIBorder())
  39. borderStyle = lipgloss.NewStyle().
  40. Padding(2).
  41. Margin(1).
  42. BorderStyle(lipgloss.NormalBorder())
  43. )
  44. // Handles all view logic for [buggo.Bug]
  45. func (m Model) renderBug() string {
  46. var output string
  47. // title
  48. output = output + titleStyle.Render(m.Bug.Title)
  49. // status
  50. output = output + fmt.Sprintf("\n%s", statusStyle.Render(m.Bug.Status.Data))
  51. // variadics
  52. var tags string
  53. for _, field := range m.Bug.Tags.Fields {
  54. tags = tags + field.Path + ", "
  55. }
  56. var blockedby string
  57. for _, field := range m.Bug.Blockedby.Fields {
  58. blockedby = blockedby + field.Path + ", "
  59. }
  60. if len(m.Bug.Tags.Fields) > 0 {
  61. output = output + variadicTitleStyle.Render("\nTags:")
  62. output = output + fmt.Sprintf("\n%s", variadicDataStyle.Render(tags))
  63. }
  64. if len(m.Bug.Blockedby.Fields) > 0 {
  65. output = output + variadicTitleStyle.Render("\n\nBlockedby:")
  66. output = output + fmt.Sprintf("\n%s", variadicDataStyle.Render(blockedby))
  67. }
  68. // description
  69. output = output + "\n---"
  70. output = output + titleStyle.Render("\nDescription:")
  71. output = output + fmt.Sprintf("\n%s", m.Bug.Description.Data)
  72. return borderStyle.Render(output)
  73. }
  74. // Wraps [buggo.Model.renderBug] in a viewport
  75. func (m Model) View() string {
  76. return m.renderBug()
  77. }