working on the file system
cd can now display folders in blue
This commit is contained in:
@ -26,6 +26,12 @@ function stdout_grid<T extends HTMLElement>(left: string[], right: string[], hea
|
|||||||
return wrap_indicator
|
return wrap_indicator
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stdout_horizontal_elements<T extends HTMLElement>(elements: T[]) {
|
||||||
|
const h_elements_out = horizontal()
|
||||||
|
h_elements_out.append(...elements)
|
||||||
|
return h_elements_out
|
||||||
|
}
|
||||||
|
|
||||||
function stdout_horizontal(strs: string[]) {
|
function stdout_horizontal(strs: string[]) {
|
||||||
const p = create("p")
|
const p = create("p")
|
||||||
strs.forEach((str, i) => {
|
strs.forEach((str, i) => {
|
||||||
@ -48,7 +54,8 @@ export default function stdout(str: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
stdout_grid,
|
stdout_horizontal_elements,
|
||||||
stdout_horizontal,
|
stdout_horizontal,
|
||||||
|
stdout_grid,
|
||||||
stdout_bold
|
stdout_bold
|
||||||
}
|
}
|
@ -1,13 +1,15 @@
|
|||||||
import { set_working_dir, SetDirStatus } from "../../fs/fn"
|
import { set_working_dir, SetDirStatus } from "../../fs/fn"
|
||||||
import type { Args, Term } from "../list"
|
import type { Args, Term } from "../list"
|
||||||
|
|
||||||
|
import stdout from "../../../elements/stdout"
|
||||||
|
|
||||||
export default function cd(term: Term, args: Args): boolean {
|
export default function cd(term: Term, args: Args): boolean {
|
||||||
const new_dir_status = set_working_dir(args[1])
|
const new_dir_status = set_working_dir(args[1])
|
||||||
|
|
||||||
if (new_dir_status === SetDirStatus.NotADirectory) {
|
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) {
|
} 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
|
return true
|
||||||
}
|
}
|
@ -1,11 +1,30 @@
|
|||||||
import type { Args, Term } from "../list";
|
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 {
|
export default function ls(term: Term, args: Args): boolean {
|
||||||
// if (args[1] === undefined) {
|
const ls_elements = element_collection()
|
||||||
// for (const dir_name in working_dir) {
|
if (args[1] === undefined) {
|
||||||
|
get_working_dir_entries().forEach(entry => {
|
||||||
// }
|
if (entry.type === EntryType.Directory) {
|
||||||
// return <p>{`${working_dir}`}</p>
|
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
|
return true
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
import { EntryType, fs, type FsEntrySignature } from "./fs"
|
import { EntryType, fs, type FsDirectory, type FsEntry } from "./fs"
|
||||||
|
|
||||||
let working_dir = ["/", "home", "user"]
|
let working_dir = ["/", "home", "user"]
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ const enum SetDirStatus {
|
|||||||
NotADirectory
|
NotADirectory
|
||||||
}
|
}
|
||||||
interface FsIterEntry {
|
interface FsIterEntry {
|
||||||
readonly entry: FsEntrySignature | null,
|
readonly entry: FsDirectory | null,
|
||||||
readonly status: SetDirStatus
|
readonly status: SetDirStatus
|
||||||
}
|
}
|
||||||
function iter_fs_to_goal(w_dir_clone: string[]): FsIterEntry {
|
function iter_fs_to_goal(w_dir_clone: string[]): FsIterEntry {
|
||||||
@ -41,7 +41,7 @@ function iter_fs_to_goal(w_dir_clone: string[]): FsIterEntry {
|
|||||||
if (found.name === w_dir_clone[w_dir_clone.length-1]) {
|
if (found.name === w_dir_clone[w_dir_clone.length-1]) {
|
||||||
return { entry: next_iter, status: SetDirStatus.Valid }
|
return { entry: next_iter, status: SetDirStatus.Valid }
|
||||||
} else {
|
} else {
|
||||||
next_iter = found.inner as FsEntrySignature
|
next_iter = found.inner as FsDirectory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,15 +61,21 @@ function set_working_dir(name: string): SetDirStatus {
|
|||||||
return iter_status.status
|
return iter_status.status
|
||||||
}
|
}
|
||||||
|
|
||||||
function working_dir_entries() {
|
function get_working_dir_entries(): FsEntry[] {
|
||||||
|
const entries: FsEntry[] = []
|
||||||
const w_dir_clone = [...working_dir]
|
const w_dir_clone = [...working_dir]
|
||||||
const iter_status = iter_fs_to_goal(w_dir_clone)
|
const iter_status = iter_fs_to_goal(w_dir_clone)
|
||||||
|
|
||||||
|
if (iter_status.entry && iter_status.entry.inner) {
|
||||||
|
iter_status.entry.inner.forEach(dir => entries.push(dir))
|
||||||
|
}
|
||||||
|
return entries
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
get_working_dir_name,
|
get_working_dir_name,
|
||||||
get_working_dir_name_full,
|
get_working_dir_name_full,
|
||||||
|
get_working_dir_entries,
|
||||||
set_working_dir,
|
set_working_dir,
|
||||||
SetDirStatus
|
SetDirStatus
|
||||||
}
|
}
|
@ -8,7 +8,8 @@ const enum Permissions {
|
|||||||
rw
|
rw
|
||||||
}
|
}
|
||||||
|
|
||||||
type FsEntrySignature = Entry<Entry<{}>[]> //I did this!
|
type FsEntry = Entry<{}>
|
||||||
|
type FsDirectory = Entry<FsEntry[]>
|
||||||
|
|
||||||
const user = [
|
const user = [
|
||||||
Entry("about_me.txt", "about me inside", Permissions.rw),
|
Entry("about_me.txt", "about me inside", Permissions.rw),
|
||||||
@ -44,7 +45,8 @@ function Entry<T = File>(name: string, inner: T, permissions: Permissions): Entr
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
fs,
|
fs,
|
||||||
type FsEntrySignature,
|
type FsDirectory,
|
||||||
|
type FsEntry,
|
||||||
EntryType,
|
EntryType,
|
||||||
Permissions,
|
Permissions,
|
||||||
Entry
|
Entry
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
@use "../variables.scss";
|
||||||
|
|
||||||
@mixin text-styles {
|
@mixin text-styles {
|
||||||
.red { color: rgb(var(--color-red)) }
|
.red { color: rgb(var(--color-red)) }
|
||||||
.green { color: rgb(var(--color-green)) }
|
.green { color: rgb(var(--color-green)) }
|
||||||
@ -30,17 +32,13 @@
|
|||||||
@mixin formatting {
|
@mixin formatting {
|
||||||
@include stdout-layouts;
|
@include stdout-layouts;
|
||||||
@include term-elements;
|
@include term-elements;
|
||||||
|
@include text-styles;
|
||||||
|
|
||||||
|
p, a, span {
|
||||||
|
font-size: variables.$default-font-size
|
||||||
|
}
|
||||||
p {
|
p {
|
||||||
@include text-styles;
|
|
||||||
|
|
||||||
font-size: 1.2rem;
|
|
||||||
margin: 5px;
|
margin: 5px;
|
||||||
|
a:hover { text-decoration: underline; }
|
||||||
span { font-size: inherit; }
|
|
||||||
a {
|
|
||||||
font-size: inherit;
|
|
||||||
&:hover { text-decoration: underline; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
$default-font-size: 1.2rem;
|
||||||
|
|
||||||
$header-Y: 30px;
|
$header-Y: 30px;
|
||||||
$footer-Y: 30px;
|
$footer-Y: 30px;
|
||||||
$component-padding: 20px;
|
$component-padding: 20px;
|
||||||
|
Reference in New Issue
Block a user