themes.lua 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. -- Theme configuration for Lumacs
  2. -- This file demonstrates how to configure and switch themes from Lua
  3. -- Theme switching functions
  4. function switch_to_theme(theme_name)
  5. local success, message = execute_command("set-theme", {theme_name})
  6. if not success then
  7. message("Failed to switch theme: " .. message)
  8. end
  9. end
  10. -- Specific theme switchers
  11. function switch_to_everforest()
  12. switch_to_theme("everforest-dark")
  13. end
  14. function switch_to_default()
  15. switch_to_theme("default")
  16. end
  17. function switch_to_dracula()
  18. switch_to_theme("dracula")
  19. end
  20. function switch_to_solarized()
  21. switch_to_theme("solarized-dark")
  22. end
  23. function switch_to_nord()
  24. switch_to_theme("nord")
  25. end
  26. function switch_to_gruvbox_light()
  27. switch_to_theme("gruvbox-light")
  28. end
  29. -- Enhanced theme listing
  30. function list_themes()
  31. local success, message = execute_command("list-themes")
  32. if success then
  33. message(message)
  34. else
  35. message("Failed to list themes: " .. message)
  36. end
  37. end
  38. -- Theme management utilities
  39. function create_theme(name, config)
  40. -- Helper function to create custom themes from Lua
  41. if not config then
  42. message("Theme configuration required")
  43. return
  44. end
  45. -- This would be extended to allow custom theme creation
  46. message("Custom theme creation not yet implemented")
  47. end
  48. function get_current_theme()
  49. local themes = editor.theme_manager:theme_names()
  50. -- This could be enhanced to return the actual current theme
  51. message("Current theme detection needs implementation")
  52. end
  53. -- Register theme management commands
  54. register_command("list-available-themes", "List all available themes with descriptions", function(args)
  55. local themes = editor.theme_manager:theme_names()
  56. if #themes == 0 then
  57. return {success = true, message = "No themes available"}
  58. end
  59. local descriptions = {
  60. ["default"] = "Default light theme with basic colors",
  61. ["everforest-dark"] = "Everforest dark theme - comfortable green-tinted dark theme",
  62. ["dracula"] = "Dracula theme - popular dark theme with purple accents",
  63. ["solarized-dark"] = "Solarized Dark - precision colors for machines and people",
  64. ["nord"] = "Nord - arctic, north-bluish clean and elegant theme",
  65. ["gruvbox-light"] = "Gruvbox Light - retro groove warm light theme"
  66. }
  67. local result = "Available themes:\n"
  68. local current_theme = editor.theme_manager.active_theme
  69. local current_name = current_theme and current_theme:name() or "none"
  70. for i, name in ipairs(themes) do
  71. local indicator = (name == current_name) and " (current)" or ""
  72. local desc = descriptions[name] or "No description available"
  73. result = result .. " " .. name .. indicator .. " - " .. desc .. "\n"
  74. end
  75. return {success = true, message = result}
  76. end)
  77. register_command("set-random-theme", "Switch to a random theme", function(args)
  78. local themes = editor.theme_manager:theme_names()
  79. if #themes == 0 then
  80. return {success = false, message = "No themes available"}
  81. end
  82. math.randomseed(os.time())
  83. local random_index = math.random(1, #themes)
  84. local random_theme = themes[random_index]
  85. local success, message = execute_command("set-theme", {random_theme})
  86. if success then
  87. return {success = true, message = "Switched to random theme: " .. random_theme}
  88. else
  89. return {success = false, message = "Failed to switch theme: " .. message}
  90. end
  91. end)
  92. register_command("cycle-themes", "Cycle through available themes", function(args)
  93. local themes = editor.theme_manager:theme_names()
  94. if #themes <= 1 then
  95. return {success = false, message = "Need at least 2 themes to cycle"}
  96. end
  97. local current_theme = editor.theme_manager.active_theme
  98. local current_name = current_theme and current_theme:name() or ""
  99. -- Find current theme index
  100. local current_index = 1
  101. for i, name in ipairs(themes) do
  102. if name == current_name then
  103. current_index = i
  104. break
  105. end
  106. end
  107. -- Switch to next theme (wrap around)
  108. local next_index = (current_index % #themes) + 1
  109. local next_theme = themes[next_index]
  110. local success, message = execute_command("set-theme", {next_theme})
  111. if success then
  112. return {success = true, message = "Cycled to theme: " .. next_theme}
  113. else
  114. return {success = false, message = "Failed to cycle theme: " .. message}
  115. end
  116. end)
  117. -- Key bindings for theme management
  118. bind_key("C-x t e", switch_to_everforest, "Switch to Everforest theme")
  119. bind_key("C-x t d", switch_to_default, "Switch to default theme")
  120. bind_key("C-x t v", switch_to_dracula, "Switch to Dracula theme")
  121. bind_key("C-x t s", switch_to_solarized, "Switch to Solarized Dark theme")
  122. bind_key("C-x t n", switch_to_nord, "Switch to Nord theme")
  123. bind_key("C-x t g", switch_to_gruvbox_light, "Switch to Gruvbox Light theme")
  124. bind_key("C-x t l", list_themes, "List all themes")
  125. bind_key("C-x t r", function() execute_command("set-random-theme") end, "Switch to random theme")
  126. bind_key("C-x t c", function() execute_command("cycle-themes") end, "Cycle through themes")
  127. print("Enhanced theme configuration loaded - try C-x t for theme commands or M-x set-theme")