1
0
Fork 0
mirror of https://github.com/jiriks74/presence.nvim synced 2025-03-15 02:33:01 +01:00

Compare commits

...

9 commits

Author SHA1 Message Date
a76b1d74e3
fix: move to a new application id
to prevent potential issues with the original project
2023-11-09 15:57:47 +01:00
5fa130577a
fix(featreq_template): change name from Issue report to Feature request (#20) 2023-09-29 02:56:40 +02:00
dbb8f797f4
feat(featreq_template): convert from markdown to issue form (#18) 2023-09-29 02:51:28 +02:00
faa6371d23
feat(bug_template): add checks, add log formating (#16) 2023-09-29 02:41:15 +02:00
c295e1e14f
fix(formatting): Fix formatting using stylua (#11) 2023-09-29 02:14:33 +02:00
9e478c9960
fix(ci/cd-stylua): cannot contain spaces, invalid StyLua version (#15)
* fix(ci/cd-stylua): cannot contain spaces

* fix(ci/cs-stylua): invalid version number
2023-09-29 02:14:06 +02:00
e9db37bcfa
fix(ci/cd-stylua): Missing runs on, steps, names (#14)
* fix(ci/cd-luacheck): Rename job from sile to Luacheck

* fix(ci/cd-stylua): Missing runs on, steps, names
2023-09-29 02:08:42 +02:00
804f14842f
fix(ci/cd-luacheck): Rename job from sile to Luacheck (#13) 2023-09-29 02:03:51 +02:00
fb129b1de7
feat(ci/cd): add stylua action (#12)
* feat(ci/cd): add stylua action

* docs: Add StyLua disclaimer to README

* fix(ci/cd-stylua): Secret started with GITHUB_

* fix(ci/cd-stylua): Missing name, on, jobs
2023-09-29 01:57:42 +02:00
15 changed files with 2177 additions and 1929 deletions

View file

@ -1,47 +1,98 @@
name: Issue report name: Issue report
description: Report any errors, bugs, or unexpected behaviors related to presence.nvim description: Report any errors, bugs, or unexpected behaviors related to presence.nvim
title: "[Bug]: "
labels: [bug] labels: [bug]
assignees:
- jiriks74
body: body:
- type: markdown - type: markdown
attributes: attributes:
value: | value: |
Before reporting, please search [existing issues](https://github.com/andweeb/presence.nvim/issues) and make sure that presence.nvim is updated to the latest version. Before reporting, please search [existing issues](https://github.com/andweeb/presence.nvim/issues) and make sure that presence.nvim is updated to the latest version.
- type: checkboxes
attributes:
label: Are you on the latest version?
options:
- label: I have updated to the latest version.
required: true
- type: checkboxes
attributes:
label: Have you tried it with default config?
options:
- label: I have tried the default config.
required: true
- type: textarea - type: textarea
attributes: attributes:
label: "Description" label: "Description"
description: "A short summary of the error, bug, or unexpected behavior you're facing." description: "A short summary of the error, bug, or unexpected behavior you're facing."
validations: validations:
required: true required: true
- type: textarea - type: textarea
attributes: attributes:
label: "Neovim version" label: "Neovim version"
description: "Output of `nvim --version`" description: "Output of `nvim --version`"
render: markdown render: markdown
placeholder: | placeholder: |
NVIM v0.6.0-dev+209-g0603eba6e NVIM: v0.6.0-dev+209-g0603eba6e
Build type: Release Build type: Release
LuaJIT 2.1.0-beta3 LuaJIT: 2.1.0-beta3
value: |
NVIM:
Build type:
LuaJIT:
validations: validations:
required: true required: true
- type: input - type: input
attributes: attributes:
label: "OS information" label: "OS information"
placeholder: "macOS 12.0.1" placeholder: "macOS 12.0.1"
validations: validations:
required: true required: true
- type: textarea - type: textarea
attributes: attributes:
label: "Steps to reproduce" label: "Steps to reproduce"
description: "Steps to reproduce the issue with your config(s) if applicable" description: "Steps to reproduce the issue with your config(s) if applicable."
placeholder: | placeholder: |
1. Setup presence.nvim with `require("presence"):setup({...})` 1. Setup presence.nvim with `require("presence"):setup({...})`
2. Run Neovim with `nvim test.txt` 2. Run Neovim with `nvim test.txt`
3. ... 3. ...
validations: validations:
required: true required: true
- type: textarea - type: textarea
attributes: attributes:
label: "Logs" label: "Logs"
description: "The full list of `:messages` from one or more `nvim` instances" description: "The full list of `:messages` from one or more `nvim` instances.\nPlease insert the logs into code blocks."
placeholder: |
<details>
```
[presence.nvim] Using runtime path: /run/user/1000
[presence.nvim] Using Discord IPC socket path: /run/user/1000/discord-ipc-0
[presence.nvim] Checking Discord IPC socket at /run/user/1000/discord-ipc-0...
```
</details>
value: |
<details>
```
```
</details>
validations: validations:
required: true required: true
- type: textarea
attributes:
label: "Aditional info"
description: "If you'd like to add anything else put it here."
validations:
required: false

View file

@ -1,20 +0,0 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

View file

@ -0,0 +1,34 @@
name: Feature request
description: Report any errors, bugs, or unexpected behaviors related to presence.nvim
title: "[FEAT]: "
labels: [enhancement]
assignees:
- jiriks74
body:
- type: textarea
attributes:
label: Is your feature request related to a problem?
description: A clear and concise description of what the problem is. Ex. I'm always frustrated when...
validations:
required: true
- type: textarea
attributes:
label: Describe the solution you'd like
description: A clear and concise description of what you want to happen.
validations:
required: false
- type: textarea
attributes:
label: Describe alternatives you've considered
description: A clear and concise description of any alternative solutions or features you've considered.
validations:
required: false
- type: textarea
attributes:
label: Additional context
description: Add any other context or screenshots about the feature request here.
validations:
required: false

View file

@ -1,7 +1,7 @@
name: Luacheck name: Luacheck
on: [push, pull_request] on: [push, pull_request]
jobs: jobs:
sile: Luacheck:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout

15
.github/workflows/stylua.yml vendored Normal file
View file

@ -0,0 +1,15 @@
name: StyLua
on: [push, pull_request]
jobs:
StyLuacheck:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: StyLua check
uses: JohnnyMorganz/stylua-action@v3
with:
token: ${{ secrets.GH_TOKEN }}
version: v0.18.2 # NOTE: we recommend pinning to a specific version in case of formatting changes
# CLI arguments
args: --check .

View file

@ -62,7 +62,7 @@ require("presence").setup({
auto_update = true, -- Update activity based on autocmd events (if `false`, map or manually execute `:lua package.loaded.presence:update()`) auto_update = true, -- Update activity based on autocmd events (if `false`, map or manually execute `:lua package.loaded.presence:update()`)
neovim_image_text = "The One True Text Editor", -- Text displayed when hovered over the Neovim image neovim_image_text = "The One True Text Editor", -- Text displayed when hovered over the Neovim image
main_image = "neovim", -- Main image display (either "neovim" or "file") main_image = "neovim", -- Main image display (either "neovim" or "file")
client_id = "793271441293967371", -- Use your own Discord application client id (not recommended) client_id = "1172122807501594644", -- Use your own Discord application client id (not recommended)
log_level = nil, -- Log messages at or above this level (one of the following: "debug", "info", "warn", "error") log_level = nil, -- Log messages at or above this level (one of the following: "debug", "info", "warn", "error")
debounce_timeout = 10, -- Number of seconds to debounce events (or calls to `:lua package.loaded.presence:update(<filename>, true)`) debounce_timeout = 10, -- Number of seconds to debounce events (or calls to `:lua package.loaded.presence:update(<filename>, true)`)
enable_line_number = false, -- Displays the current line number instead of the current project enable_line_number = false, -- Displays the current line number instead of the current project
@ -91,7 +91,7 @@ Or if global variables are more your thing, you can use any of the following ins
let g:presence_auto_update = 1 let g:presence_auto_update = 1
let g:presence_neovim_image_text = "The One True Text Editor" let g:presence_neovim_image_text = "The One True Text Editor"
let g:presence_main_image = "neovim" let g:presence_main_image = "neovim"
let g:presence_client_id = "793271441293967371" let g:presence_client_id = "1172122807501594644"
let g:presence_log_level let g:presence_log_level
let g:presence_debounce_timeout = 10 let g:presence_debounce_timeout = 10
let g:presence_enable_line_number = 0 let g:presence_enable_line_number = 0
@ -142,6 +142,8 @@ errors: `luacheck lua`
**Please use [Conventional Commits](https://www.conventionalcommits.org/) if you want to contribute. **Please use [Conventional Commits](https://www.conventionalcommits.org/) if you want to contribute.
It makes everyones jobs easier.** It makes everyones jobs easier.**
**This project uses [StyLua](https://github.com/JohnnyMorganz/StyLua). Please format your code using StyLua for better readability**
Pull requests are very welcome, feel free to open an issue to work on Pull requests are very welcome, feel free to open an issue to work on
or message [me (@jiriks74)](https://discordapp.com/users/517810049360461837) on my or message [me (@jiriks74)](https://discordapp.com/users/517810049360461837) on my
[Discord server](https://discord.gg/cCq3qcB4jB)! [Discord server](https://discord.gg/cCq3qcB4jB)!

View file

@ -19,7 +19,6 @@ local function byte_mod(x,v)
return (x % v) return (x % v)
end end
-- buffer -- buffer
local strbuf = "" -- for unpacking local strbuf = "" -- for unpacking
local strary = {} -- for packing local strary = {} -- for packing
@ -35,11 +34,10 @@ local function strary_append_int32(n,h)
if n < 0 then if n < 0 then
n = n + 4294967296 n = n + 4294967296
end end
table.insert(strary, tostr(h, table.insert(
math.floor(n / 16777216), strary,
math.floor(n / 65536) % 256, tostr(h, math.floor(n / 16777216), math.floor(n / 65536) % 256, math.floor(n / 256) % 256, n % 256)
math.floor(n / 256) % 256, )
n % 256 ))
end end
local doubleto8bytes local doubleto8bytes
@ -59,7 +57,10 @@ doubleto8bytes = function(x)
return math.floor(v / 256), tostr(math.fmod(math.floor(v), 256)) return math.floor(v / 256), tostr(math.fmod(math.floor(v), 256))
end end
local sign = 0 local sign = 0
if x < 0 then sign = 1; x = -x end if x < 0 then
sign = 1
x = -x
end
local mantissa, exponent = math.frexp(x) local mantissa, exponent = math.frexp(x)
if x == 0 then -- zero if x == 0 then -- zero
mantissa, exponent = 0, 0 mantissa, exponent = 0, 0
@ -73,10 +74,13 @@ doubleto8bytes = function(x)
local v, byte = "" -- convert to bytes local v, byte = "" -- convert to bytes
x = mantissa x = mantissa
for _ = 1, 6 do for _ = 1, 6 do
_, byte = grab_byte(x); v = v..byte -- 47:0 _, byte = grab_byte(x)
v = v .. byte -- 47:0
end end
x, byte = grab_byte(exponent * 16 + x); v = v..byte -- 55:48 x, byte = grab_byte(exponent * 16 + x)
x, byte = grab_byte(sign * 128 + x); v = v..byte -- 63:56 v = v .. byte -- 55:48
x, byte = grab_byte(sign * 128 + x)
v = v .. byte -- 63:56
return v, x return v, x
end end
@ -108,17 +112,33 @@ local function bytestodouble(v)
local exp = band(v:byte(8), 127) * 16 + rshift(v:byte(7), 4) - 1023 -- bias local exp = band(v:byte(8), 127) * 16 + rshift(v:byte(7), 4) - 1023 -- bias
-- frac: 52 bit -- frac: 52 bit
local fracbytes = { local fracbytes = {
band( v:byte(7), 15 ), v:byte(6), v:byte(5), v:byte(4), v:byte(3), v:byte(2), v:byte(1) -- big endian band(v:byte(7), 15),
v:byte(6),
v:byte(5),
v:byte(4),
v:byte(3),
v:byte(2),
v:byte(1), -- big endian
} }
local bits = bytestobits(fracbytes) local bits = bytestobits(fracbytes)
for _ = 1, 4 do table.remove(bits,1) end for _ = 1, 4 do
table.remove(bits, 1)
end
if sign == 1 then sign = -1 else sign = 1 end if sign == 1 then
sign = -1
else
sign = 1
end
local frac = bitstofrac(bits) local frac = bitstofrac(bits)
if exp == -1023 and frac==0 then return 0 end if exp == -1023 and frac == 0 then
if exp == 1024 and frac==0 then return 1/0 *sign end return 0
end
if exp == 1024 and frac == 0 then
return 1 / 0 * sign
end
local real = math.ldexp(1 + frac, exp) local real = math.ldexp(1 + frac, exp)
@ -208,8 +228,12 @@ packers.table = function(data)
local is_map, ndata, nmax = false, 0, 0 local is_map, ndata, nmax = false, 0, 0
for k, _ in pairs(data) do for k, _ in pairs(data) do
if type(k) == "number" then if type(k) == "number" then
if k > nmax then nmax = k end if k > nmax then
else is_map = true end nmax = k
end
else
is_map = true
end
ndata = ndata + 1 ndata = ndata + 1
end end
if is_map then -- pack as map if is_map then -- pack as map
@ -236,7 +260,9 @@ packers.table = function(data)
else else
error("overflow") error("overflow")
end end
for i=1,nmax do packers[type(data[i])](data[i]) end for i = 1, nmax do
packers[type(data[i])](data[i])
end
end end
end end
@ -265,26 +291,36 @@ local types_map = {
} }
local type_for = function(n) local type_for = function(n)
if types_map[n] then
if types_map[n] then return types_map[n] return types_map[n]
elseif n < 0xc0 then elseif n < 0xc0 then
if n < 0x80 then return "fixnum_posi" if n < 0x80 then
elseif n < 0x90 then return "fixmap" return "fixnum_posi"
elseif n < 0xa0 then return "fixarray" elseif n < 0x90 then
else return "fixraw" end return "fixmap"
elseif n > 0xdf then return "fixnum_neg" elseif n < 0xa0 then
else return "undefined" end return "fixarray"
else
return "fixraw"
end
elseif n > 0xdf then
return "fixnum_neg"
else
return "undefined"
end
end end
local types_len_map = { local types_len_map = {
uint16 = 2, uint32 = 4, uint64 = 8, uint16 = 2,
int16 = 2, int32 = 4, int64 = 8, uint32 = 4,
float = 4, double = 8, uint64 = 8,
int16 = 2,
int32 = 4,
int64 = 8,
float = 4,
double = 8,
} }
--- unpackers --- unpackers
local unpackers = {} local unpackers = {}
@ -308,12 +344,16 @@ local unpack_number = function(offset,ntype,nlen)
elseif ntype == "int16_t" then elseif ntype == "int16_t" then
local n = b1 * 256 + b2 local n = b1 * 256 + b2
local nn = (65536 - n) * -1 local nn = (65536 - n) * -1
if nn == -65536 then nn = 0 end if nn == -65536 then
nn = 0
end
return nn return nn
elseif ntype == "int32_t" then elseif ntype == "int32_t" then
local n = b1 * 65536 * 256 + b2 * 65536 + b3 * 256 + b4 local n = b1 * 65536 * 256 + b2 * 65536 + b3 * 256 + b4
local nn = (4294967296 - n) * -1 local nn = (4294967296 - n) * -1
if nn == -4294967296 then nn = 0 end if nn == -4294967296 then
nn = 0
end
return nn return nn
elseif ntype == "double_t" then elseif ntype == "double_t" then
local s = tostr(b8, b7, b6, b5, b4, b3, b2, b1) local s = tostr(b8, b7, b6, b5, b4, b3, b2, b1)
@ -325,13 +365,11 @@ local unpack_number = function(offset,ntype,nlen)
end end
end end
local function unpacker_number(offset) local function unpacker_number(offset)
local obj_type = type_for(string.byte(strbuf, offset + 1, offset + 1)) local obj_type = type_for(string.byte(strbuf, offset + 1, offset + 1))
local nlen = types_len_map[obj_type] local nlen = types_len_map[obj_type]
local ntype local ntype
if (obj_type == "float") then if obj_type == "float" then
error("float is not implemented") error("float is not implemented")
else else
ntype = obj_type .. "_t" ntype = obj_type .. "_t"
@ -362,7 +400,9 @@ local function unpack_array(offset,n)
end end
function unpackers.dynamic(offset) function unpackers.dynamic(offset)
if offset >= #strbuf then error("need more data") end if offset >= #strbuf then
error("need more data")
end
local obj_type = type_for(string.byte(strbuf, offset + 1, offset + 1)) local obj_type = type_for(string.byte(strbuf, offset + 1, offset + 1))
return unpackers[obj_type](offset) return unpackers[obj_type](offset)
end end
@ -485,8 +525,12 @@ local ljp_pack = function(data)
end end
local ljp_unpack = function(s, offset) local ljp_unpack = function(s, offset)
if offset == nil then offset = 0 end if offset == nil then
if type(s) ~= "string" then return false,"invalid argument" end offset = 0
end
if type(s) ~= "string" then
return false, "invalid argument"
end
local data local data
strbuf = s strbuf = s
offset, data = unpackers.dynamic(offset) offset, data = unpackers.dynamic(offset)
@ -496,14 +540,14 @@ end
local function ljp_stat() local function ljp_stat()
return { return {
double_decode_count = double_decode_count, double_decode_count = double_decode_count,
double_encode_count = double_encode_count double_encode_count = double_encode_count,
} }
end end
local msgpack = { local msgpack = {
pack = ljp_pack, pack = ljp_pack,
unpack = ljp_unpack, unpack = ljp_unpack,
stat = ljp_stat stat = ljp_stat,
} }
return msgpack return msgpack

View file

@ -1,140 +1,265 @@
local n, v = "serpent", "0.302" -- (C) 2012-18 Paul Kulchenko; MIT License local n, v = "serpent", "0.302" -- (C) 2012-18 Paul Kulchenko; MIT License
local c, d = "Paul Kulchenko", "Lua serializer and pretty printer" local c, d = "Paul Kulchenko", "Lua serializer and pretty printer"
local snum = {[tostring(1/0)]='1/0 --[[math.huge]]',[tostring(-1/0)]='-1/0 --[[-math.huge]]',[tostring(0/0)]='0/0'} local snum = {
[tostring(1 / 0)] = "1/0 --[[math.huge]]",
[tostring(-1 / 0)] = "-1/0 --[[-math.huge]]",
[tostring(0 / 0)] = "0/0",
}
local badtype = { thread = true, userdata = true, cdata = true } local badtype = { thread = true, userdata = true, cdata = true }
local getmetatable = debug and debug.getmetatable or getmetatable local getmetatable = debug and debug.getmetatable or getmetatable
local pairs = function(t) return next, t end -- avoid using __pairs in Lua 5.2+ local pairs = function(t)
return next, t
end -- avoid using __pairs in Lua 5.2+
local keyword, globals, G = {}, {}, (_G or _ENV) local keyword, globals, G = {}, {}, (_G or _ENV)
for _,k in ipairs({'and', 'break', 'do', 'else', 'elseif', 'end', 'false', for _, k in ipairs({
'for', 'function', 'goto', 'if', 'in', 'local', 'nil', 'not', 'or', 'repeat', "and",
'return', 'then', 'true', 'until', 'while'}) do keyword[k] = true end "break",
for k,v in pairs(G) do globals[v] = k end -- build func to name mapping "do",
for _,g in ipairs({'coroutine', 'debug', 'io', 'math', 'string', 'table', 'os'}) do "else",
for k,v in pairs(type(G[g]) == 'table' and G[g] or {}) do globals[v] = g..'.'..k end end "elseif",
"end",
"false",
"for",
"function",
"goto",
"if",
"in",
"local",
"nil",
"not",
"or",
"repeat",
"return",
"then",
"true",
"until",
"while",
}) do
keyword[k] = true
end
for k, v in pairs(G) do
globals[v] = k
end -- build func to name mapping
for _, g in ipairs({ "coroutine", "debug", "io", "math", "string", "table", "os" }) do
for k, v in pairs(type(G[g]) == "table" and G[g] or {}) do
globals[v] = g .. "." .. k
end
end
local function s(t, opts) local function s(t, opts)
local name, indent, fatal, maxnum = opts.name, opts.indent, opts.fatal, opts.maxnum local name, indent, fatal, maxnum = opts.name, opts.indent, opts.fatal, opts.maxnum
local sparse, custom, huge = opts.sparse, opts.custom, not opts.nohuge local sparse, custom, huge = opts.sparse, opts.custom, not opts.nohuge
local space, maxl = (opts.compact and '' or ' '), (opts.maxlevel or math.huge) local space, maxl = (opts.compact and "" or " "), (opts.maxlevel or math.huge)
local maxlen, metatostring = tonumber(opts.maxlength), opts.metatostring local maxlen, metatostring = tonumber(opts.maxlength), opts.metatostring
local iname, comm = '_'..(name or ''), opts.comment and (tonumber(opts.comment) or math.huge) local iname, comm = "_" .. (name or ""), opts.comment and (tonumber(opts.comment) or math.huge)
local numformat = opts.numformat or "%.17g" local numformat = opts.numformat or "%.17g"
local seen, sref, syms, symn = {}, {'local '..iname..'={}'}, {}, 0 local seen, sref, syms, symn = {}, { "local " .. iname .. "={}" }, {}, 0
local function gensym(val) return '_'..(tostring(tostring(val)):gsub("[^%w]",""):gsub("(%d%w+)", local function gensym(val)
return "_"
.. (
tostring(tostring(val)):gsub("[^%w]", ""):gsub(
"(%d%w+)",
-- tostring(val) is needed because __tostring may return a non-string value -- tostring(val) is needed because __tostring may return a non-string value
function(s) if not syms[s] then symn = symn+1; syms[s] = symn end return tostring(syms[s]) end)) end function(s)
local function safestr(s) return type(s) == "number" and tostring(huge and snum[tostring(s)] or numformat:format(s)) if not syms[s] then
symn = symn + 1
syms[s] = symn
end
return tostring(syms[s])
end
)
)
end
local function safestr(s)
return type(s) == "number" and tostring(huge and snum[tostring(s)] or numformat:format(s))
or type(s) ~= "string" and tostring(s) -- escape NEWLINE/010 and EOF/026 or type(s) ~= "string" and tostring(s) -- escape NEWLINE/010 and EOF/026
or ("%q"):format(s):gsub("\010","n"):gsub("\026","\\026") end or ("%q"):format(s):gsub("\010", "n"):gsub("\026", "\\026")
local function comment(s,l) return comm and (l or 0) < comm and ' --[['..select(2, pcall(tostring, s))..']]' or '' end end
local function globerr(s,l) return globals[s] and globals[s]..comment(s,l) or not fatal local function comment(s, l)
and safestr(select(2, pcall(tostring, s))) or error("Can't serialize "..tostring(s)) end return comm and (l or 0) < comm and " --[[" .. select(2, pcall(tostring, s)) .. "]]" or ""
end
local function globerr(s, l)
return globals[s] and globals[s] .. comment(s, l)
or not fatal and safestr(select(2, pcall(tostring, s)))
or error("Can't serialize " .. tostring(s))
end
local function safename(path, name) -- generates foo.bar, foo[3], or foo['b a r'] local function safename(path, name) -- generates foo.bar, foo[3], or foo['b a r']
local n = name == nil and '' or name local n = name == nil and "" or name
local plain = type(n) == "string" and n:match("^[%l%u_][%w_]*$") and not keyword[n] local plain = type(n) == "string" and n:match("^[%l%u_][%w_]*$") and not keyword[n]
local safe = plain and n or '['..safestr(n)..']' local safe = plain and n or "[" .. safestr(n) .. "]"
return (path or '')..(plain and path and '.' or '')..safe, safe end return (path or "") .. (plain and path and "." or "") .. safe, safe
local alphanumsort = type(opts.sortkeys) == 'function' and opts.sortkeys or function(k, o, n) -- k=keys, o=originaltable, n=padding end
local maxn, to = tonumber(n) or 12, {number = 'a', string = 'b'} local alphanumsort = type(opts.sortkeys) == "function" and opts.sortkeys
local function padnum(d) return ("%0"..tostring(maxn).."d"):format(tonumber(d)) end or function(k, o, n) -- k=keys, o=originaltable, n=padding
local maxn, to = tonumber(n) or 12, { number = "a", string = "b" }
local function padnum(d)
return ("%0" .. tostring(maxn) .. "d"):format(tonumber(d))
end
table.sort(k, function(a, b) table.sort(k, function(a, b)
-- sort numeric keys first: k[key] is not nil for numerical keys -- sort numeric keys first: k[key] is not nil for numerical keys
return (k[a] ~= nil and 0 or to[type(a)] or 'z')..(tostring(a):gsub("%d+",padnum)) return (k[a] ~= nil and 0 or to[type(a)] or "z") .. (tostring(a):gsub("%d+", padnum))
< (k[b] ~= nil and 0 or to[type(b)] or 'z')..(tostring(b):gsub("%d+",padnum)) end) end < (k[b] ~= nil and 0 or to[type(b)] or "z") .. (tostring(b):gsub("%d+", padnum))
end)
end
local function val2str(t, name, indent, insref, path, plainindex, level) local function val2str(t, name, indent, insref, path, plainindex, level)
local ttype, level, mt = type(t), (level or 0), getmetatable(t) local ttype, level, mt = type(t), (level or 0), getmetatable(t)
local spath, sname = safename(path, name) local spath, sname = safename(path, name)
local tag = plainindex and local tag = plainindex and ((type(name) == "number") and "" or name .. space .. "=" .. space)
((type(name) == "number") and '' or name..space..'='..space) or or (name ~= nil and sname .. space .. "=" .. space or "")
(name ~= nil and sname..space..'='..space or '')
if seen[t] then -- already seen this element if seen[t] then -- already seen this element
sref[#sref+1] = spath..space..'='..space..seen[t] sref[#sref + 1] = spath .. space .. "=" .. space .. seen[t]
return tag..'nil'..comment('ref', level) end return tag .. "nil" .. comment("ref", level)
end
-- protect from those cases where __tostring may fail -- protect from those cases where __tostring may fail
if type(mt) == 'table' and metatostring ~= false then if type(mt) == "table" and metatostring ~= false then
local to, tr = pcall(function() return mt.__tostring(t) end) local to, tr = pcall(function()
local so, sr = pcall(function() return mt.__serialize(t) end) return mt.__tostring(t)
if (to or so) then -- knows how to serialize itself end)
local so, sr = pcall(function()
return mt.__serialize(t)
end)
if to or so then -- knows how to serialize itself
seen[t] = insref or spath seen[t] = insref or spath
t = so and sr or tr t = so and sr or tr
ttype = type(t) ttype = type(t)
end -- new value falls through to be serialized end -- new value falls through to be serialized
end end
if ttype == "table" then if ttype == "table" then
if level >= maxl then return tag..'{}'..comment('maxlvl', level) end if level >= maxl then
return tag .. "{}" .. comment("maxlvl", level)
end
seen[t] = insref or spath seen[t] = insref or spath
if next(t) == nil then return tag..'{}'..comment(t, level) end -- table empty if next(t) == nil then
if maxlen and maxlen < 0 then return tag..'{}'..comment('maxlen', level) end return tag .. "{}" .. comment(t, level)
end -- table empty
if maxlen and maxlen < 0 then
return tag .. "{}" .. comment("maxlen", level)
end
local maxn, o, out = math.min(#t, maxnum or #t), {}, {} local maxn, o, out = math.min(#t, maxnum or #t), {}, {}
for key = 1, maxn do o[key] = key end for key = 1, maxn do
o[key] = key
end
if not maxnum or #o < maxnum then if not maxnum or #o < maxnum then
local n = #o -- n = n + 1; o[n] is much faster than o[#o+1] on large tables local n = #o -- n = n + 1; o[n] is much faster than o[#o+1] on large tables
for key in pairs(t) do if o[key] ~= key then n = n + 1; o[n] = key end end end for key in pairs(t) do
if maxnum and #o > maxnum then o[maxnum+1] = nil end if o[key] ~= key then
if opts.sortkeys and #o > maxn then alphanumsort(o, t, opts.sortkeys) end n = n + 1
o[n] = key
end
end
end
if maxnum and #o > maxnum then
o[maxnum + 1] = nil
end
if opts.sortkeys and #o > maxn then
alphanumsort(o, t, opts.sortkeys)
end
local sparse = sparse and #o > maxn -- disable sparsness if only numeric keys (shorter output) local sparse = sparse and #o > maxn -- disable sparsness if only numeric keys (shorter output)
for n, key in ipairs(o) do for n, key in ipairs(o) do
local value, ktype, plainindex = t[key], type(key), n <= maxn and not sparse local value, ktype, plainindex = t[key], type(key), n <= maxn and not sparse
if opts.valignore and opts.valignore[value] -- skip ignored values; do nothing if
opts.valignore and opts.valignore[value] -- skip ignored values; do nothing
or opts.keyallow and not opts.keyallow[key] or opts.keyallow and not opts.keyallow[key]
or opts.keyignore and opts.keyignore[key] or opts.keyignore and opts.keyignore[key]
or opts.valtypeignore and opts.valtypeignore[type(value)] -- skipping ignored value types or opts.valtypeignore and opts.valtypeignore[type(value)] -- skipping ignored value types
or sparse and value == nil then -- skipping nils; do nothing or sparse and value == nil
elseif ktype == 'table' or ktype == 'function' or badtype[ktype] then then -- skipping nils; do nothing
elseif ktype == "table" or ktype == "function" or badtype[ktype] then
if not seen[key] and not globals[key] then if not seen[key] and not globals[key] then
sref[#sref+1] = 'placeholder' sref[#sref + 1] = "placeholder"
local sname = safename(iname, gensym(key)) -- iname is table for local variables local sname = safename(iname, gensym(key)) -- iname is table for local variables
sref[#sref] = val2str(key,sname,indent,sname,iname,true) end sref[#sref] = val2str(key, sname, indent, sname, iname, true)
sref[#sref+1] = 'placeholder' end
local path = seen[t]..'['..tostring(seen[key] or globals[key] or gensym(key))..']' sref[#sref + 1] = "placeholder"
sref[#sref] = path..space..'='..space..tostring(seen[value] or val2str(value,nil,indent,path)) local path = seen[t] .. "[" .. tostring(seen[key] or globals[key] or gensym(key)) .. "]"
sref[#sref] = path
.. space
.. "="
.. space
.. tostring(seen[value] or val2str(value, nil, indent, path))
else else
out[#out + 1] = val2str(value, key, indent, nil, seen[t], plainindex, level + 1) out[#out + 1] = val2str(value, key, indent, nil, seen[t], plainindex, level + 1)
if maxlen then if maxlen then
maxlen = maxlen - #out[#out] maxlen = maxlen - #out[#out]
if maxlen < 0 then break end if maxlen < 0 then
break
end end
end end
end end
local prefix = string.rep(indent or '', level) end
local head = indent and '{\n'..prefix..indent or '{' local prefix = string.rep(indent or "", level)
local body = table.concat(out, ','..(indent and '\n'..prefix..indent or space)) local head = indent and "{\n" .. prefix .. indent or "{"
local tail = indent and "\n"..prefix..'}' or '}' local body = table.concat(out, "," .. (indent and "\n" .. prefix .. indent or space))
local tail = indent and "\n" .. prefix .. "}" or "}"
return (custom and custom(tag, head, body, tail, level) or tag .. head .. body .. tail) .. comment(t, level) return (custom and custom(tag, head, body, tail, level) or tag .. head .. body .. tail) .. comment(t, level)
elseif badtype[ttype] then elseif badtype[ttype] then
seen[t] = insref or spath seen[t] = insref or spath
return tag .. globerr(t, level) return tag .. globerr(t, level)
elseif ttype == 'function' then elseif ttype == "function" then
seen[t] = insref or spath seen[t] = insref or spath
if opts.nocode then return tag.."function() --[[..skipped..]] end"..comment(t, level) end if opts.nocode then
return tag .. "function() --[[..skipped..]] end" .. comment(t, level)
end
local ok, res = pcall(string.dump, t) local ok, res = pcall(string.dump, t)
local func = ok and "((loadstring or load)(" .. safestr(res) .. ",'@serialized'))" .. comment(t, level) local func = ok and "((loadstring or load)(" .. safestr(res) .. ",'@serialized'))" .. comment(t, level)
return tag .. (func or globerr(t, level)) return tag .. (func or globerr(t, level))
else return tag..safestr(t) end -- handle all other types else
return tag .. safestr(t)
end -- handle all other types
end end
local sepr = indent and "\n" or ";" .. space local sepr = indent and "\n" or ";" .. space
local body = val2str(t, name, indent) -- this call also populates sref local body = val2str(t, name, indent) -- this call also populates sref
local tail = #sref>1 and table.concat(sref, sepr)..sepr or '' local tail = #sref > 1 and table.concat(sref, sepr) .. sepr or ""
local warn = opts.comment and #sref>1 and space.."--[[incomplete output with shared/self-references skipped]]" or '' local warn = opts.comment and #sref > 1 and space .. "--[[incomplete output with shared/self-references skipped]]"
or ""
return not name and body .. warn or "do local " .. body .. sepr .. tail .. "return " .. name .. sepr .. "end" return not name and body .. warn or "do local " .. body .. sepr .. tail .. "return " .. name .. sepr .. "end"
end end
local function deserialize(data, opts) local function deserialize(data, opts)
local env = (opts and opts.safe == false) and G local env = (opts and opts.safe == false) and G
or setmetatable({}, { or setmetatable({}, {
__index = function(t,k) return t end, __index = function(t, k)
__call = function(t,...) error("cannot call functions") end return t
end,
__call = function(t, ...)
error("cannot call functions")
end,
}) })
local f, res = (loadstring or load)('return '..data, nil, nil, env) local f, res = (loadstring or load)("return " .. data, nil, nil, env)
if not f then f, res = (loadstring or load)(data, nil, nil, env) end if not f then
if not f then return f, res end f, res = (loadstring or load)(data, nil, nil, env)
if setfenv then setfenv(f, env) end end
if not f then
return f, res
end
if setfenv then
setfenv(f, env)
end
return pcall(f) return pcall(f)
end end
local function merge(a, b) if b then for k,v in pairs(b) do a[k] = v end end; return a; end local function merge(a, b)
return { _NAME = n, _COPYRIGHT = c, _DESCRIPTION = d, _VERSION = v, serialize = s, if b then
for k, v in pairs(b) do
a[k] = v
end
end
return a
end
return {
_NAME = n,
_COPYRIGHT = c,
_DESCRIPTION = d,
_VERSION = v,
serialize = s,
load = deserialize, load = deserialize,
dump = function(a, opts) return s(a, merge({name = '_', compact = true, sparse = true}, opts)) end, dump = function(a, opts)
line = function(a, opts) return s(a, merge({sortkeys = true, comment = true}, opts)) end, return s(a, merge({ name = "_", compact = true, sparse = true }, opts))
block = function(a, opts) return s(a, merge({indent = ' ', sortkeys = true, comment = true}, opts)) end } end,
line = function(a, opts)
return s(a, merge({ sortkeys = true, comment = true }, opts))
end,
block = function(a, opts)
return s(a, merge({ indent = " ", sortkeys = true, comment = true }, opts))
end,
}

View file

@ -8,12 +8,12 @@ function struct.pack(format, ...)
for i = 1, format:len() do for i = 1, format:len() do
local opt = format:sub(i, i) local opt = format:sub(i, i)
if opt == '<' then if opt == "<" then
endianness = true endianness = true
elseif opt == '>' then elseif opt == ">" then
endianness = false endianness = false
elseif opt:find('[bBhHiIlL]') then elseif opt:find("[bBhHiIlL]") then
local n = opt:find('[hH]') and 2 or opt:find('[iI]') and 4 or opt:find('[lL]') and 8 or 1 local n = opt:find("[hH]") and 2 or opt:find("[iI]") and 4 or opt:find("[lL]") and 8 or 1
local val = tonumber(table.remove(vars, 1)) local val = tonumber(table.remove(vars, 1))
local bytes = {} local bytes = {}
@ -27,7 +27,7 @@ function struct.pack(format, ...)
else else
table.insert(stream, table.concat(bytes)) table.insert(stream, table.concat(bytes))
end end
elseif opt:find('[fd]') then elseif opt:find("[fd]") then
local val = tonumber(table.remove(vars, 1)) local val = tonumber(table.remove(vars, 1))
local sign = 0 local sign = 0
@ -41,12 +41,12 @@ function struct.pack(format, ...)
mantissa = 0 mantissa = 0
exponent = 0 exponent = 0
else else
mantissa = (mantissa * 2 - 1) * math.ldexp(0.5, (opt == 'd') and 53 or 24) mantissa = (mantissa * 2 - 1) * math.ldexp(0.5, (opt == "d") and 53 or 24)
exponent = exponent + ((opt == 'd') and 1022 or 126) exponent = exponent + ((opt == "d") and 1022 or 126)
end end
local bytes = {} local bytes = {}
if opt == 'd' then if opt == "d" then
val = mantissa val = mantissa
for _ = 1, 6 do for _ = 1, 6 do
table.insert(bytes, string.char(math.floor(val) % (2 ^ 8))) table.insert(bytes, string.char(math.floor(val) % (2 ^ 8)))
@ -59,8 +59,8 @@ function struct.pack(format, ...)
val = math.floor(val / (2 ^ 8)) val = math.floor(val / (2 ^ 8))
end end
table.insert(bytes, string.char(math.floor(exponent * ((opt == 'd') and 16 or 128) + val) % (2 ^ 8))) table.insert(bytes, string.char(math.floor(exponent * ((opt == "d") and 16 or 128) + val) % (2 ^ 8)))
val = math.floor((exponent * ((opt == 'd') and 16 or 128) + val) / (2 ^ 8)) val = math.floor((exponent * ((opt == "d") and 16 or 128) + val) / (2 ^ 8))
table.insert(bytes, string.char(math.floor(sign * 128 + val) % (2 ^ 8))) table.insert(bytes, string.char(math.floor(sign * 128 + val) % (2 ^ 8)))
if not endianness then if not endianness then
@ -68,18 +68,18 @@ function struct.pack(format, ...)
else else
table.insert(stream, table.concat(bytes)) table.insert(stream, table.concat(bytes))
end end
elseif opt == 's' then elseif opt == "s" then
table.insert(stream, tostring(table.remove(vars, 1))) table.insert(stream, tostring(table.remove(vars, 1)))
table.insert(stream, string.char(0)) table.insert(stream, string.char(0))
elseif opt == 'c' then elseif opt == "c" then
local n = format:sub(i + 1):match('%d+') local n = format:sub(i + 1):match("%d+")
local str = tostring(table.remove(vars, 1)) local str = tostring(table.remove(vars, 1))
local len = tonumber(n) local len = tonumber(n)
if len <= 0 then if len <= 0 then
len = str:len() len = str:len()
end end
if len - str:len() > 0 then if len - str:len() > 0 then
str = str .. string.rep(' ', len - str:len()) str = str .. string.rep(" ", len - str:len())
end end
table.insert(stream, str:sub(1, len)) table.insert(stream, str:sub(1, len))
end end
@ -96,12 +96,12 @@ function struct.unpack(format, stream, pos)
for i = 1, format:len() do for i = 1, format:len() do
local opt = format:sub(i, i) local opt = format:sub(i, i)
if opt == '<' then if opt == "<" then
endianness = true endianness = true
elseif opt == '>' then elseif opt == ">" then
endianness = false endianness = false
elseif opt:find('[bBhHiIlL]') then elseif opt:find("[bBhHiIlL]") then
local n = opt:find('[hH]') and 2 or opt:find('[iI]') and 4 or opt:find('[lL]') and 8 or 1 local n = opt:find("[hH]") and 2 or opt:find("[iI]") and 4 or opt:find("[lL]") and 8 or 1
local signed = opt:lower() == opt local signed = opt:lower() == opt
local val = 0 local val = 0
@ -120,8 +120,8 @@ function struct.unpack(format, stream, pos)
end end
table.insert(vars, math.floor(val)) table.insert(vars, math.floor(val))
elseif opt:find('[fd]') then elseif opt:find("[fd]") then
local n = (opt == 'd') and 8 or 4 local n = (opt == "d") and 8 or 4
local x = stream:sub(iterator, iterator + n - 1) local x = stream:sub(iterator, iterator + n - 1)
iterator = iterator + n iterator = iterator + n
@ -130,7 +130,7 @@ function struct.unpack(format, stream, pos)
end end
local sign = 1 local sign = 1
local mantissa = string.byte(x, (opt == 'd') and 7 or 3) % ((opt == 'd') and 16 or 128) local mantissa = string.byte(x, (opt == "d") and 7 or 3) % ((opt == "d") and 16 or 128)
for j = n - 2, 1, -1 do for j = n - 2, 1, -1 do
mantissa = mantissa * (2 ^ 8) + string.byte(x, j) mantissa = mantissa * (2 ^ 8) + string.byte(x, j)
end end
@ -139,19 +139,18 @@ function struct.unpack(format, stream, pos)
sign = -1 sign = -1
end end
local exponent = (string.byte(x, n) % 128) * ((opt == 'd') and 16 or 2) + local exponent = (string.byte(x, n) % 128) * ((opt == "d") and 16 or 2)
math.floor(string.byte(x, n - 1) / + math.floor(string.byte(x, n - 1) / ((opt == "d") and 16 or 128))
((opt == 'd') and 16 or 128))
if exponent == 0 then if exponent == 0 then
table.insert(vars, 0.0) table.insert(vars, 0.0)
else else
mantissa = (math.ldexp(mantissa, (opt == 'd') and -52 or -23) + 1) * sign mantissa = (math.ldexp(mantissa, (opt == "d") and -52 or -23) + 1) * sign
table.insert(vars, math.ldexp(mantissa, exponent - ((opt == 'd') and 1023 or 127))) table.insert(vars, math.ldexp(mantissa, exponent - ((opt == "d") and 1023 or 127)))
end end
elseif opt == 's' then elseif opt == "s" then
local bytes = {} local bytes = {}
for j = iterator, stream:len() do for j = iterator, stream:len() do
if stream:sub(j,j) == string.char(0) or stream:sub(j) == '' then if stream:sub(j, j) == string.char(0) or stream:sub(j) == "" then
break break
end end
@ -161,8 +160,8 @@ function struct.unpack(format, stream, pos)
local str = table.concat(bytes) local str = table.concat(bytes)
iterator = iterator + str:len() + 1 iterator = iterator + str:len() + 1
table.insert(vars, str) table.insert(vars, str)
elseif opt == 'c' then elseif opt == "c" then
local n = format:sub(i + 1):match('%d+') local n = format:sub(i + 1):match("%d+")
local len = tonumber(n) local len = tonumber(n)
if len <= 0 then if len <= 0 then
len = table.remove(vars) len = table.remove(vars)

View file

@ -89,7 +89,6 @@ function Discord:read_message(nonce, on_response, err, chunk)
local err_message = string.format(err_format, err) local err_message = string.format(err_format, err)
on_response(err_message) on_response(err_message)
elseif chunk then elseif chunk then
-- Strip header from the chunk -- Strip header from the chunk
local message = chunk:match("({.+)") local message = chunk:match("({.+)")
@ -171,9 +170,7 @@ function Discord.generate_uuid(seed)
index = index + 1 index = index + 1
math.randomseed((seed or os.clock()) / index) math.randomseed((seed or os.clock()) / index)
local n = char == "x" local n = char == "x" and math.random(0, 0xf) or math.random(8, 0xb)
and math.random(0, 0xf)
or math.random(8, 0xb)
return string.format("%x", n) return string.format("%x", n)
end) end)

View file

@ -5,6 +5,6 @@ return {
["[defx] default-"] = "Defx", ["[defx] default-"] = "Defx",
["netrw"] = "Netrw", ["netrw"] = "Netrw",
["TelescopePrompt"] = "Telescope", ["TelescopePrompt"] = "Telescope",
['neo-tree'] = 'Neotree', ["neo-tree"] = "Neotree",
['fern'] = 'Fern' ["fern"] = "Fern",
} }

View file

@ -116,7 +116,7 @@ function Presence:setup(...)
-- General options -- General options
self:set_option("auto_update", 1) self:set_option("auto_update", 1)
self:set_option("client_id", "793271441293967371") self:set_option("client_id", "1172122807501594644")
self:set_option("debounce_timeout", 10) self:set_option("debounce_timeout", 10)
self:set_option("neovim_image_text", "The One True Text Editor") self:set_option("neovim_image_text", "The One True Text Editor")
self:set_option("main_image", "neovim") self:set_option("main_image", "neovim")
@ -848,8 +848,9 @@ function Presence:update_for_buffer(buffer, should_debounce)
local use_file_as_main_image = self.options.main_image == "file" local use_file_as_main_image = self.options.main_image == "file"
local use_neovim_as_main_image = self.options.main_image == "neovim" local use_neovim_as_main_image = self.options.main_image == "neovim"
local assets = { local assets = {
large_image = use_file_as_main_image and asset_key or use_neovim_as_main_image large_image = use_file_as_main_image and asset_key
and "neovim" or self.options.main_image, or use_neovim_as_main_image and "neovim"
or self.options.main_image,
large_text = use_file_as_main_image and file_text or neovim_image_text, large_text = use_file_as_main_image and file_text or neovim_image_text,
small_image = use_file_as_main_image and "neovim" or asset_key, small_image = use_file_as_main_image and "neovim" or asset_key,
small_text = use_file_as_main_image and neovim_image_text or file_text, small_text = use_file_as_main_image and neovim_image_text or file_text,