From 1f6dbed26b9f42805069dea5d788d5a985e70917 Mon Sep 17 00:00:00 2001 From: Akianonymus Date: Fri, 20 Aug 2021 14:52:27 +0530 Subject: [PATCH] Improve hiding/showing statusline via config --- lua/chadrc.lua | 12 ++++++++---- lua/default_config.lua | 13 +++++++++---- lua/options.lua | 5 +++-- lua/utils.lua | 22 ++++++++++++++++++++++ 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/lua/chadrc.lua b/lua/chadrc.lua index c2d7343..522b9e8 100644 --- a/lua/chadrc.lua +++ b/lua/chadrc.lua @@ -17,12 +17,16 @@ M.ui = { -- For Ex : if you have onedark set in nvchad , set onedark's bg color on your terminal transparency = false, - hidden_statusline = { + -- statusline related options + statusline = { -- these are filetypes, not pattern matched - "NvimTree", - "terminal", + -- if a filetype is present in shown, it will always show the statusline, irrespective of filetypes in hidden + hidden = {}, + shown = { + -- "terminal" + }, + style = "default", -- default, round , slant , block , arrow }, - statusline_style = "default", -- default, round , slant , block , arrow } M.options = { diff --git a/lua/default_config.lua b/lua/default_config.lua index 3ebcaf6..27da9ba 100644 --- a/lua/default_config.lua +++ b/lua/default_config.lua @@ -17,12 +17,17 @@ M.ui = { -- For Ex : if you have onedark set in nvchad , set onedark's bg color on your terminal transparency = false, - hidden_statusline = { + -- statusline related options + statusline = { -- these are filetypes, not pattern matched - "NvimTree", - -- "terminal", + -- if a filetype is present in shown, it will always show the statusline, irrespective of filetypes in hidden + hidden = { + "NvimTree", + "terminal", + }, + shown = {}, + style = "default", -- default, round , slant , block , arrow }, - statusline_style = "default", -- default, round , slant , block , arrow } M.options = { diff --git a/lua/options.lua b/lua/options.lua index e0aff03..62f4515 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -78,9 +78,10 @@ end -- Don't show any numbers inside terminals vim.cmd [[ au TermOpen term://* setlocal nonumber norelativenumber ]] --- Don't show status line on certain windows vim.cmd [[ au TermOpen term://* setfiletype terminal ]] -vim.cmd [[ let hidden_statusline = luaeval('require("utils").load_config().ui.hidden_statusline') | autocmd BufEnter,BufWinEnter,WinEnter,CmdwinEnter,TermEnter * nested if index(hidden_statusline, &ft) >= 0 | set laststatus=0 | else | set laststatus=2 | endif ]] + +-- Don't show status line on certain windows +vim.cmd [[ autocmd BufEnter,BufWinEnter,WinEnter,CmdwinEnter,TermEnter * lua require("utils").hide_statusline() ]] -- Open a file from its last left off position -- vim.cmd [[ au BufReadPost * if expand('%:p') !~# '\m/\.git/' && line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif ]] diff --git a/lua/utils.lua b/lua/utils.lua index abbfcf8..96d5771 100644 --- a/lua/utils.lua +++ b/lua/utils.lua @@ -181,6 +181,28 @@ M.file = function(mode, filepath, content) return data end +-- hide statusline +-- tables fetched from load_config function +M.hide_statusline = function(values) + local hidden = require("utils").load_config().ui.statusline.hidden + local shown = require("utils").load_config().ui.statusline.shown + local api = vim.api + local buftype = api.nvim_buf_get_option("%", "ft") + + -- shown table from config has the highest priority + if vim.tbl_contains(shown, buftype) then + api.nvim_set_option("laststatus", 2) + return + end + + if vim.tbl_contains(hidden, buftype) then + api.nvim_set_option("laststatus", 0) + return + else + api.nvim_set_option("laststatus", 2) + end +end + -- return a table of available themes M.list_themes = function(return_type) local themes = {}