This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Midnightas's profile picture

Run shell.run("edit "..input) and then return to the current program?

Started by Midnightas, 29 December 2014 - 08:14 AM
Midnightas #1
Posted 29 December 2014 - 09:14 AM
Hello everyone, im making a small "artificial" operating system for the Advanced Wireless Pocket Computers called McMCOS (McMinecraft Operating System) and i made a button that runs the edit command and edits
the files that the user specifies.
Whenever i press the button then everything works fine, but when pressing Ctrl then selecting Exit, it does back to the
DOS type of console again, when i need it to return me back to the current program.
I cannot make it run the program again because it has a splash screen and it will be bad if it will show the splash every time the user exits.

This is my code (McMCOS):

-- Desktop
textColor = 1
backColor = 8
state = 0;
function drawSplash()
state = 0;
splashthing = paintutils.loadImage(".mcmcsplash")
paintutils.drawImage(splashthing, 2, 2)
end
local function areYouSure(msga, y)
local msg = "  "..msga.."  "
local w, h = term.getSize()
term.setBackgroundColor(32768)
term.setTextColor(16)
term.setCursorPos(math.floor((w-#msg)/2) + (#msg % 2 == 0 and 1 or 0), h/2 - 2)
print(msg)
write("  ")
lengthz = msg:len()
for i=1,lengthz do
  write(" ");
end
print("  ")
end
function drawDesktop()
term.clear()
term.setCursorPos(1,1)
term.setTextColor(textColor)
term.setBackgroundColor(backColor)
term.clear()
term.setCursorPos(2,1)
print("<Launch>")
end
function drawMenuLaunch()
term.setCursorPos(1,1)
term.setTextColor(256)
term.setBackgroundColor(128)
term.setCursorPos(1,2)
print("  Turtle Commander  ")
print("	 Craftpad++	 ")
print("	  Shutdown	  ")
end
-- Turtle Commander
function turtleCommanderDraw()
term.setBackgroundColor(32768)
term.setTextColor(16)
term.clear()
print("Turtle Commander - Integrated with McMCOS")
while true do
  write(">> ")
  inputthing = read()
  if inputthing == "turtlequit" then
   break;
  else
   shell.run(inputthing)
  end
end
state = 1;
drawDesktop()
end
-- End of Turtle Commander
-- Craftpad++
function craftPadDraw()
term.setBackgroundColor(32768)
term.setTextColor(16)
term.setCursorPos(20,3)
while true do
  write("> ")
  inputthing = read()
  shell.run("edit "..inputthing)
end
state = 1;
drawDesktop()
end
-- End of Craftpad++
drawSplash();
os.sleep(3);
state = 1;
drawDesktop()
while true do
event, button, X, Y = os.pullEventRaw();
if event == "mouse_click" then
  if X >= 2 and X <= 9 and Y == 1 then
   drawMenuLaunch()
  else
   drawDesktop()
  end
  if X >= 2 and X <= 22 and Y == 2 then
   state = 2
   turtleCommanderDraw()
  end
  if X >= 2 and X <= 22 and Y == 3 then
   craftPadDraw()
  end
  if X >= 2 and X <= 22 and Y == 4 then
   break;
  end
end
end
term.setBackgroundColor(32768)
term.setTextColor(16)
term.clear()
term.setCursorPos(1, 1)

It runs shell.run("edit"..inputthing) in the craftPadDraw() function.
Midnightas #2
Posted 29 December 2014 - 09:32 AM
Never mind, it wasent actually the console it was still the program :)/>