fix(filename): include window_width to space estimation & expose

shorting_target option

setting shorting target to 0 disables path shorting
closes #8

Co-authored-by: NullVoxPopuli <LPSego3+dev@gmail.com>
This commit is contained in:
shadmansaleh 2021-05-28 15:49:44 -04:00
parent ee5c56e911
commit d360039969
3 changed files with 17 additions and 7 deletions

View File

@ -320,7 +320,9 @@ sections = {
{
'filename',
file_status = true, -- displays file status (readonly status, modified status)
path = 0 -- 0 = just filename, 1 = relative path, 2 = absolute path
path = 0, -- 0 = just filename, 1 = relative path, 2 = absolute path
shorting_target = 40 -- Shortens path to leave 40 space in the window
-- for other components. Terrible name any suggestions?
}
}
}

View File

@ -252,6 +252,8 @@ Component specific local options~
'filename',
file_status = true, -- displays file status (readonly status, modified status)
path = 0 -- 0 = just filename, 1 = relative path, 2 = absolute path
shorting_target = 40 -- Shortens path to leave 40 space in the window
-- for other components. Terrible name any suggestions?
}
}
}

View File

@ -24,6 +24,9 @@ FileName.new = function(self, options, child)
new_instance.options.file_status = true
end
if new_instance.options.path == nil then new_instance.options.path = 0 end
if new_instance.options.shorting_target == nil then
new_instance.options.shorting_target = 40
end
return new_instance
end
@ -43,14 +46,17 @@ FileName.update_status = function(self)
if data == '' then data = '[No Name]' end
if self.options.shorting_target ~= 0 then
local windwidth = vim.fn.winwidth(0)
local estimated_space_available = 40
local estimated_space_available = windwidth - self.options.shorting_target
local path_separator = package.config:sub(1, 1)
for _ = 0, count(data, path_separator) do
if windwidth <= 84 or #data > estimated_space_available then
data = shorten_path(data, path_separator)
end
end
end
if self.options.file_status then
if vim.bo.modified then