1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
local M = {}
local nb = vim.api.nvim_create_namespace('noiceboard')
local opts = { noremap = true, silent = true }
local settings = {
header = {
" /$$ ",
" |__/ ",
" /$$$$$$$ /$$$$$$ /$$$$$$ /$$ /$$ /$$ /$$$$$$/$$$$ ",
"| $$__ $$ /$$__ $$ /$$__ $$| $$ /$$/| $$| $$_ $$_ $$",
"| $$ \\ $$| $$$$$$$$| $$ \\ $$ \\ $$/$$/ | $$| $$ \\ $$ \\ $$",
"| $$ | $$| $$_____/| $$ | $$ \\ $$$/ | $$| $$ | $$ | $$",
"| $$ | $$| $$$$$$$| $$$$$$/ \\ $/ | $$| $$ | $$ | $$",
"|__/ |__/ \\_______/ \\______/ \\_/ |__/|__/ |__/ |__/",
},
tools = {
["Find File"] = "Telescope find_files",
["Find Word"] = "Telescope live_grep",
["Recent Files"] = "Telescope oldfiles",
["File Browser"] = "Telescope file_browser",
},
mappings = {
}
}
function M.check_line()
local line = vim.api.nvim_get_current_line()
for name, command in pairs(settings.tools) do
if line:match(name) then
vim.cmd(command)
end
end
end
local function center(dict)
local centered = {}
local space_left = vim.o.columns - string.len(dict[1])
for _, line in ipairs(dict) do
table.insert(centered, string.rep(" ", space_left/2) .. line)
end
return centered
end
local count = 1
local function set_lines(len, text, hi, pass)
vim.api.nvim_buf_set_lines(0, count, count+len, false, center(text))
vim.api.nvim_win_set_cursor(0, {count, 0})
if pass then vim.g.section_length = count end
for i=count,count+len do
vim.api.nvim_buf_add_highlight(0, nb, hi, i, 1, -1)
end
count = count + len
end
local function empty()
set_lines(1, {" "}, "TSString")
end
function M.display()
vim.api.nvim_buf_set_keymap(0, "n", "<CR>", ":lua require'startuptools'.check_line()<CR>", opts)
empty()
set_lines(#settings.header, settings.header, 'TSString')
local toolnames = {}
for name, _ in pairs(settings.tools) do
table.insert(toolnames, name)
end
empty()
set_lines(#toolnames, toolnames, 'TSString')
vim.cmd[[silent! %s/\s\+$//]] -- clear trailing whitespace
vim.api.nvim_buf_set_option(0, 'bufhidden', 'wipe')
vim.api.nvim_buf_set_option(0, 'buftype', 'nofile')
vim.api.nvim_buf_set_option(0, 'swapfile', false)
vim.cmd[[set nonumber
set norelativenumber
]]
end
function M.setup()
vim.cmd[[
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * lua if vim.fn.argc() == 0 and vim.fn.exists('std_in') then require"startuptools".display() end
]]
end
return M
|