From e94945129780fa5b43447ecc0a4b0273892043e3 Mon Sep 17 00:00:00 2001 From: Evgeni Chasnovski Date: Tue, 21 May 2024 17:16:33 +0300 Subject: [PATCH] feat(statusline)!: make default active content include `section_diff()` 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'. --- CHANGELOG.md | 1 + doc/mini-statusline.txt | 5 +++-- lua/mini/statusline.lua | 10 ++++++---- ...--Default-content---active---test-+-args-{-120-} | 4 ++-- ...---Default-content---active---test-+-args-{-39-} | 13 +++++++++++++ ...---Default-content---active---test-+-args-{-40-} | 13 +++++++++++++ ...---Default-content---active---test-+-args-{-74-} | 13 ------------- ...---Default-content---active---test-+-args-{-75-} | 4 ++-- tests/test_statusline.lua | 5 +++-- 9 files changed, 43 insertions(+), 25 deletions(-) create mode 100644 tests/screenshots/tests-test_statusline.lua---Default-content---active---test-+-args-{-39-} create mode 100644 tests/screenshots/tests-test_statusline.lua---Default-content---active---test-+-args-{-40-} delete mode 100644 tests/screenshots/tests-test_statusline.lua---Default-content---active---test-+-args-{-74-} diff --git a/CHANGELOG.md b/CHANGELOG.md index e6875b16..71444340 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/doc/mini-statusline.txt b/doc/mini-statusline.txt index dd841e06..ab20aa12 100644 --- a/doc/mini-statusline.txt +++ b/doc/mini-statusline.txt @@ -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 }) @@ -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 diff --git a/lua/mini/statusline.lua b/lua/mini/statusline.lua index b069ecf1..7b7bdeb2 100644 --- a/lua/mini/statusline.lua +++ b/lua/mini/statusline.lua @@ -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 }) @@ -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 @@ -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 }) @@ -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 diff --git a/tests/screenshots/tests-test_statusline.lua---Default-content---active---test-+-args-{-120-} b/tests/screenshots/tests-test_statusline.lua---Default-content---active---test-+-args-{-120-} index c38df057..6245bcbd 100644 --- a/tests/screenshots/tests-test_statusline.lua---Default-content---active---test-+-args-{-120-} +++ b/tests/screenshots/tests-test_statusline.lua---Default-content---active---test-+-args-{-120-} @@ -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 ') 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()%}')