config.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package main
  2. import (
  3. "os"
  4. "github.com/BurntSushi/toml"
  5. )
  6. var conf *config
  7. type keybindingsChannelsTree struct {
  8. Focus string
  9. }
  10. type keybindingsMessagesView struct {
  11. Focus string
  12. SelectPrevious string
  13. SelectNext string
  14. SelectFirst string
  15. SelectLast string
  16. Reply string
  17. ReplyMention string
  18. }
  19. type keybindingsMessageInputField struct {
  20. Focus string
  21. }
  22. type keybindings struct {
  23. ChannelsTree keybindingsChannelsTree
  24. MessagesView keybindingsMessagesView
  25. MessageInputField keybindingsMessageInputField
  26. }
  27. type themeBackground struct {
  28. // Main background color for primitives.
  29. Primitive string
  30. // Background color for contrasting elements.
  31. Contrast string
  32. // Background color for even more contrasting elements.
  33. MoreContrast string
  34. }
  35. type themeText struct {
  36. // Primary text.
  37. Primary string
  38. // Secondary text (e.g. labels).
  39. Secondary string
  40. // Tertiary text (e.g. subtitles, notes).
  41. Tertiary string
  42. // Text on primary-colored backgrounds.
  43. Inverse string
  44. // Secondary text on ContrastBackgroundColor-colored backgrounds.
  45. ContrastSecondary string
  46. }
  47. type theme struct {
  48. // Box borders.
  49. Border string
  50. // Box titles.
  51. Title string
  52. // Graphics.
  53. Graphics string
  54. Background themeBackground
  55. Text themeText
  56. }
  57. type config struct {
  58. Token string
  59. Mouse bool
  60. Notifications bool
  61. UserAgent string
  62. GetMessagesLimit int
  63. Theme theme
  64. Keybindings keybindings
  65. }
  66. func loadConfig() *config {
  67. u, err := os.UserHomeDir()
  68. if err != nil {
  69. panic(err)
  70. }
  71. configPath := u + "/.config/discordo.toml"
  72. if _, err = os.Stat(configPath); os.IsNotExist(err) {
  73. f, err := os.Create(configPath)
  74. if err != nil {
  75. panic(err)
  76. }
  77. defer f.Close()
  78. c := config{
  79. Mouse: true,
  80. Notifications: true,
  81. UserAgent: "" +
  82. "Mozilla/5.0 (X11; Linux x86_64) " +
  83. "AppleWebKit/537.36 (KHTML, like Gecko) " +
  84. "Chrome/92.0.4515.131 Safari/537.36",
  85. GetMessagesLimit: 50,
  86. Theme: theme{
  87. Border: "white",
  88. Title: "white",
  89. Graphics: "white",
  90. Background: themeBackground{
  91. Primitive: "black",
  92. Contrast: "blue",
  93. MoreContrast: "green",
  94. },
  95. Text: themeText{
  96. Primary: "white",
  97. Secondary: "yellow",
  98. Tertiary: "green",
  99. Inverse: "blue",
  100. ContrastSecondary: "darkcyan",
  101. },
  102. },
  103. Keybindings: keybindings{
  104. ChannelsTree: keybindingsChannelsTree{
  105. Focus: "Alt+Rune[1]",
  106. },
  107. MessagesView: keybindingsMessagesView{
  108. Focus: "Alt+Rune[2]",
  109. SelectPrevious: "Up",
  110. SelectNext: "Down",
  111. SelectFirst: "Home",
  112. SelectLast: "End",
  113. Reply: "Rune[r]",
  114. ReplyMention: "Rune[R]",
  115. },
  116. MessageInputField: keybindingsMessageInputField{
  117. Focus: "Alt+Rune[3]",
  118. },
  119. },
  120. }
  121. err = toml.NewEncoder(f).Encode(c)
  122. if err != nil {
  123. panic(err)
  124. }
  125. return &c
  126. }
  127. var c config
  128. _, err = toml.DecodeFile(configPath, &c)
  129. if err != nil {
  130. panic(err)
  131. }
  132. return &c
  133. }