added handling invalid invoke functions and ported a couple of apps
stopped component.invoke from throwing a cryptic error, and ported over cat, cd, clear, cp, edit, ls, lsdrv, and mkdir
This commit is contained in:
+3
-2
@@ -1,4 +1,5 @@
|
||||
local files = {...}
|
||||
local shell = require("shell")
|
||||
local fs = require("filesystem")
|
||||
if not files or not files[1] then
|
||||
shell.run("help cat")
|
||||
@@ -6,7 +7,7 @@ if not files or not files[1] then
|
||||
end
|
||||
for _, file in ipairs(files) do
|
||||
if file:sub(1, 1) ~= "/" then
|
||||
file = fs.concat(shell.workingDirectory, file)
|
||||
file = fs.concat(shell.getWorkingDirectory(), file)
|
||||
end
|
||||
if not fs.exists(file) then
|
||||
print("\27[91mFile does not exist.")
|
||||
@@ -15,6 +16,6 @@ for _, file in ipairs(files) do
|
||||
local data
|
||||
repeat
|
||||
data = handle:read(math.huge or math.maxinteger)
|
||||
termlib.write(data)
|
||||
terminal.write(data)
|
||||
until not data
|
||||
end
|
||||
|
||||
+3
-2
@@ -1,14 +1,15 @@
|
||||
local directory = ...
|
||||
local fs = require("filesystem")
|
||||
local shell = require("shell")
|
||||
|
||||
if not directory then
|
||||
return
|
||||
end
|
||||
if directory:sub(1, 1) ~= "/" then
|
||||
directory = fs.concat(shell.workingDirectory, directory)
|
||||
directory = fs.concat(shell.getWorkingDirectory(), directory)
|
||||
end
|
||||
if fs.exists(directory) and fs.isDirectory(directory) then
|
||||
shell.workingDirectory = fs.canonical(directory)
|
||||
shell.setWorkingDirectory(fs.canonical(directory))
|
||||
else
|
||||
print("\27[91mNo such directory.")
|
||||
end
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
clear()
|
||||
terminal.clear()
|
||||
-- truly so much going on here
|
||||
|
||||
+3
-2
@@ -1,15 +1,16 @@
|
||||
local fromFile, toFile = ...
|
||||
local fs = require("filesystem")
|
||||
local shell = require("shell")
|
||||
|
||||
if not fromFile or not toFile then
|
||||
shell.run("help cp")
|
||||
return
|
||||
end
|
||||
if fromFile:sub(1, 1) ~= "/" then
|
||||
fromFile = fs.concat(shell.workingDirectory, fromFile)
|
||||
fromFile = fs.concat(shell.getWorkingDirectory(), fromFile)
|
||||
end
|
||||
if toFile:sub(1, 1) ~= "/" then
|
||||
toFile = fs.concat(shell.workingDirectory, toFile)
|
||||
toFile = fs.concat(shell.getWorkingDirectory(), toFile)
|
||||
end
|
||||
if fromFile == toFile then
|
||||
print("\27[91mSource and destination are the same.")
|
||||
|
||||
+13
-15
@@ -3,6 +3,7 @@ local fs = require("filesystem")
|
||||
local event = require("event")
|
||||
local component = require("component")
|
||||
local unicode = require("unicode")
|
||||
local workingDirectory = require("shell").getWorkingDirectory()
|
||||
local gpu = component.gpu
|
||||
local width, height = gpu.getResolution()
|
||||
local scrollPosX, scrollPosY = 1, 1
|
||||
@@ -15,9 +16,8 @@ local tab = " "
|
||||
--local ocelot = component.ocelot
|
||||
|
||||
local function rawset(x, y, text)
|
||||
termlib.cursorPosX = x
|
||||
termlib.cursorPosY = y
|
||||
termlib.write(text, false)
|
||||
terminal.setCursorPos(x,y)
|
||||
terminal.write(text, false)
|
||||
end
|
||||
|
||||
local filestring, filepath, handle, data, tmpdata
|
||||
@@ -25,7 +25,7 @@ if file then
|
||||
if file:sub(1, 1) == "/" then
|
||||
filepath = file
|
||||
else
|
||||
filepath = shell.workingDirectory .. file
|
||||
filepath = workingDirectory .. file
|
||||
end
|
||||
handle, data, tmpdata = fs.open(filepath, "r"), "", nil
|
||||
if fs.exists(filepath) then
|
||||
@@ -44,7 +44,7 @@ if file then
|
||||
tmpdata = {data}
|
||||
end
|
||||
else
|
||||
filepath = shell.workingDirectory .. file
|
||||
filepath = workingDirectory .. file
|
||||
filestring = "[NEW FILE]"
|
||||
tmpdata = {""}
|
||||
end
|
||||
@@ -55,7 +55,7 @@ else
|
||||
end
|
||||
local function render()
|
||||
gpu.setActiveBuffer(renderBuffer)
|
||||
clear()
|
||||
terminal.clear()
|
||||
--ocelot.log(tostring(scrollPosY))
|
||||
local realCursorX = math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY + scrollPosY - 1]) - scrollPosX + 2)
|
||||
if realCursorX < 1 then
|
||||
@@ -152,7 +152,7 @@ local function processEvent(args)
|
||||
if args[1] == "key_down" then
|
||||
local keycode = args[4]
|
||||
local key = keyboard.keys[keycode]
|
||||
if keyboard.ctrlDown then
|
||||
if keyboard.getCtrlDown() then
|
||||
return false, false, key
|
||||
end
|
||||
if key == "down" and cursorPosY < #tmpdata then
|
||||
@@ -261,14 +261,13 @@ local function save()
|
||||
gpu.setBackground(0xFFFFFF)
|
||||
gpu.setForeground(0)
|
||||
gpu.set(1, height - 1, string.rep(" ", width))
|
||||
termlib.cursorPosX = 1
|
||||
termlib.cursorPosY = height - 1
|
||||
local savepath = read(nil, "\27[107m\27[30mSave location: ", filepath)
|
||||
terminal.setCursorPos(1, height - 1)
|
||||
local savepath = terminal.read(nil, "\27[107m\27[30mSave location: ", filepath)
|
||||
gpu.setBackground(0xFFFFFF)
|
||||
gpu.setForeground(0)
|
||||
if fs.exists(savepath) then
|
||||
gpu.set(1, height - 1, string.rep(" ", width))
|
||||
local answer = read(nil, "\27[107m\27[30mFile already exists. Overwrite it? [Y/n] ")
|
||||
local answer = terminal.read(nil, "\27[107m\27[30mFile already exists. Overwrite it? [Y/n] ")
|
||||
if answer:lower() == "n" then
|
||||
gpu.setBackground(0xFFFFFF)
|
||||
gpu.setForeground(0)
|
||||
@@ -301,15 +300,14 @@ while true do
|
||||
renderFlag, cursorRenderFlag, specialKey = processEvent(args)
|
||||
if specialKey == "x" then
|
||||
if changesMade then
|
||||
termlib.cursorPosX = 1
|
||||
termlib.cursorPosY = height - 1
|
||||
local response = read(nil, "\27[107m\27[30mWould you like to save changes? [Y/n] ")
|
||||
terminal.setCursorPos(1, height - 1)
|
||||
local response = terminal.read(nil, "\27[107m\27[30mWould you like to save changes? [Y/n] ")
|
||||
if response:lower() ~= "n" then
|
||||
save()
|
||||
end
|
||||
end
|
||||
gpu.freeAllBuffers()
|
||||
clear()
|
||||
terminal.clear()
|
||||
return
|
||||
end
|
||||
if specialKey == "s" then
|
||||
|
||||
+3
-2
@@ -7,13 +7,14 @@ local maxLength = 0
|
||||
local margin = 2 -- minimum space between filename and size
|
||||
local dirTable = {}
|
||||
local fileTable = {}
|
||||
local workingDirectory = require("shell").getWorkingDirectory()
|
||||
|
||||
if target then
|
||||
if target:sub(1, 1) ~= "/" then
|
||||
target = fs.concat(shell.workingDirectory, target)
|
||||
target = fs.concat(workingDirectory, target)
|
||||
end
|
||||
else
|
||||
target = shell.workingDirectory
|
||||
target = workingDirectory
|
||||
end
|
||||
|
||||
local files = fs.list(target)
|
||||
|
||||
+19
-6
@@ -106,7 +106,7 @@ local function formatSize(mem)
|
||||
end
|
||||
|
||||
local function fileExists(proxy,path)
|
||||
return proxy.exists(path) and not proxy.isDirectory(path)
|
||||
return proxy.exists and proxy.isDirectory and proxy.exists(path) and not proxy.isDirectory(path)
|
||||
end
|
||||
|
||||
local function getBootCode(proxy)
|
||||
@@ -140,24 +140,37 @@ local function handleComponent(id,type)
|
||||
-- for i=1,#tableOut do table.insert(out,"unknown") end
|
||||
local slot,capacity,managed,readOnly,mount,bootable,label
|
||||
|
||||
local virtual,vproc = component.virtual.check(id)
|
||||
local cslot = component.slot(id)
|
||||
if cslot==-1 then
|
||||
slot="Virtual"
|
||||
if virtual then
|
||||
if vproc and vproc.name then
|
||||
slot="Virtual ("..vproc.name..")"
|
||||
else
|
||||
slot="Virtual (unknown)"
|
||||
end
|
||||
elseif cslot==-1 then
|
||||
slot="External"
|
||||
elseif cslot==9 then
|
||||
slot="EEPROM"
|
||||
elseif cslot==5 or cslot==6 then
|
||||
slot="HDD #"..(cslot-4)
|
||||
elseif cslot==7 then
|
||||
slot="Floppy"
|
||||
else
|
||||
slot="#"..(cslot+2)
|
||||
end
|
||||
|
||||
managed="Yes"
|
||||
managed="No"
|
||||
readOnly="No"
|
||||
if type=="drive" then
|
||||
managed="No"
|
||||
capacity=formatSize(proxy.getCapacity())
|
||||
mount="/special/drive/"..id:sub(1,3)
|
||||
elseif type=="filesystem" then
|
||||
managed="Yes"
|
||||
if proxy.spaceTotal then
|
||||
capacity=formatSize(proxy.spaceTotal())
|
||||
if proxy.isReadOnly() then
|
||||
end
|
||||
if not proxy.isReadOnly or proxy.isReadOnly() then
|
||||
readOnly="Yes"
|
||||
end
|
||||
mount="/mnt/"..id:sub(1,3)
|
||||
|
||||
@@ -2,11 +2,11 @@ local directory = ...
|
||||
local fs = require("filesystem")
|
||||
|
||||
if not directory then
|
||||
shell.run("help mkdir")
|
||||
require("shell").run("help mkdir")
|
||||
return
|
||||
end
|
||||
if directory:sub(1, 1) ~= "/" then
|
||||
directory = fs.concat(shell.workingDirectory, directory)
|
||||
directory = fs.concat(require("shell").getWorkingDirectory(), directory)
|
||||
end
|
||||
if fs.exists(directory) then
|
||||
print("\27[91mAn object already exists at the specified path.")
|
||||
|
||||
@@ -79,6 +79,7 @@ function compLib.invoke(address, funcName, ...)
|
||||
--ocelot.log("Invoking " .. funcName .. " from " .. address)
|
||||
if componentlib.additions[address] then
|
||||
--ocelot.log("vcomponent")
|
||||
if not componentlib.additions[address].proxy[funcName] then error("no such method") end
|
||||
return componentlib.additions[address].proxy[funcName](...)
|
||||
else
|
||||
return LLcomponent.invoke(address, funcName, ...)
|
||||
|
||||
Reference in New Issue
Block a user