bug.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 string // The description of the bug
  10. Status string // The status of the bug
  11. Tags []Tag // A slice of [buggo.Tag] structs
  12. Blockedby []Blocker // A slice of [buggo.Blocker] structs
  13. path string // The path to the bug
  14. machineTitle string // The machine parseable bug title
  15. }
  16. type (
  17. Tag string // A string representing a single tag
  18. Blocker string // A string representing a single blocker
  19. )
  20. // Reads a bug from disk
  21. // func (b Bug) Read() (bug Bug, err error) { return Bug{}, nil }
  22. // Writes a bug to disk
  23. func (b Bug) Write() (success bool, err error) { return false, nil }
  24. // Removes a bug from disk
  25. func (b Bug) Delete() (success bool, err error) { return false, nil }
  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 {
  41. tags = tags + string(tag) + ", "
  42. }
  43. var blockers string
  44. for _, blocker := range b.Blockedby {
  45. blockers = blockers + string(blocker) + ", "
  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),
  50. tagsStyle.Render(tags),
  51. tagsStyle.Render(blockers),
  52. b.Description,
  53. )
  54. }