Added presets and updated documentation
This commit is contained in:
+11
-11
@@ -1,7 +1,7 @@
|
||||
---@type table
|
||||
local M = {}
|
||||
|
||||
---@type table|nil
|
||||
---@type table
|
||||
local opts = {}
|
||||
|
||||
---@class Preset
|
||||
@@ -11,7 +11,7 @@ local opts = {}
|
||||
---@field bottom_padding integer
|
||||
|
||||
---@type Preset
|
||||
local centered = {
|
||||
local center = {
|
||||
left_padding = 0,
|
||||
right_padding = 0,
|
||||
top_padding = 0,
|
||||
@@ -19,7 +19,7 @@ local centered = {
|
||||
}
|
||||
|
||||
---@type Preset
|
||||
local center_paneled = {
|
||||
local center_panel = {
|
||||
left_padding = 0,
|
||||
right_padding = 100,
|
||||
top_padding = 0,
|
||||
@@ -35,7 +35,7 @@ local right_panel = {
|
||||
}
|
||||
|
||||
---@type Preset
|
||||
local cornered = {
|
||||
local corner = {
|
||||
left_padding = 100,
|
||||
right_padding = 0,
|
||||
top_padding = 25,
|
||||
@@ -44,18 +44,18 @@ local cornered = {
|
||||
}
|
||||
|
||||
---@param preset string
|
||||
---@return table|nil
|
||||
---@return table
|
||||
function M.getPresets(preset)
|
||||
if preset == "custom" then
|
||||
opts = nil
|
||||
elseif preset == "centered" then
|
||||
opts = centered
|
||||
-- if preset == "custom" then
|
||||
-- opts = nil
|
||||
if preset == "centered" then
|
||||
opts = center
|
||||
elseif preset == "center_panel" then
|
||||
opts = center_paneled
|
||||
opts = center_panel
|
||||
elseif preset == "right_panel" then
|
||||
opts = right_panel
|
||||
elseif preset == "cornered" then
|
||||
opts = cornered
|
||||
opts = corner
|
||||
else
|
||||
print("Preset option: " .. preset .. " does not exist")
|
||||
end
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
local pickers = require "telescope.pickers"
|
||||
local finders = require "telescope.finders"
|
||||
local conf = require("telescope.config").values
|
||||
local actions = require "telescope.actions"
|
||||
local action_state = require "telescope.actions.state"
|
||||
|
||||
-- our picker function: colors
|
||||
local colors = function(opts)
|
||||
opts = opts or {}
|
||||
pickers.new(opts, {
|
||||
prompt_title = "colors",
|
||||
finder = finders.new_table {
|
||||
results = { "red", "green", "blue" }
|
||||
},
|
||||
sorter = conf.generic_sorter(opts),
|
||||
attach_mappings = function(prompt_bufnr, map)
|
||||
actions.select_default:replace(function()
|
||||
actions.close(prompt_bufnr)
|
||||
local selection = action_state.get_selected_entry()
|
||||
-- print(vim.inspect(selection))
|
||||
vim.api.nvim_put({ selection[1] }, "", false, true)
|
||||
end)
|
||||
return true
|
||||
end,
|
||||
}):find()
|
||||
end
|
||||
|
||||
-- to execute the function
|
||||
colors(require("telescope.themes").get_dropdown{})
|
||||
+4
-10
@@ -7,7 +7,7 @@ local M = {}
|
||||
---@type table
|
||||
M.opts = {}
|
||||
|
||||
---@type table|nil
|
||||
---@type table
|
||||
local presets_opts = {}
|
||||
|
||||
---@param opts table
|
||||
@@ -25,18 +25,12 @@ function M.write_file(path, content)
|
||||
print(path .. " created successfully!")
|
||||
end
|
||||
|
||||
local function set_presets_opts()
|
||||
if presets.getPresets(M.opts.presets) ~= nil then
|
||||
presets_opts = presets.getPresets(M.opts.presets)
|
||||
else
|
||||
presets_opts = M.opts
|
||||
end
|
||||
end
|
||||
|
||||
---@param cmd string
|
||||
---@return boolean, table
|
||||
function M.open_float_terminal(cmd)
|
||||
set_presets_opts()
|
||||
if presets.getPresets(M.opts.presets) ~= nil then
|
||||
presets_opts = presets.getPresets(M.opts.presets)
|
||||
end
|
||||
local ui = vim.api.nvim_list_uis()[1]
|
||||
|
||||
local width = math.max(1, math.floor(ui.width * 0.9) - presets_opts.left_padding - presets_opts.right_padding)
|
||||
|
||||
Reference in New Issue
Block a user