Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use show-line-numbers instead of line-numbers #5

Merged
merged 7 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 22 additions & 28 deletions lua/charm-freeze/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ M.allowed_opts = {
margin = { "string", "table" },
background = "string",
theme = "string",
line_numbers = "boolean",
show_line_numbers = "boolean",
line_height = "number",
language = "string",
font = {
Expand Down Expand Up @@ -79,49 +79,43 @@ M.parse_options = function(opts)
return options
end

-- Generate the command line arguments
M.get_arguments = function(args, options)
local cmd = {}
local value = nil

table.insert(cmd, options.command)

for k, v in pairs(options) do
-- handle margin and padding sepreatly as tables
local function populate_cmd(cmd, args, tbl, prefix)
for k,v in pairs(tbl) do
-- handle margin and padding separately as tables
if k == "margin" or k == "padding" then
if type(v) == "table" then
table.insert(cmd, "--" .. k)
table.insert(cmd, "--" .. prefix .. k)
table.insert(cmd, table.concat(v, ","))
end
-- table options ('border', 'font', 'shadow')
elseif type(v) == "table" and not is_array(v) then
for _k, _v in pairs(v) do
table.insert(cmd, "--" .. k .. "." .. string.gsub(_k, "_", "-"))
if type(_v) == "boolean" then
if _v then
table.insert(cmd)
end
else
table.insert(cmd, _v)
end
end
-- handle boolean options, they are just flags with no value
elseif type(v) == "boolean" then
if v then
table.insert(cmd, "--" .. string.gsub(k, "_", "-"))
end
populate_cmd(cmd, args, v, prefix .. k .. '.')
-- handle anything that is not the command or language option
elseif k ~= "command" and k ~= "language" then
table.insert(cmd, "--" .. string.gsub(k, "_", "-"))
table.insert(cmd, "--" .. prefix .. string.gsub(k, "_", "-"))

-- if the value is a function, call it with the args, otherwise just use the value
local value = nil
if type(v) == "function" then
value = v(args)
else
value = v
end
table.insert(cmd, value)

-- Don't append the value if it's a boolean option.
if type(v) ~= "boolean" then
table.insert(cmd, value)
end
end
end
end

-- Generate the command line arguments
M.get_arguments = function(args, options)
local cmd = {}

table.insert(cmd, options.command)
populate_cmd(cmd, args, options, '')

return cmd
end
Expand Down
4 changes: 2 additions & 2 deletions tests/charm-freeze/test_all.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ end

T["invalid_options.boolean"] = function()
e(function()
child.lua([[P.setup({line_numbers = "chesee"})]])
child.lua([[P.setup({show_line_numbers = "chesee"})]])
end)
end

Expand Down Expand Up @@ -78,7 +78,7 @@ end

T["valid_options.boolean"] = function()
ne(function()
child.lua([[P.setup({line_numbers = false})]])
child.lua([[P.setup({show_line_numbers = false})]])
end)
end

Expand Down