bug.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Data and interface definitions for bugs
  2. package buggo
  3. import (
  4. "fmt"
  5. "github.com/charmbracelet/lipgloss"
  6. )
  7. type Bug struct {
  8. Title string // The title of the bug in human readable format
  9. Description Field // The description of the bug
  10. Status Field // The status of the bug
  11. Tags VariadicField // A slice of [buggo.Tag] structs
  12. Blockedby VariadicField // A slice of [buggo.Blocker] structs
  13. Path string // The path to the bug
  14. machineTitle string // The machine parseable bug title
  15. }
  16. // A struct representing data that is tied to data on disk
  17. type Field struct {
  18. path string
  19. data string
  20. }
  21. // VariadicFields hold lists of Field objects.
  22. type VariadicField struct {
  23. Path string // The associated path on disk of Fields represented by Variadic Field
  24. Fields []Field // The underlying slice of Field objects
  25. }
  26. // Renders a bug as text
  27. func (b Bug) View() string {
  28. headerStyle := lipgloss.NewStyle().
  29. Width(120).
  30. Foreground(lipgloss.Color("#00FF00"))
  31. subtitleStyle := lipgloss.NewStyle().
  32. Width(120).
  33. Faint(true).
  34. Underline(true).
  35. Italic(true)
  36. tagsStyle := lipgloss.NewStyle().
  37. Width(50).
  38. Italic(true)
  39. var tags string
  40. for _, tag := range b.Tags.Fields {
  41. tags = tags + string(tag.data) + ", "
  42. }
  43. var blockers string
  44. for _, blocker := range b.Blockedby.Fields {
  45. blockers = blockers + string(blocker.data) + ", "
  46. }
  47. return fmt.Sprintf("%s\n\n%s\n---\nTags:\t%s\nBlockedby:\t%s\n---\n%s",
  48. headerStyle.Render(b.Title),
  49. subtitleStyle.Render("status:\t"+b.Status.data),
  50. tagsStyle.Render(tags),
  51. tagsStyle.Render(blockers),
  52. b.Description,
  53. )
  54. }
  55. // Parses human readable titles as path
  56. func (b *Bug) parseHumanToMachine() string { return "" } // TODO: implement!
  57. // Parses machine parseable titles as human readable
  58. func (b *Bug) parseMachineToHuman() string { return "" } // TODO: implement!