1 Commits

Author SHA1 Message Date
f8cddaf340 --emptyOutDir for silenting a build warning 2025-02-23 20:31:45 -05:00
22 changed files with 165 additions and 449 deletions

View File

@ -9,9 +9,9 @@
"preview": "vite preview" "preview": "vite preview"
}, },
"devDependencies": { "devDependencies": {
"sass": "^1.85.1", "sass": "^1.85.0",
"typescript": "^5.8.2", "typescript": "^5.7.3",
"vite": "^6.2.1", "vite": "^6.1.1",
"vite-plugin-html": "^3.2.2" "vite-plugin-html": "^3.2.2"
} }
} }

View File

@ -1,5 +1,5 @@
<!doctype html> <!doctype html>
<html> <html lang="en">
<head> <head>
<meta charset="UTF-8"/> <meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width"/> <meta name="viewport" content="width=device-width"/>
@ -56,6 +56,6 @@
</style> </style>
</noscript> </noscript>
</footer> </footer>
<script type="module" src="./rt/emulator/terminal.ts"></script> <script type="module" src="./rt/terminal.ts"></script>
</body> </body>
</html> </html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 70 KiB

View File

@ -1,5 +1,5 @@
import { cyan, green } from "../shell/color" import { cyan, green } from "../shell/color"
import { get_working_dir_name } from "../rfwfs/library" import { get_working_dir_name } from "../shell/fs/fn"
import create from "./create" import create from "./create"

View File

@ -26,12 +26,6 @@ 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) => {
@ -54,8 +48,7 @@ export default function stdout(str: string) {
} }
export { export {
stdout_horizontal_elements,
stdout_horizontal,
stdout_grid, stdout_grid,
stdout_horizontal,
stdout_bold stdout_bold
} }

View File

@ -1,5 +1,5 @@
import run from "../shell/command/command" import run from "./shell/command/command"
import history from "../shell/history" import history from "./shell/history"
type InputClosure = (key_event: KeyboardEvent) => void type InputClosure = (key_event: KeyboardEvent) => void
interface EnterArgs { interface EnterArgs {

View File

@ -1,47 +0,0 @@
type ConstEnum = number
const enum EntryType {
Directory,
Binary,
File,
}
const enum Permissions {
r,
w,
rw,
none,
}
const enum PermissionsBinary {
r,
w,
x,
rw,
rwx,
rx,
wx,
none,
}
const enum PushStatus {
Ok,
Duplicate,
Denied,
}
const enum ReadStatus {
Ok,
NotFound,
Denied,
}
const enum Result {
None,
Ok,
}
export {
type ConstEnum,
PermissionsBinary,
Permissions,
PushStatus,
ReadStatus,
EntryType,
Result,
}

View File

@ -1,41 +0,0 @@
import { Permissions } from "../enum"
import rfwfs from "../main"
const time_now = (Date.now()/1000)|0
// ------------ Home ------------
const config = rfwfs.directory(".config", Permissions.rw, time_now)
const local = rfwfs.directory(".local", Permissions.rw, time_now)
const downloads = rfwfs.directory("Downloads", Permissions.rw, time_now)
const pictures = rfwfs.directory("Pictures", Permissions.rw, time_now)
const desktop = rfwfs.directory("Desktop", Permissions.rw, time_now)
const videos = rfwfs.directory("Videos", Permissions.rw, time_now)
const music = rfwfs.directory("Music", Permissions.rw, time_now)
const user = rfwfs.directory("user", Permissions.r, time_now, [
config,
local,
downloads,
pictures,
videos,
music,
desktop,
])
// /home/
const home = rfwfs.directory("home", Permissions.r, time_now, [user])
// ------------
// ------------ root ------------
const bin = rfwfs.directory("bin", Permissions.r, time_now)
const vard = rfwfs.directory("var", Permissions.r, time_now)
const etc = rfwfs.directory("etc", Permissions.r, time_now)
// ------------
export default rfwfs.directory("/", Permissions.r, time_now, [
bin,
home,
vard,
etc,
])

View File

@ -1,51 +0,0 @@
import { type FileInner } from "./main"
interface HashTable {
[index: string]: FileInner
}
interface Hash {
readonly inner: HashTable,
sha256: (file_inner: FileInner) => Promise<string>,
push: (hash: string) => void,
find: (hash: string) => FileInner | undefined,
pop: (hash: string) => FileInner | undefined,
}
async function sha256(inner_as_string: string): Promise<string> {
const encoder = new TextEncoder()
const hash = await crypto.subtle.digest("SHA-256", encoder.encode(inner_as_string))
const hash_as_uint8 = new Uint8Array(hash)
return Array.from(hash_as_uint8).map(byte => byte.toString(16).padStart(2, "0")).join("")
}
const hash_table = { inner: {} } as Hash
hash_table.sha256 = async function(file_inner) {
return await sha256(file_inner.toString())
}
hash_table.find = function(hash) {
const hash_entry = this.inner[hash]
if (hash_entry) {
return hash_entry
}
return undefined
}
hash_table.pop = function(hash) {
const hash_entry = this.find(hash)
if (hash_entry) {
delete this.inner[hash_entry]
return hash_entry
}
return undefined
}
hash_table.push = function(hash) {
}
export default hash_table
export {
type HashTable,
}

View File

@ -1,20 +0,0 @@
import { type Entry } from "./main"
import { wrap_bsearch, type WrapBSearch } from "./wrap"
export default function directory_search<T extends Entry>(entry_collection: T[], file_name: string): WrapBSearch<T> | undefined {
let start = 0
let end = entry_collection.length-1
while (start<=end) {
const median = (start+end)>>1
const median_name = entry_collection[median].name
if (median_name === file_name) {
return wrap_bsearch(median, entry_collection[median])
} else if (median_name<file_name) {
start = median+1
} else {
end = median-1
}
}
return undefined
}

View File

@ -1,180 +0,0 @@
import { EntryType, PushStatus, ReadStatus, Permissions, ConstEnum, PermissionsBinary } from "./enum"
import { wrap_entry, wrap_none, WrapResultEntry, WrapResultNone } from "./wrap"
import directory_search from "./index"
import hash_table from "./hash"
type FileInner = string | number
type EntryFileInner = EntryValue<FileInner, FileInner | undefined>
//please do not change the inner values directly on entries or else there will be catastrophic consequences
interface EntryValue<T, U = T> {
__inner: T,
write: (value: T) => boolean,
read: () => U,
}
interface Entry {
permissions: Permissions,
timestamp: EntryValue<number>,
name: EntryValue<string>,
readonly type: EntryType,
}
interface EntryFile extends Entry {
inner: EntryFileInner,
hash: string,
}
interface EntryCollection<T extends Entry> extends Entry {
inner: EntryCollectionManipulate<T>,
}
interface EntryCollectionManipulate<T extends Entry> {
__inner: T[],
clone: (file_name: string) => WrapResultEntry<T, ReadStatus>
find: (file_name: string) => WrapResultEntry<T, ReadStatus>
push: (entry: Entry) => WrapResultNone<PushStatus>,
sort: () => void,
pop: (file_name: string) => WrapResultEntry<T, ReadStatus>,
}
interface Rfwfs {
directory: <T extends Entry>(default_name: string, default_permissions: Permissions, default_timestamp?: number, default_inner?: T[]) => EntryCollection<T>,
file: (default_name: string, default_permissions: Permissions, default_timestamp?: number, default_inner?: FileInner) => Promise<EntryFile>,
is_binary: <T extends Entry>(entry: T) => boolean,
is_file: <T extends Entry>(entry: T) => boolean,
is_dir: <T extends Entry>(entry: T) => boolean,
}
function execute_access<P extends ConstEnum>(permissions: P): boolean {
return permissions === PermissionsBinary.rwx
|| permissions === PermissionsBinary.rx
|| permissions === PermissionsBinary.wx
|| permissions === PermissionsBinary.x
}
function read_write_access<P extends ConstEnum>(permissions: P): boolean {
return permissions === Permissions.rw
}
function read_access<P extends ConstEnum>(permissions: P): boolean {
return read_write_access(permissions) || permissions === Permissions.r
}
function write_access<P extends ConstEnum>(permissions: P): boolean {
return read_write_access(permissions) || permissions === Permissions.w
}
function directory_sort<E extends Entry>(self: EntryCollectionManipulate<E>) {
self.__inner.sort((a,z) => a.name.read().localeCompare(z.name.read()))
}
function directory_push<E extends Entry>(self: EntryCollection<E>, entry: E): WrapResultNone<PushStatus> {
if (write_access(self.permissions)) {
const no_duplicates = directory_search(self.inner.__inner, entry.name.read())
if (!no_duplicates) {
self.inner.__inner.push(entry)
self.inner.__inner.sort()
return wrap_none(PushStatus.Ok)
}
return wrap_none(PushStatus.Duplicate)
}
return wrap_none(PushStatus.Denied)
}
function directory_find<E extends Entry>(self: EntryCollection<E>, file_name: string): WrapResultEntry<E, ReadStatus> {
if (read_access(self.permissions)) {
const file_search = directory_search(self.inner.__inner, file_name)
if (file_search) {
return wrap_entry(ReadStatus.Ok, file_search.result)
}
return wrap_entry(ReadStatus.NotFound)
}
return wrap_entry(ReadStatus.Denied)
}
function directory_pop<E extends Entry>(self: EntryCollection<E>, file_name: string): WrapResultEntry<E, ReadStatus> {
if (read_write_access(self.permissions)) {
const pop_find = directory_search(self.inner.__inner, file_name)
if (pop_find) {
self.inner.__inner.splice(pop_find.some, 1)
return wrap_entry(ReadStatus.Ok, pop_find.result)
}
return wrap_entry(ReadStatus.NotFound)
}
return wrap_entry(ReadStatus.Denied)
}
function directory_clone<E extends Entry>(self: EntryCollection<E>, file_name: string): WrapResultEntry<E, ReadStatus> {
if (read_write_access(self.permissions)) {
const clone_find = directory_search(self.inner.__inner, file_name)
if (clone_find) {
return wrap_entry(ReadStatus.Ok, { ...clone_find.result })
}
return wrap_entry(ReadStatus.NotFound)
}
return wrap_entry(ReadStatus.Denied)
}
function inner_read<I extends FileInner, P extends ConstEnum>(self: EntryValue<I>, permissions: P): FileInner | undefined {
return read_access(permissions) ? self.__inner : undefined
}
function inner_write<I extends FileInner, P extends ConstEnum>(self: EntryValue<I>, permissions: P, item: I): boolean {
if (write_access(permissions)) {
self.__inner = item
return true
}
return false
}
function inner<P extends ConstEnum, I, R extends EntryValue<I>>(permissions: P, inner_default: I): R {
const inner_trait = { __inner: inner_default } as R
inner_trait.write = function(item) { return inner_write(this, permissions, item) }
inner_trait.read = function() { return inner_read(this, permissions) }
return inner_trait
}
function dir_inner<T extends Entry>(self: EntryCollection<T>, collection: T[]): EntryCollectionManipulate<T> {
const collection_trait = { __inner: collection } as EntryCollectionManipulate<T>
collection_trait.clone = function(file_name) { return directory_clone(self, file_name) }
collection_trait.find = function(file_name) { return directory_find(self, file_name) }
collection_trait.push = function(entry) { return directory_push(self, entry) }
collection_trait.sort = function() { return directory_sort(this) }
collection_trait.pop = function(file_name) { return directory_pop(self, file_name) }
collection_trait.sort() //the default collection is automatically sorted on directory creation.
return collection_trait
}
const rfwfs = {} as Rfwfs
rfwfs.is_dir = function(entry) {
return entry.type === EntryType.Directory
}
rfwfs.is_file = function(entry) {
return entry.type === EntryType.File
}
rfwfs.is_binary = function(entry) {
return entry.type === EntryType.Binary
}
rfwfs.file = async function(default_name, default_permissions, default_timestamp, default_inner = "") {
const file = { type: EntryType.File } as EntryFile
file.permissions = default_permissions
file.timestamp = inner(default_permissions, default_timestamp ? default_timestamp : (Date.now()/1000)|0)
file.inner = inner(default_permissions, default_inner)
file.name = inner(default_permissions, default_name)
file.hash = await hash_table.sha256(default_inner)
return file
}
rfwfs.directory = function<T extends Entry>(default_name: string, default_permissions: Permissions, default_timestamp?: number, default_inner?: T[]): EntryCollection<T> {
const directory = { type: EntryType.Directory } as EntryCollection<T>
directory.permissions = default_permissions
directory.timestamp = inner(default_permissions, default_timestamp ? default_timestamp : (Date.now()/1000)|0)
directory.inner = inner(default_permissions, default_inner)
directory.name = inner(default_permissions, default_name)
return directory
}
export default rfwfs
export {
type EntryCollectionManipulate,
type EntryCollection,
type FileInner,
type EntryFile,
type Entry,
}

View File

@ -1,40 +0,0 @@
import { Result, type ConstEnum } from "./enum"
import { type Entry } from "./main"
type WrapResultEntry<T extends Entry, U> = WrapResult<T | undefined, U>
type WrapBSearch<T extends Entry> = WrapResult<T, number>
type WrapResultNone<T> = WrapResult<Result.None, T>
interface WrapResult<T, U> {
/** The resulting value if `U` is a success */
readonly result: T,
/** Represents some arbitrary extra value, usually a success status */
readonly some: U
}
function wrap<T, U>(result: T, some: U): WrapResult<T, U> {
return { result: result, some: some }
}
function wrap_bsearch<T extends Entry>(index: number, result: T): WrapBSearch<T> {
return wrap(result, index)
}
function wrap_entry<T extends ConstEnum, U extends Entry>(status: T, result?: U): WrapResultEntry<U, T> {
return wrap(result, status)
}
function wrap_none<T extends ConstEnum>(status: T): WrapResultNone<T> {
return wrap(Result.None, status)
}
export default wrap
export {
wrap_bsearch,
wrap_entry,
wrap_none,
type WrapResultEntry,
type WrapResultNone,
type WrapBSearch,
type WrapResult,
}

View File

@ -7,23 +7,20 @@ const enum Colors {
cyan = "cyan", cyan = "cyan",
bold = "bold" bold = "bold"
} }
function newcolor(inner: string, color?: Colors, bold?: boolean) { function newcolor(inner: string, color?: Colors) {
const span = create("span", color) const span = create("span", color)
span.innerText = inner span.innerText = inner
if (bold) {
span.className = color ? color+" bold" : "bold"
}
return span return span
} }
const red = (s: string, bold?: boolean) => newcolor(s, Colors.red, bold) const red = (s: string) => newcolor(s, Colors.red )
const green = (s: string, bold?: boolean) => newcolor(s, Colors.green, bold) const green = (s: string) => newcolor(s, Colors.green)
const blue = (s: string, bold?: boolean) => newcolor(s, Colors.blue, bold) const blue = (s: string) => newcolor(s, Colors.blue)
const cyan = (s: string, bold?: boolean) => newcolor(s, Colors.cyan, bold) const cyan = (s: string) => newcolor(s, Colors.cyan)
const bold = (s: string) => newcolor(s, Colors.bold) const bold = (s: string) => newcolor(s, Colors.bold)
export default function rgb(s: string, Ru8: number, Gu8: number, Bu8: number, bold?: boolean) { export default function rgb(s: string, Ru8: number, Gu8: number, Bu8: number) {
const rgb_span = newcolor(s, undefined, bold) const rgb_span = newcolor(s)
rgb_span.style.color = `rgb(${Ru8},${Gu8},${Bu8})` rgb_span.style.color = `rgb(${Ru8},${Gu8},${Bu8})`
return rgb_span return rgb_span
} }

View File

@ -1,15 +1,13 @@
import { set_working_dir, SetDirStatus } from "../../../rfwfs/library" 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) {
term.appendChild(stdout(`cd: "${args[1]}" is not a directory`)) // return <p>{"cd: \""}{bold(args[1])}{"\" is not a directory"}</p>
} else if (new_dir_status === SetDirStatus.NotFound) { } else if (new_dir_status === SetDirStatus.NotFound) {
term.appendChild(stdout(`cd: The directory "${args[1]}" does not exist`)) // return <p>{"cd: The directory \""}{bold(args[1])}{"\" does not exist"}</p>
} }
return true return true
} }

View File

@ -7,7 +7,7 @@ import history from "../../history";
const history_command = new SubCommand("Show and manipulate command history") const history_command = new SubCommand("Show and manipulate command history")
history_command.add("show", "Show the history", function(term: Term, _args: Args) { history_command.add("show", "Show the history", function(term: Term, _args: Args) {
history.file.inner.forEach((entry, ind) => term.appendChild(stdout(`${ind+1} ${entry}`))) history.file.inner.forEach((entry, ind) => term.appendChild(stdout(`${ind} ${entry}`)))
}) })
history_command.add("clear", "Delete the entire command history", function(term: Term, _args: Args) { history_command.add("clear", "Delete the entire command history", function(term: Term, _args: Args) {

View File

@ -1,30 +1,11 @@
import type { Args, Term } from "../list"; import type { Args, Term } from "../list";
import { blue } from "../../color";
import { get_working_dir_entries } from "../../../rfwfs/library";
import { EntryType, FsEntry } from "../../../rfwfs/core";
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 {
const ls_elements = element_collection() // if (args[1] === undefined) {
if (args[1] === undefined) { // for (const dir_name in working_dir) {
get_working_dir_entries().forEach(entry => {
if (entry.type === EntryType.Directory) { // }
ls_elements.push(show_directory(entry)) // return <p>{`${working_dir}`}</p>
} else if (entry.type === EntryType.File) { // }
ls_elements.push(stdout(entry.name))
}
})
}
term.appendChild(stdout_horizontal_elements(ls_elements))
return true return true
} }

View File

@ -1,4 +1,4 @@
import { get_working_dir_name_full } from "../../../rfwfs/library"; import { get_working_dir_name_full } from "../../fs/fn";
import type { Args, Term } from "../list"; import type { Args, Term } from "../list";
import stdout from "../../../elements/stdout"; import stdout from "../../../elements/stdout";

75
src/rt/shell/fs/fn.ts Normal file
View File

@ -0,0 +1,75 @@
import { EntryType, fs, type FsEntrySignature } from "./fs"
let working_dir = ["/", "home", "user"]
function get_working_dir_name() {
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()
if (root) {
return root+w_dir_clone.join("/")
}
return "shift-error"
}
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]
for (const w_dir of w_dir_clone) {
if (w_dir === "/") { continue }
if (next_iter && next_iter.inner) {
const found = next_iter.inner.find(entry => 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,
get_working_dir_name_full,
set_working_dir,
SetDirStatus
}

51
src/rt/shell/fs/fs.ts Normal file
View File

@ -0,0 +1,51 @@
const enum EntryType {
Directory,
File
}
const enum Permissions {
r,
w,
rw
}
type FsEntrySignature = Entry<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)
]
const root = [
Entry("home", home, Permissions.r),
Entry("bin", {}, Permissions.r),
]
const fs = [
Entry("/", root, Permissions.r)
]
type File = string
interface Entry<T = File> {
readonly inner?: T,
readonly name: string,
readonly type: EntryType,
readonly permissions: Permissions
}
function Entry<T = File>(name: string, inner: T, permissions: Permissions): Entry<T> {
return {
type: typeof inner == "object" ? EntryType.Directory : EntryType.File,
inner: inner,
name: name,
permissions: permissions
}
}
export {
fs,
type FsEntrySignature,
EntryType,
Permissions,
Entry
}

View File

@ -1,5 +1,5 @@
import history from "../shell/history" import history from "./shell/history"
import prompt from "../elements/prompt" import prompt from "./elements/prompt"
import keys from "./keys" import keys from "./keys"
const term_win_unsafe = document.querySelector("main") const term_win_unsafe = document.querySelector("main")

View File

@ -1,5 +1,3 @@
@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)) }
@ -32,13 +30,17 @@
@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; }
}
} }
} }

View File

@ -1,5 +1,3 @@
$default-font-size: 1.2rem;
$header-Y: 30px; $header-Y: 30px;
$footer-Y: 30px; $footer-Y: 30px;
$component-padding: 20px; $component-padding: 20px;