aboutsummaryrefslogtreecommitdiff
path: root/console/src/jsMain/kotlin
diff options
context:
space:
mode:
authorecho <91651232+exhq@users.noreply.github.com>2022-09-04 13:39:20 +0430
committerecho <91651232+exhq@users.noreply.github.com>2022-09-04 13:39:20 +0430
commit14adaf0f91705ad36c85aa875b48e8566f42f6ee (patch)
treed78fbd460b95e32a61e40c73313660f3dfac79b1 /console/src/jsMain/kotlin
parent3c12124d0eddda121f035dbfe9770d6b02a94fac (diff)
downloadexhq.github.io-14adaf0f91705ad36c85aa875b48e8566f42f6ee.tar.gz
exhq.github.io-14adaf0f91705ad36c85aa875b48e8566f42f6ee.tar.bz2
exhq.github.io-14adaf0f91705ad36c85aa875b48e8566f42f6ee.zip
i literally rewrote the entire ls command to add a fucking bracket i dont like my life
Diffstat (limited to 'console/src/jsMain/kotlin')
-rw-r--r--console/src/jsMain/kotlin/main.kt30
1 files changed, 29 insertions, 1 deletions
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"))