From 9970c58e2b5df993dd9bd9f50c82669cabc7b7d1 Mon Sep 17 00:00:00 2001 From: rhpidfyre Date: Tue, 11 Feb 2025 15:20:57 -0500 Subject: [PATCH] cd needs work --- bun.lock | 4 +- package.json | 2 +- src/components/button.astro | 6 +- src/components/react/shell/command/list.tsx | 23 ++++--- src/components/react/shell/fs/fn.ts | 66 +++++++++++++++++---- src/components/react/shell/fs/fs.ts | 6 +- src/components/react/shell/prompt.tsx | 4 +- src/layouts/Webpage.astro | 2 +- 8 files changed, 83 insertions(+), 30 deletions(-) diff --git a/bun.lock b/bun.lock index 7864799..7ca0287 100644 --- a/bun.lock +++ b/bun.lock @@ -10,7 +10,7 @@ "astro": "^5.2.5", "react": "^19.0.0", "react-dom": "^19.0.0", - "sass": "^1.83.4", + "sass": "^1.84.0", "scss": "^0.2.4", }, }, @@ -722,7 +722,7 @@ "run-parallel": ["run-parallel@1.2.0", "", { "dependencies": { "queue-microtask": "^1.2.2" } }, "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA=="], - "sass": ["sass@1.83.4", "", { "dependencies": { "chokidar": "^4.0.0", "immutable": "^5.0.2", "source-map-js": ">=0.6.2 <2.0.0" }, "optionalDependencies": { "@parcel/watcher": "^2.4.1" }, "bin": { "sass": "sass.js" } }, "sha512-B1bozCeNQiOgDcLd33e2Cs2U60wZwjUUXzh900ZyQF5qUasvMdDZYbQ566LJu7cqR+sAHlAfO6RMkaID5s6qpA=="], + "sass": ["sass@1.84.0", "", { "dependencies": { "chokidar": "^4.0.0", "immutable": "^5.0.2", "source-map-js": ">=0.6.2 <2.0.0" }, "optionalDependencies": { "@parcel/watcher": "^2.4.1" }, "bin": { "sass": "sass.js" } }, "sha512-XDAbhEPJRxi7H0SxrnOpiXFQoUJHwkR2u3Zc4el+fK/Tt5Hpzw5kkQ59qVDfvdaUq6gCrEZIbySFBM2T9DNKHg=="], "scheduler": ["scheduler@0.25.0", "", {}, "sha512-xFVuu11jh+xcO7JOAGJNOXld8/TcEHK/4CituBUeUb5hqxJLj9YuemAEuvm9gQ/+pgXYfbQuqAkiYu+u7YEsNA=="], diff --git a/package.json b/package.json index 117b1a7..727e928 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "astro": "^5.2.5", "react": "^19.0.0", "react-dom": "^19.0.0", - "sass": "^1.83.4", + "sass": "^1.84.0", "scss": "^0.2.4" } } \ No newline at end of file diff --git a/src/components/button.astro b/src/components/button.astro index 1327a52..ca2ddd4 100644 --- a/src/components/button.astro +++ b/src/components/button.astro @@ -16,6 +16,10 @@ const {href, display, color = "transparent"} = Astro.props height: 100%; padding: 0 20px 0 20px; - &:hover { background-color: var(--hf-button-hover-color) !important } + &:hover { + background-color: var(--hf-button-hover-color) !important; + + & > a { color: black } + } } \ No newline at end of file diff --git a/src/components/react/shell/command/list.tsx b/src/components/react/shell/command/list.tsx index 324018e..4e06b88 100644 --- a/src/components/react/shell/command/list.tsx +++ b/src/components/react/shell/command/list.tsx @@ -1,10 +1,9 @@ import type { JSX } from "react" -import { Entry } from "../fs/fs" -import { blue } from "../color" -import { set_working_dir } from "../fs/fn" +import { bold } from "../color" +import { get_working_dir_name_full, set_working_dir, SetDirStatus } from "../fs/fn" type args = string[] -type command = JSX.Element | undefined +type command = JSX.Element | boolean function parse_ls(entries: JSX.Element[]) { return
@@ -13,7 +12,14 @@ function parse_ls(entries: JSX.Element[]) { } function cd(args: args): command { - set_working_dir(args[1]) + const new_dir_status = set_working_dir(args[1]) + + if (new_dir_status === SetDirStatus.NotADirectory) { + return

{"cd: \""}{bold(args[1])}{"\" is not a directory"}

+ } else if (new_dir_status === SetDirStatus.NotFound) { + return

{"cd: The directory \""}{bold(args[1])}{"\" does not exist"}

+ } + return true } function ls(args: args): command { @@ -23,16 +29,15 @@ function ls(args: args): command { // } // return

{`${working_dir}`}

// } + return true } function pwd(args: args): command { - const tree: string[] = [] - - return

{`${tree.join("/")}`}

+ return

{`${get_working_dir_name_full()}`}

} function cat(args: args): command { - return + return true } interface commands_list { diff --git a/src/components/react/shell/fs/fn.ts b/src/components/react/shell/fs/fn.ts index 8a91bf4..4b5ff92 100644 --- a/src/components/react/shell/fs/fn.ts +++ b/src/components/react/shell/fs/fn.ts @@ -1,7 +1,11 @@ -import { fs } from "./fs" +import { Entry, EntryType, fs, type FsEntrySignature } from "./fs" let working_dir = ["/", "home", "user"] +function get_working_dir_name(): string { + return working_dir[working_dir.length-1] +} + function get_working_dir_name_full(): string { const w_dir_clone = [...working_dir] const root = w_dir_clone.shift() @@ -11,25 +15,61 @@ function get_working_dir_name_full(): string { return "shift-error" } -function get_working_dir_name(): string { - return working_dir[working_dir.length-1] +const enum SetDirStatus { + Valid, + NotFound, + NotADirectory } +interface FsIterEntry { + readonly entry: FsEntrySignature | null, + readonly status: SetDirStatus +} +function iter_fs_to_goal(w_dir_clone: string[]): FsIterEntry { + let next_iter = fs[0] -function set_working_dir(name: string) { - let new_dir; - const w_dir_clone = [...working_dir] - w_dir_clone.push(name) - w_dir_clone.map(p => p !== "/" ? p+"/" : p).forEach(f => { - for (let i = 0; i entry.name === w_dir) + if (!found) { + return { entry: null, status: SetDirStatus.NotFound } + } + if (found.type !== EntryType.Directory) { + return { entry: null, status: SetDirStatus.NotADirectory } + } + if (found.name === w_dir_clone[w_dir_clone.length-1]) { + return { entry: next_iter, status: SetDirStatus.Valid } + } else { + next_iter = found.inner as FsEntrySignature } } - }) + } + return { entry: null, status: SetDirStatus.NotFound } +} + +function set_working_dir(name: string): SetDirStatus { + if (name === ".") { return SetDirStatus.Valid } + + const w_dir_clone = [...working_dir] + if (name === "..") { w_dir_clone.pop() } else { w_dir_clone.push(name) } + + const iter_status = iter_fs_to_goal(w_dir_clone) + if (iter_status.status === SetDirStatus.Valid) { + working_dir = w_dir_clone + } + return iter_status.status +} + +function working_dir_entries() { + const w_dir_clone = [...working_dir] + const iter_status = iter_fs_to_goal(w_dir_clone) + } export { - get_working_dir_name_full, get_working_dir_name, - set_working_dir + get_working_dir_name_full, + set_working_dir, + SetDirStatus } \ No newline at end of file diff --git a/src/components/react/shell/fs/fs.ts b/src/components/react/shell/fs/fs.ts index 5397ef5..4b554e3 100644 --- a/src/components/react/shell/fs/fs.ts +++ b/src/components/react/shell/fs/fs.ts @@ -8,9 +8,12 @@ const enum Permissions { rw } +type FsEntrySignature = Entry[]> //I did this! + const user = [ Entry("about_me.txt", "about me inside", Permissions.rw), Entry("services.txt", "services inside", Permissions.rw), + Entry("hi", [], Permissions.rw) ] const home = [ Entry("user", user, Permissions.rw) @@ -25,7 +28,7 @@ const fs = [ type File = string interface Entry { - readonly inner: T, + readonly inner?: T, readonly name: string, readonly type: EntryType, readonly permissions: Permissions @@ -41,6 +44,7 @@ function Entry(name: string, inner: T, permissions: Permissions): Entr export { fs, + type FsEntrySignature, EntryType, Permissions, Entry diff --git a/src/components/react/shell/prompt.tsx b/src/components/react/shell/prompt.tsx index a6f4033..11ca7aa 100644 --- a/src/components/react/shell/prompt.tsx +++ b/src/components/react/shell/prompt.tsx @@ -1,4 +1,4 @@ -import { get_working_dir_name_full } from "./fs/fn" +import { get_working_dir_name } from "./fs/fn" import { cyan, green } from "./color" const userAgent = navigator.userAgent @@ -10,7 +10,7 @@ if (browser_name_fallible) { } function working_dir() { - const name = get_working_dir_name_full() + const name = get_working_dir_name() return name === "user" ? "~" : name } diff --git a/src/layouts/Webpage.astro b/src/layouts/Webpage.astro index b9ba5f3..5de073f 100644 --- a/src/layouts/Webpage.astro +++ b/src/layouts/Webpage.astro @@ -25,7 +25,7 @@ import Footer from "../components/footer.astro" color-scheme: dark; --body-background-color: rgb(0,0,0); - --hf-button-hover-color: rgb(50,50,50); + --hf-button-hover-color: rgb(255,255,255); } ::selection { background-color: rgb(255,255,255);