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

docs: update #242

Closed
wants to merge 2 commits into from
Closed
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
10 changes: 10 additions & 0 deletions .markdownlint.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
// Line length
"MD013": false,
// Fenced code blocks should have a language specified
"MD040": false,
// Inline HTML
"MD033": false,
// Bare URL used
"MD034": false,
}
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<!-- markdownlint-disable MD001 MD013 MD034 MD033 MD051 -->

# 🌈 colorbox.nvim

<p>
Expand All @@ -11,9 +9,9 @@
<a href="https://app.codecov.io/github/linrongbin16/colorbox.nvim"><img alt="codecov" src="https://img.shields.io/codecov/c/github/linrongbin16/colorbox.nvim/main?label=codecov" /></a>
</p>

Do you want all the **most popular** (Neo)vim colorschemes than only one? Do you want to change colorscheme from time to time?
Do you want all the **most popular** (Neo)vim colorschemes than only one? Do you want to change them from time to time?

This is it! Let's load all the ultra colorschemes into the Neovim player!
This is it! Let's load all the ultra colorschemes into Neovim player!

https://github.com/linrongbin16/colorbox.nvim/assets/6496887/8fff55ea-749d-4064-90b8-a3799519898d

Expand Down Expand Up @@ -88,13 +86,13 @@ And multiple trigger timings:
- [4. Enable only top stars (&ge; 1000) & primary colors](#4-enable-only-top-stars--1000--primary-colors)
- [5. Disable by name](#5-disable-by-name)
- [6. Disable by plugin](#6-disable-by-plugin)
- [Development](#-development)
- [Development](#%EF%B8%8F-development)
- [Contribute](#-contribute)

## ✅ Requirements

- neovim &ge; 0.9.
- [git](https://git-scm.com/).
- Neovim &ge; 0.9.
- [Git](https://git-scm.com/).

## 📦 Install

Expand Down
124 changes: 53 additions & 71 deletions lua/colorbox/commons/fileio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -196,79 +196,65 @@ M.readfile = function(filename, opts)
return opts.trim and vim.trim(content) or content
end

--- @alias commons.AsyncReadFileOnComplete fun(data:string?):any
--- @alias commons.AsyncReadFileOnError fun(step:string?,err:string?):any
--- @param filename string
--- @param on_complete fun(data:string?):any
--- @param opts {trim:boolean?}?
--- @param on_complete commons.AsyncReadFileOnComplete
--- @param opts {trim:boolean?,on_error:commons.AsyncReadFileOnError?}?
M.asyncreadfile = function(filename, on_complete, opts)
opts = opts or { trim = false }
opts.trim = type(opts.trim) == "boolean" and opts.trim or false

local open_result, open_err = uv.fs_open(filename, "r", 438, function(open_complete_err, fd)
if open_complete_err then
if type(opts.on_error) ~= "function" then
opts.on_error = function(step1, err1)
error(
string.format(
"failed to complete open(r) file %s: %s",
"failed to read file(%s), filename:%s, error:%s",
vim.inspect(step1),
vim.inspect(filename),
vim.inspect(open_complete_err)
vim.inspect(err1)
)
)
end
end

local open_result, open_err = uv.fs_open(filename, "r", 438, function(open_complete_err, fd)
if open_complete_err then
opts.on_error("fs_open complete", open_complete_err)
return
end
uv.fs_fstat(fd --[[@as integer]], function(fstat_err, stat)
if fstat_err then
error(
string.format(
"failed to fstat file %s: %s",
vim.inspect(filename),
vim.inspect(fstat_err)
)
)
uv.fs_fstat(fd --[[@as integer]], function(fstat_complete_err, stat)
if fstat_complete_err then
opts.on_error("fs_fstat complete", fstat_complete_err)
return
end
if not stat then
error(
string.format(
"failed to fstat file %s (empty stat): %s",
vim.inspect(filename),
vim.inspect(fstat_err)
)
)
opts.on_error("fs_fstat returns nil", fstat_complete_err)
return
end
uv.fs_read(fd --[[@as integer]], stat.size, 0, function(read_err, data)
if read_err then
error(
string.format(
"failed to read file %s: %s",
vim.inspect(filename),
vim.inspect(read_err)
)
)
uv.fs_read(fd --[[@as integer]], stat.size, 0, function(read_complete_err, data)
if read_complete_err then
opts.on_error("fs_read complete", read_complete_err)
return
end
uv.fs_close(fd --[[@as integer]], function(close_err)
on_complete((opts.trim and type(data) == "string") and vim.trim(data) or data)
if close_err then
error(
string.format(
"failed to close file %s: %s",
vim.inspect(filename),
vim.inspect(close_err)
)
)
uv.fs_close(fd --[[@as integer]], function(close_complete_err)
if opts.trim and type(data) == "string" then
local trimmed_data = vim.trim(data)
on_complete(trimmed_data)
else
on_complete(data)
end

if close_complete_err then
opts.on_error("fs_close complete", close_complete_err)
end
end)
end)
end)
end)
assert(
open_result ~= nil,
string.format(
"failed to open(read) file: %s, error: %s",
vim.inspect(filename),
vim.inspect(open_err)
)
)
if open_result == nil then
opts.on_error("fs_open", open_err)
end
end

--- @param filename string
Expand All @@ -286,45 +272,43 @@ M.readlines = function(filename)
return results
end

--- @alias commons.AsyncReadLinesOnLine fun(line:string):any
--- @alias commons.AsyncReadLinesOnComplete fun(bytes:integer):any
--- @alias commons.AsyncReadLinesOnError fun(step:string?,err:string?):any
--- @param filename string
--- @param opts {on_line:fun(line:string):any,on_complete:fun(bytes:integer):any,on_error:fun(err:string?):any,batchsize:integer?}
--- @param opts {on_line:commons.AsyncReadLinesOnLine,on_complete:commons.AsyncReadLinesOnComplete,on_error:commons.AsyncReadLinesOnError?,batchsize:integer?}
M.asyncreadlines = function(filename, opts)
assert(type(opts) == "table")
assert(type(opts.on_line) == "function")
---@diagnostic disable-next-line: undefined-field
local batchsize = opts.batchsize or 4096

local function _handle_error(err, msg)
---@diagnostic disable-next-line: undefined-field
if type(opts.on_error) == "function" then
---@diagnostic disable-next-line: undefined-field
opts.on_error(err)
else
if type(opts.on_error) ~= "function" then
opts.on_error = function(step1, err1)
error(
string.format(
"failed to async read file(%s): %s, error: %s",
vim.inspect(msg),
"failed to async read file by lines(%s), filename:%s, error:%s",
vim.inspect(step1),
vim.inspect(filename),
vim.inspect(err)
vim.inspect(err1)
)
)
end
end

local open_result, open_err = uv.fs_open(filename, "r", 438, function(open_complete_err, fd)
if open_complete_err then
_handle_error(open_complete_err, "fs_open complete")
opts.on_error("fs_open complete", open_complete_err)
return
end
local fstat_result, fstat_err = uv.fs_fstat(
fd --[[@as integer]],
function(fstat_complete_err, stat)
if fstat_complete_err then
_handle_error(fstat_complete_err, "fs_fstat complete")
opts.on_error("fs_fstat complete", fstat_complete_err)
return
end
if stat == nil then
_handle_error("stat is nil", "fs_fstat complete")
opts.on_error("fs_fstat returns nil", fstat_complete_err)
return
end

Expand Down Expand Up @@ -355,7 +339,7 @@ M.asyncreadlines = function(filename, opts)
offset,
function(read_complete_err, data)
if read_complete_err then
_handle_error(read_complete_err, "fs_read complete")
opts.on_error("fs_read complete", read_complete_err)
return
end

Expand Down Expand Up @@ -386,23 +370,21 @@ M.asyncreadlines = function(filename, opts)
fd --[[@as integer]],
function(close_complete_err)
if close_complete_err then
_handle_error(close_complete_err, "fs_close complete")
opts.on_error("fs_close complete", close_complete_err)
end
---@diagnostic disable-next-line: undefined-field
if type(opts.on_complete) == "function" then
---@diagnostic disable-next-line: undefined-field
opts.on_complete(fsize)
end
end
)
if close_result == nil then
_handle_error(close_err, "fs_close")
opts.on_error("fs_close", close_err)
end
end
end
)
if read_result == nil then
_handle_error(read_err, "fs_read")
opts.on_error("fs_read", read_err)
end
end

Expand All @@ -411,11 +393,11 @@ M.asyncreadlines = function(filename, opts)
)

if fstat_result == nil then
_handle_error(fstat_err, "fs_fstat")
opts.on_error("fs_fstat", fstat_err)
end
end)
if open_result == nil then
_handle_error(open_err, "fs_open")
opts.on_error("fs_open", open_err)
end
end

Expand Down
6 changes: 5 additions & 1 deletion lua/colorbox/commons/tbl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ end
--- @param ... any
--- @return any
M.tbl_get = function(t, ...)
local args = { ... }
if #args == 0 then
return t
end
local e = t --[[@as table]]
for _, k in ipairs({ ... }) do
for _, k in ipairs(args) do
if type(e) == "table" and e[k] ~= nil then
e = e[k]
else
Expand Down
2 changes: 1 addition & 1 deletion lua/colorbox/commons/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.0.0
19.0.0