aboutsummaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authortamton-aquib <[email protected]>2021-10-06 18:55:51 +0530
committertamton-aquib <[email protected]>2021-10-06 18:56:42 +0530
commitdf57521572afd04e31b016a17c9328e0be4b61e6 (patch)
tree2b4fbba3fc2d9bfd4b414cae3bb442905c7821bf /lua
parent5f791209522895abd0ee9f951f8b8f4f2e8502b3 (diff)
structural changes
Diffstat (limited to 'lua')
-rw-r--r--lua/startup.lua119
-rw-r--r--lua/startup/config.lua39
-rw-r--r--lua/startup/utils.lua31
3 files changed, 110 insertions, 79 deletions
diff --git a/lua/startup.lua b/lua/startup.lua
index 3e681a0..cffe0b9 100644
--- a/lua/startup.lua
+++ b/lua/startup.lua
@@ -2,55 +2,11 @@ local M = {}
local ns = vim.api.nvim_create_namespace "startup"
local opts = { noremap = true, silent = true }
+local settings = require "startup.config"
-local settings = {
- -- every line should be same width without escaped \
- header = {
- " /$$ ",
- " |__/ ",
- " /$$$$$$$ /$$$$$$ /$$$$$$ /$$ /$$ /$$ /$$$$$$/$$$$ ",
- "| $$__ $$ /$$__ $$ /$$__ $$| $$ /$$/| $$| $$_ $$_ $$",
- "| $$ \\ $$| $$$$$$$$| $$ \\ $$ \\ $$/$$/ | $$| $$ \\ $$ \\ $$",
- "| $$ | $$| $$_____/| $$ | $$ \\ $$$/ | $$| $$ | $$ | $$",
- "| $$ | $$| $$$$$$$| $$$$$$/ \\ $/ | $$| $$ | $$ | $$",
- "|__/ |__/ \\_______/ \\______/ \\_/ |__/|__/ |__/ |__/",
- },
- -- name which will be displayed and command
- tools = {
- [" Find File"] = {"Telescope find_files", "<leader>ff"},
- [" Find Word"] = {"Telescope live_grep", "<leader>lg"},
- [" Recent Files"] = {"Telescope oldfiles", "<leader>of"},
- [" File Browser"] = {"Telescope file_browser", "<leader>fb"},
- [" Config Files"] = {'lua require("telescope.builtin").find_files({cwd="~/.config"})', "<leader>cf"},
- [" Colorschemes"] = {"Telescope colorscheme", "<leader>cs"},
- [" New File"] = {"lua require'startup'.new_file()", "<leader>nf"},
- ["ﲉ Help Files"] = {"Telescope help_tags", "<leader>fh"},
- },
- options = {
- align = "center", -- center or padding
- mapping_names = true,
- padding = 5, -- only used if align padding
- },
- colors = {
- background = "#1f2227",
- heading_fg = "#009900",
- tools_fg = "#009900",
- }
-}
-
-local function spaces(amount)
- return string.rep(" ", amount)
-end
-
-local function longest_line(lines)
- local longest = 0
- for _, line in ipairs(lines) do
- if line:len() > longest then
- longest = line:len()
- end
- end
- return longest
-end
+local utils = require "startup.utils"
+local spaces = utils.spaces
+local empty = utils.empty
local function create_mappings()
vim.api.nvim_buf_set_keymap(
@@ -61,7 +17,13 @@ local function create_mappings()
opts
)
for _, cmd in pairs(settings.tools) do
- vim.api.nvim_buf_set_keymap(0, "n", cmd[2], "<cmd>"..cmd[1].."<CR>", opts)
+ vim.api.nvim_buf_set_keymap(
+ 0,
+ "n",
+ cmd[2],
+ "<cmd>" .. cmd[1] .. "<CR>",
+ opts
+ )
end
end
@@ -79,22 +41,17 @@ function M.check_line()
end
end
-local function create_hls()
- vim.cmd('highlight StartupHeading guibg=' .. settings.colors.background .. ' guifg=' .. settings.colors.heading_fg)
- vim.cmd('highlight StartupTools guibg=' .. settings.colors.background .. ' guifg=' .. settings.colors.tools_fg)
-end
-
local function align(dict)
local aligned = {}
if settings.options.align == "center" then
- local max_len = longest_line(dict)
+ local max_len = utils.longest_line(dict)
local space_left = vim.o.columns - max_len
for _, line in ipairs(dict) do
- table.insert(aligned, spaces(space_left/2).. line)
+ table.insert(aligned, spaces(space_left / 2) .. line)
end
elseif settings.options.align == "padding" then
for _, line in ipairs(dict) do
- table.insert(aligned, spaces(settings.options.padding).. line)
+ table.insert(aligned, spaces(settings.options.padding) .. line)
end
end
return aligned
@@ -117,46 +74,50 @@ local function empty()
set_lines(1, { " " }, "StartupTools")
end
-local function set_options()
- 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
- ]]
+local function body()
+ local toolnames = {}
+ for name, cmd in pairs(settings.tools) do
+ if not limited_space then
+ table.insert(toolnames, " ")
+ end
+ if settings.options.mapping_names then
+ table.insert(toolnames, name .. " " .. cmd[2])
+ else
+ table.insert(toolnames, name)
+ end
+ end
+
+ return toolnames
end
function M.display()
local limited_space = false
local rly_limited_space = false
- if vim.o.lines < (#settings.header + (#settings.tools*2) + 20) then
+
+ if vim.o.lines < (#settings.header + (#settings.tools * 2) + 20) then
limited_space = true
end
+
create_mappings()
- create_hls()
+ utils.create_hls()
-- vim.api.nvim_buf_set_keymap(0, "n", "j", "2j", opts)
-- vim.api.nvim_buf_set_keymap(0, "n", "k", "2k", opts)
if not limited_space then
empty()
end
set_lines(#settings.header, settings.header, "StartupHeading")
- local toolnames = {}
- for name, cmd in pairs(settings.tools) do
- if not limited_space then
- table.insert(toolnames, " ")
- end
- if settings.options.mapping_names then
- table.insert(toolnames, name .. " " .. cmd[2])
- else
- table.insert(toolnames, name)
- end
- end
+
+ local toolnames = body()
empty()
set_lines(#toolnames, toolnames, "StartupTools")
+
vim.cmd [[silent! %s/\s\+$//]] -- clear trailing whitespace
- set_options()
+ U.set_buf_options()
if limited_space then
- vim.api.nvim_win_set_cursor(0, {#settings.header + 3, math.floor(vim.o.columns/2)})
+ vim.api.nvim_win_set_cursor(
+ 0,
+ { #settings.header + 3, math.floor(vim.o.columns / 2) }
+ )
end
end
diff --git a/lua/startup/config.lua b/lua/startup/config.lua
new file mode 100644
index 0000000..13a5df0
--- /dev/null
+++ b/lua/startup/config.lua
@@ -0,0 +1,39 @@
+local settings = {
+ -- every line should be same width without escaped \
+ header = {
+ " /$$ ",
+ " |__/ ",
+ " /$$$$$$$ /$$$$$$ /$$$$$$ /$$ /$$ /$$ /$$$$$$/$$$$ ",
+ "| $$__ $$ /$$__ $$ /$$__ $$| $$ /$$/| $$| $$_ $$_ $$",
+ "| $$ \\ $$| $$$$$$$$| $$ \\ $$ \\ $$/$$/ | $$| $$ \\ $$ \\ $$",
+ "| $$ | $$| $$_____/| $$ | $$ \\ $$$/ | $$| $$ | $$ | $$",
+ "| $$ | $$| $$$$$$$| $$$$$$/ \\ $/ | $$| $$ | $$ | $$",
+ "|__/ |__/ \\_______/ \\______/ \\_/ |__/|__/ |__/ |__/",
+ },
+ -- name which will be displayed and command
+ tools = {
+ [" Find File"] = { "Telescope find_files", "<leader>ff" },
+ [" Find Word"] = { "Telescope live_grep", "<leader>lg" },
+ [" Recent Files"] = { "Telescope oldfiles", "<leader>of" },
+ [" File Browser"] = { "Telescope file_browser", "<leader>fb" },
+ [" Config Files"] = {
+ 'lua require("telescope.builtin").find_files({cwd="~/.config"})',
+ "<leader>cf",
+ },
+ [" Colorschemes"] = { "Telescope colorscheme", "<leader>cs" },
+ [" New File"] = { "lua require'startup'.new_file()", "<leader>nf" },
+ ["ﲉ Help Files"] = { "Telescope help_tags", "<leader>fh" },
+ },
+ options = {
+ align = "center", -- center or padding
+ mapping_names = true,
+ padding = 5, -- only used if align padding
+ },
+ colors = {
+ background = "#1f2227",
+ heading_fg = "#009900",
+ tools_fg = "#009900",
+ },
+}
+
+return settings
diff --git a/lua/startup/utils.lua b/lua/startup/utils.lua
new file mode 100644
index 0000000..8498b1f
--- /dev/null
+++ b/lua/startup/utils.lua
@@ -0,0 +1,31 @@
+U = {}
+local colors = require("startup.config").colors
+
+function U.spaces(amount)
+ return string.rep(" ", amount)
+end
+
+function U.longest_line(lines)
+ local longest = 0
+ for _, line in ipairs(lines) do
+ if line:len() > longest then
+ longest = line:len()
+ end
+ end
+ return longest
+end
+
+function U.create_hls()
+ vim.cmd( "hi StartupHeading guifg=" .. colors.heading_fg)
+ vim.cmd( "hi StartupTools guifg=" .. colors.tools_fg)
+end
+
+function U.set_buf_options()
+ 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, "filetype", "dashboard")
+ vim.api.nvim_buf_set_option(0, "swapfile", false)
+ vim.cmd [[setlocal nonu nornu]]
+end
+
+return U