text.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package util
  2. import (
  3. "strings"
  4. "github.com/charmbracelet/lipgloss/v2"
  5. )
  6. // PreventHyphenBreaks replaces regular hyphens with non-breaking hyphens to prevent
  7. // sparse word breaks in hyphenated terms like "claude-code-action".
  8. // This improves readability by keeping hyphenated words together.
  9. func PreventHyphenBreaks(text string) string {
  10. return strings.ReplaceAll(text, "-", "\u2011")
  11. }
  12. // RestoreHyphens converts non-breaking hyphens back to regular hyphens.
  13. // This should be called after text processing (like word wrapping) is complete.
  14. func RestoreHyphens(text string) string {
  15. return strings.ReplaceAll(text, "\u2011", "-")
  16. }
  17. // ProcessTextWithHyphens applies hyphen preservation to text during processing.
  18. // It wraps the provided processFunc with hyphen handling.
  19. func ProcessTextWithHyphens(text string, processFunc func(string) string) string {
  20. preserved := PreventHyphenBreaks(text)
  21. processed := processFunc(preserved)
  22. return RestoreHyphens(processed)
  23. }
  24. // GetMessageContainerFrame calculates the actual horizontal frame size
  25. // (padding + borders) for message containers based on current theme.
  26. func GetMessageContainerFrame() int {
  27. style := lipgloss.NewStyle().
  28. BorderStyle(lipgloss.ThickBorder()).
  29. BorderLeft(true).
  30. BorderRight(true).
  31. PaddingLeft(2).
  32. PaddingRight(2)
  33. return style.GetHorizontalFrameSize()
  34. }
  35. // GetMarkdownContainerFrame calculates the actual horizontal frame size
  36. // for markdown containers based on current theme.
  37. func GetMarkdownContainerFrame() int {
  38. // Markdown containers use the same styling as message containers
  39. return GetMessageContainerFrame()
  40. }