1
0

config.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package editor
  2. import (
  3. "github.com/creasty/defaults"
  4. "github.com/gdamore/tcell/v3"
  5. )
  6. type Config struct {
  7. StyleDefault tcell.Style
  8. Style Style
  9. }
  10. type Style struct {
  11. MainBackground string `default:"#090603"`
  12. MainForeground string `default:"#dddddd"`
  13. LineNumberBackground string `default:"#090603"`
  14. LineNumberForeground string `default:"#dddddd"`
  15. CursorColor string `default:"#777777"`
  16. CursorColorWrite string `default:"#dddddd"`
  17. PaletteBarBackground string `default:"#3b3b3b"`
  18. PaletteBarForeground string `default:"#dddddd"`
  19. PaletteInputBackground string `default:"#090603"`
  20. PaletteInputForeground string `default:"#dddddd"`
  21. InfoMsgBackground string `default:"#090603"`
  22. InfoMsgForeground string `default:"#dddddd"`
  23. WarnMsgBackground string `default:"#090603"`
  24. WarnMsgForeground string `default:"#efc541"`
  25. ErrorMsgBackground string `default:"#090603"`
  26. ErrorMsgForeground string `default:"#ff5e56"`
  27. WorkspaceBackground string `default:"#3b3b3b"`
  28. WorkspaceForeground string `default:"#b9b9b9"`
  29. WorkspaceBackgroundActive string `default:"#3b3b3b"`
  30. WorkspaceForegroundActive string `default:"#dddddd"`
  31. TabBackground string `default:"#3b3b3b"`
  32. TabForeground string `default:"#b9b9b9"`
  33. TabBackgroundActive string `default:"#3b3b3b"`
  34. TabForegroundActive string `default:"#dddddd"`
  35. }
  36. func DefaultConfig() Config {
  37. config := Config{}
  38. if err := defaults.Set(&config); err != nil {
  39. panic(err)
  40. }
  41. config.StyleDefault = tcell.StyleDefault.Background(tcell.GetColor(config.Style.MainBackground)).Foreground(tcell.GetColor(config.Style.MainForeground))
  42. return config
  43. }
  44. func (m *Model) ReloadConfig() {
  45. m.Config.StyleDefault = m.Config.StyleDefault.Background(tcell.GetColor(m.Config.Style.MainBackground)).Foreground(tcell.GetColor(m.Config.Style.MainForeground))
  46. m.Screen.SetStyle(m.Config.StyleDefault)
  47. }