feat: Make short statusline toggleable from chadrc

This commit is contained in:
Akianonymus 2021-10-02 10:37:42 +05:30 committed by siduck76
parent a1c234e001
commit 317eedd9b2
2 changed files with 16 additions and 10 deletions

View file

@ -91,6 +91,8 @@ M.plugins = {
"NvimTree", "NvimTree",
"terminal", "terminal",
}, },
-- show short statusline on small screens
shortline = true,
shown = {}, shown = {},
-- default, round , slant , block , arrow -- default, round , slant , block , arrow
style = "default", style = "default",

View file

@ -42,8 +42,12 @@ local icon_styles = {
}, },
} }
local user_statusline_style = require("core.utils").load_config().plugins.options.statusline.style local config = require("core.utils").load_config().plugins.options.statusline
-- statusline style
local user_statusline_style = config.style
local statusline_style = icon_styles[user_statusline_style] local statusline_style = icon_styles[user_statusline_style]
-- if show short statusline on small screens
local shortline = config.shortline
-- Initialize the components table -- Initialize the components table
local components = { local components = {
@ -81,7 +85,7 @@ components.active[1][2] = {
end end
return " " .. icon .. " " .. filename .. " " return " " .. icon .. " " .. filename .. " "
end, end,
enabled = function(winid) enabled = shortline and function(winid)
return vim.api.nvim_win_get_width(winid) > 70 return vim.api.nvim_win_get_width(winid) > 70
end, end,
hl = { hl = {
@ -98,7 +102,7 @@ components.active[1][3] = {
return "" .. dir_name .. " " return "" .. dir_name .. " "
end, end,
enabled = function(winid) enabled = shortline and function(winid)
return vim.api.nvim_win_get_width(winid) > 80 return vim.api.nvim_win_get_width(winid) > 80
end, end,
@ -209,7 +213,7 @@ components.active[2][1] = {
end end
return "" return ""
end, end,
enabled = function(winid) enabled = shortline and function(winid)
return vim.api.nvim_win_get_width(winid) > 80 return vim.api.nvim_win_get_width(winid) > 80
end, end,
hl = { fg = colors.green }, hl = { fg = colors.green },
@ -223,7 +227,7 @@ components.active[3][1] = {
return "" return ""
end end
end, end,
enabled = function(winid) enabled = shortline and function(winid)
return vim.api.nvim_win_get_width(winid) > 70 return vim.api.nvim_win_get_width(winid) > 70
end, end,
hl = { fg = colors.grey_fg2, bg = colors.statusline_bg }, hl = { fg = colors.grey_fg2, bg = colors.statusline_bg },
@ -231,7 +235,7 @@ components.active[3][1] = {
components.active[3][2] = { components.active[3][2] = {
provider = "git_branch", provider = "git_branch",
enabled = function(winid) enabled = shortline and function(winid)
return vim.api.nvim_win_get_width(winid) > 70 return vim.api.nvim_win_get_width(winid) > 70
end, end,
hl = { hl = {
@ -308,7 +312,7 @@ components.active[3][6] = {
components.active[3][7] = { components.active[3][7] = {
provider = statusline_style.left, provider = statusline_style.left,
enabled = function(winid) enabled = shortline and function(winid)
return vim.api.nvim_win_get_width(winid) > 90 return vim.api.nvim_win_get_width(winid) > 90
end, end,
hl = { hl = {
@ -319,7 +323,7 @@ components.active[3][7] = {
components.active[3][8] = { components.active[3][8] = {
provider = statusline_style.left, provider = statusline_style.left,
enabled = function(winid) enabled = shortline and function(winid)
return vim.api.nvim_win_get_width(winid) > 90 return vim.api.nvim_win_get_width(winid) > 90
end, end,
hl = { hl = {
@ -330,7 +334,7 @@ components.active[3][8] = {
components.active[3][9] = { components.active[3][9] = {
provider = statusline_style.position_icon, provider = statusline_style.position_icon,
enabled = function(winid) enabled = shortline and function(winid)
return vim.api.nvim_win_get_width(winid) > 90 return vim.api.nvim_win_get_width(winid) > 90
end, end,
hl = { hl = {
@ -353,7 +357,7 @@ components.active[3][10] = {
return " " .. result .. "%% " return " " .. result .. "%% "
end, end,
enabled = function(winid) enabled = shortline and function(winid)
return vim.api.nvim_win_get_width(winid) > 90 return vim.api.nvim_win_get_width(winid) > 90
end, end,