This repository was archived by the owner on Jun 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExplorer.lua
More file actions
182 lines (137 loc) · 4.63 KB
/
Copy pathExplorer.lua
File metadata and controls
182 lines (137 loc) · 4.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
-- //AUTO-GENERATED-CODE//
local APLibPath = settings.get('APLibPath')
assert( -- check if setup was done before, if not return with an error
type(APLibPath) == 'string',
'Couldn\'t open APLib through path: '..tostring(
APLibPath
)..'; probably you haven\'t completed Lib setup via \'LIBFILE setup\' or the setup failed'
)
assert( -- check if Lib is still there, if not return with an error
fs.exists(APLibPath),
'Couldn\'t open APLib through path: '..tostring(
APLibPath
)..'; remember that if you move the Lib\'s folder you must set it up again via \'LIBFILE setup\''
)
os.loadAPI(APLibPath) -- load Lib with CraftOS's built-in feature
APLibPath = fs.getName(APLibPath)
if APLibPath:sub(#APLibPath - 3) == '.lua' then APLibPath = APLibPath:sub(1, #APLibPath - 4); end
local APLib = _ENV[APLibPath]
APLib.APLibPath = APLibPath
APLibPath = nil
-- //MAIN-PROGRAM//
Path = ''
FSDirs = {}
FSFiles = {}
function reloadFS(_path)
local _list = fs.list(_path)
FSDirs = {}
FSFiles = {}
local _FSDirs = {}
local _FSFiles = {}
for key, value in pairs(_list) do
if fs.isDir(_path..'/'..value) then
table.insert(_FSDirs, value)
else
table.insert(_FSFiles, value)
end
end
table.sort(_FSDirs)
table.sort(_FSFiles)
if Path ~= '' then
table.insert(FSDirs, {name = '..'})
end
for key, value in pairs(_FSDirs) do
table.insert(FSDirs, {name = value})
end
for key, value in pairs(_FSFiles) do
table.insert(FSFiles, {name = value, size = fs.getSize(_path..'/'..value)})
end
end
function mFSReset()
mFSDirs:clear()
mFSFiles:clear()
local oldLine = mFSDirs.cursor.pos.line
for key, value in pairs(FSDirs) do
mFSDirs:print(' '..value.name)
end
table.remove(mFSDirs.lines)
mFSDirs:setCursorPos(1, oldLine)
oldLine = mFSFiles.cursor.pos.line
for key, value in pairs(FSFiles) do
mFSFiles:print(' '..value.name..' - Size:'..tostring(value.size))
end
table.remove(mFSFiles.lines)
mFSFiles:setCursorPos(1, oldLine)
end
reloadFS(Path)
-- HEADER
hTitle = APLib.Header.new(1, {'EXPLORER', colors.red, colors.gray})
-- MEMOs
mFSDirs = APLib.Memo.new(1, 2, 25, 19, {colors.lime, nil, colors.lightGray, colors.lightGray})
mFSFiles = APLib.Memo.new(27, 2, 51, 19, {colors.white, nil, colors.lightGray, colors.lightGray})
mFSDirs.editSettings.charEvent = false
mFSDirs.editSettings.keyEvent = false
mFSFiles.editSettings.charEvent = false
mFSFiles.editSettings.keyEvent = false
mFSDirs:setCursorLimits(nil, nil)
mFSFiles:setCursorLimits(nil, nil)
mFSDirs.cursor.text = '>'
mFSFiles.cursor.text = '>'
mFSDirs.cursor.colors.textColor = colors.red
mFSFiles.cursor.colors.textColor = colors.red
mFSReset()
mFSDirs:setCallback(
APLib.event.memo.onEdit,
function (self, event)
if event[1] == 'key' then
if event[2] == 208 then -- DOWN KEY
self:setCursorPos(1, self.cursor.pos.line + 1)
elseif event[2] == 200 then -- UP KEY
self:setCursorPos(1, self.cursor.pos.line - 1)
elseif event[2] == 28 then -- ENTER
local _selDir = FSDirs[self.cursor.pos.line]
if _selDir then
_selDir = _selDir.name
if _selDir == '..' then
Path = fs.getDir(Path)
else
Path = Path..'/'.._selDir
end
reloadFS(Path)
mFSReset()
end
end
end
end
)
mFSFiles:setCallback(
APLib.event.memo.onEdit,
function (self, event)
if event[1] == 'key' then
if event[2] == 208 then -- DOWN KEY
self:setCursorPos(1, self.cursor.pos.line + 1)
elseif event[2] == 200 then -- UP KEY
self:setCursorPos(1, self.cursor.pos.line - 1)
elseif event[2] == 28 then -- ENTER
local _selFile = FSFiles[self.cursor.pos.line]
if _selFile then
_selFile = _selFile.name
os.run({}, '/Note.lua', 'open', Path..'/'.._selFile)
end
end
end
end
)
APLib.setLoopCallback(
APLib.event.loop.onClock,
function (_event)
APLib.setBackground(colors.gray)
end
)
APLib.setBackground(colors.gray)
APLib.addLoopGroup('main', {hTitle, mFSDirs, mFSFiles})
APLib.setLoopGroup('main')
APLib.loop()
-- //AUTO-GENERATED-CODE//
os.unloadAPI(APLib.APLibPath)
-- //--//