voyeg3r

colors.lua

Feb 1st, 2022 (edited)
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.29 KB | None | 0 0
  1. -- File: /home/sergio/.config/nvim/lua/colors.lua
  2. -- Last Change: Tue, 01 Feb 2022 08:16
  3.  
  4. -- This code comes from a series of 7 videos on how to use telescope pickers
  5. -- to change colorschemes on neovim, here is the list:
  6.  
  7. -- video 1: https://youtu.be/vjKEKsQbQMU
  8. -- video 2: https://youtu.be/2LSGlOgI9Cg
  9. -- video 3: https://youtu.be/-SwYCH4Ht2g
  10. -- video 5: https://youtu.be/Wq3wbplnxug
  11. -- video 6: https://youtu.be/BMTXuY640dA
  12. -- video 7: https://youtu.be/zA-VXoZ-Q8E
  13.  
  14. -- In order to mapp this function you have to map the command below:
  15. -- :lua require('colors').choose_colors()
  16. --
  17. -- Modify the list of colors or uncomment the function that takes all possible colors
  18.  
  19. local M = {}
  20.  
  21. M.choose_colors = function()
  22.     local actions = require "telescope.actions"
  23.     local actions_state = require "telescope.actions.state"
  24.     local pickers = require "telescope.pickers"
  25.     local finders = require "telescope.finders"
  26.     local sorters = require "telescope.sorters"
  27.     local dropdown = require "telescope.themes".get_dropdown()
  28.  
  29.     function enter(prompt_bufnr)
  30.         local selected = actions_state.get_selected_entry()
  31.         local cmd = 'colorscheme ' .. selected[1]
  32.         vim.cmd(cmd)
  33.         actions.close(prompt_bufnr)
  34.     end
  35.  
  36.     function next_color(prompt_bufnr)
  37.         actions.move_selection_next(prompt_bufnr)
  38.         local selected = actions_state.get_selected_entry()
  39.         local cmd = 'colorscheme ' .. selected[1]
  40.         vim.cmd(cmd)
  41.     end
  42.  
  43.     function prev_color(prompt_bufnr)
  44.         actions.move_selection_previous(prompt_bufnr)
  45.         local selected = actions_state.get_selected_entry()
  46.         local cmd = 'colorscheme ' .. selected[1]
  47.         vim.cmd(cmd)
  48.     end
  49.  
  50.     -- local colors = vim.fn.getcompletion("", "color")
  51.  
  52.     local opts = {
  53.  
  54.         finder = finders.new_table {"gruvbox", "nordfox", "nightfox", "monokai", "tokyonight"},
  55.         -- finder = finders.new_table(colors),
  56.         sorter = sorters.get_generic_fuzzy_sorter({}),
  57.  
  58.         attach_mappings = function(prompt_bufnr, map)
  59.             map("i", "<CR>", enter)
  60.             map("i", "<C-j>", next_color)
  61.             map("i", "<C-k>", prev_color)
  62.             return true
  63.         end,
  64.  
  65.     }
  66.  
  67.     local colors = pickers.new(dropdown, opts)
  68.  
  69.     colors:find()
  70. end
  71.  
  72. return M
  73.  
Add Comment
Please, Sign In to add comment