style.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package diffview
  2. import (
  3. "charm.land/lipgloss/v2"
  4. "github.com/charmbracelet/x/exp/charmtone"
  5. )
  6. // LineStyle defines the styles for a given line type in the diff view.
  7. type LineStyle struct {
  8. LineNumber lipgloss.Style
  9. Symbol lipgloss.Style
  10. Code lipgloss.Style
  11. }
  12. // Style defines the overall style for the diff view, including styles for
  13. // different line types such as divider, missing, equal, insert, and delete
  14. // lines.
  15. type Style struct {
  16. DividerLine LineStyle
  17. MissingLine LineStyle
  18. EqualLine LineStyle
  19. InsertLine LineStyle
  20. DeleteLine LineStyle
  21. }
  22. // DefaultLightStyle provides a default light theme style for the diff view.
  23. func DefaultLightStyle() Style {
  24. return Style{
  25. DividerLine: LineStyle{
  26. LineNumber: lipgloss.NewStyle().
  27. Foreground(charmtone.Iron).
  28. Background(charmtone.Thunder),
  29. Code: lipgloss.NewStyle().
  30. Foreground(charmtone.Oyster).
  31. Background(charmtone.Anchovy),
  32. },
  33. MissingLine: LineStyle{
  34. LineNumber: lipgloss.NewStyle().
  35. Background(charmtone.Ash),
  36. Code: lipgloss.NewStyle().
  37. Background(charmtone.Ash),
  38. },
  39. EqualLine: LineStyle{
  40. LineNumber: lipgloss.NewStyle().
  41. Foreground(charmtone.Charcoal).
  42. Background(charmtone.Ash),
  43. Code: lipgloss.NewStyle().
  44. Foreground(charmtone.Pepper).
  45. Background(charmtone.Salt),
  46. },
  47. InsertLine: LineStyle{
  48. LineNumber: lipgloss.NewStyle().
  49. Foreground(charmtone.Turtle).
  50. Background(lipgloss.Color("#c8e6c9")),
  51. Symbol: lipgloss.NewStyle().
  52. Foreground(charmtone.Turtle).
  53. Background(lipgloss.Color("#e8f5e9")),
  54. Code: lipgloss.NewStyle().
  55. Foreground(charmtone.Pepper).
  56. Background(lipgloss.Color("#e8f5e9")),
  57. },
  58. DeleteLine: LineStyle{
  59. LineNumber: lipgloss.NewStyle().
  60. Foreground(charmtone.Cherry).
  61. Background(lipgloss.Color("#ffcdd2")),
  62. Symbol: lipgloss.NewStyle().
  63. Foreground(charmtone.Cherry).
  64. Background(lipgloss.Color("#ffebee")),
  65. Code: lipgloss.NewStyle().
  66. Foreground(charmtone.Pepper).
  67. Background(lipgloss.Color("#ffebee")),
  68. },
  69. }
  70. }
  71. // DefaultDarkStyle provides a default dark theme style for the diff view.
  72. func DefaultDarkStyle() Style {
  73. return Style{
  74. DividerLine: LineStyle{
  75. LineNumber: lipgloss.NewStyle().
  76. Foreground(charmtone.Smoke).
  77. Background(charmtone.Sapphire),
  78. Code: lipgloss.NewStyle().
  79. Foreground(charmtone.Smoke).
  80. Background(charmtone.Ox),
  81. },
  82. MissingLine: LineStyle{
  83. LineNumber: lipgloss.NewStyle().
  84. Background(charmtone.Charcoal),
  85. Code: lipgloss.NewStyle().
  86. Background(charmtone.Charcoal),
  87. },
  88. EqualLine: LineStyle{
  89. LineNumber: lipgloss.NewStyle().
  90. Foreground(charmtone.Ash).
  91. Background(charmtone.Charcoal),
  92. Code: lipgloss.NewStyle().
  93. Foreground(charmtone.Salt).
  94. Background(charmtone.Pepper),
  95. },
  96. InsertLine: LineStyle{
  97. LineNumber: lipgloss.NewStyle().
  98. Foreground(charmtone.Turtle).
  99. Background(lipgloss.Color("#293229")),
  100. Symbol: lipgloss.NewStyle().
  101. Foreground(charmtone.Turtle).
  102. Background(lipgloss.Color("#303a30")),
  103. Code: lipgloss.NewStyle().
  104. Foreground(charmtone.Salt).
  105. Background(lipgloss.Color("#303a30")),
  106. },
  107. DeleteLine: LineStyle{
  108. LineNumber: lipgloss.NewStyle().
  109. Foreground(charmtone.Cherry).
  110. Background(lipgloss.Color("#332929")),
  111. Symbol: lipgloss.NewStyle().
  112. Foreground(charmtone.Cherry).
  113. Background(lipgloss.Color("#3a3030")),
  114. Code: lipgloss.NewStyle().
  115. Foreground(charmtone.Salt).
  116. Background(lipgloss.Color("#3a3030")),
  117. },
  118. }
  119. }