ls command working, need to debug sort, and figure out how to prevent sorting on flag (will need further debugging probs)

This commit is contained in:
2025-12-06 07:52:29 +01:00
parent 60eb56da56
commit 8a06d7cb93
5 changed files with 24 additions and 19 deletions

View File

@@ -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}`);
}
}

View File

@@ -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();

View File

@@ -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) {

View File

@@ -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.

View File

@@ -8,7 +8,7 @@
<span class=" pointer self-start pr-2">$</span>
<p>{cmd}</p>
</div>
<div style="white-space: preserve;" class=" relative wrap-break-word">
<div style="white-space: nowrap;" class=" relative">
{#if typeof output === 'string'}
{output}
{:else if output instanceof Element}