Bladeren bron

refactor, fix galaxyline

christianchiarulli 4 jaren geleden
bovenliggende
commit
16d67ecf76
5 gewijzigde bestanden met toevoegingen van 318 en 319 verwijderingen
  1. 290 317
      lua/core/galaxyline.lua
  2. 19 0
      lua/core/status_colors.lua
  3. 1 1
      lua/default-config.lua
  4. 7 0
      lua/lv-utils/init.lua
  5. 1 1
      lua/plugins.lua

+ 290 - 317
lua/core/galaxyline.lua

@@ -1,353 +1,326 @@
-local M = {}
-M.config = function()
-  O.plugin.galaxyline = {
-    active = true,
-    colors = {
-      alt_bg = "#2E2E2E",
-      grey = "#858585",
-      blue = "#569CD6",
-      green = "#608B4E",
-      yellow = "#DCDCAA",
-      orange = "#FF8800",
-      purple = "#C586C0",
-      magenta = "#D16D9E",
-      cyan = "#4EC9B0",
-      red = "#D16969",
-      error_red = "#F44747",
-      warning_orange = "#FF8800",
-      info_yellow = "#FFCC66",
-      hint_blue = "#9CDCFE",
-    },
-  }
+-- if not package.loaded['galaxyline'] then
+--   return
+-- end
+local status_ok, gl = pcall(require, "galaxyline")
+if not status_ok then
+  return
 end
 
-M.setup = function()
-  -- if not package.loaded['galaxyline'] then
-  --   return
-  -- end
-  local status_ok, gl = pcall(require, "galaxyline")
-  if not status_ok then
-    return
-  end
-
-  -- NOTE: if someone defines colors but doesn't have them then this will break
-  local palette_status_ok, colors = pcall(require, O.colorscheme .. ".palette")
-  if not palette_status_ok then
-    colors = O.plugin.galaxyline.colors
-  end
+-- NOTE: if someone defines colors but doesn't have them then this will break
+local palette_status_ok, colors = pcall(require, O.colorscheme .. ".palette")
+if not palette_status_ok then
+  colors = O.plugin.galaxyline.colors
+end
 
-  local condition = require "galaxyline.condition"
-  local gls = gl.section
-  gl.short_line_list = { "NvimTree", "vista", "dbui", "packer" }
+local condition = require "galaxyline.condition"
+local gls = gl.section
+gl.short_line_list = { "NvimTree", "vista", "dbui", "packer" }
 
-  table.insert(gls.left, {
-    ViMode = {
-      provider = function()
-        -- auto change color according the vim mode
-        local mode_color = {
-          n = colors.blue,
-          i = colors.green,
-          v = colors.purple,
-          [""] = colors.purple,
-          V = colors.purple,
-          c = colors.magenta,
-          no = colors.blue,
-          s = colors.orange,
-          S = colors.orange,
-          [""] = colors.orange,
-          ic = colors.yellow,
-          R = colors.red,
-          Rv = colors.red,
-          cv = colors.blue,
-          ce = colors.blue,
-          r = colors.cyan,
-          rm = colors.cyan,
-          ["r?"] = colors.cyan,
-          ["!"] = colors.blue,
-          t = colors.blue,
-        }
-        vim.api.nvim_command("hi GalaxyViMode guifg=" .. mode_color[vim.fn.mode()])
-        return "▊"
-      end,
-      separator_highlight = { "NONE", colors.alt_bg },
-      highlight = { "NONE", colors.alt_bg },
-    },
-  })
-  -- print(vim.fn.getbufvar(0, 'ts'))
-  vim.fn.getbufvar(0, "ts")
+table.insert(gls.left, {
+  ViMode = {
+    provider = function()
+      -- auto change color according the vim mode
+      local mode_color = {
+        n = colors.blue,
+        i = colors.green,
+        v = colors.purple,
+        [""] = colors.purple,
+        V = colors.purple,
+        c = colors.magenta,
+        no = colors.blue,
+        s = colors.orange,
+        S = colors.orange,
+        [""] = colors.orange,
+        ic = colors.yellow,
+        R = colors.red,
+        Rv = colors.red,
+        cv = colors.blue,
+        ce = colors.blue,
+        r = colors.cyan,
+        rm = colors.cyan,
+        ["r?"] = colors.cyan,
+        ["!"] = colors.blue,
+        t = colors.blue,
+      }
+      vim.api.nvim_command("hi GalaxyViMode guifg=" .. mode_color[vim.fn.mode()])
+      return "▊"
+    end,
+    separator_highlight = { "NONE", colors.alt_bg },
+    highlight = { "NONE", colors.alt_bg },
+  },
+})
+-- print(vim.fn.getbufvar(0, 'ts'))
+vim.fn.getbufvar(0, "ts")
 
-  table.insert(gls.left, {
-    GitIcon = {
-      provider = function()
-        return "  "
-      end,
-      condition = condition.check_git_workspace,
-      separator = " ",
-      separator_highlight = { "NONE", colors.alt_bg },
-      highlight = { colors.orange, colors.alt_bg },
-    },
-  })
+table.insert(gls.left, {
+  GitIcon = {
+    provider = function()
+      return "  "
+    end,
+    condition = condition.check_git_workspace,
+    separator = " ",
+    separator_highlight = { "NONE", colors.alt_bg },
+    highlight = { colors.orange, colors.alt_bg },
+  },
+})
 
-  table.insert(gls.left, {
-    GitBranch = {
-      provider = "GitBranch",
-      condition = condition.check_git_workspace,
-      separator = " ",
-      separator_highlight = { "NONE", colors.alt_bg },
-      highlight = { colors.grey, colors.alt_bg },
-    },
-  })
+table.insert(gls.left, {
+  GitBranch = {
+    provider = "GitBranch",
+    condition = condition.check_git_workspace,
+    separator = " ",
+    separator_highlight = { "NONE", colors.alt_bg },
+    highlight = { colors.grey, colors.alt_bg },
+  },
+})
 
-  table.insert(gls.left, {
-    DiffAdd = {
-      provider = "DiffAdd",
-      condition = condition.hide_in_width,
-      icon = "  ",
-      highlight = { colors.green, colors.alt_bg },
-    },
-  })
+table.insert(gls.left, {
+  DiffAdd = {
+    provider = "DiffAdd",
+    condition = condition.hide_in_width,
+    icon = "  ",
+    highlight = { colors.green, colors.alt_bg },
+  },
+})
 
-  table.insert(gls.left, {
-    DiffModified = {
-      provider = "DiffModified",
-      condition = condition.hide_in_width,
-      icon = " 柳",
-      highlight = { colors.blue, colors.alt_bg },
-    },
-  })
+table.insert(gls.left, {
+  DiffModified = {
+    provider = "DiffModified",
+    condition = condition.hide_in_width,
+    icon = " 柳",
+    highlight = { colors.blue, colors.alt_bg },
+  },
+})
 
-  table.insert(gls.left, {
-    DiffRemove = {
-      provider = "DiffRemove",
-      condition = condition.hide_in_width,
-      icon = "  ",
-      highlight = { colors.red, colors.alt_bg },
-    },
-  })
+table.insert(gls.left, {
+  DiffRemove = {
+    provider = "DiffRemove",
+    condition = condition.hide_in_width,
+    icon = "  ",
+    highlight = { colors.red, colors.alt_bg },
+  },
+})
 
-  table.insert(gls.left, {
-    Filler = {
-      provider = function()
-        return " "
-      end,
-      highlight = { colors.grey, colors.alt_bg },
-    },
-  })
-  -- get output from shell command
-  function os.capture(cmd, raw)
-    local f = assert(io.popen(cmd, "r"))
-    local s = assert(f:read "*a")
-    f:close()
-    if raw then
-      return s
-    end
-    s = string.gsub(s, "^%s+", "")
-    s = string.gsub(s, "%s+$", "")
-    s = string.gsub(s, "[\n\r]+", " ")
+table.insert(gls.left, {
+  Filler = {
+    provider = function()
+      return " "
+    end,
+    highlight = { colors.grey, colors.alt_bg },
+  },
+})
+-- get output from shell command
+function os.capture(cmd, raw)
+  local f = assert(io.popen(cmd, "r"))
+  local s = assert(f:read "*a")
+  f:close()
+  if raw then
     return s
   end
-  -- cleanup virtual env
-  local function 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
+  s = string.gsub(s, "^%s+", "")
+  s = string.gsub(s, "%s+$", "")
+  s = string.gsub(s, "[\n\r]+", " ")
+  return s
+end
+-- cleanup virtual env
+local function env_cleanup(venv)
+  if string.find(venv, "/") then
+    local final_venv = venv
+    for w in venv:gmatch "([^/]+)" do
+      final_venv = w
     end
-    return venv
+    venv = final_venv
   end
-  local PythonEnv = function()
-    if vim.bo.filetype == "python" then
-      local venv = os.getenv "CONDA_DEFAULT_ENV"
-      if venv ~= nil then
-        return "  (" .. env_cleanup(venv) .. ")"
-      end
-      venv = os.getenv "VIRTUAL_ENV"
-      if venv ~= nil then
-        return "  (" .. env_cleanup(venv) .. ")"
-      end
-      return ""
+  return venv
+end
+local PythonEnv = function()
+  if vim.bo.filetype == "python" then
+    local venv = os.getenv "CONDA_DEFAULT_ENV"
+    if venv ~= nil then
+      return "  (" .. env_cleanup(venv) .. ")"
+    end
+    venv = os.getenv "VIRTUAL_ENV"
+    if venv ~= nil then
+      return "  (" .. env_cleanup(venv) .. ")"
     end
     return ""
   end
-  table.insert(gls.left, {
-    VirtualEnv = {
-      provider = PythonEnv,
-      event = "BufEnter",
-      highlight = { colors.green, colors.alt_bg },
-    },
-  })
+  return ""
+end
+table.insert(gls.left, {
+  VirtualEnv = {
+    provider = PythonEnv,
+    event = "BufEnter",
+    highlight = { colors.green, colors.alt_bg },
+  },
+})
 
-  table.insert(gls.right, {
-    DiagnosticError = {
-      provider = "DiagnosticError",
-      icon = "  ",
-      highlight = { colors.red, colors.alt_bg },
-    },
-  })
-  table.insert(gls.right, {
-    DiagnosticWarn = {
-      provider = "DiagnosticWarn",
-      icon = "  ",
-      highlight = { colors.orange, colors.alt_bg },
-    },
-  })
+table.insert(gls.right, {
+  DiagnosticError = {
+    provider = "DiagnosticError",
+    icon = "  ",
+    highlight = { colors.red, colors.alt_bg },
+  },
+})
+table.insert(gls.right, {
+  DiagnosticWarn = {
+    provider = "DiagnosticWarn",
+    icon = "  ",
+    highlight = { colors.orange, colors.alt_bg },
+  },
+})
 
-  table.insert(gls.right, {
-    DiagnosticInfo = {
-      provider = "DiagnosticInfo",
-      icon = "  ",
-      highlight = { colors.yellow, colors.alt_bg },
-    },
-  })
+table.insert(gls.right, {
+  DiagnosticInfo = {
+    provider = "DiagnosticInfo",
+    icon = "  ",
+    highlight = { colors.yellow, colors.alt_bg },
+  },
+})
 
-  table.insert(gls.right, {
-    DiagnosticHint = {
-      provider = "DiagnosticHint",
-      icon = "  ",
-      highlight = { colors.blue, colors.alt_bg },
-    },
-  })
+table.insert(gls.right, {
+  DiagnosticHint = {
+    provider = "DiagnosticHint",
+    icon = "  ",
+    highlight = { colors.blue, colors.alt_bg },
+  },
+})
 
-  table.insert(gls.right, {
-    TreesitterIcon = {
-      provider = function()
-        if next(vim.treesitter.highlighter.active) ~= nil then
-          return "  "
-        end
-        return ""
-      end,
-      separator = " ",
-      separator_highlight = { "NONE", colors.alt_bg },
-      highlight = { colors.green, colors.alt_bg },
-    },
-  })
+table.insert(gls.right, {
+  TreesitterIcon = {
+    provider = function()
+      if next(vim.treesitter.highlighter.active) ~= nil then
+        return "  "
+      end
+      return ""
+    end,
+    separator = " ",
+    separator_highlight = { "NONE", colors.alt_bg },
+    highlight = { colors.green, colors.alt_bg },
+  },
+})
 
-  local get_lsp_client = function(msg)
-    msg = msg or "LSP Inactive"
-    local buf_ft = vim.api.nvim_buf_get_option(0, "filetype")
-    local clients = vim.lsp.get_active_clients()
-    if next(clients) == nil then
-      return msg
-    end
-    local lsps = ""
-    for _, client in ipairs(clients) do
-      local filetypes = client.config.filetypes
-      if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
-        -- print(client.name)
-        if lsps == "" then
-          -- print("first", lsps)
-          lsps = client.name
-        else
-          if not string.find(lsps, client.name) then
-            lsps = lsps .. ", " .. client.name
-          end
-          -- print("more", lsps)
+local get_lsp_client = function(msg)
+  msg = msg or "LSP Inactive"
+  local buf_ft = vim.api.nvim_buf_get_option(0, "filetype")
+  local clients = vim.lsp.get_active_clients()
+  if next(clients) == nil then
+    return msg
+  end
+  local lsps = ""
+  for _, client in ipairs(clients) do
+    local filetypes = client.config.filetypes
+    if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
+      -- print(client.name)
+      if lsps == "" then
+        -- print("first", lsps)
+        lsps = client.name
+      else
+        if not string.find(lsps, client.name) then
+          lsps = lsps .. ", " .. client.name
         end
+        -- print("more", lsps)
       end
     end
-    if lsps == "" then
-      return msg
-    else
-      return lsps
-    end
   end
+  if lsps == "" then
+    return msg
+  else
+    return lsps
+  end
+end
 
-  table.insert(gls.right, {
-    ShowLspClient = {
-      provider = get_lsp_client,
-      condition = function()
-        local tbl = { ["dashboard"] = true, [" "] = true }
-        if tbl[vim.bo.filetype] then
-          return false
-        end
-        return true
-      end,
-      icon = " ",
-      highlight = { colors.grey, colors.alt_bg },
-    },
-  })
-
-  table.insert(gls.right, {
-    LineInfo = {
-      provider = "LineColumn",
-      separator = "  ",
-      separator_highlight = { "NONE", colors.alt_bg },
-      highlight = { colors.grey, colors.alt_bg },
-    },
-  })
+table.insert(gls.right, {
+  ShowLspClient = {
+    provider = get_lsp_client,
+    condition = function()
+      local tbl = { ["dashboard"] = true, [" "] = true }
+      if tbl[vim.bo.filetype] then
+        return false
+      end
+      return true
+    end,
+    icon = " ",
+    highlight = { colors.grey, colors.alt_bg },
+  },
+})
 
-  table.insert(gls.right, {
-    PerCent = {
-      provider = "LinePercent",
-      separator = " ",
-      separator_highlight = { "NONE", colors.alt_bg },
-      highlight = { colors.grey, colors.alt_bg },
-    },
-  })
+table.insert(gls.right, {
+  LineInfo = {
+    provider = "LineColumn",
+    separator = "  ",
+    separator_highlight = { "NONE", colors.alt_bg },
+    highlight = { colors.grey, colors.alt_bg },
+  },
+})
 
-  table.insert(gls.right, {
-    Tabstop = {
-      provider = function()
-        return "Spaces: " .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " "
-      end,
-      condition = condition.hide_in_width,
-      separator = " ",
-      separator_highlight = { "NONE", colors.alt_bg },
-      highlight = { colors.grey, colors.alt_bg },
-    },
-  })
+table.insert(gls.right, {
+  PerCent = {
+    provider = "LinePercent",
+    separator = " ",
+    separator_highlight = { "NONE", colors.alt_bg },
+    highlight = { colors.grey, colors.alt_bg },
+  },
+})
 
-  table.insert(gls.right, {
-    BufferType = {
-      provider = "FileTypeName",
-      condition = condition.hide_in_width,
-      separator = " ",
-      separator_highlight = { "NONE", colors.alt_bg },
-      highlight = { colors.grey, colors.alt_bg },
-    },
-  })
+table.insert(gls.right, {
+  Tabstop = {
+    provider = function()
+      return "Spaces: " .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " "
+    end,
+    condition = condition.hide_in_width,
+    separator = " ",
+    separator_highlight = { "NONE", colors.alt_bg },
+    highlight = { colors.grey, colors.alt_bg },
+  },
+})
 
-  table.insert(gls.right, {
-    FileEncode = {
-      provider = "FileEncode",
-      condition = condition.hide_in_width,
-      separator = " ",
-      separator_highlight = { "NONE", colors.alt_bg },
-      highlight = { colors.grey, colors.alt_bg },
-    },
-  })
+table.insert(gls.right, {
+  BufferType = {
+    provider = "FileTypeName",
+    condition = condition.hide_in_width,
+    separator = " ",
+    separator_highlight = { "NONE", colors.alt_bg },
+    highlight = { colors.grey, colors.alt_bg },
+  },
+})
 
-  table.insert(gls.right, {
-    Space = {
-      provider = function()
-        return " "
-      end,
-      separator = " ",
-      separator_highlight = { "NONE", colors.alt_bg },
-      highlight = { colors.grey, colors.alt_bg },
-    },
-  })
+table.insert(gls.right, {
+  FileEncode = {
+    provider = "FileEncode",
+    condition = condition.hide_in_width,
+    separator = " ",
+    separator_highlight = { "NONE", colors.alt_bg },
+    highlight = { colors.grey, colors.alt_bg },
+  },
+})
 
-  table.insert(gls.short_line_left, {
-    BufferType = {
-      provider = "FileTypeName",
-      separator = " ",
-      separator_highlight = { "NONE", colors.alt_bg },
-      highlight = { colors.grey, colors.alt_bg },
-    },
-  })
+table.insert(gls.right, {
+  Space = {
+    provider = function()
+      return " "
+    end,
+    separator = " ",
+    separator_highlight = { "NONE", colors.alt_bg },
+    highlight = { colors.grey, colors.alt_bg },
+  },
+})
 
-  table.insert(gls.short_line_left, {
-    SFileName = {
-      provider = "SFileName",
-      condition = condition.buffer_not_empty,
-      highlight = { colors.grey, colors.alt_bg },
-    },
-  })
+table.insert(gls.short_line_left, {
+  BufferType = {
+    provider = "FileTypeName",
+    separator = " ",
+    separator_highlight = { "NONE", colors.alt_bg },
+    highlight = { colors.grey, colors.alt_bg },
+  },
+})
 
-  --table.insert(gls.short_line_right[1] = {BufferIcon = {provider = 'BufferIcon', highlight = {colors.grey, colors.alt_bg}}})
-end
+table.insert(gls.short_line_left, {
+  SFileName = {
+    provider = "SFileName",
+    condition = condition.buffer_not_empty,
+    highlight = { colors.grey, colors.alt_bg },
+  },
+})
 
-return M
+--table.insert(gls.short_line_right[1] = {BufferIcon = {provider = 'BufferIcon', highlight = {colors.grey, colors.alt_bg}}})

+ 19 - 0
lua/core/status_colors.lua

@@ -0,0 +1,19 @@
+O.plugin.galaxyline = {
+  active = true,
+  colors = {
+    alt_bg = "#2E2E2E",
+    grey = "#858585",
+    blue = "#569CD6",
+    green = "#608B4E",
+    yellow = "#DCDCAA",
+    orange = "#FF8800",
+    purple = "#C586C0",
+    magenta = "#D16D9E",
+    cyan = "#4EC9B0",
+    red = "#D16969",
+    error_red = "#F44747",
+    warning_orange = "#FF8800",
+    info_yellow = "#FFCC66",
+    hint_blue = "#9CDCFE",
+  },
+}

+ 1 - 1
lua/default-config.lua

@@ -284,13 +284,13 @@ O = {
   },
 }
 
+require "core.status_colors"
 require("core.gitsigns").config()
 require("core.compe").config()
 require("core.dashboard").config()
 require("core.dap").config()
 require("core.floatterm").config()
 require("core.zen").config()
-require("core.galaxyline").config()
 require("core.telescope").config()
 require("core.treesitter").config()
 require("core.which-key").config()

+ 7 - 0
lua/lv-utils/init.lua

@@ -7,6 +7,7 @@ function lv_utils.reload_lv_config()
   vim.cmd "source ~/.config/nvim/lua/core/formatter.lua"
   vim.cmd ":PackerCompile"
   vim.cmd ":PackerInstall"
+  -- vim.cmd ":PackerClean"
 end
 
 function lv_utils.check_lsp_client_active(name)
@@ -54,6 +55,11 @@ lv_utils.define_augroups {
       "*",
       "setlocal formatoptions-=c formatoptions-=r formatoptions-=o",
     },
+    {
+      "BufWinEnter",
+      "dashboard",
+      "setlocal cursorline signcolumn=yes cursorcolumn number",
+    },
     {
       "BufRead",
       "*",
@@ -95,6 +101,7 @@ lv_utils.define_augroups {
     -- will cause split windows to be resized evenly if main window is resized
     { "BufWritePost", "plugins.lua", "PackerCompile" },
   },
+
   -- _fterm_lazygit = {
   --   -- will cause esc key to exit lazy git
   --   {"TermEnter", "*", "call LazyGitNativation()"}

+ 1 - 1
lua/plugins.lua

@@ -145,7 +145,7 @@ return require("packer").startup(function(use)
   use {
     "glepnir/galaxyline.nvim",
     config = function()
-      require("core.galaxyline").setup()
+      require "core.galaxyline"
     end,
     event = "BufWinEnter",
     disable = not O.plugin.galaxyline.active,