Skip to content

Commit 932ead2

Browse files
committed
feat(VisualBell): Flashes the screen as a visual notification
1 parent e5b8712 commit 932ead2

File tree

2 files changed

+205
-0
lines changed

2 files changed

+205
-0
lines changed

Source/VisualBell.spoon/docs.json

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
[
2+
{
3+
"Constant" : [
4+
5+
],
6+
"submodules" : [
7+
8+
],
9+
"Function" : [
10+
11+
],
12+
"Variable" : [
13+
{
14+
"name" : "color",
15+
"desc" : "The color of the flash",
16+
"stripped_doc" : [
17+
"The color of the flash"
18+
],
19+
"doc" : "The color of the flash",
20+
"notes" : [
21+
22+
],
23+
"signature" : "VisualBell.color",
24+
"type" : "Variable",
25+
"returns" : [
26+
27+
],
28+
"def" : "VisualBell.color",
29+
"parameters" : [
30+
31+
]
32+
},
33+
{
34+
"name" : "duration",
35+
"desc" : "The duration of the flash",
36+
"stripped_doc" : [
37+
"The duration of the flash"
38+
],
39+
"doc" : "The duration of the flash",
40+
"notes" : [
41+
42+
],
43+
"signature" : "VisualBell.duration",
44+
"type" : "Variable",
45+
"returns" : [
46+
47+
],
48+
"def" : "VisualBell.duration",
49+
"parameters" : [
50+
51+
]
52+
}
53+
],
54+
"stripped_doc" : [
55+
56+
],
57+
"Deprecated" : [
58+
59+
],
60+
"desc" : "Flashes the screen as a visual notification, similar to Vim's 'visualbell'.",
61+
"type" : "Module",
62+
"Constructor" : [
63+
64+
],
65+
"items" : [
66+
{
67+
"name" : "color",
68+
"desc" : "The color of the flash",
69+
"stripped_doc" : [
70+
"The color of the flash"
71+
],
72+
"doc" : "The color of the flash",
73+
"notes" : [
74+
75+
],
76+
"signature" : "VisualBell.color",
77+
"type" : "Variable",
78+
"returns" : [
79+
80+
],
81+
"def" : "VisualBell.color",
82+
"parameters" : [
83+
84+
]
85+
},
86+
{
87+
"name" : "duration",
88+
"desc" : "The duration of the flash",
89+
"stripped_doc" : [
90+
"The duration of the flash"
91+
],
92+
"doc" : "The duration of the flash",
93+
"notes" : [
94+
95+
],
96+
"signature" : "VisualBell.duration",
97+
"type" : "Variable",
98+
"returns" : [
99+
100+
],
101+
"def" : "VisualBell.duration",
102+
"parameters" : [
103+
104+
]
105+
},
106+
{
107+
"name" : "flash",
108+
"desc" : "Flashes the screen using the configured color and duration",
109+
"stripped_doc" : [
110+
"Flashes the screen using the configured color and duration",
111+
""
112+
],
113+
"doc" : "Flashes the screen using the configured color and duration\n\nParameters:\n * None",
114+
"notes" : [
115+
116+
],
117+
"signature" : "VisualBell:flash()",
118+
"type" : "Method",
119+
"returns" : [
120+
121+
],
122+
"def" : "VisualBell:flash()",
123+
"parameters" : [
124+
" * None"
125+
]
126+
}
127+
],
128+
"Method" : [
129+
{
130+
"name" : "flash",
131+
"desc" : "Flashes the screen using the configured color and duration",
132+
"stripped_doc" : [
133+
"Flashes the screen using the configured color and duration",
134+
""
135+
],
136+
"doc" : "Flashes the screen using the configured color and duration\n\nParameters:\n * None",
137+
"notes" : [
138+
139+
],
140+
"signature" : "VisualBell:flash()",
141+
"type" : "Method",
142+
"returns" : [
143+
144+
],
145+
"def" : "VisualBell:flash()",
146+
"parameters" : [
147+
" * None"
148+
]
149+
}
150+
],
151+
"Command" : [
152+
153+
],
154+
"doc" : "Flashes the screen as a visual notification, similar to Vim's 'visualbell'.",
155+
"Field" : [
156+
157+
],
158+
"name" : "VisualBell"
159+
}
160+
]

Source/VisualBell.spoon/init.lua

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
--- === VisualBell ===
2+
---
3+
--- Flashes the screen as a visual notification, similar to Vim's 'visualbell'.
4+
---
5+
---
6+
7+
local obj = {}
8+
obj.__index = obj
9+
10+
obj.name = "VisualBell"
11+
obj.version = "1.0"
12+
obj.author = "Jon Lorusso <jonlorusso@gmail.com>"
13+
obj.homepage = "https://github.com/Hammerspoon/Spoons"
14+
obj.license = "MIT - https://opensource.org/licenses/MIT"
15+
16+
--- VisualBell.color
17+
--- Variable
18+
--- The color of the flash
19+
obj.color = { white = 1.0, alpha = 0.2 }
20+
21+
22+
--- VisualBell.duration
23+
--- Variable
24+
--- The duration of the flash
25+
obj.duration = 0.15
26+
27+
--- VisualBell:flash()
28+
--- Method
29+
--- Flashes the screen using the configured color and duration
30+
---
31+
--- Parameters:
32+
--- * None
33+
function obj:flash()
34+
local screenFrame = hs.screen.mainScreen():fullFrame()
35+
local flash = hs.drawing.rectangle(screenFrame)
36+
37+
flash:setFillColor(obj.color)
38+
flash:setFill(true)
39+
flash:setLevel(hs.drawing.windowLevels.overlay)
40+
flash:show()
41+
42+
hs.timer.doAfter(obj.duration, function() flash:delete() end)
43+
end
44+
45+
return obj

0 commit comments

Comments
 (0)