Skip to content

Commit 76970b6

Browse files
committed
feat: implement scrolling
1 parent 3bc9d7b commit 76970b6

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

.luarc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"diagnostics.globals": [
33
"ui",
44
"Command",
5-
"ya"
5+
"ya",
6+
"cx",
7+
"units"
68
]
79
}

init.lua

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,53 @@
11
local M = {}
22

33
function M:peek()
4-
local output, code = Command("transmission-show")
4+
-- launch process
5+
local process, code = Command("transmission-show")
56
:args({
67
tostring(self.file.url),
78
})
89
:stdout(Command.PIPED)
9-
:output()
10+
:spawn()
1011

11-
local p
12-
p = ui.Paragraph.parse(self.area, output.stdout)
12+
local limit = self.area.h
13+
-- read and count lines from process
14+
local i, lines = 0, ""
15+
repeat
16+
local next, event = process:read_line()
17+
if event ~= 0 then
18+
break
19+
end
1320

14-
ya.preview_widgets(self, { p:wrap(ui.Paragraph.WRAP) })
21+
i = i + 1
22+
-- only concatenate lines that are past 'skip' number of STDOUT
23+
if i > self.skip then
24+
lines = lines .. next
25+
end
26+
until i >= self.skip + limit -- until reader reaches max number of lines on screen plus skip
27+
28+
process:start_kill()
29+
30+
-- if paged below all output, run peek again with smaller skip
31+
if self.skip > 0 and i < self.skip + limit then
32+
ya.manager_emit(
33+
"peek",
34+
{ tostring(math.max(0, i - limit)), only_if = tostring(self.file.url), upper_bound = "" }
35+
)
36+
-- preview torrent
37+
else
38+
ya.preview_widgets(self, { ui.Paragraph.parse(self.area, lines):wrap(ui.Paragraph.WRAP) })
39+
end
1540
end
1641

17-
function M:seek() end
42+
function M:seek(units)
43+
local h = cx.active.current.hovered
44+
if h and h.url == self.file.url then
45+
local step = math.floor(units * self.area.h / 10)
46+
ya.manager_emit("peek", {
47+
math.max(0, cx.active.preview.skip + step),
48+
only_if = self.file.url,
49+
})
50+
end
51+
end
1852

1953
return M

0 commit comments

Comments
 (0)