From 4f1a96fcec9b7c03fd7ef3bfccfa2a86908e6da1 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 9 May 2020 22:36:24 +0800 Subject: [PATCH] draw scroll progress --- rockspec/{ltui-1.9-2.rockspec => ltui-1.9-3.rockspec} | 2 +- src/ltui/textarea.lua | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) rename rockspec/{ltui-1.9-2.rockspec => ltui-1.9-3.rockspec} (99%) diff --git a/rockspec/ltui-1.9-2.rockspec b/rockspec/ltui-1.9-3.rockspec similarity index 99% rename from rockspec/ltui-1.9-2.rockspec rename to rockspec/ltui-1.9-3.rockspec index e0bc2b9..b1ec70e 100644 --- a/rockspec/ltui-1.9-2.rockspec +++ b/rockspec/ltui-1.9-3.rockspec @@ -1,5 +1,5 @@ package = "ltui" -version = "1.9-2" +version = "1.9-3" source = { url = "git://github.com/tboox/ltui", tag = "v1.9" diff --git a/src/ltui/textarea.lua b/src/ltui/textarea.lua index e307a3c..f06b647 100644 --- a/src/ltui/textarea.lua +++ b/src/ltui/textarea.lua @@ -62,9 +62,12 @@ function textarea:on_draw(transparent) -- draw progress if self:option("progress") then - local progress = math.floor((self._STARTLINE + math.min(self:height(), self._LINECOUNT)) * 100 / self._LINECOUNT) - if (self._STARTLINE > 0 or progress < 100) and self:width() > 20 then - self:canvas():move(self:width() - 10, self:height() - 1):putstr(string.format("(%d%%)", progress)) + local tb = self._STARTLINE + local fator = self:height() / self._LINECOUNT + local sb = math.min(math.floor(tb * fator), self:height() - 1) + local se = math.min(sb + math.ceil(self:height() * fator), self:height()) + if se > sb and se - sb < self:height() then + self:canvas():attr("black"):move(self:width() - 1, sb):putchar(' ', se - sb, true) end end end