Meh I'll figure out submodules later

This commit is contained in:
mustard 2025-09-16 01:01:02 +02:00
parent 4ca9d44a90
commit 8cb281f436
352 changed files with 66107 additions and 0 deletions

View file

@ -0,0 +1,42 @@
local compat = {}
---@return boolean
compat.noref = function()
return vim.fn.has("nvim-0.10") == 1 and true or {} --[[@as boolean]]
end
---source: https://github.com/Validark/Lua-table-functions/blob/master/table.lua
---Moves elements [f, e] from array a1 into a2 starting at index t
---table.move implementation
---@generic T: table
---@param a1 T from which to draw elements from range
---@param f integer starting index for range
---@param e integer ending index for range
---@param t integer starting index to move elements from a1 within [f, e]
---@param a2 T the second table to move these elements to
---@default a2 = a1
---@returns a2
local table_move = function(a1, f, e, t, a2)
a2 = a2 or a1
t = t + e
for i = e, f, -1 do
t = t - 1
a2[t] = a1[i]
end
return a2
end
---source:
compat.table_move = table.move or table_move
---@vararg any
local table_pack = function(...)
-- Returns a new table with parameters stored into an array, with field "n" being the total number of parameters
local t = { ... }
---@diagnostic disable-next-line: inject-field
t.n = #t
return t
end
compat.table_pack = table.pack or table_pack
return compat

View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 Boris Nagaev
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,134 @@
-- lua-filesize, generate a human readable string describing the file size
-- Copyright (c) 2016 Boris Nagaev
-- See the LICENSE file for terms of use.
local si = {
bits = { "b", "Kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb" },
bytes = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" },
}
local function isNan(num)
-- http://lua-users.org/wiki/InfAndNanComparisons
-- NaN is the only value that doesn't equal itself
return num ~= num
end
local function roundNumber(num, digits)
local fmt = "%." .. digits .. "f"
return tonumber(fmt:format(num))
end
local function filesize(size, options)
-- copy options to o
local o = {}
for key, value in pairs(options or {}) do
o[key] = value
end
local function setDefault(name, default)
if o[name] == nil then
o[name] = default
end
end
setDefault("bits", false)
setDefault("unix", false)
setDefault("base", 2)
setDefault("round", o.unix and 1 or 2)
setDefault("spacer", o.unix and "" or " ")
setDefault("suffixes", {})
setDefault("output", "string")
setDefault("exponent", -1)
assert(not isNan(size), "Invalid arguments")
local ceil = (o.base > 2) and 1000 or 1024
local negative = (size < 0)
if negative then
-- Flipping a negative number to determine the size
size = -size
end
local result
-- Zero is now a special case because bytes divide by 1
if size == 0 then
result = {
0,
o.unix and "" or (o.bits and "b" or "B"),
}
else
-- Determining the exponent
if o.exponent == -1 or isNan(o.exponent) then
o.exponent = math.floor(math.log(size) / math.log(ceil))
end
-- Exceeding supported length, time to reduce & multiply
if o.exponent > 8 then
o.exponent = 8
end
local val
if o.base == 2 then
val = size / math.pow(2, o.exponent * 10)
else
val = size / math.pow(1000, o.exponent)
end
if o.bits then
val = val * 8
if val > ceil then
val = val / ceil
o.exponent = o.exponent + 1
end
end
result = {
roundNumber(val, o.exponent > 0 and o.round or 0),
(o.base == 10 and o.exponent == 1) and (o.bits and "kb" or "kB")
or si[o.bits and "bits" or "bytes"][o.exponent + 1],
}
if o.unix then
result[2] = result[2]:sub(1, 1)
if result[2] == "b" or result[2] == "B" then
result = {
math.floor(result[1]),
"",
}
end
end
end
assert(result)
-- Decorating a 'diff'
if negative then
result[1] = -result[1]
end
-- Applying custom suffix
result[2] = o.suffixes[result[2]] or result[2]
-- Applying custom suffix
result[2] = o.suffixes[result[2]] or result[2]
-- Returning Array, Object, or String (default)
if o.output == "array" then
return result
elseif o.output == "exponent" then
return o.exponent
elseif o.output == "object" then
return {
value = result[1],
suffix = result[2],
}
elseif o.output == "string" then
local value = tostring(result[1])
value = value:gsub("%.0$", "")
local suffix = result[2]
return value .. o.spacer .. suffix
end
end
return filesize

File diff suppressed because it is too large Load diff