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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -22,6 +22,7 @@ export type PrintData = {
|
||||
|
||||
export type PageCallbacks = {
|
||||
print: (data: PrintData) => void;
|
||||
getWidth: () => number;
|
||||
};
|
||||
|
||||
export class Terminal {
|
||||
@@ -86,6 +87,14 @@ export class Terminal {
|
||||
return result;
|
||||
}
|
||||
|
||||
getTerminalWidth(): number {
|
||||
const width = this.callbacks.getWidth?.();
|
||||
if(!width) { throw new Error('somehow width is undefined still after all the checks'); }
|
||||
|
||||
console.log(width);
|
||||
return width;
|
||||
}
|
||||
|
||||
executeCommand(input: string): void {
|
||||
this.bash.updateHistory(input);
|
||||
const parsed: ParsedInput = this._parseInput(input);
|
||||
|
||||
Reference in New Issue
Block a user