@ -107,17 +107,34 @@ local function shorten_path(path, max_len)
end
local segments = vim.split ( path , sep )
for idx = 1 , # segments - 1 do
local start = 1
if segments [ 1 ] == " ~ " then
start = start + 1
end
for idx = start , # segments - 1 do
if len <= max_len then
break
end
local segment = segments [ idx ]
local shortened = segment : sub ( 1 , vim.startswith ( segment , ' . ' ) and 2 or 1 )
local short_end = 1
if ( vim.startswith ( segment , ' . ' ) or vim.startswith ( segment , ' _ ' ) ) then
short_end = 2
end
local shortened = segment : sub ( 1 , short_end )
segments [ idx ] = shortened
len = len - ( # segment - # shortened )
end
if ( len > max_len and # segments > 3 ) then
while ( len > max_len and # segments > 3 ) do
table.remove ( segments , 2 )
end
table.insert ( segments , 2 , " ... " )
end
return table.concat ( segments , sep )
end
@ -169,49 +186,48 @@ local function statusline_focused()
local winwidth = vim.fn . winwidth ( 0 )
local left = table.concat {
gen_section ( accent_color , { get_mode_display_name ( mg ) } ) ,
gen_section ( " %#Middle# " , { shorten_path ( file , winwidth / 3 ) } ) ,
gen_section ( " %#Bottom# " , { " %m " , " %r " } ) ,
gen_section (
" %#Alert# " ,
{
process_diagnostics (
globals.sign_error .. " " ,
diagnostics.error ,
" %#DiagnosticVirtualTextError# "
) ,
process_diagnostics (
globals.sign_warn .. " " ,
diagnostics.warn ,
" %#DiagnosticVirtualTextWarn# "
) ,
process_diagnostics (
globals.sign_info .. " " ,
diagnostics.info ,
" %#DiagnosticVirtualTextInfo# "
)
}
)
}
gen_section ( accent_color , { get_mode_display_name ( mg ) } ) ,
gen_section ( " %#Middle# " , { shorten_path ( file , winwidth / 2 ) } ) ,
gen_section ( " %#Bottom# " , { " %m " , " %r " } ) ,
gen_section (
" %#Alert# " ,
{
process_diagnostics (
globals.sign_error .. " " ,
diagnostics.error ,
" %#DiagnosticVirtualTextError# "
) ,
process_diagnostics (
globals.sign_warn .. " " ,
diagnostics.warn ,
" %#DiagnosticVirtualTextWarn# "
) ,
process_diagnostics (
globals.sign_info .. " " ,
diagnostics.info ,
" %#DiagnosticVirtualTextInfo# "
)
}
)
}
local right = table.concat {
gen_section (
" %#Bottom# " ,
{
spell_check ( ) ,
vim.bo . filetype
}
) ,
gen_section ( " %#Middle# " , { " %03.p%% " } ) ,
gen_section ( " %#Top# " , { " -%03.c- " } )
}
gen_section (
" %#Bottom# " ,
{
spell_check ( ) ,
vim.bo . filetype
}
) ,
gen_section ( " %#Middle# " , { " %03.p%% " } ) ,
gen_section ( " %#Top# " , { " -%03.c- " } )
}
return table.concat {
left ,
" %#Statusline# " ,
" %= " ,
right
}
left ,
" %#Statusline# " ,
" %= " ,
right
}
end
local function statusline_not_focused ( )
@ -219,14 +235,14 @@ local function statusline_not_focused()
local file = vim.fn . expand ( " # " .. bufnr .. " :p:~ " )
local winwidth = vim.fn . winwidth ( 0 )
return table.concat {
gen_section ( " %#StatuslineNF# " , {
shorten_path ( file , winwidth / 3 ) ,
" %m "
} ) ,
" %= " ,
gen_section ( " %#StatuslineNF# " , { " %03.p%% " } ) ,
gen_section ( " %#StatuslineNF# " , { " -%03.c- " } )
}
gen_section ( " %#StatuslineNF# " , {
shorten_path ( file , winwidth / 2 ) ,
" %m "
} ) ,
" %= " ,
gen_section ( " %#StatuslineNF# " , { " %03.p%% " } ) ,
gen_section ( " %#StatuslineNF# " , { " -%03.c- " } )
}
end
function _G . gen_statusline ( )