summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/interface
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2022-01-13 19:12:32 +0100
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2022-01-13 19:12:32 +0100
commit73a60f5ee71bb60265ec0c97be7531a5e7605d8c (patch)
treed46283a3d04285c5a5ead92d5bbb3b1fe424b736 /.config/nvim/lua/interface
parent19c1942757f07387b95db3ddbc39d9b561d5b51d (diff)
Remove bloat nvim config
Diffstat (limited to '.config/nvim/lua/interface')
-rw-r--r--.config/nvim/lua/interface/popup.lua62
-rw-r--r--.config/nvim/lua/interface/text.lua98
2 files changed, 0 insertions, 160 deletions
diff --git a/.config/nvim/lua/interface/popup.lua b/.config/nvim/lua/interface/popup.lua
deleted file mode 100644
index b628125..0000000
--- a/.config/nvim/lua/interface/popup.lua
+++ /dev/null
@@ -1,62 +0,0 @@
-local Popup = {}
-
---- Create a new floating window
--- @param config The configuration passed to vim.api.nvim_open_win
--- @param win_opts The options registered with vim.api.nvim_win_set_option
--- @param buf_opts The options registered with vim.api.nvim_buf_set_option
--- @return A new popup
-function Popup:new(opts)
- opts = opts or {}
- opts.layout = opts.layout or {}
- opts.win_opts = opts.win_opts or {}
- opts.buf_opts = opts.buf_opts or {}
-
- Popup.__index = Popup
-
- local editor_layout = {
- height = vim.o.lines - vim.o.cmdheight - 2, -- Add margin for status and buffer line
- width = vim.o.columns,
- }
- local popup_layout = {
- relative = "editor",
- height = math.floor(editor_layout.height * 0.9),
- width = math.floor(editor_layout.width * 0.8),
- style = "minimal",
- border = "rounded",
- }
- popup_layout.row = math.floor((editor_layout.height - popup_layout.height) / 2)
- popup_layout.col = math.floor((editor_layout.width - popup_layout.width) / 2)
-
- local obj = {
- buffer = vim.api.nvim_create_buf(false, true),
- layout = vim.tbl_deep_extend("force", popup_layout, opts.layout),
- win_opts = opts.win_opts,
- buf_opts = opts.buf_opts,
- }
-
- setmetatable(obj, Popup)
-
- return obj
-end
-
---- Display the popup with the provided content
--- @param content_provider A function accepting the popup's layout and returning the content to display
-function Popup:display(content_provider)
- self.win_id = vim.api.nvim_open_win(self.buffer, true, self.layout)
- vim.lsp.util.close_preview_autocmd({ "BufHidden", "BufLeave" }, self.win_id)
-
- local lines = content_provider(self.layout)
- vim.api.nvim_buf_set_lines(self.bufnr, 0, -1, false, lines)
-
- -- window options
- for key, value in pairs(self.win_opts) do
- vim.api.nvim_win_set_option(self.win_id, key, value)
- end
-
- -- buffer options
- for key, value in pairs(self.buf_opts) do
- vim.api.nvim_buf_set_option(self.buffer, key, value)
- end
-end
-
-return Popup
diff --git a/.config/nvim/lua/interface/text.lua b/.config/nvim/lua/interface/text.lua
deleted file mode 100644
index c17d403..0000000
--- a/.config/nvim/lua/interface/text.lua
+++ /dev/null
@@ -1,98 +0,0 @@
-local M = {}
-
-local function max_len_line(lines)
- local max_len = 0
-
- for _, line in ipairs(lines) do
- local line_len = line:len()
- if line_len > max_len then
- max_len = line_len
- end
- end
-
- return max_len
-end
-
---- Center align lines relatively to the parent container
--- @param container The container where lines will be displayed
--- @param lines The text to align
--- @param alignment The alignment value, range: [0-1]
-function M.align_left(container, lines, alignment)
- local max_len = max_len_line(lines)
- local indent_amount = math.ceil(math.max(container.width - max_len, 0) * alignment)
- return M.shift_right(lines, indent_amount)
-end
-
---- Center align lines relatively to the parent container
--- @param container The container where lines will be displayed
--- @param lines The text to align
--- @param alignment The alignment value, range: [0-1]
-function M.align_center(container, lines, alignment)
- local output = {}
- local max_len = max_len_line(lines)
-
- for _, line in ipairs(lines) do
- local padding = string.rep(
- " ",
- (math.max(container.width, max_len) - line:len()) * alignment
- )
- table.insert(output, padding .. line)
- end
-
- return output
-end
-
---- Shift lines by a given amount
--- @params lines The lines the shift
--- @param amount The amount of spaces to add
-function M.shift_right(lines, amount)
- local output = {}
- local padding = string.rep(" ", amount)
-
- for _, line in ipairs(lines) do
- table.insert(output, padding .. line)
- end
-
- return output
-end
-
---- Pretty format tables
--- @param entries The table to format
--- @param col_count The number of column to span the table on
--- @param col_sep The separator between each colummn, default: " "
-function M.format_table(entries, col_count, col_sep)
- col_sep = col_sep or " "
-
- local col_rows = math.ceil(vim.tbl_count(entries) / col_count)
- local cols = {}
- local count = 0
-
- for i, entry in ipairs(entries) do
- if ((i - 1) % col_rows) == 0 then
- table.insert(cols, {})
- count = count + 1
- end
- table.insert(cols[count], entry)
- end
-
- local col_max_len = {}
- for _, col in ipairs(cols) do
- table.insert(col_max_len, max_len_line(col))
- end
-
- local output = {}
- for i, col in ipairs(cols) do
- for j, entry in ipairs(col) do
- if not output[j] then
- output[j] = entry
- else
- local padding = string.rep(" ", col_max_len[i - 1] - cols[i - 1][j]:len())
- output[j] = output[j] .. padding .. col_sep .. entry
- end
- end
- end
-
- return output
-end
-
-return M