From 6ff1ab2670ab4dcab41ae623fc282b806e97f568 Mon Sep 17 00:00:00 2001 From: Brazly Date: Fri, 16 Jan 2026 03:10:57 +0000 Subject: [PATCH] you can now find retrieve data using cat without changing the directory --- .../Scripts/UI/terminal/terminal_controls.gd | 51 ++++++++++++++----- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/Assets/Scripts/UI/terminal/terminal_controls.gd b/Assets/Scripts/UI/terminal/terminal_controls.gd index 919956d..b01e079 100644 --- a/Assets/Scripts/UI/terminal/terminal_controls.gd +++ b/Assets/Scripts/UI/terminal/terminal_controls.gd @@ -132,32 +132,55 @@ func ResolvePath(current: String, target: String) -> String: return parts[0] + "/" var joined = current + target return joined if joined.ends_with("/") else joined + "/" - + func GetDirAtPath(path: String): - if path == "~/": return fileSystem + if path == "~/" or path == "": return fileSystem + var cleanPath = path.trim_prefix("~/").trim_suffix("/") var folders = cleanPath.split("/") var current = fileSystem + for folder in folders: - if current is Dictionary and current.has(folder) and current[folder] is Dictionary: - current = current[folder] + if folder == "": continue + if current is Dictionary and current.has(folder): + if current[folder] is Dictionary: + current = current[folder] + else: + # We hit a file, not a directory + return null else: return null - return current if current is Dictionary else null + return current + +func RetrieveData(inputPath: String): + var targetFileName: String + var targetDirData: Dictionary + + if "/" in inputPath: + var pathParts = inputPath.rsplit("/", true, 1) + var dirPath = pathParts[0] + targetFileName = pathParts[1] + + var resolvedDirPath = ResolvePath(directory, dirPath) + var result = GetDirAtPath(resolvedDirPath) + + if result is Dictionary: + targetDirData = result + else: + CreateHistoryEntry("cat: " + dirPath + ": No such directory") + return + else: + targetFileName = inputPath + targetDirData = GetDirAtPath(directory) -func RetrieveData(filename: String): - var currentData = GetDirAtPath(directory) - if currentData == null: - CreateHistoryEntry("Error: Current directory invalid.") - return - if currentData.has(filename): - var content = currentData[filename] + if targetDirData.has(targetFileName): + var content = targetDirData[targetFileName] if content is Dictionary: - CreateHistoryEntry("cat: " + filename + ": is a directory") + CreateHistoryEntry("cat: " + targetFileName + ": Is a directory") else: CreateHistoryEntry(str(content)) else: - CreateHistoryEntry("cat: " + filename + ": no such file") + CreateHistoryEntry("cat: " + targetFileName + ": No such file or directory") func UpdateCaretPos(): var last_char_index = terminalLine.text.length() - 1