update nvim

This commit is contained in:
msevgi 2025-08-11 15:51:30 +03:00
parent 3338d39206
commit 786b0e0970
31 changed files with 2204 additions and 15 deletions

View file

@ -0,0 +1,9 @@
-- Helper function to return a character from a string.
-- @param str {string}
-- @param index {number}
-- @returns {string}
local char_at = function(str, index)
return string.sub(str, index, index)
end
return char_at

View file

@ -0,0 +1,45 @@
local hsl_convert = require 'lush.vivid.hsl.convert'
local M = {}
M.hsl = function(h, s, l)
return hsl_convert.hsl_to_hex { h = h, s = s, l = l }
end
M.hex_to_rgb = function(hex)
hex = hex:gsub('#', '')
return {
r = tonumber('0x' .. hex:sub(1, 2)) / 255,
g = tonumber('0x' .. hex:sub(3, 4)) / 255,
b = tonumber('0x' .. hex:sub(5, 6)) / 255,
}
end
M.rgb_to_hex = function(rgb)
return string.format('#%02x%02x%02x', rgb.r * 255, rgb.g * 255, rgb.b * 255)
end
M.rgb_to_hsl = function(rgb)
local r, g, b = rgb.r, rgb.g, rgb.b
local max, min = math.max(r, g, b), math.min(r, g, b)
local h, s, l = (max + min) / 2, (max + min) / 2, (max + min) / 2
if max == min then
-- achromatic
h, s = 0, 0
else
local delta = max - min
s = l > 0.5 and delta / (2 - max - min) or delta / (max + min)
if max == r then
h = (g - b) / delta + (g < b and 6 or 0)
elseif max == g then
h = (b - r) / delta + 2
elseif max == b then
h = (r - g) / delta + 4
end
h = h / 6
end
return { h = h, s = s, l = l }
end
return M

View file

@ -0,0 +1,43 @@
local slice_table = require("phoenix.utils.slice_table")
local char_at = require("phoenix.utils.char_at")
local shrink_path = function(path)
if char_at(path, 1) == "." then
return char_at(path, 1) .. char_at(path, 2)
else
return char_at(path, 1)
end
end
local substitute_home = function(path)
return vim.fn.substitute(path, vim.fn.expand("$HOME"), "~", "")
end
local fish_like_path = function(path, level)
if path == "" then
return "[No Name]"
end
local paths = vim.fn.split(substitute_home(path), "/")
if #paths == 0 then
return "/"
elseif #paths == 1 then
if paths[1] == "~" then
return "~/"
else
return path
end
end
local after = slice_table(paths, -level)
local before = slice_table(paths, 1, -level)
for key, value in pairs(before) do
before[key] = shrink_path(value)
end
return vim.fn.join(before, "/") .. "/" .. vim.fn.join(after, "/")
end
return fish_like_path

View file

@ -0,0 +1,14 @@
---@param mode string Mode short-name, see |nvim_set_keymap()|. Can also be list of modes to create mapping on multiple modes.
---@param lhs string|table Left-hand side |{lhs}| of the mapping.
---@param rhs string|function Right-hand side |{rhs}| of the mapping, can be a Lua function.
---@param opts table|nil Table of |:map-arguments|. Defaults to `{noremap = true, silent = true}`.
---@see |nvim_set_keymap()|
local keymap = function(mode, key, action, opts)
local options = { noremap = true, silent = true }
if opts then
options = vim.tbl_extend('force', options, opts)
end
vim.keymap.set(mode, key, action, options)
end
return keymap

View file

@ -0,0 +1,36 @@
local checkers = require("phoenix.utils.type-checkers")
-- Returns a shallow copy of a portion of a table into a new table
-- @param obj {table}
-- @param start {number} start value
-- @param finish {number} end value
-- @return {boolean}
local slice_table = function(obj, start, finish)
if checkers.is_empty(obj) or start == finish then
return {}
end
local output = {}
local _finish = #obj
local _start = 1
if start >= 0 then
_start = start
elseif checkers.is_nil(finish) and start < 0 then
_start = #obj + start + 1
end
if finish and finish >= 0 then
_finish = finish - 1
elseif finish and finish < 0 then
_finish = #obj + finish
end
for i = _start, _finish do
table.insert(output, obj[i])
end
return output
end
return slice_table

View file

@ -0,0 +1,43 @@
local checkers = {}
-- Helper function to check if value passed by parameter is a table
-- @obj {table}
-- @returns {boolean}
checkers.is_table = function(obj)
return type(obj) == "table"
end
-- Verify if table object works as an array
-- @param obj {table}
-- @return {boolean}
checkers.is_array = function(obj)
if not checkers.is_table(obj) then
return false
end
local i = 0
for _ in pairs(obj) do
i = i + 1
if obj[i] == nil then
return false
end
end
return true
end
-- Checks wether value is nil
-- @obj {any}
-- @returns {boolean}
checkers.is_nil = function(value)
return value == nil
end
-- Checks if parameter is an empty table
-- @param obj {table}
-- @return {boolean}
checkers.is_empty = function(obj)
return checkers.is_array(obj) and #obj == 0
end
return checkers