theme.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. }
  74. GuildsTreeTheme struct {
  75. AutoExpandFolders bool `toml:"auto_expand_folders"`
  76. Graphics bool `toml:"graphics"`
  77. PrivateChannelColor string `toml:"private_channel_color"`
  78. GuildColor string `toml:"guild_color"`
  79. ChannelColor string `toml:"channel_color"`
  80. }
  81. MessagesTextTheme struct {
  82. ShowNicknames bool `toml:"show_user_nicks"`
  83. ShowUsernameColors bool `toml:"show_user_colors"`
  84. ReplyIndicator string `toml:"reply_indicator"`
  85. ForwardedIndicator string `toml:"forwarded_indicator"`
  86. AuthorStyle StyleWrapper `toml:"author_style"`
  87. MentionStyle StyleWrapper `toml:"mention_style"`
  88. EmojiStyle StyleWrapper `toml:"emoji_style"`
  89. URLStyle StyleWrapper `toml:"url_style"`
  90. AttachmentStyle StyleWrapper `toml:"attachment_style"`
  91. }
  92. )