added getWidth method to bash and terminal + callbackf unction on the end for width rertival and calculations in the ls command

This commit is contained in:
2026-01-02 16:52:20 +01:00
parent 582eb68139
commit 7852a77a7c
5 changed files with 74 additions and 53 deletions

View File

@@ -91,6 +91,10 @@ export class Bash {
return this.vfs;
}
getTerminalWidth(): number {
return this._terminal.getTerminalWidth();
}
hasSudoPerms(uid: number): boolean {
return this._group[1].members.includes(uid);
}

View File

@@ -206,14 +206,12 @@ function result_ls(this: Bash, data: any, args: CommandArgs): HTMLElement {
rows.push('\n');
}
if(shouldShift) {
for(const row of rows) {
const name: string = row[row.length - 1];
if(!name.startsWith('"') || !name.startsWith("'"))
name.padStart(1, ' ');
else continue;
}
}
for(const row of rows) {
const name: string = row[row.length - 1];
if(!name.startsWith('"') || !name.startsWith("'"))
name.padStart(1, ' ');
else continue;
}
for (let i = 0; i < rows.length; i++) {
const p: HTMLElement = document.createElement('p');
@@ -270,7 +268,16 @@ function formatOwners(this: Bash, node: TreeNode, flag: any): string {
}
function formatPermission(node: TreeNode): string {
return `${node.type === Type.Directory ? 'd' : '-'}${parsePerms(node.permission)}`;
switch(node.type) {
case Type.Directory:
return `d${parsePerms(node.permission)}`;
case Type.File:
return `-${parsePerms(node.permission)}`;
case Type.SymbolicLink:
return `l${parsePerms(node.permission)}`;
default:
throw new Error(`Node of unexpected type - ${node.type}`);
}
}
function formatChildren(node: TreeNode): string {