summaryrefslogtreecommitdiff
path: root/lua/core/lualine
diff options
context:
space:
mode:
authorchristianchiarulli <[email protected]>2021-08-29 14:17:32 -0400
committerchristianchiarulli <[email protected]>2021-08-29 14:17:32 -0400
commited5559d259e38a78796a7d81421f02ba6dafac4b (patch)
treeafa9c00c017382bac547265a8a1e16b9770a07eb /lua/core/lualine
parente7b6d3b6f5982ea1042ffd499a7b85c18f0b782e (diff)
parentc7a5122fe2c14dba0f28f1c077f838f957884afc (diff)
Merge branch 'rolling' of github.com:ChristianChiarulli/LunarVim
Diffstat (limited to 'lua/core/lualine')
-rw-r--r--lua/core/lualine/colors.lua16
-rw-r--r--lua/core/lualine/components.lua152
-rw-r--r--lua/core/lualine/conditions.lua17
-rw-r--r--lua/core/lualine/init.lua47
-rw-r--r--lua/core/lualine/styles.lua137
-rw-r--r--lua/core/lualine/utils.lua27
6 files changed, 396 insertions, 0 deletions
diff --git a/lua/core/lualine/colors.lua b/lua/core/lualine/colors.lua
new file mode 100644
index 00000000..4984cd1f
--- /dev/null
+++ b/lua/core/lualine/colors.lua
@@ -0,0 +1,16 @@
+local colors = {
+ bg = "#202328",
+ fg = "#bbc2cf",
+ yellow = "#ECBE7B",
+ cyan = "#008080",
+ darkblue = "#081633",
+ green = "#98be65",
+ orange = "#FF8800",
+ violet = "#a9a1e1",
+ magenta = "#c678dd",
+ purple = "#c678dd",
+ blue = "#51afef",
+ red = "#ec5f67",
+}
+
+return colors
diff --git a/lua/core/lualine/components.lua b/lua/core/lualine/components.lua
new file mode 100644
index 00000000..894d9e9b
--- /dev/null
+++ b/lua/core/lualine/components.lua
@@ -0,0 +1,152 @@
+local conditions = require "core.lualine.conditions"
+local colors = require "core.lualine.colors"
+
+local function diff_source()
+ local gitsigns = vim.b.gitsigns_status_dict
+ if gitsigns then
+ return {
+ added = gitsigns.added,
+ modified = gitsigns.changed,
+ removed = gitsigns.removed,
+ }
+ end
+end
+
+return {
+ mode = {
+ function()
+ return " "
+ end,
+ left_padding = 0,
+ right_padding = 0,
+ color = {},
+ condition = nil,
+ },
+ branch = {
+ "b:gitsigns_head",
+ icon = " ",
+ color = { gui = "bold" },
+ condition = conditions.hide_in_width,
+ },
+ filename = {
+ "filename",
+ color = {},
+ condition = nil,
+ },
+ diff = {
+ "diff",
+ source = diff_source,
+ symbols = { added = "  ", modified = "柳", removed = " " },
+ color_added = { fg = colors.green },
+ color_modified = { fg = colors.yellow },
+ color_removed = { fg = colors.red },
+ color = {},
+ condition = nil,
+ },
+ python_env = {
+ function()
+ local utils = require "core.lualine.utils"
+ if vim.bo.filetype == "python" then
+ local venv = os.getenv "CONDA_DEFAULT_ENV"
+ if venv then
+ return string.format("  (%s)", utils.env_cleanup(venv))
+ end
+ venv = os.getenv "VIRTUAL_ENV"
+ if venv then
+ return string.format("  (%s)", utils.env_cleanup(venv))
+ end
+ return ""
+ end
+ return ""
+ end,
+ color = { fg = colors.green },
+ condition = conditions.hide_in_width,
+ },
+ diagnostics = {
+ "diagnostics",
+ sources = { "nvim_lsp" },
+ symbols = { error = " ", warn = " ", info = " ", hint = " " },
+ color = {},
+ condition = conditions.hide_in_width,
+ },
+ treesitter = {
+ function()
+ if next(vim.treesitter.highlighter.active) then
+ return "  "
+ end
+ return ""
+ end,
+ color = { fg = colors.green },
+ condition = conditions.hide_in_width,
+ },
+ lsp = {
+ function(msg)
+ msg = msg or "LSP Inactive"
+ local buf_clients = vim.lsp.buf_get_clients()
+ if next(buf_clients) == nil then
+ return msg
+ end
+ local buf_ft = vim.bo.filetype
+ local buf_client_names = {}
+
+ -- add client
+ local utils = require "lsp.utils"
+ local active_client = utils.get_active_client_by_ft(buf_ft)
+ for _, client in pairs(buf_clients) do
+ if client.name ~= "null-ls" then
+ table.insert(buf_client_names, client.name)
+ end
+ end
+ vim.list_extend(buf_client_names, active_client or {})
+
+ -- add formatter
+ local formatters = require "lsp.null-ls.formatters"
+ local supported_formatters = formatters.list_supported_names(buf_ft)
+ vim.list_extend(buf_client_names, supported_formatters)
+
+ -- add linter
+ local linters = require "lsp.null-ls.linters"
+ local supported_linters = linters.list_supported_names(buf_ft)
+ vim.list_extend(buf_client_names, supported_linters)
+
+ return table.concat(buf_client_names, ", ")
+ end,
+ icon = " ",
+ color = { gui = "bold" },
+ condition = conditions.hide_in_width,
+ },
+ location = { "location", condition = conditions.hide_in_width, color = {} },
+ progress = { "progress", condition = conditions.hide_in_width, color = {} },
+ spaces = {
+ function()
+ local label = "Spaces: "
+ if not vim.api.nvim_buf_get_option(0, "expandtab") then
+ label = "Tab size: "
+ end
+ return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " "
+ end,
+ condition = conditions.hide_in_width,
+ color = {},
+ },
+ encoding = {
+ "o:encoding",
+ upper = true,
+ color = {},
+ condition = conditions.hide_in_width,
+ },
+ filetype = { "filetype", condition = conditions.hide_in_width, color = {} },
+ scrollbar = {
+ function()
+ local current_line = vim.fn.line "."
+ local total_lines = vim.fn.line "$"
+ local chars = { "__", "▁▁", "▂▂", "▃▃", "▄▄", "▅▅", "▆▆", "▇▇", "██" }
+ local line_ratio = current_line / total_lines
+ local index = math.ceil(line_ratio * #chars)
+ return chars[index]
+ end,
+ left_padding = 0,
+ right_padding = 0,
+ color = { fg = colors.yellow, bg = colors.bg },
+ condition = nil,
+ },
+}
diff --git a/lua/core/lualine/conditions.lua b/lua/core/lualine/conditions.lua
new file mode 100644
index 00000000..3ee4fbb8
--- /dev/null
+++ b/lua/core/lualine/conditions.lua
@@ -0,0 +1,17 @@
+local window_width_limit = 80
+
+local conditions = {
+ buffer_not_empty = function()
+ return vim.fn.empty(vim.fn.expand "%:t") ~= 1
+ end,
+ hide_in_width = function()
+ return vim.fn.winwidth(0) > window_width_limit
+ end,
+ -- check_git_workspace = function()
+ -- local filepath = vim.fn.expand "%:p:h"
+ -- local gitdir = vim.fn.finddir(".git", filepath .. ";")
+ -- return gitdir and #gitdir > 0 and #gitdir < #filepath
+ -- end,
+}
+
+return conditions
diff --git a/lua/core/lualine/init.lua b/lua/core/lualine/init.lua
new file mode 100644
index 00000000..aa6fe098
--- /dev/null
+++ b/lua/core/lualine/init.lua
@@ -0,0 +1,47 @@
+local M = {}
+M.config = function()
+ lvim.builtin.lualine = {
+ active = true,
+ style = "lvim",
+ options = {
+ icons_enabled = nil,
+ component_separators = nil,
+ section_separators = nil,
+ theme = nil,
+ disabled_filetypes = nil,
+ },
+ sections = {
+ lualine_a = nil,
+ lualine_b = nil,
+ lualine_c = nil,
+ lualine_x = nil,
+ lualine_y = nil,
+ lualine_z = nil,
+ },
+ inactive_sections = {
+ lualine_a = nil,
+ lualine_b = nil,
+ lualine_c = nil,
+ lualine_x = nil,
+ lualine_y = nil,
+ lualine_z = nil,
+ },
+ tabline = nil,
+ extensions = nil,
+ on_config_done = nil,
+ }
+end
+
+M.setup = function()
+ require("core.lualine.styles").update()
+ require("core.lualine.utils").validate_theme()
+
+ local lualine = require "lualine"
+ lualine.setup(lvim.builtin.lualine)
+
+ if lvim.builtin.lualine.on_config_done then
+ lvim.builtin.lualine.on_config_done(lualine)
+ end
+end
+
+return M
diff --git a/lua/core/lualine/styles.lua b/lua/core/lualine/styles.lua
new file mode 100644
index 00000000..3595e5e3
--- /dev/null
+++ b/lua/core/lualine/styles.lua
@@ -0,0 +1,137 @@
+local M = {}
+local components = require "core.lualine.components"
+
+local styles = {
+ lvim = nil,
+ default = nil,
+ none = nil,
+}
+
+styles.none = {
+ style = "none",
+ options = {
+ icons_enabled = true,
+ component_separators = "",
+ section_separators = "",
+ disabled_filetypes = {},
+ },
+ sections = {
+ lualine_a = {},
+ lualine_b = {},
+ lualine_c = {},
+ lualine_x = {},
+ lualine_y = {},
+ lualine_z = {},
+ },
+ inactive_sections = {
+ lualine_a = {},
+ lualine_b = {},
+ lualine_c = {},
+ lualine_x = {},
+ lualine_y = {},
+ lualine_z = {},
+ },
+ tabline = {},
+ extensions = {},
+}
+
+styles.default = {
+ style = "default",
+ options = {
+ icons_enabled = true,
+ component_separators = { "", "" },
+ section_separators = { "", "" },
+ disabled_filetypes = {},
+ },
+ sections = {
+ lualine_a = { "mode" },
+ lualine_b = { "branch" },
+ lualine_c = { "filename" },
+ lualine_x = { "encoding", "fileformat", "filetype" },
+ lualine_y = { "progress" },
+ lualine_z = { "location" },
+ },
+ inactive_sections = {
+ lualine_a = {},
+ lualine_b = {},
+ lualine_c = { "filename" },
+ lualine_x = { "location" },
+ lualine_y = {},
+ lualine_z = {},
+ },
+ tabline = {},
+ extensions = {},
+}
+
+styles.lvim = {
+ style = "lvim",
+ options = {
+ icons_enabled = true,
+ component_separators = "",
+ section_separators = "",
+ disabled_filetypes = { "dashboard", "NvimTree", "Outline" },
+ },
+ sections = {
+ lualine_a = {
+ components.mode,
+ },
+ lualine_b = {
+ components.branch,
+ components.filename,
+ },
+ lualine_c = {
+ components.diff,
+ components.python_env,
+ },
+ lualine_x = {
+ components.diagnostics,
+ components.treesitter,
+ components.lsp,
+ components.filetype,
+ },
+ lualine_y = {},
+ lualine_z = {
+ components.scrollbar,
+ },
+ },
+ inactive_sections = {
+ lualine_a = {
+ "filename",
+ },
+ lualine_b = {},
+ lualine_c = {},
+ lualine_x = {},
+ lualine_y = {},
+ lualine_z = {},
+ },
+ tabline = {},
+ extensions = { "nvim-tree" },
+}
+
+function M.get_style(style)
+ local style_keys = vim.tbl_keys(styles)
+ if not vim.tbl_contains(style_keys, style) then
+ local Log = require "core.log"
+ Log:error(
+ "Invalid lualine style",
+ string.format('"%s"', style),
+ "options are: ",
+ string.format('"%s"', table.concat(style_keys, '", "'))
+ )
+ Log:debug '"lvim" style is applied.'
+ style = "lvim"
+ end
+
+ return vim.deepcopy(styles[style])
+end
+
+function M.update()
+ local style = M.get_style(lvim.builtin.lualine.style)
+ if lvim.builtin.lualine.options.theme == nil then
+ lvim.builtin.lualine.options.theme = lvim.colorscheme
+ end
+
+ lvim.builtin.lualine = vim.tbl_deep_extend("keep", lvim.builtin.lualine, style)
+end
+
+return M
diff --git a/lua/core/lualine/utils.lua b/lua/core/lualine/utils.lua
new file mode 100644
index 00000000..cf80a99e
--- /dev/null
+++ b/lua/core/lualine/utils.lua
@@ -0,0 +1,27 @@
+local M = {}
+
+function M.validate_theme()
+ local theme = lvim.builtin.lualine.options.theme
+ if type(theme) == "table" then
+ return
+ end
+
+ local lualine_loader = require "lualine.utils.loader"
+ local ok = pcall(lualine_loader.load_theme, theme)
+ if not ok then
+ lvim.builtin.lualine.options.theme = "auto"
+ end
+end
+
+function M.env_cleanup(venv)
+ if string.find(venv, "/") then
+ local final_venv = venv
+ for w in venv:gmatch "([^/]+)" do
+ final_venv = w
+ end
+ venv = final_venv
+ end
+ return venv
+end
+
+return M