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:
@@ -152,7 +152,6 @@ export class Bash {
|
|||||||
|
|
||||||
getGroupByName(name: string): Group {
|
getGroupByName(name: string): Group {
|
||||||
const out: Group | undefined = this._group.find((group) => group.groupname === name);
|
const out: Group | undefined = this._group.find((group) => group.groupname === name);
|
||||||
console.log(out);
|
|
||||||
|
|
||||||
if (out) return 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 named ${name}`);
|
||||||
@@ -160,7 +159,6 @@ export class Bash {
|
|||||||
|
|
||||||
getUserByName(name: string): User {
|
getUserByName(name: string): User {
|
||||||
const out: User | undefined = this._passwd.find((user) => user.username === name);
|
const out: User | undefined = this._passwd.find((user) => user.username === name);
|
||||||
console.log(out);
|
|
||||||
|
|
||||||
if (out) return out;
|
if (out) return out;
|
||||||
else throw new Error(`Cannot find a user named ${name}`);
|
else throw new Error(`Cannot find a user named ${name}`);
|
||||||
@@ -168,17 +166,15 @@ export class Bash {
|
|||||||
|
|
||||||
getGroupByGid(gid: number): Group {
|
getGroupByGid(gid: number): Group {
|
||||||
const out: Group | undefined = this._group.find((group) => group.gid === gid);
|
const out: Group | undefined = this._group.find((group) => group.gid === gid);
|
||||||
console.log(out);
|
|
||||||
|
|
||||||
if (out) return 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 {
|
getUserByUid(uid: number): User {
|
||||||
const out: User | undefined = this._passwd.find((user) => user.uid === uid);
|
const out: User | undefined = this._passwd.find((user) => user.uid === uid);
|
||||||
console.log(out);
|
|
||||||
|
|
||||||
if (out) return 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}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,17 +77,20 @@ function result_ls(this: Bash, data: any, args: CommandArgs): HTMLElement {
|
|||||||
|
|
||||||
for (const node of nodes) {
|
for (const node of nodes) {
|
||||||
const elem: HTMLElement = document.createElement('div');
|
const elem: HTMLElement = document.createElement('div');
|
||||||
|
let children: TreeNode[] = [];
|
||||||
const rows: string[] = [];
|
const rows: string[] = [];
|
||||||
|
|
||||||
if (!flagInfo.has('U') && !flagInfo.has('f'))
|
if (!flagInfo.has('U') && !flagInfo.has('f')) {
|
||||||
//TODO: Add sort by option later on
|
//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 sizes = node.children.map((child) => (this.getFs().getNodeByINode(child).size));
|
||||||
const maxSizeWidth = Math.max(...sizes.map((size) => size));
|
const maxSizeWidth = Math.max(...sizes.map((size) => size));
|
||||||
|
|
||||||
for (const inode of node.children) {
|
for (let i = 0; i < node.children.length; i++) {
|
||||||
const child: TreeNode = this.getFs().getNodeByINode(inode);
|
const child: TreeNode = children[i];
|
||||||
|
|
||||||
if (child.name.startsWith('.') && !(f_a || flagInfo.has('A'))) continue;
|
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}`;
|
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.
|
const byteSize: number = node.type === Type.Directory ? 4096 : 1; //TEMP, later calculate the size.
|
||||||
let size: string;
|
let size: string;
|
||||||
if (human) {
|
if (humanReadable) {
|
||||||
size = this.formatBytes(byteSize);
|
size = this.formatBytes(byteSize);
|
||||||
} else size = byteSize.toString();
|
} else size = byteSize.toString();
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export enum SortBy {
|
|||||||
|
|
||||||
export class Sort {
|
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!');
|
if(nodes.length === 0) throw new Error('Tried to sort an empty node array!');
|
||||||
const parsedNodes: TreeNode[] = [];
|
const parsedNodes: TreeNode[] = [];
|
||||||
|
|
||||||
@@ -24,7 +24,13 @@ export class Sort {
|
|||||||
parsedNodes.push(node);
|
parsedNodes.push(node);
|
||||||
}
|
}
|
||||||
Sort.nodeQSort(parsedNodes, reverse, sortBy, 0, parsedNodes.length - 1);
|
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) {
|
private static nodeQSort(array: TreeNode[], reverse: boolean, sortBy: SortBy, start: number, end: number) {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export const GROUP: Group[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
groupname: 'users',
|
groupname: 'users',
|
||||||
gid: 1000,
|
gid: 984,
|
||||||
members: [1001, 1002]
|
members: [1001, 1002]
|
||||||
}
|
}
|
||||||
] as const;
|
] as const;
|
||||||
@@ -50,7 +50,7 @@ export const PASSWD: User[] = [
|
|||||||
{
|
{
|
||||||
username: 'admin',
|
username: 'admin',
|
||||||
passwd: '456',
|
passwd: '456',
|
||||||
uid: 1001,
|
uid: 1000,
|
||||||
gid: 1000,
|
gid: 1000,
|
||||||
home: '/home/admin',
|
home: '/home/admin',
|
||||||
history: [] //TODO: Delete this and declare a new history array when logging the user in.
|
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',
|
username: 'user',
|
||||||
passwd: '789',
|
passwd: '789',
|
||||||
uid: 1002,
|
uid: 1001,
|
||||||
gid: 1000,
|
gid: 1000,
|
||||||
home: '/home/user',
|
home: '/home/user',
|
||||||
history: [] //TODO: Delete this and declare a new history array when logging the user in.
|
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',
|
username: 'kamil',
|
||||||
passwd: '000',
|
passwd: '000',
|
||||||
uid: 1003,
|
uid: 1002,
|
||||||
gid: 1000,
|
gid: 1000,
|
||||||
home: '/home/kamil',
|
home: '/home/kamil',
|
||||||
history: [] //TODO: Delete this and declare a new history array when logging the user in.
|
history: [] //TODO: Delete this and declare a new history array when logging the user in.
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<span class=" pointer self-start pr-2">$</span>
|
<span class=" pointer self-start pr-2">$</span>
|
||||||
<p>{cmd}</p>
|
<p>{cmd}</p>
|
||||||
</div>
|
</div>
|
||||||
<div style="white-space: preserve;" class=" relative wrap-break-word">
|
<div style="white-space: nowrap;" class=" relative">
|
||||||
{#if typeof output === 'string'}
|
{#if typeof output === 'string'}
|
||||||
{output}
|
{output}
|
||||||
{:else if output instanceof Element}
|
{:else if output instanceof Element}
|
||||||
|
|||||||
Reference in New Issue
Block a user