Skip to content

Commit

Permalink
Merge branch 'master' into drop_older_nvim_support
Browse files Browse the repository at this point in the history
  • Loading branch information
shadmansaleh authored Oct 18, 2023
2 parents 3c2f99a + c55af3b commit 6afe950
Show file tree
Hide file tree
Showing 18 changed files with 217 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
run: |
mkdir -p ./tmp_home/nvim/pack/vendor/start
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ./tmp_home/nvim/pack/vendor/start/plenary.nvim
git clone --depth 1 https://github.com/kyazdani42/nvim-web-devicons ./tmp_home/nvim/pack/vendor/start/nvim-web-devicons
git clone --depth 1 https://github.com/nvim-tree/nvim-web-devicons ./tmp_home/nvim/pack/vendor/start/nvim-web-devicons
ln -s $(pwd) ./tmp_home/nvim/pack/vendor/start
- name: Setup neovim ${{matrix.nvim_version}}
uses: rhysd/action-setup-vim@v1
Expand Down
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,9 @@ sections = {
colored = true, -- Displays a colored diff status if set to true
diff_color = {
-- Same color values as the general color option can be used here.
added = 'DiffAdd', -- Changes the diff's added color
modified = 'DiffChange', -- Changes the diff's modified color
removed = 'DiffDelete', -- Changes the diff's removed color you
added = 'LuaLineDiffAdd', -- Changes the diff's added color
modified = 'LuaLineDiffChange', -- Changes the diff's modified color
removed = 'LuaLineDiffDelete', -- Changes the diff's removed color you
},
symbols = {added = '+', modified = '~', removed = '-'}, -- Changes the symbols used by the diff.
source = nil, -- A function that works as a data source for diff.
Expand Down Expand Up @@ -629,6 +629,7 @@ sections = {
-- 1: Relative path
-- 2: Absolute path
-- 3: Absolute path, with tilde as the home directory
-- 4: Filename and parent dir, with tilde as the home directory

shorting_target = 40, -- Shortens path to leave 40 spaces in the window
-- for other components. (terrible name, any suggestions?)
Expand Down Expand Up @@ -681,6 +682,7 @@ sections = {
lualine_a = {
{
'tabs',
tab_max_length = 40, -- Maximum width of each tab. The content will be shorten dynamically (example: apple/orange -> a/orange)
max_length = vim.o.columns / 3, -- Maximum width of tabs component.
-- Note:
-- It can also be a function that returns
Expand All @@ -689,6 +691,11 @@ sections = {
-- 1: Shows tab_name
-- 2: Shows tab_nr + tab_name

path = 0, -- 0: just shows the filename
-- 1: shows the relative path and shorten $HOME to ~
-- 2: shows the full path
-- 3: shows the full path and shorten $HOME to ~

-- Automatically updates active tab color to match color of other components (will be overidden if buffers_color is set)
use_mode_colors = false,

Expand All @@ -698,6 +705,11 @@ sections = {
inactive = 'lualine_{section}_inactive', -- Color for inactive tab.
},

show_modified_status = true, -- Shows a symbol next to the tab name if the file has been modified.
symbols = {
modified = '[+]', -- Text to show when the file is modified.
},

fmt = function(name, context)
-- Show + if buffer is modified in tab
local buflist = vim.fn.tabpagebuflist(context.tabnr)
Expand Down Expand Up @@ -903,6 +915,7 @@ extensions = {'quickfix'}
- symbols-outline
- toggleterm
- trouble
- mason

#### Custom extensions

Expand Down
19 changes: 16 additions & 3 deletions doc/lualine.txt
Original file line number Diff line number Diff line change
Expand Up @@ -606,9 +606,9 @@ Component specific options These are options that are available on
colored = true, -- Displays a colored diff status if set to true
diff_color = {
-- Same color values as the general color option can be used here.
added = 'DiffAdd', -- Changes the diff's added color
modified = 'DiffChange', -- Changes the diff's modified color
removed = 'DiffDelete', -- Changes the diff's removed color you
added = 'LuaLineDiffAdd', -- Changes the diff's added color
modified = 'LuaLineDiffChange', -- Changes the diff's modified color
removed = 'LuaLineDiffDelete', -- Changes the diff's removed color you
},
symbols = {added = '+', modified = '~', removed = '-'}, -- Changes the symbols used by the diff.
source = nil, -- A function that works as a data source for diff.
Expand Down Expand Up @@ -652,6 +652,7 @@ Component specific options These are options that are available on
-- 1: Relative path
-- 2: Absolute path
-- 3: Absolute path, with tilde as the home directory
-- 4: Filename and parent dir, with tilde as the home directory
shorting_target = 40, -- Shortens path to leave 40 spaces in the window
-- for other components. (terrible name, any suggestions?)
Expand Down Expand Up @@ -707,6 +708,7 @@ Component specific options These are options that are available on
lualine_a = {
{
'tabs',
tab_max_length = 40, -- Maximum width of each tab. The content will be shorten dynamically (example: apple/orange -> a/orange)
max_length = vim.o.columns / 3, -- Maximum width of tabs component.
-- Note:
-- It can also be a function that returns
Expand All @@ -715,6 +717,11 @@ Component specific options These are options that are available on
-- 1: Shows tab_name
-- 2: Shows tab_nr + tab_name
path = 0, -- 0: just shows the filename
-- 1: shows the relative path and shorten $HOME to ~
-- 2: shows the full path
-- 3: shows the full path and shorten $HOME to ~
-- Automatically updates active tab color to match color of other components (will be overidden if buffers_color is set)
use_mode_colors = false,
Expand All @@ -724,6 +731,11 @@ Component specific options These are options that are available on
inactive = 'lualine_{section}_inactive', -- Color for inactive tab.
},
show_modified_status = true, -- Shows a symbol next to the tab name if the file has been modified.
symbols = {
modified = '[+]', -- Text to show when the file is modified.
},
fmt = function(name, context)
-- Show + if buffer is modified in tab
local buflist = vim.fn.tabpagebuflist(context.tabnr)
Expand Down Expand Up @@ -954,6 +966,7 @@ extensions with:
- symbols-outline
- toggleterm
- trouble
- mason


*lualine-Custom-extensions*
Expand Down
2 changes: 1 addition & 1 deletion examples/evil_lualine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ ins_right {
ins_right {
'diff',
-- Is it me or the symbol for modified us really weird
symbols = { added = '', modified = ' ', removed = '' },
symbols = { added = '', modified = '󰝤 ', removed = '' },
diff_color = {
added = { fg = colors.green },
modified = { fg = colors.orange },
Expand Down
21 changes: 12 additions & 9 deletions lua/lualine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ local function fill_section_separator(status, is_focused, str_checked, last_hl,
end

--- processes statusline string
--- replaces %s/S{sep} with proper left/right separator highlight + sep
--- replaces %z/Z{sep} with proper left/right separator highlight + sep
---@param status string : unprocessed statusline string
---@return string : processed statusline string
local function apply_transitional_separators(status, is_focused)
Expand All @@ -90,7 +90,7 @@ local function apply_transitional_separators(status, is_focused)
local copied_pos = 1 -- Tracks how much we've copied over to status_applied
local str_checked = 1 -- Tracks where the searcher head is at

-- Process entire status replace the %s{sep} & %S{sep} placeholders
-- Process entire status replace the %z{sep} & %Z{sep} placeholders
-- with proper transitional separator.
while str_checked ~= nil do
str_checked = status:find('%%', str_checked)
Expand All @@ -105,9 +105,9 @@ local function apply_transitional_separators(status, is_focused)
-- %#hl_name# highlights
last_hl = status:match('^%%#(.-)#', str_checked)
str_checked = str_checked + #last_hl + 3
elseif next_char == 's' then
-- %s{sep} is marker for left separator and
local sep = status:match('^%%s{(.-)}', str_checked)
elseif next_char == 'z' then
-- %z{sep} is marker for left separator and
local sep = status:match('^%%z{(.-)}', str_checked)
str_checked = str_checked + #sep + 4 -- 4 = len(%{})
if not (last_hl == nil and last_hl_reseted) then
local trans_sep = fill_section_separator(status, is_focused, str_checked, last_hl, sep, false)
Expand All @@ -119,11 +119,11 @@ local function apply_transitional_separators(status, is_focused)
last_hl_reseted = false
end
copied_pos = str_checked
elseif next_char == 'S' then
-- %S{sep} is marker for right separator and
local sep = status:match('^%%S{(.-)}', str_checked)
elseif next_char == 'Z' then
-- %Z{sep} is marker for right separator and
local sep = status:match('^%%Z{(.-)}', str_checked)
str_checked = str_checked + #sep + 4 -- 4 = len(%{})
if status:find('^%%s', str_checked) or status:find('^%%<%%s', str_checked) then
if status:find('^%%z', str_checked) or status:find('^%%<%%Z', str_checked) then
-- When transitional right_sep and left_sep are right next to each other
-- and in this exact order skip the left sep as we can't draw both.
str_checked = status:find('}', str_checked) + 1
Expand Down Expand Up @@ -248,6 +248,9 @@ local function setup_theme()
elseif type(theme_name) == 'table' then
-- use the provided theme as-is
return config.options.theme
elseif type(theme_name) == 'function' then
-- call function and use returned (dynamic) theme as-is
return config.options.theme()
end
if theme_name ~= 'auto' then
notify_theme_error(theme_name)
Expand Down
4 changes: 2 additions & 2 deletions lua/lualine/component.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ function M:apply_section_separators()
return
end
if self.options.separator.left ~= nil and self.options.separator.left ~= '' then
self.status = string.format('%%s{%s}%s', self.options.separator.left, self.status)
self.status = string.format('%%z{%s}%s', self.options.separator.left, self.status)
self.strip_previous_separator = true
end
if self.options.separator.right ~= nil and self.options.separator.right ~= '' then
self.status = string.format('%s%%S{%s}', self.status, self.options.separator.right)
self.status = string.format('%s%%Z{%s}', self.status, self.options.separator.right)
end
end

Expand Down
22 changes: 17 additions & 5 deletions lua/lualine/components/branch/git_branch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,27 @@ local function update_branch()
branch_cache[vim.api.nvim_get_current_buf()] = current_git_branch
end

---updates the current value of current_git_branch and sets up file watch on HEAD file if value changed
local function update_current_git_dir(git_dir)
if current_git_dir ~= git_dir then
current_git_dir = git_dir
update_branch()
end
end

---returns full path to git directory for dir_path or current directory
---@param dir_path string|nil
---@return string
---@return string|nil
function M.find_git_dir(dir_path)
local git_dir = vim.env.GIT_DIR
if git_dir then
update_current_git_dir(git_dir)
return git_dir
end

-- get file dir so we can search from that dir
local file_dir = dir_path or vim.fn.expand('%:p:h')
local root_dir = file_dir
local git_dir
-- Search upward for .git file or folder
while root_dir do
if git_dir_cache[root_dir] then
Expand Down Expand Up @@ -101,9 +114,8 @@ function M.find_git_dir(dir_path)
end

git_dir_cache[file_dir] = git_dir
if dir_path == nil and current_git_dir ~= git_dir then
current_git_dir = git_dir
update_branch()
if dir_path == nil then
update_current_git_dir(git_dir)
end
return git_dir
end
Expand Down
4 changes: 2 additions & 2 deletions lua/lualine/components/buffers/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ end
---@return string
function Buffer:separator_before()
if self.current or self.aftercurrent then
return '%S{' .. self.options.section_separators.left .. '}'
return '%Z{' .. self.options.section_separators.left .. '}'
else
return self.options.component_separators.left
end
Expand All @@ -113,7 +113,7 @@ end
---@return string
function Buffer:separator_after()
if self.current or self.beforecurrent then
return '%s{' .. self.options.section_separators.right .. '}'
return '%z{' .. self.options.section_separators.right .. '}'
else
return self.options.component_separators.right
end
Expand Down
8 changes: 4 additions & 4 deletions lua/lualine/components/diagnostics/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ local M = {}
-- default symbols for diagnostics component
M.symbols = {
icons = {
error = ' ', -- xf659
warn = ' ', -- xf529
info = ' ', -- xf7fc
hint = ' ', -- xf835
error = '󰅚 ', -- x000f015a
warn = '󰀪 ', -- x000f002a
info = '󰋽 ', -- x000f02fd
hint = '󰌶 ', -- x000f0336
},
no_icons = { error = 'E:', warn = 'W:', info = 'I:', hint = 'H:' },
}
Expand Down
6 changes: 3 additions & 3 deletions lua/lualine/components/diff/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ local function apply_default_colors(opts)
added = {
fg = modules.utils.extract_color_from_hllist(
'fg',
{ 'GitSignsAdd', 'GitGutterAdd', 'DiffAdded', 'DiffAdd' },
{ 'LuaLineDiffAdd', 'GitSignsAdd', 'GitGutterAdd', 'DiffAdded', 'DiffAdd' },
'#90ee90'
),
},
modified = {
fg = modules.utils.extract_color_from_hllist(
'fg',
{ 'GitSignsChange', 'GitGutterChange', 'DiffChanged', 'DiffChange' },
{ 'LuaLineDiffChange', 'GitSignsChange', 'GitGutterChange', 'DiffChanged', 'DiffChange' },
'#f0e130'
),
},
removed = {
fg = modules.utils.extract_color_from_hllist(
'fg',
{ 'GitSignsDelete', 'GitGutterDelete', 'DiffRemoved', 'DiffDelete' },
{ 'LuaLineDiffDelete', 'GitSignsDelete', 'GitGutterDelete', 'DiffRemoved', 'DiffDelete' },
'#ff0038'
),
},
Expand Down
16 changes: 15 additions & 1 deletion lua/lualine/components/filename.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,24 @@ local function shorten_path(path, sep, max_len)
return table.concat(segments, sep)
end

local function filename_and_parent(path, sep)
local segments = vim.split(path, sep)
if #segments == 0 then
return path
elseif #segments == 1 then
return segments[#segments]
else
return table.concat({ segments[#segments - 1], segments[#segments] }, sep)
end
end

M.init = function(self, options)
M.super.init(self, options)
self.options = vim.tbl_deep_extend('keep', self.options or {}, default_options)
end

M.update_status = function(self)
local path_separator = package.config:sub(1, 1)
local data
if self.options.path == 1 then
-- relative path
Expand All @@ -66,6 +78,9 @@ M.update_status = function(self)
elseif self.options.path == 3 then
-- absolute path, with tilde
data = vim.fn.expand('%:p:~')
elseif self.options.path == 4 then
-- filename and immediate parent
data = filename_and_parent(vim.fn.expand('%:p:~'), path_separator)
else
-- just filename
data = vim.fn.expand('%:t')
Expand All @@ -81,7 +96,6 @@ M.update_status = function(self)
local windwidth = self.options.globalstatus and vim.go.columns or vim.fn.winwidth(0)
local estimated_space_available = windwidth - self.options.shorting_target

local path_separator = package.config:sub(1, 1)
data = shorten_path(data, path_separator, estimated_space_available)
end

Expand Down
4 changes: 4 additions & 0 deletions lua/lualine/components/searchcount.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ function M:update_status()
end

local result = vim.fn.searchcount { maxcount = self.options.maxcount, timeout = self.options.timeout }
if next(result) == nil then
return ''
end

local denominator = math.min(result.total, result.maxcount)
return string.format('[%d/%d]', result.current, denominator)
end
Expand Down
6 changes: 6 additions & 0 deletions lua/lualine/components/tabs/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ local highlight = require('lualine.highlight')

local default_options = {
max_length = 0,
tab_max_length = 40,
mode = 0,
use_mode_colors = false,
path = 0,
tabs_color = {
active = nil,
inactive = nil,
},
show_modified_status = true,
symbols = {
modified = '[+]',
},
}

-- This function is duplicated in buffers
Expand Down
Loading

0 comments on commit 6afe950

Please sign in to comment.