Skip to content
Open

Ref #358

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
34 changes: 32 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ on:
jobs:
lint:
runs-on: ubuntu-latest
name: Stylua Check
steps:
- uses: actions/checkout@v3
- name: Stylua
uses: JohnnyMorganz/stylua-action@v1.1.2
uses: JohnnyMorganz/stylua-action@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: latest
args: --check .

docs:
Expand All @@ -36,3 +37,32 @@ jobs:
commit_user_name: "github-actions[bot]"
commit_user_email: "github-actions[bot]@users.noreply.github.com"
commit_author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"

test:
name: Run Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v3
- uses: rhysd/action-setup-vim@v1
id: vim
with:
neovim: true
version: nightly

- name: luajit
uses: leafo/gh-actions-lua@v10
with:
luaVersion: "luajit-2.1.0-beta3"

- name: luarocks
uses: leafo/gh-actions-luarocks@v4

- name: run test
shell: bash
run: |
luarocks install luacheck
luarocks install vusted
vusted ./test
8 changes: 1 addition & 7 deletions doc/dashboard.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*dashboard.txt* For Nvim 0.8.0 Last change: 2023 May 03
*dashboard.txt* For Nvim 0.8.0 Last change: 2023 June 08

==============================================================================
Table of Contents *dashboard-table-of-contents*
Expand All @@ -19,15 +19,13 @@ Fancy and Blazing Fast start screen plugin of neovim --------------------------
==============================================================================
1. Feature *dashboard-feature*


- Low memory usage. dashboard does not store the all user configs in memory like header etc these string will take some memory. now it will be clean after you open a file. you can still use dashboard command to open a new one , then dashboard will read the config from cache.
- Blazing fast


==============================================================================
2. Install *dashboard-install*


- Lazy.nvim

>lua
Expand All @@ -43,7 +41,6 @@ Fancy and Blazing Fast start screen plugin of neovim --------------------------
}
<


- Packer

>lua
Expand Down Expand Up @@ -152,7 +149,6 @@ instead

COMMANDS ~


- `Dashboard` open dashboard
- `DbProjectDelete count` delete project in cache works for hyper theme. count is number

Expand Down Expand Up @@ -248,15 +244,13 @@ Doom ~

CHANGED ~


- Removed Session as a start screen plugin speed is first.if you want use session you can take a
look at glepnir/dbsession.nvim <https://github.com/glepnir/dbsession.nvim>
- Removed Ueberzug script, as the Ueberzug author has deleted the repository.


TODO ~


- I will write a plugin to implement some popular terminal evaluators image protocol then I think
can make it work with dashboard

Expand Down
104 changes: 104 additions & 0 deletions lua/dashboard/async.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
local uv = vim.loop

local function async(fn)
local co = coroutine.create(fn)
return function(...)
local status, result = coroutine.resume(co, ...)
if not status then
error(result)
end
return result
end
end

local function await(promise)
if type(promise) ~= 'function' then
return promise
end
local co = assert(coroutine.running())
promise(function(...)
coroutine.resume(co, ...)
end)
return (coroutine.yield())
end

local function fs_module(filename)
local fs = {}
local task = {}

function fs:open(flag)
task[#task + 1] = function(callback)
uv.fs_open(filename, flag, tonumber('644', 8), function(err, fd)
assert(not err)
self.fd = fd
callback(fd)
end)
end
return self
end

function fs:size()
task[#task + 1] = function(callback)
uv.fs_fstat(self.fd, function(err, stat)
assert(not err)
self.size = stat.size
callback(stat.size)
end)
end
return self
end

function fs:read()
task[#task + 1] = function(callback)
uv.fs_read(self.fd, self.size, function(err, data)
assert(not err)
assert(uv.fs_close(self.fd))
callback(data)
end)
end
return self
end

function fs:write(content)
task[#task + 1] = function()
uv.fs_write(self.fd, content, function(err, bytes)
assert(not err)
if bytes == 0 then
print('note write 0 bytes')
end
assert(uv.fs_close(self.fd))
end)
end
return self
end

function fs:run(callback)
async(function()
for i, t in ipairs(task) do
local res = await(t)
if i == #task and callback then
callback(res)
end
end
end)()
end

return fs
end

local function async_read(filename, callback)
local fs = fs_module(filename)
fs:open('r'):size():read():run(callback)
end

local function async_write(filename, content)
local fs = fs_module(filename)
fs:open('w'):size():write(content):run()
end

return {
async = async,
await = await,
async_read = async_read,
async_write = async_write,
}
85 changes: 85 additions & 0 deletions lua/dashboard/entry.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
local api = vim.api
local nvim_buf_set_keymap = api.nvim_buf_set_keymap
local add_highlight = api.nvim_buf_add_highlight
local buf_set_lines, buf_set_extmark = api.nvim_buf_set_lines, api.nvim_buf_set_extmark
local ns = api.nvim_create_namespace('dashboard')
local entry = {}

local function box()
local t = {}
t.__index = t

function t:append(lines)
local bufnr = self.bufnr
if type(lines) == 'string' then
lines = { lines }
elseif type(lines) == 'function' then
lines = lines()
end
local count = api.nvim_buf_line_count(bufnr)
buf_set_lines(bufnr, count, -1, false, lines)

local obj = {}

function obj:iterate()
local index = 1
return function()
local line = lines[index]
index = index + 1
return line
end
end

function obj:hi(callback)
local iter = self:iterate()
local index = -1
for data in iter do
index = index + 1
if callback then
local hi = callback(data, count + index)
if hi then
add_highlight(bufnr, ns, hi, count + index, 0, -1)
end
end
end

return obj
end

function obj:tailbtn(callback)
local iter = self:iterate()
local index = -1
for data in iter do
index = index + 1
local btn, hi, action = callback(data)
if btn then
buf_set_extmark(bufnr, ns, count + index, 0, {
virt_text = { { btn, hi } },
})

nvim_buf_set_keymap(bufnr, 'n', btn, '', {
callback = function()
if type(action) == 'string' then
vim.cmd(action)
elseif type(action) == 'function' then
action()
end
end,
})
end
end

return obj
end

return setmetatable(obj, t)
end

return t
end

function entry:new(wininfo)
return setmetatable(wininfo, box())
end

return entry
57 changes: 0 additions & 57 deletions lua/dashboard/events.lua

This file was deleted.

Loading