From 14adaf0f91705ad36c85aa875b48e8566f42f6ee Mon Sep 17 00:00:00 2001 From: echo <91651232+exhq@users.noreply.github.com> Date: Sun, 4 Sep 2022 13:39:20 +0430 Subject: i literally rewrote the entire ls command to add a fucking bracket i dont like my life --- console/src/jsMain/kotlin/main.kt | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/console/src/jsMain/kotlin/main.kt b/console/src/jsMain/kotlin/main.kt index 50ed218..fac5f2d 100644 --- a/console/src/jsMain/kotlin/main.kt +++ b/console/src/jsMain/kotlin/main.kt @@ -86,7 +86,35 @@ fun main() { console.addMultilineText(startupmsg) console.fileAccessor!!.cd("/home/exhq") console.rerender() - console.registerCommand(defaultLsCommand("ls", delayBetweenLines = 0.milliseconds)) + console.registerCommand(command("ls"){ + val fa = requireFileAccessor() + val path = when(args.size){ + 0 -> "." + 1 -> args[0] + else -> { + console.addLine("Usage: ls [directory or file]") + return@command + } + } + val file = fa.resolve(path) + if (file == null){ + console.addLine("ls : Could not find dile or directory") + return@command + } + when(file){ + is KFile.Directory ->{ + val longestName = file.files.keys.maxOf { it.length } + file.files.forEach { (name, file) -> + console.addLine( + name + " ".repeat(longestName + 1 - name.length) + "(${file.fileType})" + ) + console.rerender() + } + } + + else -> console.addLine("ls: is a ${file.fileType}") + } + }) console.registerCommand(defaultCdCommand("cd")) console.registerCommand(defaultCatCommand("cat")) console.registerCommand(defaultCwdCommand("cwd", "pwd")) -- cgit