perf: new image_delay option debounces image previews to avoid lag caused by terminal image decoding during fast scrolling (#1512)

This commit is contained in:
三咲雅 · Misaki Masa 2024-08-18 23:30:32 +08:00 committed by sxyazi
parent 99a3b3a043
commit 0f106b591c
No known key found for this signature in database
7 changed files with 27 additions and 25 deletions

View File

@ -21,6 +21,7 @@ tab_size = 2
max_width = 600
max_height = 900
cache_dir = ""
image_delay = 30
image_filter = "triangle"
image_quality = 75
sixel_fraction = 15

View File

@ -15,6 +15,7 @@ pub struct Preview {
pub cache_dir: PathBuf,
pub image_delay: u8,
pub image_filter: String,
pub image_quality: u8,
pub sixel_fraction: u8,
@ -63,6 +64,8 @@ impl FromStr for Preview {
cache_dir: Option<String>,
#[validate(range(min = 0, max = 100))]
image_delay: u8,
image_filter: String,
#[validate(range(min = 50, max = 90))]
image_quality: u8,
@ -87,6 +90,7 @@ impl FromStr for Preview {
cache_dir,
image_delay: preview.image_delay,
image_filter: preview.image_filter,
image_quality: preview.image_quality,
sixel_fraction: preview.sixel_fraction,

View File

@ -3,15 +3,14 @@ local TEXT = "ABCDEFGHIJKLM\nNOPQRSTUVWXYZ\nabcdefghijklm\nnopqrstuvwxyz\n123456
local M = {}
function M:peek()
local cache = ya.file_cache(self)
if not cache then
local start, cache = os.clock(), ya.file_cache(self)
if not cache or self:preload() ~= 1 then
return
end
if self:preload() == 1 then
ya.image_show(cache, self.area)
ya.preview_widgets(self, {})
end
ya.sleep(math.max(0, PREVIEW.image_delay / 1000 + start - os.clock()))
ya.image_show(cache, self.area)
ya.preview_widgets(self, {})
end
function M:seek() end

View File

@ -1,11 +1,12 @@
local M = {}
function M:peek()
local url = ya.file_cache(self)
local start, url = os.clock(), ya.file_cache(self)
if not url or not fs.cha(url) then
url = self.file.url
end
ya.sleep(math.max(0, PREVIEW.image_delay / 1000 + start - os.clock()))
ya.image_show(url, self.area)
ya.preview_widgets(self, {})
end

View File

@ -1,15 +1,14 @@
local M = {}
function M:peek()
local cache = ya.file_cache(self)
if not cache then
local start, cache = os.clock(), ya.file_cache(self)
if not cache or self:preload() ~= 1 then
return
end
if self:preload() == 1 then
ya.image_show(cache, self.area)
ya.preview_widgets(self, {})
end
ya.sleep(math.max(0, PREVIEW.image_delay / 1000 + start - os.clock()))
ya.image_show(cache, self.area)
ya.preview_widgets(self, {})
end
function M:seek() end

View File

@ -1,15 +1,14 @@
local M = {}
function M:peek()
local cache = ya.file_cache(self)
if not cache then
local start, cache = os.clock(), ya.file_cache(self)
if not cache or self:preload() ~= 1 then
return
end
if self:preload() == 1 then
ya.image_show(cache, self.area)
ya.preview_widgets(self, {})
end
ya.sleep(math.max(0, PREVIEW.image_delay / 1000 + start - os.clock()))
ya.image_show(cache, self.area)
ya.preview_widgets(self, {})
end
function M:seek(units)

View File

@ -1,15 +1,14 @@
local M = {}
function M:peek()
local cache = ya.file_cache(self)
if not cache then
local start, cache = os.clock(), ya.file_cache(self)
if not cache or self:preload() ~= 1 then
return
end
if self:preload() == 1 then
ya.image_show(cache, self.area)
ya.preview_widgets(self, {})
end
ya.sleep(math.max(0, PREVIEW.image_delay / 1000 + start - os.clock()))
ya.image_show(cache, self.area)
ya.preview_widgets(self, {})
end
function M:seek(units)