From d5527664922d858b76c431ce68a9621fa8f1ba80 Mon Sep 17 00:00:00 2001 From: dmyTRUEk <25669613+dmyTRUEk@users.noreply.github.com> Date: Mon, 13 Jun 2022 14:45:03 +0300 Subject: [PATCH] Handle empty head or tail --- doc/scrollbar.txt | 2 +- lua/scrollbar.lua | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/doc/scrollbar.txt b/doc/scrollbar.txt index 551904e..a35374d 100644 --- a/doc/scrollbar.txt +++ b/doc/scrollbar.txt @@ -61,7 +61,7 @@ Set scrollbar offset from right border of window. By default it is set to 1. *g:scrollbar_shape* Set scrollbar shape. By default it is set to "{'head': '▲', 'body': '█', 'tail': -'▼'}". +'▼'}". Empty 'head' or 'tail' are allowed. > let g:scrollbar_shape = { \ 'head': '▲', diff --git a/lua/scrollbar.lua b/lua/scrollbar.lua index f69bdb4..c694ace 100644 --- a/lua/scrollbar.lua +++ b/lua/scrollbar.lua @@ -51,11 +51,18 @@ end)() local function gen_bar_lines(size) local shape = option.shape - local lines = { shape.head } - for _ = 2, size-1 do + local lines = {} + if shape.head ~= "" then + table.insert(lines, shape.head) + end + local start_index = shape.head == "" and 1 or 2 + local end_index = shape.tail == "" and size or size-1 + for _ = start_index, end_index do table.insert(lines, shape.body) end - table.insert(lines, shape.tail) + if shape.tail ~= "" then + table.insert(lines, shape.tail) + end return lines end