theme.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 (sw *StyleWrapper) UnmarshalTOML(v any) error {
  34. m, ok := v.(map[string]any)
  35. if !ok {
  36. return nil
  37. }
  38. for k, v := range m {
  39. s, ok := v.(string)
  40. if !ok {
  41. continue
  42. }
  43. switch k {
  44. case "foreground":
  45. color := tcell.GetColor(s)
  46. sw.Style = sw.Foreground(color)
  47. case "background":
  48. color := tcell.GetColor(s)
  49. sw.Style = sw.Background(color)
  50. }
  51. }
  52. return nil
  53. }
  54. type (
  55. BorderTheme struct {
  56. Enabled bool `toml:"enabled"`
  57. Padding [4]int `toml:"padding"`
  58. Set BorderSetWrapper `toml:"set"`
  59. Style StyleWrapper `toml:"style"`
  60. ActiveStyle StyleWrapper `toml:"active_style"`
  61. }
  62. TitleTheme struct {
  63. Style StyleWrapper `toml:"style"`
  64. ActiveStyle StyleWrapper `toml:"active_style"`
  65. Alignment AlignmentWrapper `toml:"alignment"`
  66. }
  67. Theme struct {
  68. BackgroundColor string `toml:"background_color"`
  69. Title TitleTheme `toml:"title"`
  70. Border BorderTheme `toml:"border"`
  71. GuildsTree GuildsTreeTheme `toml:"guilds_tree"`
  72. MessagesText MessagesTextTheme `toml:"messages_text"`
  73. Autocomplete AutocompleteTheme `toml:"autocomplete"`
  74. }
  75. GuildsTreeTheme struct {
  76. AutoExpandFolders bool `toml:"auto_expand_folders"`
  77. Graphics bool `toml:"graphics"`
  78. GraphicsColor string `toml:"graphics_color"`
  79. PrivateChannelColor string `toml:"private_channel_color"`
  80. GuildColor string `toml:"guild_color"`
  81. ChannelColor string `toml:"channel_color"`
  82. }
  83. MessagesTextTheme struct {
  84. ShowNicknames bool `toml:"show_user_nicks"`
  85. ShowUsernameColors bool `toml:"show_user_colors"`
  86. ReplyIndicator string `toml:"reply_indicator"`
  87. ForwardedIndicator string `toml:"forwarded_indicator"`
  88. AuthorStyle StyleWrapper `toml:"author_style"`
  89. MentionStyle StyleWrapper `toml:"mention_style"`
  90. EmojiStyle StyleWrapper `toml:"emoji_style"`
  91. URLStyle StyleWrapper `toml:"url_style"`
  92. AttachmentStyle StyleWrapper `toml:"attachment_style"`
  93. }
  94. AutocompleteTheme struct {
  95. ShowNicknames bool `toml:"show_user_nicks"`
  96. ShowUsernameColors bool `toml:"show_user_colors"`
  97. MinWidth uint `toml:"min_width"`
  98. MaxHeight uint `toml:"max_height"`
  99. }
  100. )