themes_init.lua 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 = editor:execute_command("set-theme", {theme_name})
  6. if not success then
  7. editor:message("Failed to switch theme: " .. message) -- Corrected message call
  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 = editor:execute_command("list-available-themes") -- Corrected command name
  32. if success then
  33. editor:message(message) -- Corrected message call
  34. else
  35. editor:message("Failed to list themes: " .. message) -- Corrected message call
  36. end
  37. end
  38. -- Theme management utilities (create_theme and get_current_theme are now largely obsolete
  39. -- as themes are defined in separate files and active_theme is exposed directly)
  40. -- function create_theme(name, config)
  41. -- message("Custom theme creation is now done by creating a new Lua file in lua/themes/")
  42. -- end
  43. -- function get_current_theme()
  44. -- local active_theme_obj = editor.theme_manager.active_theme
  45. -- if active_theme_obj then
  46. -- editor:message("Current theme: " .. active_theme_obj:name())
  47. -- else
  48. -- editor:message("No active theme.")
  49. -- end
  50. -- end
  51. -- Register theme management commands (these are mostly retained for M-x interaction)
  52. editor:register_command("list-available-themes", "List all available themes with descriptions", function(args)
  53. local themes = editor.theme_manager:theme_names()
  54. if #themes == 0 then
  55. return {success = true, message = "No themes available"}
  56. end
  57. -- NOTE: Descriptions are hardcoded here for display purposes.
  58. -- A more robust solution might store descriptions within the Theme object itself.
  59. local descriptions = {
  60. ["default"] = "Default light theme with comprehensive styling and clear contrast",
  61. ["everforest-dark"] = "Everforest dark theme - comfortable green-tinted dark theme with rich typography",
  62. ["dracula"] = "Dracula theme - popular dark theme with vibrant purple accents and modern fonts",
  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. ["catppuccin-mocha"] = "Catppuccin Mocha - warm, cozy dark theme with pastel colors and excellent readability",
  67. ["tokyo-night"] = "Tokyo Night - modern dark theme inspired by the neon lights of Tokyo",
  68. ["ayu-dark"] = "Ayu Dark - minimal dark theme with excellent contrast and clean typography"
  69. }
  70. local result = "Available themes:\n"
  71. local current_theme = editor.theme_manager:active_theme()
  72. local current_name = current_theme and current_theme:name() or "none"
  73. for i, name in ipairs(themes) do
  74. local indicator = (name == current_name) and " (current)" or ""
  75. local desc = descriptions[name] or "No description available"
  76. result = result .. " " .. name .. indicator .. " - " .. desc .. "\n"
  77. end
  78. return {success = true, message = result}
  79. end)
  80. editor:register_command("set-random-theme", "Switch to a random theme", function(args)
  81. local themes = editor.theme_manager:theme_names()
  82. if #themes == 0 then
  83. return {success = false, message = "No themes available"}
  84. end
  85. math.randomseed(os.time())
  86. local random_index = math.random(1, #themes)
  87. local random_theme = themes[random_index]
  88. local success, message = editor:execute_command("set-theme", {random_theme})
  89. if success then
  90. return {success = true, message = "Switched to random theme: " .. random_theme}
  91. else
  92. return {success = false, message = "Failed to switch theme: " .. message}
  93. end
  94. end)
  95. editor:register_command("cycle-themes", "Cycle through available themes", function(args)
  96. local themes = editor.theme_manager:theme_names()
  97. if #themes <= 1 then
  98. return {success = false, message = "Need at least 2 themes to cycle"}
  99. end
  100. local current_theme = editor.theme_manager:active_theme()
  101. local current_name = current_theme and current_theme:name() or ""
  102. -- Find current theme index
  103. local current_index = 1
  104. for i, name in ipairs(themes) do
  105. if name == current_name then
  106. current_index = i
  107. break
  108. end
  109. end
  110. -- Switch to next theme (wrap around)
  111. local next_index = (current_index % #themes) + 1
  112. local next_theme = themes[next_index]
  113. local success, message = editor:execute_command("set-theme", {next_theme})
  114. if success then
  115. return {success = true, message = "Cycled to theme: " .. next_theme}
  116. else
  117. return {success = false, message = "Failed to cycle theme: " .. message}
  118. end
  119. end)
  120. -- Key bindings for theme management
  121. editor:bind_key("C-x t e", switch_to_everforest, "Switch to Everforest theme")
  122. editor:bind_key("C-x t d", switch_to_default, "Switch to default theme")
  123. editor:bind_key("C-x t v", switch_to_dracula, "Switch to Dracula theme")
  124. editor:bind_key("C-x t s", switch_to_solarized, "Switch to Solarized Dark theme")
  125. editor:bind_key("C-x t n", switch_to_nord, "Switch to Nord theme")
  126. editor:bind_key("C-x t g", switch_to_gruvbox_light, "Switch to Gruvbox Light theme")
  127. editor:bind_key("C-x t l", list_themes, "List all themes")
  128. editor:bind_key("C-x t r", function() editor:execute_command("set-random-theme") end, "Switch to random theme")
  129. editor:bind_key("C-x t c", function() editor:execute_command("cycle-themes") end, "Cycle through themes")
  130. print("Enhanced theme configuration loaded - try C-x t for theme commands or M-x set-theme")
  131. -- Set initial theme after all themes are loaded
  132. switch_to_theme("everforest-dark")