diff --git a/scripts/libs/vshell.inc.src b/scripts/libs/vshell.inc.src index 2693b6268d26af67f37cd608d333354697274a75..3917dd8822bed776c764b60f2b9d63a2479108bd 100644 --- a/scripts/libs/vshell.inc.src +++ b/scripts/libs/vshell.inc.src @@ -4,53 +4,34 @@ "#import libs/utils.inc.src" "#import libs/file.inc.src" +"#import libs/shellapi.inc.src" -"#ifbuild" -if not globals.hasIndex("imports") then imports = {} -imports.temp = {} -"#endif" -imports.vshell = {} -"#ifbuild" -vshell = imports.vshell -"#endif" +imports.shellapi.vshell = {} -imports.vshell.EXIT = "exit" - -imports.vshell.constrs = {} +imports.shellapi.vshell.navigate = function(file, target) + originSteps = file.path.split("/") + targetSteps = file.path.split("/") + // TODO: File navigation + return null +end function -imports.vshell.constrs.shell = function(object) - result = {} +imports.shellapi.vshell.init = function(object) + if typeof(object) == "shell" then object = object.host_computer + type = typeof(object) + if type != "computer" and type != "file" then return null - result.start_terminal = function() - while true - print("Please enter a command:"+imports.file.NEW_LINE) - command = user_prompt().split(" ") - if command[0] == imports.vshell.EXIT then break - cmd = imports.utils.SafeMapAccess(imports.vshell.cmds,command[0]) - if cmd == null then - print(cmd+ " is not a recognized command") - return - end if - - // Remove the command name - params = [] - for i in range(1,command.len-1) - params.push(command[i]) - end for - - heart = result.heart - current_path = result.current_path - - result = cmd(self, params) - if result and typeof(result) != "function" then - print(command[0] +" error: "+result) - // Rollback - result.heart = heart - result.current_path = current_path - end if - end while + result = imports.shellapi.constrs.shellui(imports.shellapi.vshell.cmds) + + // Add support for command errors + result.transaction = function() + return [self.heart, self.current_path] + end function + result.rollback = function(transaction) + result.heart = transaction[0] + result.current_path = transaction[1] end function + // Add vshell-specific inner functionalities result.navigate = function(path) isFile = typeof(self.heart) == "file" if not path then @@ -82,41 +63,27 @@ imports.vshell.constrs.shell = function(object) end function result.heart = object - // Init the current_path var if typeof(object) == "file" then path = object.path else path = object.current_path result.navigate(path) return result + end function -imports.vshell.navigate = function(file, target) - originSteps = file.path.split("/") - targetSteps = file.path.split("/") - // TODO: File navigation - return null -end function - -imports.vshell.init = function(object) - if typeof(object) == "shell" then object = object.host_computer - type = typeof(object) - if type != "computer" and type != "file" then return null - return imports.vshell.constrs.shell(object) -end function - -imports.vshell.run = function(object) +imports.shellapi.vshell.run = function(object) imports.vshell.init(object).start_terminal() end function -imports.vshell.read = function(shell, params) +imports.shellapi.vshell.read = function(shell, params) if params.len > 0 then return "Parameter required" file = shell.navigate(params[0]) // TODO: File reading end function -imports.vshell.cmds = {} +imports.shellapi.vshell.cmds = {} -imports.vshell.cmds.help = function(shell, params) +imports.shellapi.vshell.cmds.help = function(shell, params) names = ["exit"] for name in imports.vshell.cmds.values names.put(name) @@ -125,7 +92,7 @@ imports.vshell.cmds.help = function(shell, params) print(imports.utils.PrintList(names,imports.file.NEW_LINE)) end function -imports.vshell.cmds.cd = function(shell, params) +imports.shellapi.vshell.cmds.cd = function(shell, params) if params.len == 0 then path = "" else path = params[0] if not shell.navigate(path).is_folder then return "target is not a folder!" @@ -141,19 +108,19 @@ imports.vshell.cmds.cd = function(shell, params) print(imports.utils.PrintList(names,imports.file.NEW_LINE)) end function -imports.vshell.cmds.read = function(shell, params) +imports.shellapi.vshell.cmds.read = function(shell, params) result = imports.vshell.read(shell,params) if typeof(result) != "list" then return result print(imports.utils.PrintList(result,imports.file.NEW_LINE)) end function -imports.vshell.cmds.get = function(shell, params) +imports.shellapi.vshell.cmds.get = function(shell, params) result = imports.vshell.read(shell,params) if typeof(result) != "list" then return result content = imports.utils.PrintList(result,imports.file.NEW_LINE) end function -imports.vshell.cmds.delete = function(shell, params) +imports.shellapi.vshell.cmds.delete = function(shell, params) if params.len > 0 then return "Parameter required" file = shell.navigate(params[0]) if not imports.utils.UserPrompt("Do you *REALLY* want to delete '"+file.path+"' ?") then return "Execution cancelled by user"