shell.run("monitor", "top", "readFile") ;
shell.run("monitor", "top", "readTable")
I tried this but it doesn't work.
Edit: Ninja'd by icehaunter, but I think that you will still want to try these functions as it is much more user friendly. No offence icehaunter :)/>/>The reason that doesn't work is because you are trying to run functions rather than a program. I would actually suggest not using the default monitor program. The difficulty with using it is that it only prints to the monitor, making it difficult to input commands. Instead try using the peripheral api.
Here are the codes that I modified to make it print to the monitor and the terminal at the same time:
Config
monitor = peripheral.wrap("top")
monX, monY = monitor.getSize()
termX, termY = term.getSize()
Functions
function write(text,boolValue)
x,y = monitor.getCursorPos()
if y == monY then
monitor.scroll(1) --If the cursor is at the bottom of the console, scroll down
end
monitor.write(text) --Write to both the monitor...
term.write(text) --...and the computer terminal
if y ~= monY and boolValue ~= false then
monitor.setCursorPos(1, y + 1) --Goto the next line if the user does not pass false to boolValue
end
end
function clear()
term.clear()
term.setCursorPos(1,1)
monitor.clear()
monitor.setCursorPos(1,1)
end
Modified Functions
function writeToFile()
local file = fs.open("aList", "a")
while true do
write("Input Task: ",false) --Make sure that the monitor does not move to the next line yet
input = io.read()
currentX,currentY = monitor.getCursorPos()
monitor.write(input)
if currentY ~= monY then
monitor.setCursorPos(1,currentY + 1) --Now it can move to the next line
end
if input == "" then
file.close()
break
elseif input == "/erase" then
file.close()
file = fs.open("list","w")
file.close()
else
file.writeLine(input)
end
end
end
Modification to main code: Replaced any mention of 'shell.run("clear")' with the function clear()
And here's the whole file all together:
Spoiler
--CONFIG--
strTable = {}
v = 0
monitor = peripheral.wrap("top")
monX, monY = monitor.getSize()
termX, termY = term.getSize()
--FUNCTIONS--
function write(text,boolValue)
x,y = monitor.getCursorPos()
if y == monY then
monitor.scroll(1) --If the cursor is at the bottom of the console, scroll down
end
monitor.write(text) --Write to both the monitor...
term.write(text) --...and the computer terminal
if y ~= monY and boolValue ~= false then
monitor.setCursorPos(1, y + 1) --Goto the next line if the user does not pass false to boolValue
end
end
function clear()
term.clear()
term.setCursorPos(1,1)
monitor.clear()
monitor.setCursorPos(1,1)
end
function readFile()
file = fs.open("aList", "r")
tempString = file.readLine()
while tempString ~= nil do
table.insert(strTable, tempString)
tempString = file.readLine()
end
file.close()
end
function readTable()
for i, v in ipairs(strTable) do
write(i..": "..v)
currentX, currentY = term.getCursorPos()
if currentY ~= termY then
term.setCursorPos(1, currentY + 1)
end
os.pullEvent()
end
end
function writeToFile()
local file = fs.open("aList", "a")
while true do
write("Input Task: ",false) --Make sure that the monitor does not move to the next line yet
input = io.read()
currentX,currentY = monitor.getCursorPos()
monitor.write(input)
if currentY ~= monY then
monitor.setCursorPos(1,currentY + 1) --Now it can move to the next line
end
if input == "" then
file.close()
break
elseif input == "/erase" then
file.close()
file = fs.open("list","w")
file.close()
else
file.writeLine(input)
end
end
end
--CODE--
clear()
print("Todo List v1.1 Loaded")
print("What would you like to do?")
local input = read()
if input == "newtodo" then
print("What would you like to write?")
writeToFile()
print("Would you like to enter another Todo?")
input = read()
if input == "yes" then
print("What would you like to write?")
writeToFile()
elseif input == "no" then
term.setCursorPos(1,1)
clear()
end
elseif input == "display" then
readFile()
readTable()
end