-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbell.lua
More file actions
85 lines (70 loc) · 1.84 KB
/
bell.lua
File metadata and controls
85 lines (70 loc) · 1.84 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
84
85
local micro = import("micro")
local time = import("time")
local config = import("micro/config")
local plug_path = config.ConfigDir .. "/plug/?.lua"
if not package.path:find(plug_path, 1, true) then
package.path = package.path .. ";" .. plug_path
end
local utils = require("vi/utils")
local PROGRAM_ERROR_HEAD = "** vi program error **\n"
local NOT_PLANNED_HEAD = "Not planned to implement"
local PLANNED_HEAD = "Not implemented yet, but planned"
local BELL_HEAD = " * RING! * "
local BELL_DURATION = time.ParseDuration("1s")
local function where(level)
level = (level or 3)
local info
if debug ~= nil then
info = debug.getinfo(level, "nSl")
end
if not info then
return ""
end
return string.format("[%s:%d in %s]", info.source or "?", info.currentline or -1, info.name or "?")
end
local function program_error(message)
micro.TermMessage(PROGRAM_ERROR_HEAD .. where(3) .. "\n" .. message)
end
local function not_planned(message)
if message then
micro.InfoBar():Error(NOT_PLANNED_HEAD .. ": " .. message)
else
micro.InfoBar():Error(NOT_PLANNED_HEAD)
end
end
local function planned(message)
if message then
micro.InfoBar():Error(PLANNED_HEAD .. ": " .. message)
else
micro.InfoBar():Error(PLANNED_HEAD)
end
end
local function general_error(message)
micro.InfoBar():Error(message)
end
local function show_message(message)
micro.InfoBar():Message(message)
end
local function ring(reason)
if reason then
micro.InfoBar():Error(BELL_HEAD .. "(" .. reason .. ")")
else
micro.InfoBar():Error(BELL_HEAD)
end
utils.after(BELL_DURATION, function()
micro.InfoBar():Message("")
end)
end
-------------
-- Exports --
-------------
local M = {}
M.program_error = program_error
M.not_planned = not_planned
M.planned = planned
M.error = general_error
M.info = show_message
M.vi_error = general_error
M.vi_info = show_message
M.ring = ring
return M