mirror of
https://github.com/sxyazi/yazi.git
synced 2025-01-08 09:28:03 +03:00
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:
parent
99a3b3a043
commit
0f106b591c
@ -21,6 +21,7 @@ tab_size = 2
|
|||||||
max_width = 600
|
max_width = 600
|
||||||
max_height = 900
|
max_height = 900
|
||||||
cache_dir = ""
|
cache_dir = ""
|
||||||
|
image_delay = 30
|
||||||
image_filter = "triangle"
|
image_filter = "triangle"
|
||||||
image_quality = 75
|
image_quality = 75
|
||||||
sixel_fraction = 15
|
sixel_fraction = 15
|
||||||
|
@ -15,6 +15,7 @@ pub struct Preview {
|
|||||||
|
|
||||||
pub cache_dir: PathBuf,
|
pub cache_dir: PathBuf,
|
||||||
|
|
||||||
|
pub image_delay: u8,
|
||||||
pub image_filter: String,
|
pub image_filter: String,
|
||||||
pub image_quality: u8,
|
pub image_quality: u8,
|
||||||
pub sixel_fraction: u8,
|
pub sixel_fraction: u8,
|
||||||
@ -63,6 +64,8 @@ impl FromStr for Preview {
|
|||||||
|
|
||||||
cache_dir: Option<String>,
|
cache_dir: Option<String>,
|
||||||
|
|
||||||
|
#[validate(range(min = 0, max = 100))]
|
||||||
|
image_delay: u8,
|
||||||
image_filter: String,
|
image_filter: String,
|
||||||
#[validate(range(min = 50, max = 90))]
|
#[validate(range(min = 50, max = 90))]
|
||||||
image_quality: u8,
|
image_quality: u8,
|
||||||
@ -87,6 +90,7 @@ impl FromStr for Preview {
|
|||||||
|
|
||||||
cache_dir,
|
cache_dir,
|
||||||
|
|
||||||
|
image_delay: preview.image_delay,
|
||||||
image_filter: preview.image_filter,
|
image_filter: preview.image_filter,
|
||||||
image_quality: preview.image_quality,
|
image_quality: preview.image_quality,
|
||||||
sixel_fraction: preview.sixel_fraction,
|
sixel_fraction: preview.sixel_fraction,
|
||||||
|
@ -3,15 +3,14 @@ local TEXT = "ABCDEFGHIJKLM\nNOPQRSTUVWXYZ\nabcdefghijklm\nnopqrstuvwxyz\n123456
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function M:peek()
|
function M:peek()
|
||||||
local cache = ya.file_cache(self)
|
local start, cache = os.clock(), ya.file_cache(self)
|
||||||
if not cache then
|
if not cache or self:preload() ~= 1 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if self:preload() == 1 then
|
ya.sleep(math.max(0, PREVIEW.image_delay / 1000 + start - os.clock()))
|
||||||
ya.image_show(cache, self.area)
|
ya.image_show(cache, self.area)
|
||||||
ya.preview_widgets(self, {})
|
ya.preview_widgets(self, {})
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M:seek() end
|
function M:seek() end
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function M:peek()
|
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
|
if not url or not fs.cha(url) then
|
||||||
url = self.file.url
|
url = self.file.url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
ya.sleep(math.max(0, PREVIEW.image_delay / 1000 + start - os.clock()))
|
||||||
ya.image_show(url, self.area)
|
ya.image_show(url, self.area)
|
||||||
ya.preview_widgets(self, {})
|
ya.preview_widgets(self, {})
|
||||||
end
|
end
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function M:peek()
|
function M:peek()
|
||||||
local cache = ya.file_cache(self)
|
local start, cache = os.clock(), ya.file_cache(self)
|
||||||
if not cache then
|
if not cache or self:preload() ~= 1 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if self:preload() == 1 then
|
ya.sleep(math.max(0, PREVIEW.image_delay / 1000 + start - os.clock()))
|
||||||
ya.image_show(cache, self.area)
|
ya.image_show(cache, self.area)
|
||||||
ya.preview_widgets(self, {})
|
ya.preview_widgets(self, {})
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M:seek() end
|
function M:seek() end
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function M:peek()
|
function M:peek()
|
||||||
local cache = ya.file_cache(self)
|
local start, cache = os.clock(), ya.file_cache(self)
|
||||||
if not cache then
|
if not cache or self:preload() ~= 1 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if self:preload() == 1 then
|
ya.sleep(math.max(0, PREVIEW.image_delay / 1000 + start - os.clock()))
|
||||||
ya.image_show(cache, self.area)
|
ya.image_show(cache, self.area)
|
||||||
ya.preview_widgets(self, {})
|
ya.preview_widgets(self, {})
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M:seek(units)
|
function M:seek(units)
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function M:peek()
|
function M:peek()
|
||||||
local cache = ya.file_cache(self)
|
local start, cache = os.clock(), ya.file_cache(self)
|
||||||
if not cache then
|
if not cache or self:preload() ~= 1 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if self:preload() == 1 then
|
ya.sleep(math.max(0, PREVIEW.image_delay / 1000 + start - os.clock()))
|
||||||
ya.image_show(cache, self.area)
|
ya.image_show(cache, self.area)
|
||||||
ya.preview_widgets(self, {})
|
ya.preview_widgets(self, {})
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M:seek(units)
|
function M:seek(units)
|
||||||
|
Loading…
Reference in New Issue
Block a user