From 605fa7327ed50d4f641a211eefc1390aea6cd66f Mon Sep 17 00:00:00 2001
From: LaplongeJunior <laplongejunior@gmail.com>
Date: Sat, 1 Aug 2020 16:51:07 +0000
Subject: [PATCH] Update vshell.inc.src

---
 scripts/libs/vshell.inc.src | 72 ++++++++++++++++++++++++++++++-------
 1 file changed, 59 insertions(+), 13 deletions(-)

diff --git a/scripts/libs/vshell.inc.src b/scripts/libs/vshell.inc.src
index fb8b27d..de94096 100644
--- a/scripts/libs/vshell.inc.src
+++ b/scripts/libs/vshell.inc.src
@@ -10,26 +10,67 @@ imports.vshell.constrs = {}
 imports.vshell.constrs.shell = function(object)
     result = {}
     
-    result.heart = object
-    
     result.start_terminal = function()
         while true
             print("Please enter a command:"+imports.file.NEW_LINE)
-            command = user_prompt()
-            if command == imports.vshell.EXIT then break
-            imports.vshell.cmds[command](self)
+            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")
+            end if
+            
+            // Remove the command name
+            params = []
+            for i in range(1,command.len-1)
+                params.push(command[i])
+            end for
+            
+            result = cmd(self, params)
+            if result and typeof(result) != "function" then print(command[0] +" error: "+result)
         end while
     end function
     
     result.navigate = function(path)
-        if typeof(self.heart) == "computer" then return self.heart.File(path)
-        // TODO
-        return null
+        isFile = typeof(self.heart) == "file"
+        if not path then
+            if isFile then return self.heart
+            return self.heart.File(current_path)
+        end if
+        
+        path = imports.file.AbsolutePath(path) 
+        
+        if typeof(self.heart) != "file" then // is a computer
+        if isFile then
+            result = imports.vshell.navigate(self.heart, path)
+        else 
+            result = self.heart.File(path)
+        end if
+            
+        folder = result
+        if not folder.is_folder then folder = folder.parent 
+        self.current_path = folder.path
+        
+        if typeof(self.heart) == "file" then self.heart = result
+        return result
     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
+    return null
+end function
+
 imports.vshell.init = function(object)
     if typeof(object) == "shell" then object = object.host_computer
     type = typeof(object)
@@ -43,19 +84,24 @@ end function
 
 imports.vshell.cmds = {}
 
-imports.vshell.cmds.help = function(shell)
+imports.vshell.cmds.help = function(shell, params)
     names = ["exit"]
     for name in imports.vshell.cmds.values
         names.put(name)
     end for
-    return names
+    print("List of accepted commands:")
+    print(imports.utils.PrintList(names,imports.file.NEW_LINE))
 end function
 
-imports.vshell.cmds.cd = function(shell)
+imports.vshell.cmds.cd = function(shell, params)
+    if params.len == 0 then 
+    file = shell.navigate(path)
+    print("List of accepted commands:")
+    print(imports.utils.PrintList(names,imports.file.NEW_LINE))
 end function
 
-imports.vshell.cmds.read = function(shell)
+imports.vshell.cmds.read = function(shell, params)
 end function
 
-imports.vshell.cmds.get = function(shell)
+imports.vshell.cmds.get = function(shell, params)
 end function
\ No newline at end of file
-- 
GitLab