mirror of
https://github.com/Myzel394/easytables.nvim.git
synced 2025-06-18 06:55:25 +02:00
feat: Add options
This commit is contained in:
parent
11fa81b530
commit
25f7a873e8
@ -1,6 +1,7 @@
|
||||
local table = require("easytables.table")
|
||||
local window = require("easytables.window")
|
||||
local inputHelper = require("easytables.input")
|
||||
local optionsHelper = require("easytables.options")
|
||||
|
||||
local function create_new_table(cols, rows)
|
||||
local markdown_table = table:create(cols, rows)
|
||||
@ -12,7 +13,11 @@ local function create_new_table(cols, rows)
|
||||
win:draw_table()
|
||||
end
|
||||
|
||||
local function setup()
|
||||
---Initialize `easytables` with the given options. This function **must** be called.
|
||||
---@param options table See options.lua for available options
|
||||
local function setup(options)
|
||||
optionsHelper.merge_options(options)
|
||||
|
||||
vim.api.nvim_create_user_command(
|
||||
"EasyTablesCreateNew",
|
||||
function(opt)
|
||||
|
70
lua/easytables/options.lua
Normal file
70
lua/easytables/options.lua
Normal file
@ -0,0 +1,70 @@
|
||||
-- All available options are listed below. The default values are shown.
|
||||
local DEFAULT = {
|
||||
table = {
|
||||
window = {
|
||||
preview_title = "Table Preview",
|
||||
prompt_title = "Cell content",
|
||||
-- Either "auto" to automatically size the window, or a string
|
||||
-- in the format of "<width>x<height>" (e.g. "20x10")
|
||||
size = "auto"
|
||||
},
|
||||
cell = {
|
||||
-- Min width of a cell (excluding padding)
|
||||
min_width = 3,
|
||||
-- Filler character for empty cells
|
||||
filler = " ",
|
||||
align = "left",
|
||||
-- Padding around the cell content, applied BOTH left AND right
|
||||
-- E.g: padding = 1, content = "foo" -> " foo "
|
||||
padding = 1,
|
||||
},
|
||||
-- Characters used to draw the table
|
||||
-- Do not worry about multibyte characters, they are handled correctly
|
||||
border = {
|
||||
top_left = "┌",
|
||||
top_right = "┐",
|
||||
bottom_left = "└",
|
||||
bottom_right = "┘",
|
||||
horizontal = "─",
|
||||
vertical = "│",
|
||||
left_t = "├",
|
||||
right_t = "┤",
|
||||
top_t = "┬",
|
||||
bottom_t = "┴",
|
||||
cross = "┼",
|
||||
header_left_t = "╞",
|
||||
header_right_t = "╡",
|
||||
header_bottom_t = "╧",
|
||||
header_cross = "╪",
|
||||
header_horizontal = "═",
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
-- You can ignore everything below this line
|
||||
|
||||
local options = {}
|
||||
|
||||
local function tableMerge(t1, t2)
|
||||
for k, v in pairs(t2) do
|
||||
if type(v) == "table" then
|
||||
if type(t1[k] or false) == "table" then
|
||||
tableMerge(t1[k] or {}, t2[k] or {})
|
||||
else
|
||||
t1[k] = v
|
||||
end
|
||||
else
|
||||
t1[k] = v
|
||||
end
|
||||
end
|
||||
return t1
|
||||
end
|
||||
|
||||
local function merge_options(user_options)
|
||||
options = tableMerge(DEFAULT, user_options)
|
||||
end
|
||||
|
||||
return {
|
||||
merge_options = merge_options,
|
||||
options = options
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user