diff --git a/src/lib/stores/bash/bash.ts b/src/lib/stores/bash/bash.ts index d0d25ee..fdc96c7 100644 --- a/src/lib/stores/bash/bash.ts +++ b/src/lib/stores/bash/bash.ts @@ -152,7 +152,6 @@ export class Bash { getGroupByName(name: string): Group { const out: Group | undefined = this._group.find((group) => group.groupname === name); - console.log(out); if (out) return out; else throw new Error(`Cannot find a user group named ${name}`); @@ -160,7 +159,6 @@ export class Bash { getUserByName(name: string): User { const out: User | undefined = this._passwd.find((user) => user.username === name); - console.log(out); if (out) return out; else throw new Error(`Cannot find a user named ${name}`); @@ -168,17 +166,15 @@ export class Bash { getGroupByGid(gid: number): Group { const out: Group | undefined = this._group.find((group) => group.gid === gid); - console.log(out); if (out) return out; - else throw new Error(`Cannot find a user group named ${name}`); + else throw new Error(`Cannot find a user group with id of ${gid}`); } getUserByUid(uid: number): User { const out: User | undefined = this._passwd.find((user) => user.uid === uid); - console.log(out); if (out) return out; - else throw new Error(`Cannot find a user group named ${name}`); + else throw new Error(`Cannot find a user with id of ${uid}`); } } diff --git a/src/lib/stores/bash/commands/ls.ts b/src/lib/stores/bash/commands/ls.ts index 480fa76..f255d5e 100644 --- a/src/lib/stores/bash/commands/ls.ts +++ b/src/lib/stores/bash/commands/ls.ts @@ -77,17 +77,20 @@ function result_ls(this: Bash, data: any, args: CommandArgs): HTMLElement { for (const node of nodes) { const elem: HTMLElement = document.createElement('div'); + let children: TreeNode[] = []; const rows: string[] = []; - if (!flagInfo.has('U') && !flagInfo.has('f')) + if (!flagInfo.has('U') && !flagInfo.has('f')) { //TODO: Add sort by option later on - Sort.nodeArraySort.call(this, node.children, flagInfo.has('r')); + children: TreeNode[] = Sort.nodeArraySort.call(this, node.children, flagInfo.has('r')); + console.log('had U or f'); + } const sizes = node.children.map((child) => (this.getFs().getNodeByINode(child).size)); const maxSizeWidth = Math.max(...sizes.map((size) => size)); - for (const inode of node.children) { - const child: TreeNode = this.getFs().getNodeByINode(inode); + for (let i = 0; i < node.children.length; i++) { + const child: TreeNode = children[i]; if (child.name.startsWith('.') && !(f_a || flagInfo.has('A'))) continue; @@ -202,10 +205,10 @@ function formatChildren(node: TreeNode): string { return c.length > 1 ? c : ` ${c}`; } -function formatSize(this: Bash, human: boolean, node: TreeNode, max: number): string { +function formatSize(this: Bash, humanReadable: boolean, node: TreeNode, max: number): string { const byteSize: number = node.type === Type.Directory ? 4096 : 1; //TEMP, later calculate the size. let size: string; - if (human) { + if (humanReadable) { size = this.formatBytes(byteSize); } else size = byteSize.toString(); diff --git a/src/lib/stores/bash/sort.ts b/src/lib/stores/bash/sort.ts index b3c4eb0..96e98bd 100644 --- a/src/lib/stores/bash/sort.ts +++ b/src/lib/stores/bash/sort.ts @@ -14,7 +14,7 @@ export enum SortBy { export class Sort { - public static nodeArraySort(this: Bash, nodes: TreeNode[] | number[], reverse: boolean = false, sortBy: SortBy = SortBy.NAME) { + public static nodeArraySort(this: Bash, nodes: TreeNode[] | number[], reverse: boolean = false, sortBy: SortBy = SortBy.NAME): TreeNode[] { if(nodes.length === 0) throw new Error('Tried to sort an empty node array!'); const parsedNodes: TreeNode[] = []; @@ -24,7 +24,13 @@ export class Sort { parsedNodes.push(node); } Sort.nodeQSort(parsedNodes, reverse, sortBy, 0, parsedNodes.length - 1); - } else Sort.nodeQSort(nodes as TreeNode[], reverse, sortBy, 0, nodes.length - 1); + console.log(parsedNodes); + return parsedNodes; + } else { + Sort.nodeQSort(nodes as TreeNode[], reverse, sortBy, 0, nodes.length - 1); + console.log(nodes); + return nodes as TreeNode[]; + } } private static nodeQSort(array: TreeNode[], reverse: boolean, sortBy: SortBy, start: number, end: number) { diff --git a/src/lib/stores/bash/static.ts b/src/lib/stores/bash/static.ts index e532973..f36d41b 100644 --- a/src/lib/stores/bash/static.ts +++ b/src/lib/stores/bash/static.ts @@ -33,7 +33,7 @@ export const GROUP: Group[] = [ }, { groupname: 'users', - gid: 1000, + gid: 984, members: [1001, 1002] } ] as const; @@ -50,7 +50,7 @@ export const PASSWD: User[] = [ { username: 'admin', passwd: '456', - uid: 1001, + uid: 1000, gid: 1000, home: '/home/admin', history: [] //TODO: Delete this and declare a new history array when logging the user in. @@ -58,7 +58,7 @@ export const PASSWD: User[] = [ { username: 'user', passwd: '789', - uid: 1002, + uid: 1001, gid: 1000, home: '/home/user', history: [] //TODO: Delete this and declare a new history array when logging the user in. @@ -66,7 +66,7 @@ export const PASSWD: User[] = [ { username: 'kamil', passwd: '000', - uid: 1003, + uid: 1002, gid: 1000, home: '/home/kamil', history: [] //TODO: Delete this and declare a new history array when logging the user in. diff --git a/src/modules/terminal/Output.svelte b/src/modules/terminal/Output.svelte index 7c13604..6b9f0dd 100644 --- a/src/modules/terminal/Output.svelte +++ b/src/modules/terminal/Output.svelte @@ -8,7 +8,7 @@ $

{cmd}

-
+
{#if typeof output === 'string'} {output} {:else if output instanceof Element}