mirror of
https://github.com/zoriya/auto-save.nvim.git
synced 2026-06-02 10:45:06 +00:00
style: autoformat all the things
Namely: applied stylua to the whole repo and ran marksman on README.md.
This commit is contained in:
@@ -1,70 +1,70 @@
|
||||
local M = {}
|
||||
---@param hex_str string hexadecimal value of a color
|
||||
local hex_to_rgb = function(hex_str)
|
||||
local hex = "[abcdef0-9][abcdef0-9]"
|
||||
local pat = "^#(" .. hex .. ")(" .. hex .. ")(" .. hex .. ")$"
|
||||
hex_str = string.lower(hex_str)
|
||||
local hex = "[abcdef0-9][abcdef0-9]"
|
||||
local pat = "^#(" .. hex .. ")(" .. hex .. ")(" .. hex .. ")$"
|
||||
hex_str = string.lower(hex_str)
|
||||
|
||||
assert(string.find(hex_str, pat) ~= nil, "hex_to_rgb: invalid hex_str: " .. tostring(hex_str))
|
||||
assert(string.find(hex_str, pat) ~= nil, "hex_to_rgb: invalid hex_str: " .. tostring(hex_str))
|
||||
|
||||
local red, green, blue = string.match(hex_str, pat)
|
||||
return { tonumber(red, 16), tonumber(green, 16), tonumber(blue, 16) }
|
||||
local red, green, blue = string.match(hex_str, pat)
|
||||
return { tonumber(red, 16), tonumber(green, 16), tonumber(blue, 16) }
|
||||
end
|
||||
|
||||
function M.highlight(group, color, force)
|
||||
if color.link then
|
||||
vim.api.nvim_set_hl(0, group, {
|
||||
link = color.link,
|
||||
})
|
||||
else
|
||||
if color.style then
|
||||
for _, style in ipairs(color.style) do
|
||||
color[style] = true
|
||||
end
|
||||
end
|
||||
color.style = nil
|
||||
if force then
|
||||
vim.cmd("hi " .. group .. " guifg=" .. (color.fg or "NONE") .. " guibg=" .. (color.bg or "NONE"))
|
||||
return
|
||||
end
|
||||
vim.api.nvim_set_hl(0, group, color)
|
||||
end
|
||||
if color.link then
|
||||
vim.api.nvim_set_hl(0, group, {
|
||||
link = color.link,
|
||||
})
|
||||
else
|
||||
if color.style then
|
||||
for _, style in ipairs(color.style) do
|
||||
color[style] = true
|
||||
end
|
||||
end
|
||||
color.style = nil
|
||||
if force then
|
||||
vim.cmd("hi " .. group .. " guifg=" .. (color.fg or "NONE") .. " guibg=" .. (color.bg or "NONE"))
|
||||
return
|
||||
end
|
||||
vim.api.nvim_set_hl(0, group, color)
|
||||
end
|
||||
end
|
||||
|
||||
function M.get_hl(name)
|
||||
local ok, hl = pcall(vim.api.nvim_get_hl_by_name, name, true)
|
||||
if not ok then
|
||||
return
|
||||
end
|
||||
for _, key in pairs({ "foreground", "background", "special" }) do
|
||||
if hl[key] then
|
||||
hl[key] = string.format("#%06x", hl[key])
|
||||
end
|
||||
end
|
||||
return hl
|
||||
local ok, hl = pcall(vim.api.nvim_get_hl_by_name, name, true)
|
||||
if not ok then
|
||||
return
|
||||
end
|
||||
for _, key in pairs({ "foreground", "background", "special" }) do
|
||||
if hl[key] then
|
||||
hl[key] = string.format("#%06x", hl[key])
|
||||
end
|
||||
end
|
||||
return hl
|
||||
end
|
||||
|
||||
---@param fg string forecrust color
|
||||
---@param bg string background color
|
||||
---@param alpha number number between 0 and 1. 0 results in bg, 1 results in fg
|
||||
function M.blend(fg, bg, alpha)
|
||||
bg = hex_to_rgb(bg)
|
||||
fg = hex_to_rgb(fg)
|
||||
bg = hex_to_rgb(bg)
|
||||
fg = hex_to_rgb(fg)
|
||||
|
||||
local blendChannel = function(i)
|
||||
local ret = (alpha * fg[i] + ((1 - alpha) * bg[i]))
|
||||
return math.floor(math.min(math.max(0, ret), 255) + 0.5)
|
||||
end
|
||||
local blendChannel = function(i)
|
||||
local ret = (alpha * fg[i] + ((1 - alpha) * bg[i]))
|
||||
return math.floor(math.min(math.max(0, ret), 255) + 0.5)
|
||||
end
|
||||
|
||||
return string.format("#%02X%02X%02X", blendChannel(1), blendChannel(2), blendChannel(3))
|
||||
return string.format("#%02X%02X%02X", blendChannel(1), blendChannel(2), blendChannel(3))
|
||||
end
|
||||
|
||||
function M.darken(hex, amount, bg)
|
||||
return M.blend(hex, bg or M.bg, math.abs(amount))
|
||||
return M.blend(hex, bg or M.bg, math.abs(amount))
|
||||
end
|
||||
|
||||
function M.lighten(hex, amount, fg)
|
||||
return M.blend(hex, fg or M.fg, math.abs(amount))
|
||||
return M.blend(hex, fg or M.fg, math.abs(amount))
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
local M = {}
|
||||
|
||||
function M.set_of(list)
|
||||
local set = {}
|
||||
for i = 1, #list do
|
||||
set[list[i]] = true
|
||||
end
|
||||
return set
|
||||
local set = {}
|
||||
for i = 1, #list do
|
||||
set[list[i]] = true
|
||||
end
|
||||
return set
|
||||
end
|
||||
|
||||
function M.not_in(var, arr)
|
||||
if M.set_of(arr)[var] == nil then
|
||||
return true
|
||||
end
|
||||
if M.set_of(arr)[var] == nil then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function M.do_callback(callback_name)
|
||||
local cnf = require("auto-save.config").opts
|
||||
local cnf = require("auto-save.config").opts
|
||||
|
||||
if type(cnf.callbacks[callback_name]) == "function" then
|
||||
cnf.callbacks[callback_name]()
|
||||
end
|
||||
if type(cnf.callbacks[callback_name]) == "function" then
|
||||
cnf.callbacks[callback_name]()
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
local TITLE = "auto-save"
|
||||
|
||||
return function(msg, kind)
|
||||
local has_notify_plugin = pcall(require, "notify")
|
||||
local level = {}
|
||||
local has_notify_plugin = pcall(require, "notify")
|
||||
local level = {}
|
||||
|
||||
if kind == "error" then
|
||||
level.log = vim.log.levels.ERROR
|
||||
level.type = "error"
|
||||
elseif kind == "warn" then
|
||||
level.log = vim.log.levels.WARN
|
||||
level.type = "error"
|
||||
else
|
||||
level.log = kind or vim.log.levels.INFO
|
||||
level.type = "info"
|
||||
end
|
||||
if kind == "error" then
|
||||
level.log = vim.log.levels.ERROR
|
||||
level.type = "error"
|
||||
elseif kind == "warn" then
|
||||
level.log = vim.log.levels.WARN
|
||||
level.type = "error"
|
||||
else
|
||||
level.log = kind or vim.log.levels.INFO
|
||||
level.type = "info"
|
||||
end
|
||||
|
||||
if has_notify_plugin then
|
||||
vim.notify(msg, level.log, {
|
||||
title = TITLE,
|
||||
})
|
||||
else
|
||||
vim.notify(("%s: %s"):format(TITLE, msg), level.log)
|
||||
end
|
||||
if has_notify_plugin then
|
||||
vim.notify(msg, level.log, {
|
||||
title = TITLE,
|
||||
})
|
||||
else
|
||||
vim.notify(("%s: %s"):format(TITLE, msg), level.log)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user