diff options
Diffstat (limited to 'lua/lvim/builtin/lualine')
| -rw-r--r-- | lua/lvim/builtin/lualine/colors.lua | 16 | ||||
| -rw-r--r-- | lua/lvim/builtin/lualine/components.lua | 179 | ||||
| -rw-r--r-- | lua/lvim/builtin/lualine/conditions.lua | 17 | ||||
| -rw-r--r-- | lua/lvim/builtin/lualine/init.lua | 54 | ||||
| -rw-r--r-- | lua/lvim/builtin/lualine/styles.lua | 165 | ||||
| -rw-r--r-- | lua/lvim/builtin/lualine/utils.lua | 14 | 
6 files changed, 445 insertions, 0 deletions
diff --git a/lua/lvim/builtin/lualine/colors.lua b/lua/lvim/builtin/lualine/colors.lua new file mode 100644 index 00000000..4984cd1f --- /dev/null +++ b/lua/lvim/builtin/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/lvim/builtin/lualine/components.lua b/lua/lvim/builtin/lualine/components.lua new file mode 100644 index 00000000..2f8e8b37 --- /dev/null +++ b/lua/lvim/builtin/lualine/components.lua @@ -0,0 +1,179 @@ +local conditions = require "lvim.builtin.lualine.conditions" +local colors = require "lvim.builtin.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 + +local branch = lvim.icons.git.Branch + +if lvim.colorscheme == "lunar" then +  branch = "%#SLGitIcon#" .. lvim.icons.git.Branch .. "%*" .. "%#SLBranchName#" +end + +return { +  mode = { +    function() +      return " " .. lvim.icons.ui.Target .. " " +    end, +    padding = { left = 0, right = 0 }, +    color = {}, +    cond = nil, +  }, +  branch = { +    "b:gitsigns_head", +    icon = branch, +    color = { gui = "bold" }, +  }, +  filename = { +    "filename", +    color = {}, +    cond = nil, +  }, +  diff = { +    "diff", +    source = diff_source, +    symbols = { +      added = lvim.icons.git.LineAdded .. " ", +      modified = lvim.icons.git.LineModified .. " ", +      removed = lvim.icons.git.LineRemoved .. " ", +    }, +    padding = { left = 2, right = 1 }, +    diff_color = { +      added = { fg = colors.green }, +      modified = { fg = colors.yellow }, +      removed = { fg = colors.red }, +    }, +    cond = nil, +  }, +  python_env = { +    function() +      local utils = require "lvim.builtin.lualine.utils" +      if vim.bo.filetype == "python" then +        local venv = os.getenv "CONDA_DEFAULT_ENV" or os.getenv "VIRTUAL_ENV" +        if venv then +          local icons = require "nvim-web-devicons" +          local py_icon, _ = icons.get_icon ".py" +          return string.format(" " .. py_icon .. " (%s)", utils.env_cleanup(venv)) +        end +      end +      return "" +    end, +    color = { fg = colors.green }, +    cond = conditions.hide_in_width, +  }, +  diagnostics = { +    "diagnostics", +    sources = { "nvim_diagnostic" }, +    symbols = { +      error = lvim.icons.diagnostics.BoldError .. " ", +      warn = lvim.icons.diagnostics.BoldWarning .. " ", +      info = lvim.icons.diagnostics.BoldInformation .. " ", +      hint = lvim.icons.diagnostics.BoldHint .. " ", +    }, +    -- cond = conditions.hide_in_width, +  }, +  treesitter = { +    function() +      return lvim.icons.ui.Tree +    end, +    color = function() +      local buf = vim.api.nvim_get_current_buf() +      local ts = vim.treesitter.highlighter.active[buf] +      return { fg = ts and not vim.tbl_isempty(ts) and colors.green or colors.red } +    end, +    cond = conditions.hide_in_width, +  }, +  lsp = { +    function(msg) +      msg = msg or "LS Inactive" +      local buf_clients = vim.lsp.buf_get_clients() +      if next(buf_clients) == nil then +        -- TODO: clean up this if statement +        if type(msg) == "boolean" or #msg == 0 then +          return "LS Inactive" +        end +        return msg +      end +      local buf_ft = vim.bo.filetype +      local buf_client_names = {} +      local copilot_active = false + +      -- add client +      for _, client in pairs(buf_clients) do +        if client.name ~= "null-ls" and client.name ~= "copilot" then +          table.insert(buf_client_names, client.name) +        end + +        if client.name == "copilot" then +          copilot_active = true +        end +      end + +      -- add formatter +      local formatters = require "lvim.lsp.null-ls.formatters" +      local supported_formatters = formatters.list_registered(buf_ft) +      vim.list_extend(buf_client_names, supported_formatters) + +      -- add linter +      local linters = require "lvim.lsp.null-ls.linters" +      local supported_linters = linters.list_registered(buf_ft) +      vim.list_extend(buf_client_names, supported_linters) + +      local unique_client_names = vim.fn.uniq(buf_client_names) + +      local language_servers = "[" .. table.concat(unique_client_names, ", ") .. "]" + +      if copilot_active then +        language_servers = language_servers .. "%#SLCopilot#" .. " " .. lvim.icons.git.Octoface .. "%*" +      end + +      return language_servers +    end, +    color = { gui = "bold" }, +    cond = conditions.hide_in_width, +  }, +  location = { "location" }, +  progress = { +    "progress", +    fmt = function() +      return "%P/%L" +    end, +    color = {}, +  }, + +  spaces = { +    function() +      local shiftwidth = vim.api.nvim_buf_get_option(0, "shiftwidth") +      return lvim.icons.ui.Tab .. " " .. shiftwidth +    end, +    padding = 1, +  }, +  encoding = { +    "o:encoding", +    fmt = string.upper, +    color = {}, +    cond = conditions.hide_in_width, +  }, +  filetype = { "filetype", cond = nil, padding = { left = 1, right = 1 } }, +  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, +    padding = { left = 0, right = 0 }, +    color = "SLProgress", +    cond = nil, +  }, +} diff --git a/lua/lvim/builtin/lualine/conditions.lua b/lua/lvim/builtin/lualine/conditions.lua new file mode 100644 index 00000000..42d52a83 --- /dev/null +++ b/lua/lvim/builtin/lualine/conditions.lua @@ -0,0 +1,17 @@ +local window_width_limit = 100 + +local conditions = { +  buffer_not_empty = function() +    return vim.fn.empty(vim.fn.expand "%:t") ~= 1 +  end, +  hide_in_width = function() +    return vim.o.columns > 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/lvim/builtin/lualine/init.lua b/lua/lvim/builtin/lualine/init.lua new file mode 100644 index 00000000..42859962 --- /dev/null +++ b/lua/lvim/builtin/lualine/init.lua @@ -0,0 +1,54 @@ +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 = { statusline = { "alpha" } }, +      globalstatus = true, +    }, +    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, +  } +end + +M.setup = function() +  if #vim.api.nvim_list_uis() == 0 then +    local Log = require "lvim.core.log" +    Log:debug "headless mode detected, skipping running setup for lualine" +    return +  end + +  local status_ok, lualine = pcall(require, "lualine") +  if not status_ok then +    return +  end + +  require("lvim.builtin.lualine.styles").update() + +  lualine.setup(lvim.builtin.lualine) + +  return lualine +end + +return M diff --git a/lua/lvim/builtin/lualine/styles.lua b/lua/lvim/builtin/lualine/styles.lua new file mode 100644 index 00000000..22d69e12 --- /dev/null +++ b/lua/lvim/builtin/lualine/styles.lua @@ -0,0 +1,165 @@ +local M = {} +local components = require "lvim.builtin.lualine.components" + +local styles = { +  lvim = nil, +  default = nil, +  none = nil, +} + +styles.none = { +  style = "none", +  options = { +    theme = "auto", +    globalstatus = true, +    icons_enabled = lvim.use_icons, +    component_separators = { left = "", right = "" }, +    section_separators = { left = "", right = "" }, +    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 = { +    theme = "auto", +    globalstatus = true, +    icons_enabled = lvim.use_icons, +    component_separators = { +      left = lvim.icons.ui.DividerRight, +      right = lvim.icons.ui.DividerLeft, +    }, +    section_separators = { +      left = lvim.icons.ui.BoldDividerRight, +      right = lvim.icons.ui.BoldDividerLeft, +    }, +    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 = { +    theme = "auto", +    globalstatus = true, +    icons_enabled = lvim.use_icons, +    component_separators = { left = "", right = "" }, +    section_separators = { left = "", right = "" }, +    disabled_filetypes = { "alpha" }, +  }, +  sections = { +    lualine_a = { +      components.mode, +    }, +    lualine_b = { +      components.branch, +    }, +    lualine_c = { +      components.diff, +      components.python_env, +    }, +    lualine_x = { +      components.diagnostics, +      components.lsp, +      components.spaces, +      components.filetype, +    }, +    lualine_y = { components.location }, +    lualine_z = { +      components.progress, +    }, +  }, +  inactive_sections = { +    lualine_a = { +      components.mode, +    }, +    lualine_b = { +      components.branch, +    }, +    lualine_c = { +      components.diff, +      components.python_env, +    }, +    lualine_x = { +      components.diagnostics, +      components.lsp, +      components.spaces, +      components.filetype, +    }, +    lualine_y = { components.location }, +    lualine_z = { +      components.progress, +    }, +  }, +  tabline = {}, +  extensions = {}, +} + +function M.get_style(style) +  local style_keys = vim.tbl_keys(styles) +  if not vim.tbl_contains(style_keys, style) then +    local Log = require "lvim.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) + +  lvim.builtin.lualine = vim.tbl_deep_extend("keep", lvim.builtin.lualine, style) + +  local color_template = vim.g.colors_name or lvim.colorscheme +  local theme_supported, template = pcall(function() +    require("lualine.utils.loader").load_theme(color_template) +  end) +  if theme_supported and template then +    lvim.builtin.lualine.options.theme = color_template +  end +end + +return M diff --git a/lua/lvim/builtin/lualine/utils.lua b/lua/lvim/builtin/lualine/utils.lua new file mode 100644 index 00000000..3fd3c2d3 --- /dev/null +++ b/lua/lvim/builtin/lualine/utils.lua @@ -0,0 +1,14 @@ +local M = {} + +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  | 
