theme.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package config
  2. import (
  3. "github.com/ayn2op/tview"
  4. "github.com/gdamore/tcell/v2"
  5. )
  6. type BorderSetWrapper struct{ tview.BorderSet }
  7. func (bw *BorderSetWrapper) UnmarshalTOML(v any) error {
  8. switch v.(string) {
  9. case "plain":
  10. bw.BorderSet = tview.BorderSetPlain()
  11. case "round":
  12. bw.BorderSet = tview.BorderSetRound()
  13. case "thick":
  14. bw.BorderSet = tview.BorderSetThick()
  15. case "double":
  16. bw.BorderSet = tview.BorderSetDouble()
  17. }
  18. return nil
  19. }
  20. type AlignmentWrapper struct{ tview.Alignment }
  21. func (aw *AlignmentWrapper) UnmarshalTOML(v any) error {
  22. switch v.(string) {
  23. case "left":
  24. aw.Alignment = tview.AlignmentLeft
  25. case "center":
  26. aw.Alignment = tview.AlignmentCenter
  27. case "right":
  28. aw.Alignment = tview.AlignmentRight
  29. }
  30. return nil
  31. }
  32. type StyleWrapper struct{ tcell.Style }
  33. func NewStyleWrapper(style tcell.Style) StyleWrapper {
  34. return StyleWrapper{Style: style}
  35. }
  36. func (sw *StyleWrapper) UnmarshalTOML(v any) error {
  37. m, ok := v.(map[string]any)
  38. if !ok {
  39. return nil
  40. }
  41. for k, v := range m {
  42. s, ok := v.(string)
  43. if !ok {
  44. continue
  45. }
  46. switch k {
  47. case "foreground":
  48. color := tcell.GetColor(s)
  49. sw.Style = sw.Foreground(color)
  50. case "background":
  51. color := tcell.GetColor(s)
  52. sw.Style = sw.Background(color)
  53. }
  54. }
  55. return nil
  56. }
  57. type (
  58. BorderTheme struct {
  59. Enabled bool `toml:"enabled"`
  60. Padding [4]int `toml:"padding"`
  61. Set BorderSetWrapper `toml:"set"`
  62. Style StyleWrapper `toml:"style"`
  63. ActiveStyle StyleWrapper `toml:"active_style"`
  64. }
  65. TitleTheme struct {
  66. Style StyleWrapper `toml:"style"`
  67. ActiveStyle StyleWrapper `toml:"active_style"`
  68. Alignment AlignmentWrapper `toml:"alignment"`
  69. }
  70. Theme struct {
  71. BackgroundColor string `toml:"background_color"`
  72. Title TitleTheme `toml:"title"`
  73. Border BorderTheme `toml:"border"`
  74. GuildsTree GuildsTreeTheme `toml:"guilds_tree"`
  75. MessagesText MessagesTextTheme `toml:"messages_text"`
  76. Autocomplete AutocompleteTheme `toml:"autocomplete"`
  77. }
  78. GuildsTreeTheme struct {
  79. AutoExpandFolders bool `toml:"auto_expand_folders"`
  80. Graphics bool `toml:"graphics"`
  81. GraphicsColor string `toml:"graphics_color"`
  82. PrivateChannelColor string `toml:"private_channel_color"`
  83. GuildColor string `toml:"guild_color"`
  84. ChannelColor string `toml:"channel_color"`
  85. }
  86. MessagesTextTheme struct {
  87. ShowNicknames bool `toml:"show_user_nicks"`
  88. ShowUsernameColors bool `toml:"show_user_colors"`
  89. ReplyIndicator string `toml:"reply_indicator"`
  90. ForwardedIndicator string `toml:"forwarded_indicator"`
  91. AuthorStyle StyleWrapper `toml:"author_style"`
  92. MentionStyle StyleWrapper `toml:"mention_style"`
  93. EmojiStyle StyleWrapper `toml:"emoji_style"`
  94. URLStyle StyleWrapper `toml:"url_style"`
  95. AttachmentStyle StyleWrapper `toml:"attachment_style"`
  96. }
  97. AutocompleteTheme struct {
  98. ShowNicknames bool `toml:"show_user_nicks"`
  99. ShowUsernameColors bool `toml:"show_user_colors"`
  100. MinWidth uint `toml:"min_width"`
  101. MaxHeight uint `toml:"max_height"`
  102. }
  103. )