-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdesktop.lua
61 lines (49 loc) · 1.29 KB
/
desktop.lua
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
--[[
-- Works for fen v1.1.2 or above
-- File preview script for *.desktop files
--]]
-- https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html
-- Customize the colors here:
local colorForGroupHeaders = "orange"
local colorForKeys = fen:ColorToString(fen:NewRGBColor(0, 255, 0)) -- Green
local attributesForKeys = "b" -- Bold
local colorForEquals = "blue"
local colorForValues = "default"
local State = {
Key = 1,
Value = 2,
}
local y = 0
for line in io.lines(fen.selectedFile) do
local state = State.Key
local seenEqualsSign = false
-- Group header
if line:sub(1,1) == '[' then
fen:PrintSimple("["..colorForGroupHeaders.."]"..line, 0, y)
goto continueLine
end
for i = 1, #line do
local char = line:sub(i,i)
if char == '=' and not seenEqualsSign then
seenEqualsSign = true
state = State.Value
fen:PrintSimple("["..colorForEquals.."]"..char, i-1, y)
goto continue
end
local foreground = "default"
local attributes = ""
if state == State.Key then
foreground = colorForKeys
attributes = attributesForKeys
elseif state == State.Value then
foreground = colorForValues
end
fen:PrintSimple("["..foreground.."::"..attributes.."]"..char, i-1, y)
::continue::
end
::continueLine::
y = y + 1
if y >= fen.Height then
break
end
end