you can now find retrieve data using cat without changing the directory

This commit is contained in:
Brazly
2026-01-16 03:10:57 +00:00
parent 9c7d450154
commit 6ff1ab2670

View File

@@ -134,30 +134,53 @@ func ResolvePath(current: String, target: String) -> String:
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(filename: String):
var currentData = GetDirAtPath(directory)
if currentData == null:
CreateHistoryEntry("Error: Current directory invalid.")
return
if currentData.has(filename):
var content = currentData[filename]
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)
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