-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmessage_window.lua
More file actions
81 lines (71 loc) · 1.63 KB
/
Copy pathmessage_window.lua
File metadata and controls
81 lines (71 loc) · 1.63 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
MessageWindow = {}
function MessageWindow:storeWin()
if vis.win ~= self.win then self.wintostore = vis.win end
end
function MessageWindow:restoreWin()
if self.wintostore and self.wintostrore ~= self.win then
vis.win = self.wintostore
end
self.wintostore = nil
end
function MessageWindow:destroy()
self:hide()
os.remove(self.file)
self.file = nil
end
function MessageWindow:isVisible()
if self.win then
for win in vis:windows() do
if win == self.win then return true end
end
self.win = nil
end
return false
end
function MessageWindow:setText(text, append)
if text ~= self.text or append then
local fd = io.open(self.file, append and "a" or "w")
fd:write(text.."\n")
fd:flush()
fd:close()
if self:isVisible() then
self:storeWin()
vis.win = self.win
vis:command("e!")
self:restoreWin()
end
self.text = (append and self.text or "")..text.."\n"
end
end
function MessageWindow:showOnBg()
self:storeWin()
self:show()
self:restoreWin()
end
function MessageWindow:show()
if not self:isVisible() then
vis:command("o "..self.file)
self.win = vis.win
else
vis.win = self.win
end
end
function MessageWindow:hide()
if self:isVisible() then
self:storeWin()
vis.win = self.win
vis:command("q!")
self:restoreWin()
self.win = nil
end
end
MessageWindow.new = function ()
local win = setmetatable({}, {
__index=MessageWindow,
__gc=function(o) os.remove(o.file) o.file = nil end})
win.file = os.tmpname()
win.text = ""
win.win = nil
vis.events.subscribe(vis.events.QUIT, function() win:destroy() end)
return win
end