forked from bfredl/bfredl.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoonwatch.lua
More file actions
83 lines (72 loc) · 1.54 KB
/
moonwatch.lua
File metadata and controls
83 lines (72 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
_G._moonwatch = _G._moonwatch or {}
local m = _G._moonwatch
local b = _G.bfredl
local sbuf, stage
m.ephemeral = m.ephemeral or {}
function m.float(args)
m.prepare()
if not args.relative then
args.win = stage
end
args.focusable = args.focusable or false
m.ephemeral[b.f(args)] = true
end
function m.cls()
for w,_ in pairs(m.ephemeral) do
if win.is_valid(w) then
win.close(w, false)
end
m.ephemeral[w] = nil
end
end
_G.cls = m.cls -- FIXME
function m.prepare()
if not m.stage then
local save = a.get_current_win()
m.sbuf = a.create_buf(true, true)
a.buf_set_name(m.sbuf, "[Moonwatch]")
m.stage = b.f{buf=m.sbuf, enter=true}
a.win_set_buf(m.stage, m.sbuf)
vim.cmd [[wincmd H]]
a.set_current_win(save)
end
stage, sbuf = m.stage, m.sbuf
end
function m.header(text)
m.float {r=1, center='c', text=text}
end
m.Show = {}
local Show = m.Show
Show.__index = Show
function m.make_show(name, state)
local self = setmetatable({}, Show)
self.name = name
self.slides = {}
self.order = {}
self.unorder = {}
if state then
self.cur = state.cur
end
return self
end
function Show:slide(key, fn)
if self.slides[key] then
error("duplicate "..key)
end
self.slides[key] = fn
table.insert(self.order, key)
self.unorder[key] = #self.order
end
function Show:show(id)
cls()
id = id or self.order[1]
self.slides[id]()
self.cur = id
end
function Show:mov(d)
local num = self.unorder[self.cur]
if num and self.order[num+d] then
self:show(self.order[num+d])
end
end
return m