44 Commits

Author SHA1 Message Date
e612f5762f not necessary bro 2025-03-15 20:16:13 -04:00
d4278d0d7f plumbing 2025-03-15 20:14:05 -04:00
26a7d4c21c File and Directory classes 2025-03-15 19:53:40 -04:00
305c2bd2cd vite update 2025-03-15 19:46:10 -04:00
c66a0eb4a9 prototyping with classes for Inner and Rfwfs directory 2025-03-14 17:39:07 -04:00
caedb7e8f0 push and find should use read_write_access since they read the names of inner 2025-03-12 16:36:05 -04:00
050c0f1aca (WIP) name and timestamp resepect permissions 2025-03-11 03:23:13 -04:00
d7abe20d1a PermissionsBinary 2025-03-11 03:13:28 -04:00
1d3b80515b var and etc 2025-03-08 18:31:05 -05:00
3f48a19b22 desktop dir 2025-03-08 18:26:18 -05:00
74e3d5df60 optional timestamp 2025-03-08 18:26:07 -05:00
9d0b12b47c replace tree with fs/root.ts 2025-03-08 17:41:14 -05:00
e8645d4f64 directory.clone(file_name) 2025-03-08 17:41:05 -05:00
fc0ef23bdb types/entry.d.ts not needed 2025-03-08 17:40:47 -05:00
7a457e5205 rewrite of types and names 2025-03-08 16:12:02 -05:00
6b129045e8 entry.d.ts 2025-03-08 16:11:18 -05:00
cec5642e70 branch out enums to an enum module 2025-03-08 16:09:54 -05:00
5b74400a10 wrap module, may branch this out to the entire codebase 2025-03-08 15:59:23 -05:00
384e70e286 sha256 hash module for file hashes 2025-03-08 02:10:31 -05:00
3aaedf1e8b vite update 2025-03-07 16:24:35 -05:00
17e89ef1c8 rename cloned_file_collection to entry_collection 2025-03-06 20:56:06 -05:00
aa6f8b6f8e rename new_entry and new_collection to entry and collection 2025-03-06 20:55:43 -05:00
d80887d281 PushStatus enum
i forgor about the permissions system here... maybe users soon for fun..
2025-03-06 20:47:38 -05:00
9eba512580 auto sort collections 2025-03-06 17:59:10 -05:00
8469c015f8 rename push() -> find() for entry_collection 2025-03-06 17:58:40 -05:00
b3fa561c76 typing is now correct for the file system 2025-03-06 17:29:30 -05:00
b7babb665e T extends Entry<T> -> T type error fix 2025-03-05 19:47:59 -05:00
9856b138df type fix 2025-03-05 02:58:02 -05:00
c2ac2ba28c type errors 2025-03-04 20:29:21 -05:00
c994698e2d update ts 2025-03-02 02:39:49 -05:00
fd1675f57a new structure and library structure 2025-03-02 02:39:46 -05:00
3865a79dbc new logo 2025-03-01 00:29:03 -05:00
f228d86e0b experimenting with entry 2025-02-27 00:34:53 -05:00
596a21f49d move terminal.ts and keys.ts into the emulator folder 2025-02-26 16:48:51 -05:00
e09891482e not necessary 2025-02-26 14:24:25 -05:00
f7e678190d move rfwfs into rt 2025-02-26 14:18:05 -05:00
22df34ed43 binary searching for files WIP 2025-02-26 02:03:07 -05:00
2ea415a20e fs is now named rfwfs
rhpidfyre's web file system
2025-02-26 00:53:55 -05:00
d59ea8d8a7 search.ts -> index.ts 2025-02-25 23:24:10 -05:00
4f3df58ff4 move the fs tree into tree.ts out of core.ts 2025-02-25 21:13:08 -05:00
db31f20d24 binary_nsort for no automatic sorting 2025-02-25 19:03:10 -05:00
9de5ddcfbf update deps 2025-02-25 18:32:16 -05:00
474345a204 search module for fs 2025-02-25 18:32:08 -05:00
d1fc53206c fs.ts -> core.ts, fn.ts -> library.ts 2025-02-23 23:20:35 -05:00
17 changed files with 341 additions and 148 deletions

View File

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

View File

@ -1,5 +1,5 @@
<!doctype html> <!doctype html>
<html lang="en"> <html>
<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/terminal.ts"></script> <script type="module" src="./rt/emulator/terminal.ts"></script>
</body> </body>
</html> </html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 5.7 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 "../shell/fs/fn" import { get_working_dir_name } from "../rfwfs/library"
import create from "./create" import create from "./create"

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,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")

47
src/rt/rfwfs/enum.ts Normal file
View File

@ -0,0 +1,47 @@
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,
}

41
src/rt/rfwfs/fs/root.ts Normal file
View File

@ -0,0 +1,41 @@
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,
])

11
src/rt/rfwfs/hash.ts Normal file
View File

@ -0,0 +1,11 @@
async function hash(inner_as_string: 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("")
}
export default async function generate_sha256(inner_as_string: string) {
const sha256 = await hash(inner_as_string)
return sha256
}

20
src/rt/rfwfs/index.ts Normal file
View File

@ -0,0 +1,20 @@
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
}

168
src/rt/rfwfs/main.ts Normal file
View File

@ -0,0 +1,168 @@
import { EntryType, PushStatus, ReadStatus, Permissions, ConstEnum, PermissionsBinary } from "./enum"
import { wrap_entry, wrap_none, WrapResultEntry, WrapResultNone } from "./wrap"
import directory_search from "./index"
type FileInner = string | number
interface Entry {
permissions: Permissions,
timestamp: EntryValue<number>,
name: EntryValue<string>,
readonly type: EntryType,
}
interface EntryFile extends Entry {
inner: EntryValue<FileInner>,
hash: string,
}
interface EntryCollection<T extends Entry> extends Entry {
inner: RfwfsDirectory<T>,
}
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) => 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
}
class EntryValue<T> {
public inner: T;
protected entry: Entry
constructor(entry: Entry, inner_default: T) {
this.inner = inner_default
this.entry = entry
}
public write<I extends T>(item: I): boolean {
if (write_access(this.entry.permissions)) {
this.inner = item
return true
}
return false
}
public read(): T | undefined {
return read_access(this.entry.permissions) ? this.inner : undefined
}
}
class RfwfsDirectory<T extends Entry> {
public inner: T[];
protected entry: Entry
constructor(entry: Entry, inner: T[]) {
this.inner = inner
this.entry = entry
}
public sort() {
this.inner.sort((a,z) => a.name.inner.localeCompare(z.name.inner))
}
public clone(file_name: string): WrapResultEntry<T, ReadStatus> {
if (read_write_access(this.entry.permissions)) {
const clone_find = directory_search(this.inner, file_name)
if (clone_find) {
return wrap_entry(ReadStatus.Ok, { ...clone_find.result })
}
return wrap_entry(ReadStatus.NotFound)
}
return wrap_entry(ReadStatus.Denied)
}
public find(file_name: string): WrapResultEntry<T, ReadStatus> {
if (read_write_access(this.entry.permissions)) {
const file_search = directory_search(this.inner, file_name)
if (file_search) {
return wrap_entry(ReadStatus.Ok, file_search.result)
}
return wrap_entry(ReadStatus.NotFound)
}
return wrap_entry(ReadStatus.Denied)
}
public push<E extends T>(entry: E): WrapResultNone<PushStatus> {
if (read_write_access(this.entry.permissions)) {
const no_duplicates = directory_search(this.inner, entry.name.inner)
if (!no_duplicates) {
this.inner.push(entry)
this.inner.sort()
return wrap_none(PushStatus.Ok)
}
return wrap_none(PushStatus.Duplicate)
}
return wrap_none(PushStatus.Denied)
}
public pop(file_name: string): WrapResultEntry<T, ReadStatus> {
if (read_write_access(this.entry.permissions)) {
const pop_find = directory_search(this.inner, file_name)
if (pop_find) {
this.inner.splice(pop_find.some, 1)
return wrap_entry(ReadStatus.Ok, pop_find.result)
}
return wrap_entry(ReadStatus.NotFound)
}
return wrap_entry(ReadStatus.Denied)
}
}
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 = function(default_name, default_permissions, default_timestamp, default_inner) {
const file = { type: EntryType.File } as EntryFile
file.hash = "0"
file.permissions = default_permissions
file.timestamp = new EntryValue(file, default_timestamp ? default_timestamp : (Date.now()/1000)|0)
file.inner = new EntryValue(file, default_inner ? default_inner : "")
file.name = new EntryValue(file, default_name)
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 = new EntryValue(directory, default_timestamp ? default_timestamp : (Date.now()/1000)|0)
directory.inner = new RfwfsDirectory(directory, default_inner ? default_inner : [])
directory.name = new EntryValue(directory, default_name)
return directory
}
export default rfwfs
export {
type EntryCollection,
type FileInner,
type EntryFile,
type Entry,
}

40
src/rt/rfwfs/wrap.ts Normal file
View File

@ -0,0 +1,40 @@
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

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

View File

@ -1,7 +1,7 @@
import type { Args, Term } from "../list"; import type { Args, Term } from "../list";
import { blue } from "../../color"; import { blue } from "../../color";
import { get_working_dir_entries } from "../../fs/fn"; import { get_working_dir_entries } from "../../../rfwfs/library";
import { EntryType, FsEntry } from "../../fs/fs"; import { EntryType, FsEntry } from "../../../rfwfs/core";
import stdout, { stdout_horizontal_elements } from "../../../elements/stdout"; import stdout, { stdout_horizontal_elements } from "../../../elements/stdout";
import create from "../../../elements/create"; import create from "../../../elements/create";

View File

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

View File

@ -1,81 +0,0 @@
import { EntryType, fs, type FsDirectory, type FsEntry } 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: FsDirectory | 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 FsDirectory
}
}
}
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 get_working_dir_entries(): FsEntry[] {
const entries: FsEntry[] = []
const w_dir_clone = [...working_dir]
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 {
get_working_dir_name,
get_working_dir_name_full,
get_working_dir_entries,
set_working_dir,
SetDirStatus
}

View File

@ -1,53 +0,0 @@
const enum EntryType {
Directory,
File
}
const enum Permissions {
r,
w,
rw
}
type FsEntry = Entry<{}>
type FsDirectory = Entry<FsEntry[]>
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 FsDirectory,
type FsEntry,
EntryType,
Permissions,
Entry
}