working on the file system

cd can now display folders in blue
This commit is contained in:
2025-02-23 23:13:05 -05:00
parent 86982c9b96
commit 3640f022f6
7 changed files with 60 additions and 24 deletions

View File

@ -1,13 +1,15 @@
import { set_working_dir, SetDirStatus } from "../../fs/fn"
import type { Args, Term } from "../list"
import stdout from "../../../elements/stdout"
export default function cd(term: Term, args: Args): boolean {
const new_dir_status = set_working_dir(args[1])
if (new_dir_status === SetDirStatus.NotADirectory) {
// return <p>{"cd: \""}{bold(args[1])}{"\" is not a directory"}</p>
term.appendChild(stdout(`cd: "${args[1]}" is not a directory`))
} else if (new_dir_status === SetDirStatus.NotFound) {
// return <p>{"cd: The directory \""}{bold(args[1])}{"\" does not exist"}</p>
term.appendChild(stdout(`cd: The directory "${args[1]}" does not exist`))
}
return true
}

View File

@ -1,11 +1,30 @@
import type { Args, Term } from "../list";
import { blue } from "../../color";
import { get_working_dir_entries } from "../../fs/fn";
import { EntryType, FsEntry } from "../../fs/fs";
import stdout, { stdout_horizontal_elements } from "../../../elements/stdout";
import create from "../../../elements/create";
const element_collection = <T extends HTMLElement>(): T[] => []
function show_directory(entry: FsEntry) {
const p = create("p")
p.append(blue(entry.name, true), "/")
return p
}
export default function ls(term: Term, args: Args): boolean {
// if (args[1] === undefined) {
// for (const dir_name in working_dir) {
// }
// return <p>{`${working_dir}`}</p>
// }
const ls_elements = element_collection()
if (args[1] === undefined) {
get_working_dir_entries().forEach(entry => {
if (entry.type === EntryType.Directory) {
ls_elements.push(show_directory(entry))
} else if (entry.type === EntryType.File) {
ls_elements.push(stdout(entry.name))
}
})
}
term.appendChild(stdout_horizontal_elements(ls_elements))
return true
}