Skip to content

Commit

Permalink
feat(statusline)!: make default active content include section_diff()
Browse files Browse the repository at this point in the history
This is mostly breaking because 1) there is now separate icon to the left
of diff data and 2) Git data is not shown for widths below 40.
Otherwise, it shows the same content with 'gitsigns.nvim' set up, but
also now prefers 'mini.git' and 'mini.diff'.
  • Loading branch information
echasnovski committed May 21, 2024
1 parent fe0d88f commit e949451
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

- BREAKING FEATURE: `section_git()` now prefers using data from 'mini.git' with fallback on pure HEAD data from 'lewis6991/gistigns.nvim'.
- FEATURE: add `section_diff()` to show data from 'mini.diff' with fallback on diff data from 'lewis6991/gistigns.nvim'.
- BREAKING FEATURE: update default active content to use both `section_git()` and `section_diff()`.

## mini.tabline

Expand Down
5 changes: 3 additions & 2 deletions doc/mini-statusline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ This function is used as default value for active content:
>
function()
local mode, mode_hl = MiniStatusline.section_mode({ trunc_width = 120 })
local git = MiniStatusline.section_git({ trunc_width = 75 })
local git = MiniStatusline.section_git({ trunc_width = 40 })
local diff = MiniStatusline.section_diff({ trunc_width = 75 })
local diagnostics = MiniStatusline.section_diagnostics({ trunc_width = 75 })
local filename = MiniStatusline.section_filename({ trunc_width = 140 })
local fileinfo = MiniStatusline.section_fileinfo({ trunc_width = 120 })
Expand All @@ -94,7 +95,7 @@ This function is used as default value for active content:
return MiniStatusline.combine_groups({
{ hl = mode_hl, strings = { mode } },
{ hl = 'MiniStatuslineDevinfo', strings = { git, diagnostics } },
{ hl = 'MiniStatuslineDevinfo', strings = { git, diff, diagnostics } },
'%<', -- Mark general truncate point
{ hl = 'MiniStatuslineFilename', strings = { filename } },
'%=', -- End left alignment
Expand Down
10 changes: 6 additions & 4 deletions lua/mini/statusline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
--- >
--- function()
--- local mode, mode_hl = MiniStatusline.section_mode({ trunc_width = 120 })
--- local git = MiniStatusline.section_git({ trunc_width = 75 })
--- local git = MiniStatusline.section_git({ trunc_width = 40 })
--- local diff = MiniStatusline.section_diff({ trunc_width = 75 })
--- local diagnostics = MiniStatusline.section_diagnostics({ trunc_width = 75 })
--- local filename = MiniStatusline.section_filename({ trunc_width = 140 })
--- local fileinfo = MiniStatusline.section_fileinfo({ trunc_width = 120 })
Expand All @@ -92,7 +93,7 @@
---
--- return MiniStatusline.combine_groups({
--- { hl = mode_hl, strings = { mode } },
--- { hl = 'MiniStatuslineDevinfo', strings = { git, diagnostics } },
--- { hl = 'MiniStatuslineDevinfo', strings = { git, diff, diagnostics } },
--- '%<', -- Mark general truncate point
--- { hl = 'MiniStatuslineFilename', strings = { filename } },
--- '%=', -- End left alignment
Expand Down Expand Up @@ -579,7 +580,8 @@ H.modes = setmetatable({
H.default_content_active = function()
-- stylua: ignore start
local mode, mode_hl = MiniStatusline.section_mode({ trunc_width = 120 })
local git = MiniStatusline.section_git({ trunc_width = 75 })
local git = MiniStatusline.section_git({ trunc_width = 40 })
local diff = MiniStatusline.section_diff({ trunc_width = 75 })
local diagnostics = MiniStatusline.section_diagnostics({ trunc_width = 75 })
local filename = MiniStatusline.section_filename({ trunc_width = 140 })
local fileinfo = MiniStatusline.section_fileinfo({ trunc_width = 120 })
Expand All @@ -591,7 +593,7 @@ H.default_content_active = function()
-- sections, etc.)
return MiniStatusline.combine_groups({
{ hl = mode_hl, strings = { mode } },
{ hl = 'MiniStatuslineDevinfo', strings = { git, diagnostics } },
{ hl = 'MiniStatuslineDevinfo', strings = { git, diff, diagnostics } },
'%<', -- Mark general truncate point
{ hl = 'MiniStatuslineFilename', strings = { filename } },
'%=', -- End left alignment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
1|aaaaaaaaa │
2|~ │~
3|~ │~
4| Normal  main +1 ~2 -3  E4 W3 I2 H1 tests/dir-statusline/mocked.lua  lua utf-8[unix] 10B 2/9 1|1│ 2|9 [No Name]
4| Normal  main|bisect (MM)  #4 +3 ~2 -1  E4 W3 I2 H1 <ir-statusline/mocked.lua  lua utf-8[unix] 10B 2/9 1|1│ 2|9 [No Name]
5|/a [2/9]

-|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
1|010000000222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222344444444444444444444444444444
2|555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555366666666666666666666666666666
3|555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555366666666666666666666666666666
4|777777778888888888888888888888888888888999999999999999999999999999999999999999999988888888888888888888888777777777777777999999999999999999999999999999
4|777777778888888888888888888888888888888888888888888888889999999999999999999999999988888888888888888888888777777777777777999999999999999999999999999999
5|444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
1|aaaaaaaaa │
2|~ │~
3|~ │~
4| N <statusline/mocked.lua  lua 1│ 2 [No Name]
5|/a [2/9]

-|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
1|010000000222222222222222222222222222222344444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
2|555555555555555555555555555555555555555366666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
3|555555555555555555555555555555555555555366666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
4|777888888888888888888888889999999777777888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
5|444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
1|aaaaaaaaa │
2|~ │~
3|~ │~
4| N  main|bisect (MM) <ua  lua 1│ 2 [No Name]
5|/a [2/9]

-|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
1|010000000222222222222222222222222222222234444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
2|555555555555555555555555555555555555555536666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
3|555555555555555555555555555555555555555536666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
4|777888888888888888888889999888888877777799999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
5|444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
1|aaaaaaaaa │
2|~ │~
3|~ │~
4| N  main +1 ~2 -3  E4 W3 I2 H1 <usline/mocked.lua  lua 2/9 1|1│ 2|9 [No Name]
4| N  main|bisect (MM)  #4 +3 ~2 -1  E4 W3 I2 H1 <  lua 2/9 1|1│ 2|9 [No Name]
5|/a [2/9]

-|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
1|010000000222222222222222222222222222222222222222222222222222222222222222222344444444444444444444444444444444444444444444444444444444444444444444444444
2|555555555555555555555555555555555555555555555555555555555555555555555555555366666666666666666666666666666666666666666666666666666666666666666666666666
3|555555555555555555555555555555555555555555555555555555555555555555555555555366666666666666666666666666666666666666666666666666666666666666666666666666
4|777888888888888888888888888888888899999999999999999998888888777777777777777999999999999999999999999999999999999999999999999999999999999999999999999999
4|777888888888888888888888888888888888888888888888888998888888777777777777777999999999999999999999999999999999999999999999999999999999999999999999999999
5|444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
5 changes: 3 additions & 2 deletions tests/test_statusline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -690,20 +690,21 @@ T['Default content']['active'] = new_set({
child.set_size(5, 150)

mock_devicons()
mock_gitsigns()
mock_file(10)

-- Mock filename section to use relative path for consistent screenshots
child.lua([[MiniStatusline.section_filename = function() return '%f%m%r' end]])
child.cmd('edit ' .. vim.fn.fnamemodify(mocked_filepath, ':.'))
mock_diagnostics()
mock_minigit()
mock_minidiff()
type_keys('/a', '<CR>')
end,
post_case = unmock_file,
},
-- There should also be test for 140, but it is for truncating in
-- `section_filename` from full to relative paths
parametrize = { { 120 }, { 75 }, { 74 } },
parametrize = { { 120 }, { 75 }, { 40 }, { 39 } },
}, {
test = function(window_width)
eq(child.api.nvim_win_get_option(0, 'statusline'), '%{%v:lua.MiniStatusline.active()%}')
Expand Down

0 comments on commit e949451

Please sign in to comment.