Skip to content

Instantly share code, notes, and snippets.

@severak
Last active October 19, 2018 10:09
Show Gist options
  • Save severak/2e6ae3c6d8ae4aa230694ed0fce29c56 to your computer and use it in GitHub Desktop.
Save severak/2e6ae3c6d8ae4aa230694ed0fce29c56 to your computer and use it in GitHub Desktop.
Severak file manager for LIKO-12
-- Severak file manager
local term = require "terminal"
local TW, TH = GPU.termSize()
local pwd = term.resolve "."
local items = fs.getDirectoryItems(pwd)
local selected = 1
table.insert(items, 1, "..")
for event, a, b, c, d, e, f in CPU.pullEvent do
GPU.clear()
print "Severak file manager"
for n=1, TH-2 do
local prefix = " "
if n==selected+1 then
prefix = ">"
end
if items[n] then
print(prefix .. items[n])
else
print("")
end
end
if event=="keypressed" and a=="down" then
selected = (selected + 1) % #items
end
if event=="keypressed" and a=="up" then
selected = (selected - 1) % #items
end
if event=="keypressed" and a=="escape" then
GPU.clear()
print "Bye"
return 0
end
if event=="keypressed" and a=="return" then
if fs.isDirectory(pwd .. "/" .. items[selected+1]) then
pwd = term.resolve(pwd .. "/" .. items[selected+1])
items = fs.getDirectoryItems(pwd)
selected = 1
table.insert(items, 1, "..")
else
-- here be handling of files
end
end
CPU.sleep(0.1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment