Skip to content

Instantly share code, notes, and snippets.

@taiypeo
Created December 22, 2019 06:29
Show Gist options
  • Save taiypeo/7fd83d359b3029bc6a10325b95476576 to your computer and use it in GitHub Desktop.
Save taiypeo/7fd83d359b3029bc6a10325b95476576 to your computer and use it in GitHub Desktop.
A shell I made years ago for ComputerCraft
path = ""
sel = 1
function init()
term.clear()
term.setCursorPos(1,1)
dir = fs.list("")
for a, i in ipairs(dir) do
if a == 1 then
print ("@ "..i)
else
print ("\t "..i)
end
end
keyListener()
end
function keyListener()
while true do
event, code = os.pullEvent("key")
if code == 200 then
up()
elseif code == 208 then
down()
elseif code == 14 then
back()
elseif code == 28 then
forward()
else if code == 29 then
rmb()
end
end
end
end
function up()
if sel - 1 >= 1 then
sel = sel-1
term.clear()
term.setCursorPos(1, 1)
dir = fs.list(path)
for a, i in ipairs(dir) do
if a == sel then
print("@ "..i)
else
print("\t "..i)
end
end
keyListener()
end
end
function down()
dir = fs.list(path)
if sel + 1 <= length(dir) then
sel = sel + 1
term.clear()
term.setCursorPos(1, 1)
for a, i in ipairs(dir) do
if a == sel then
print("@ "..i)
else
print("\t "..i)
end
end
keyListener()
end
end
function back()
if fs.exists(fs.getDir(path)) then
path = fs.getDir(path)
dir = fs.list(path)
term.clear()
term.setCursorPos(1, 1)
sel = 1
for a, i in ipairs(dir) do
if a == sel then
print("@ "..i)
else
print("\t "..i)
end
keyListener()
end
end
end
function forward()
dir1 = fs.list(path)
if fs.exists(path.."/"..dir1[sel]) then
path = path.."/"..dir1[sel]
if fs.isDir(path) then
dir = fs.list(path)
term.clear()
term.setCursorPos(1,1)
sel = 1
for a,i in ipairs(dir) do
if a == sel then
print("@ "..i)
else
print("\t "..i)
end
end
else
shell.run(dir1[sel])
end
keyListener()
end
end
function rmb()
dir = fs.list(path)
if fs.isDir(path) then
else
end
end
function length(t)
b = 1
for i, a in ipairs(t) do
b = i
end
return b
end
init()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment