From c4e46206d7684c75fb1da1bb8f8a0dd225cad4b6 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 6 Oct 2025 16:19:44 +0200 Subject: [PATCH] feat(nvim): add new intro image --- nvim/lua/olinpin/init.lua | 1 + nvim/lua/olinpin/intro.lua | 122 +++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 nvim/lua/olinpin/intro.lua diff --git a/nvim/lua/olinpin/init.lua b/nvim/lua/olinpin/init.lua index 60d6e9d..c77f9dc 100644 --- a/nvim/lua/olinpin/init.lua +++ b/nvim/lua/olinpin/init.lua @@ -8,3 +8,4 @@ vim.o.timeoutlen = 0 -- setup prolog require('lspconfig/prolog_lsp') require('lspconfig').prolog_lsp.setup{} +require('olinpin.intro').open() diff --git a/nvim/lua/olinpin/intro.lua b/nvim/lua/olinpin/intro.lua new file mode 100644 index 0000000..65ff7a4 --- /dev/null +++ b/nvim/lua/olinpin/intro.lua @@ -0,0 +1,122 @@ +local M = {} +local api = vim.api +local fn = vim.fn +local strw = api.nvim_strwidth +local opts = { + header = { +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣴⣶⣶⣶⣶⣦⣤⡀⠀⠀⠀⠀", +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⣿⠟⠉⠉⠉⠉⠉⠛⠻⢿⣷⣄⠀⠀", +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⠟⠁⠀⠀⢠⣤⣄⠀⠀⠀⠀⠙⣿⣷⠀", +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⣿⠏⠀⠀⠀⠀⠘⠻⠋⠀⠀⠀⠀⠀⢸⣿⡇", +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⣿⡏⠀⠀⣀⣀⣀⣠⣤⣤⣤⣤⣿⣄⠀⢠⣿⣧", +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣿⣿⠀⠀⠀⠈⠻⣿⣶⠶⣶⣤⣤⣜⣿⣦⡈⢿⣿", +"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠈⠙⠻⢶⣤⣭⣛⣿⣿⣷⣼⣿", +"⠀⠀⠀⠀⠀⣰⣶⣾⠿⠿⢿⣷⣶⣄⠀⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⠛⠛⢛⣿⣿", +"⠀⠀⠀⠀⠀⢹⣿⣆⠀⠀⠀⠈⠻⢿⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⣿⡏", +"⠀⠀⠀⠀⠀⣸⣿⣿⠀⠀⠀⠀⠀⠀⢀⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⠀", +"⠀⠀⠀⢀⣾⣿⣿⡇⠀⠀⠀⠀⠀⠀⢸⠟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀", +"⠀⠀⠀⣼⣿⠃⠹⣿⣷⣄⠀⠀⠀⠀⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⠇⠀", +"⠀⠀⠀⣿⡿⠀⠀⠈⠻⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⠀⠀", +"⠀⠀⢸⣿⣧⠀⠀⠀⠀⠸⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⡷⠀⠀", +"⠀⠀⠈⣿⣿⡄⠀⠀⠀⠀⢻⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⣿⡀⠀", +"⠀⠀⠀⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣧⠀", +"⠀⠀⠀⢻⣿⡟⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢿⣿⡇", +"⠀⠀⠀⠘⣿⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⣿⡿", +"⠀⠀⠀⣤⣸⣿⣿⡷⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⠃", +"⠀⠀⠘⣿⡿⠿⣿⣿⣿⣷⡶⢶⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⠏⠀", +"⠀⠀⢀⣿⡟⠀⠀⠀⠀⠀⠀⠈⣿⣇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⡿⠟⠉⠀⠀", +"⠀⠀⣼⣿⠇⠀⣴⣄⠀⠀⠀⠀⢹⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣶⣿⠟⠁⠀⠀⠀⠀", +"⢀⣼⣿⠋⠀⠀⠘⣿⣧⠀⠀⠀⢸⣿⣧⣄⣀⠀⠀⠀⢀⣀⣤⣶⣿⣿⠋⠁⠀⠀⠀⠀⠀⠀", +"⢾⣯⣁⠀⠀⠀⠀⠈⢿⡄⠀⠀⣸⡿⠉⠙⠛⠛⠛⠛⢻⣿⡏⢹⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀", +"⠀⠛⢿⣷⣦⣤⣀⡀⠀⠀⠀⣠⣿⣷⣶⣶⣶⣶⣶⣦⣤⣿⣿⡜⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀", +"⠀⠀⠀⠈⠙⠛⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⢻⡿⣷⣶⣤⣀⠀⠀⠀⠀", +"⠀⠀⠀⠀⠀⠀⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣏⣁⡸⠟⠈⣩⣿⣿⣿⠶⠀⠀", +"⠀⠀⠀⣠⣴⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⠟⠋⠁⠀⠀⠀⠀", +"⠀⠀⠀⠙⠿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠋⠉⠀⠀⠀⠀⠀⠀⠀⠀", +"⠀⠀⠀⠀⠀⠀⠈⠉⠉⠉⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", +" WADDLE WADDLE WADDLE ", +}, + buttons = {} +} + +M.open = function(buf, win, action) + action = action or "open" + + win = win or api.nvim_get_current_win() + + if not vim.bo.buflisted and action == "open" then + if vim.t.bufs[1] then + win = vim.fn.bufwinid(vim.t.bufs[1]) + api.nvim_set_current_win(win) + end + end + + local ns = api.nvim_create_namespace "nvdash" + local winh = api.nvim_win_get_height(win) + local winw = api.nvim_win_get_width(win) + buf = buf or vim.api.nvim_create_buf(false, true) + + local nvdash_w = 0 + + if action == "open" then + api.nvim_win_set_buf(0, buf) + end + + opts.header = type(opts.header) == "function" and opts.header() or opts.header + + local ui = {} + + ------------------------ find largest string's width ----------------------------- + for _, v in ipairs(opts.header) do + local headerw = strw(v) + if headerw > nvdash_w then + nvdash_w = headerw + end + + local col = math.floor((winw / 2) - math.floor(strw(v) / 2)) - 6 + local opt = { virt_text_win_col = col, virt_text = { { v, "NvDashAscii" } } } + table.insert(ui, opt) + end + + opts.buttons = type(opts.buttons) == "table" and opts.buttons or opts.buttons() + + local key_lines = {} + + ----------------------- save display txt ----------------------------------------- + local dashboard_h = #ui + 3 + + -- if screen height is small + winh = dashboard_h > winh and dashboard_h or winh + + local row_i = math.floor((winh / 2) - (dashboard_h / 2)) + + for i, v in ipairs(key_lines) do + key_lines[i].i = v.i + row_i + 1 + end + + -- make all lines available + local empty_str = {} + for i = 1, winh do + empty_str[i] = "" + end + + ------------------------------ EXTMARKS : set text + highlight ------------------------------- + api.nvim_buf_set_lines(buf, 0, -1, false, empty_str) + + for i, v in ipairs(ui) do + api.nvim_buf_set_extmark(buf, ns, row_i + i, 0, v) + end + + if action == "redraw" then + return + end + + ------------------------------------ keybinds ------------------------------------------ + vim.wo[win].virtualedit = "all" + + if key_lines[1] then + api.nvim_win_set_cursor(win, { key_lines[1].i, key_lines[1].col }) + end +end + +return M