add simple statusline

This commit is contained in:
Ray Andrew 2023-08-05 16:13:05 -05:00
parent d33355ed44
commit c8a9a4c10b
No known key found for this signature in database
GPG key ID: E2E8D63137DD489E
6 changed files with 175 additions and 72 deletions

View file

@ -1,9 +1,7 @@
-- Taken from -- Taken from
-- https://github.com/LazyVim/LazyVim/blob/566049aa4a26a86219dd1ad1624f9a1bf18831b6/lua/lazyvim/config/autocmds.lua -- https://github.com/LazyVim/LazyVim/blob/566049aa4a26a86219dd1ad1624f9a1bf18831b6/lua/lazyvim/config/autocmds.lua
local function augroup(name) local augroup = require("rayandrew.util").augroup
return vim.api.nvim_create_augroup("lazyvim_" .. name, { clear = true })
end
local autocmd = vim.api.nvim_create_autocmd local autocmd = vim.api.nvim_create_autocmd

View file

@ -6,6 +6,7 @@ function M.setup()
require("rayandrew.autocmds") require("rayandrew.autocmds")
require("rayandrew.remap") require("rayandrew.remap")
require("rayandrew.theme").setup() require("rayandrew.theme").setup()
require("rayandrew.statusline").setup()
end end
return M return M

View file

@ -295,75 +295,75 @@ return {
------------------------------ ------------------------------
-- User Interface -- User Interface
------------------------------ ------------------------------
{ -- {
"folke/noice.nvim", -- "folke/noice.nvim",
event = "VeryLazy", -- event = "VeryLazy",
opts = { -- opts = {
lsp = { -- lsp = {
override = { -- override = {
["vim.lsp.util.convert_input_to_markdown_lines"] = true, -- ["vim.lsp.util.convert_input_to_markdown_lines"] = true,
["vim.lsp.util.stylize_markdown"] = true, -- ["vim.lsp.util.stylize_markdown"] = true,
["cmp.entry.get_documentation"] = true, -- ["cmp.entry.get_documentation"] = true,
}, -- },
hover = { -- hover = {
enabled = false, -- enabled = false,
}, -- },
signature = { -- signature = {
enabled = false, -- enabled = false,
}, -- },
}, -- },
cmdline = { -- cmdline = {
enabled = true, -- enabled = true,
view = "cmdline", -- view = "cmdline",
}, -- },
routes = { -- routes = {
{ -- {
filter = { -- filter = {
event = "msg_show", -- event = "msg_show",
any = { -- any = {
{ find = "%d+L, %d+B" }, -- { find = "%d+L, %d+B" },
{ find = "; after #%d+" }, -- { find = "; after #%d+" },
{ find = "; before #%d+" }, -- { find = "; before #%d+" },
}, -- },
}, -- },
view = "mini", -- view = "mini",
}, -- },
}, -- },
presets = { -- presets = {
bottom_search = true, -- bottom_search = true,
command_palette = true, -- command_palette = true,
long_message_to_split = true, -- long_message_to_split = true,
inc_rename = true, -- inc_rename = true,
}, -- },
}, -- },
-- stylua: ignore -- -- stylua: ignore
keys = { -- keys = {
{ "<S-Enter>", function() require("noice").redirect(vim.fn.getcmdline()) end, mode = "c", desc = "Redirect Cmdline" }, -- { "<S-Enter>", function() require("noice").redirect(vim.fn.getcmdline()) end, mode = "c", desc = "Redirect Cmdline" },
{ "<leader>snl", function() require("noice").cmd("last") end, desc = "Noice Last Message" }, -- { "<leader>snl", function() require("noice").cmd("last") end, desc = "Noice Last Message" },
{ "<leader>snh", function() require("noice").cmd("history") end, desc = "Noice History" }, -- { "<leader>snh", function() require("noice").cmd("history") end, desc = "Noice History" },
{ "<leader>sna", function() require("noice").cmd("all") end, desc = "Noice All" }, -- { "<leader>sna", function() require("noice").cmd("all") end, desc = "Noice All" },
{ "<leader>snd", function() require("noice").cmd("dismiss") end, desc = "Dismiss All" }, -- { "<leader>snd", function() require("noice").cmd("dismiss") end, desc = "Dismiss All" },
{ "<c-f>", function() if not require("noice.lsp").scroll(4) then return "<c-f>" end end, silent = true, expr = true, desc = "Scroll forward", mode = {"i", "n", "s"} }, -- { "<c-f>", function() if not require("noice.lsp").scroll(4) then return "<c-f>" end end, silent = true, expr = true, desc = "Scroll forward", mode = {"i", "n", "s"} },
{ "<c-b>", function() if not require("noice.lsp").scroll(-4) then return "<c-b>" end end, silent = true, expr = true, desc = "Scroll backward", mode = {"i", "n", "s"}}, -- { "<c-b>", function() if not require("noice.lsp").scroll(-4) then return "<c-b>" end end, silent = true, expr = true, desc = "Scroll backward", mode = {"i", "n", "s"}},
}, -- },
}, -- },
{ -- {
"stevearc/dressing.nvim", -- "stevearc/dressing.nvim",
lazy = true, -- lazy = true,
init = function() -- init = function()
---@diagnostic disable-next-line: duplicate-set-field -- ---@diagnostic disable-next-line: duplicate-set-field
vim.ui.select = function(...) -- vim.ui.select = function(...)
require("lazy").load({ plugins = { "dressing.nvim" } }) -- require("lazy").load({ plugins = { "dressing.nvim" } })
return vim.ui.select(...) -- return vim.ui.select(...)
end -- end
---@diagnostic disable-next-line: duplicate-set-field -- ---@diagnostic disable-next-line: duplicate-set-field
vim.ui.input = function(...) -- vim.ui.input = function(...)
require("lazy").load({ plugins = { "dressing.nvim" } }) -- require("lazy").load({ plugins = { "dressing.nvim" } })
return vim.ui.input(...) -- return vim.ui.input(...)
end -- end
end, -- end,
}, -- },
{ {
"lukas-reineke/indent-blankline.nvim", "lukas-reineke/indent-blankline.nvim",

View file

@ -24,7 +24,7 @@ opt.hlsearch = false
opt.ignorecase = true -- Ignore case opt.ignorecase = true -- Ignore case
opt.incsearch = true opt.incsearch = true
opt.inccommand = "nosplit" -- preview incremental substitute opt.inccommand = "nosplit" -- preview incremental substitute
opt.laststatus = 0 opt.laststatus = 2
opt.list = true -- Show some invisible characters (tabs... opt.list = true -- Show some invisible characters (tabs...
opt.mouse = "a" -- Enable mouse mode opt.mouse = "a" -- Enable mouse mode
opt.nu = true opt.nu = true
@ -32,6 +32,7 @@ opt.number = true -- Print line number
opt.pumblend = 10 -- Popup blend opt.pumblend = 10 -- Popup blend
opt.pumheight = 10 -- Maximum number of entries in a popup opt.pumheight = 10 -- Maximum number of entries in a popup
opt.relativenumber = true -- Relative line numbers opt.relativenumber = true -- Relative line numbers
opt.ruler = false -- Disable ruler
opt.scrolloff = 4 -- Lines of context opt.scrolloff = 4 -- Lines of context
opt.sessionoptions = { "buffers", "curdir", "tabpages", "winsize" } opt.sessionoptions = { "buffers", "curdir", "tabpages", "winsize" }
opt.shiftround = true -- Round indent opt.shiftround = true -- Round indent

View file

@ -0,0 +1,99 @@
local M = {}
local modes = {
["n"] = "NORMAL",
["no"] = "NORMAL",
["v"] = "VISUAL",
["V"] = "VISUAL LINE",
[""] = "VISUAL BLOCK",
["s"] = "SELECT",
["S"] = "SELECT LINE",
[""] = "SELECT BLOCK",
["i"] = "INSERT",
["ic"] = "INSERT",
["R"] = "REPLACE",
["Rv"] = "VISUAL REPLACE",
["c"] = "COMMAND",
["cv"] = "VIM EX",
["ce"] = "EX",
["r"] = "PROMPT",
["rm"] = "MOAR",
["r?"] = "CONFIRM",
["!"] = "SHELL",
["t"] = "TERMINAL",
}
local function mode()
local current_mode = vim.api.nvim_get_mode().mode
return string.format(" %s ", modes[current_mode]):upper()
end
local function filepath()
local fpath = vim.fn.fnamemodify(vim.fn.expand("%"), ":~:.:h")
if fpath == "" or fpath == "." then
return " "
end
return string.format(" %%<%s/", fpath)
end
local function update_mode_colors()
local current_mode = vim.api.nvim_get_mode().mode
local mode_color = "%#StatusLineAccent#"
if current_mode == "n" then
mode_color = "%#StatuslineAccent#"
elseif current_mode == "i" or current_mode == "ic" then
mode_color = "%#StatuslineInsertAccent#"
elseif current_mode == "v" or current_mode == "V" or current_mode == "" then
mode_color = "%#StatuslineVisualAccent#"
elseif current_mode == "R" then
mode_color = "%#StatuslineReplaceAccent#"
elseif current_mode == "c" then
mode_color = "%#StatuslineCmdLineAccent#"
elseif current_mode == "t" then
mode_color = "%#StatuslineTerminalAccent#"
end
return mode_color
end
local function filename()
local fname = vim.fn.expand("%:t")
if fname == "" then
return ""
end
return fname .. " "
end
function M.render()
local parts = {
"%#Statusline#",
update_mode_colors(),
mode(),
"%#Normal# ",
"%=%#StatusLineExtra#",
filepath(),
filename(),
}
local statusline = table.concat(parts, "")
return statusline
end
function M.setup()
local augroup = require("rayandrew.util").augroup
local autocmd = vim.api.nvim_create_autocmd
-- Statusline
autocmd({ "BufEnter", "BufWinEnter", "WinEnter" }, {
group = augroup("statusline"),
pattern = "*",
callback = function()
-- vim.opt_local.statusline = "%!v:lua.require('rayandrew.util').statusline()"
vim.opt_local.statusline = M.render()
end,
-- command = [[lua require("rayandrew.util").render()]],
})
end
return M

View file

@ -3,6 +3,10 @@
local M = {} local M = {}
function M.augroup(name)
return vim.api.nvim_create_augroup("rayandrew_" .. name, { clear = true })
end
---@param on_attach fun(client, buffer) ---@param on_attach fun(client, buffer)
function M.on_attach(on_attach) function M.on_attach(on_attach)
vim.api.nvim_create_autocmd("LspAttach", { vim.api.nvim_create_autocmd("LspAttach", {