From 445f7895c74c95052b685ec49bba0bafb7c09137 Mon Sep 17 00:00:00 2001 From: LDDestroier Date: Sun, 21 Apr 2019 01:44:03 -0400 Subject: [PATCH] Added clean exit --- workspace.lua | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/workspace.lua b/workspace.lua index abbcb80..ab54196 100644 --- a/workspace.lua +++ b/workspace.lua @@ -12,6 +12,14 @@ local windowHeight = scr_y -- program that will start up for workspaces local defaultProgram = "rom/programs/shell.lua" +if _G.currentlyRunningWorkspace then + print("Workspace is already running.") + return +else + _G.currentlyRunningWorkspace = true +end +local isRunning = true + -- start up lddterm local lddterm = {} lddterm.alwaysRender = false -- renders after any and all screen-changing functions. @@ -545,9 +553,15 @@ local newInstance = function(x, y, program, initialStart) term.setCursorPos(scr_x / 2 - #text / 2, scr_y / 2) term.write(text) repeat - evt = {os.pullEvent("key")} - until evt[2] == keys.space + evt = {os.pullEventRaw()} + until (evt[1] == "key" and evt[2] == keys.space) or evt[1] == "terminate" sleep(0) + + if evt[1] == "terminate" then + isRunning = false + return + end + term.setCursorPos(1,1) term.clear() term.setCursorBlink(true) @@ -632,7 +646,7 @@ end local main = function() local enteringCommand local justStarted = true - while true do + while isRunning do local evt = {os.pullEventRaw()} enteringCommand = false if evt[1] == "key" then @@ -702,3 +716,9 @@ local main = function() end main() + +_G.currentlyRunningWorkspace = false + +term.clear() +term.setCursorPos(1,1) +print("Thanks for using Workspace!")