Start of binary search for ls command
This commit is contained in:
32
package-lock.json
generated
32
package-lock.json
generated
@@ -1195,9 +1195,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@sveltejs/kit": {
|
||||
"version": "2.48.4",
|
||||
"resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.48.4.tgz",
|
||||
"integrity": "sha512-TGFX1pZUt9qqY20Cv5NyYvy0iLWHf2jXi8s+eCGsig7jQMdwZWKUFMR6TbvFNhfDSUpc1sH/Y5EHv20g3HHA3g==",
|
||||
"version": "2.50.2",
|
||||
"resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.50.2.tgz",
|
||||
"integrity": "sha512-875hTUkEbz+MyJIxWbQjfMaekqdmEKUUfR7JyKcpfMRZqcGyrO9Gd+iS1D/Dx8LpE5FEtutWGOtlAh4ReSAiOA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
@@ -1207,13 +1207,13 @@
|
||||
"@types/cookie": "^0.6.0",
|
||||
"acorn": "^8.14.1",
|
||||
"cookie": "^0.6.0",
|
||||
"devalue": "^5.3.2",
|
||||
"devalue": "^5.6.2",
|
||||
"esm-env": "^1.2.2",
|
||||
"kleur": "^4.1.5",
|
||||
"magic-string": "^0.30.5",
|
||||
"mrmime": "^2.0.0",
|
||||
"sade": "^1.8.1",
|
||||
"set-cookie-parser": "^2.6.0",
|
||||
"set-cookie-parser": "^3.0.0",
|
||||
"sirv": "^3.0.0"
|
||||
},
|
||||
"bin": {
|
||||
@@ -1226,11 +1226,15 @@
|
||||
"@opentelemetry/api": "^1.0.0",
|
||||
"@sveltejs/vite-plugin-svelte": "^3.0.0 || ^4.0.0-next.1 || ^5.0.0 || ^6.0.0-next.0",
|
||||
"svelte": "^4.0.0 || ^5.0.0-next.0",
|
||||
"typescript": "^5.3.3",
|
||||
"vite": "^5.0.3 || ^6.0.0 || ^7.0.0-beta.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@opentelemetry/api": {
|
||||
"optional": true
|
||||
},
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -2401,9 +2405,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/devalue": {
|
||||
"version": "5.4.2",
|
||||
"resolved": "https://registry.npmjs.org/devalue/-/devalue-5.4.2.tgz",
|
||||
"integrity": "sha512-MwPZTKEPK2k8Qgfmqrd48ZKVvzSQjgW0lXLxiIBA8dQjtf/6mw6pggHNLcyDKyf+fI6eXxlQwPsfaCMTU5U+Bw==",
|
||||
"version": "5.6.2",
|
||||
"resolved": "https://registry.npmjs.org/devalue/-/devalue-5.6.2.tgz",
|
||||
"integrity": "sha512-nPRkjWzzDQlsejL1WVifk5rvcFi/y1onBRxjaFMjZeR9mFpqu2gmAZ9xUB9/IEanEP/vBtGeGganC/GO1fmufg==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
@@ -3042,9 +3046,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/js-yaml": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
|
||||
"integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==",
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.1.tgz",
|
||||
"integrity": "sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -4156,9 +4160,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/set-cookie-parser": {
|
||||
"version": "2.7.2",
|
||||
"resolved": "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-2.7.2.tgz",
|
||||
"integrity": "sha512-oeM1lpU/UvhTxw+g3cIfxXHyJRc/uidd3yK1P242gzHds0udQBYzs3y8j4gCCW+ZJ7ad0yctld8RYO+bdurlvw==",
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-3.0.1.tgz",
|
||||
"integrity": "sha512-n7Z7dXZhJbwuAHhNzkTti6Aw9QDDjZtm3JTpTGATIdNzdQz5GuFs22w90BcvF4INfnrL5xrX3oGsuqO5Dx3A1Q==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
|
||||
@@ -105,6 +105,10 @@ export class Bash {
|
||||
return this._terminal.getTerminalWidth();
|
||||
}
|
||||
|
||||
getTerminalFontSize(): number {
|
||||
return this._terminal.getFontSize();
|
||||
}
|
||||
|
||||
hasSudoPerms(uid: number): boolean {
|
||||
return this._group[1].members.includes(uid);
|
||||
}
|
||||
|
||||
@@ -227,9 +227,24 @@ function result_ls(this: Bash, data: any, args: CommandArgs): HTMLElement {
|
||||
return w;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return dummysonoerror; //TEMP SO NO ERROR CUZ RETURNS HTMLElement EVERY TIME, DELETE LATER
|
||||
}
|
||||
|
||||
function checkMaxColumns(this: Bash, files: TreeNode[]) {
|
||||
const paddingWidth: number = 2;
|
||||
const maxWidth: number = (this.getTerminalWidth() / this.getTerminalFontSize()) * 0.8;
|
||||
|
||||
|
||||
//Upper bound set to max width / min column width - 1 character + padding
|
||||
let lowBound: number = 1;
|
||||
let highBound: number = Math.floor(maxWidth / (1 + paddingWidth));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function isValidNodeSortMethod(value: string): value is SortNodeBy {
|
||||
return Object.values(SortNodeBy).includes(value as SortNodeBy);
|
||||
}
|
||||
|
||||
48
src/lib/stores/bash/search.ts
Normal file
48
src/lib/stores/bash/search.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import type { Bash } from "./bash";
|
||||
import type { TreeNode } from "./fs";
|
||||
|
||||
export class Search {
|
||||
|
||||
public static nodeBinarySearch(
|
||||
this: Bash,
|
||||
nodes: TreeNode[],
|
||||
max: number
|
||||
): number {
|
||||
let low: number = 1;
|
||||
let high: number = nodes.length;
|
||||
let c: number = (low + high) / 2;
|
||||
const nameLengths: number[] = nodes.map(node => node.name.length);
|
||||
|
||||
}
|
||||
|
||||
private static binarySearchDNC(
|
||||
n: number,
|
||||
nameLengths: number[],
|
||||
low: number,
|
||||
high: number,
|
||||
max: number): number {
|
||||
|
||||
let c: number = (low + high) / 2;
|
||||
|
||||
if(low + 1 < high) {
|
||||
for(let i = 0; i < c; i++) {
|
||||
const colSize: number =
|
||||
i < (n % c) ? n : n -1;
|
||||
}
|
||||
|
||||
const calculatedWidth: number =
|
||||
nameLengths.reduce((result, value) => result + value) + (c-1) * 2
|
||||
|
||||
if (calculatedWidth <= max) {
|
||||
low = c;
|
||||
return c;
|
||||
}
|
||||
else {
|
||||
high = c;
|
||||
}
|
||||
|
||||
this.binarySearchDNC(n, nameLengths, low, high, max);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ export type PrintData = {
|
||||
export type PageCallbacks = {
|
||||
print: (data: PrintData) => void;
|
||||
getWidth: () => number;
|
||||
getFontSize: () => number;
|
||||
};
|
||||
|
||||
export class Terminal {
|
||||
@@ -110,6 +111,14 @@ export class Terminal {
|
||||
return width;
|
||||
}
|
||||
|
||||
getFontSize(): number {
|
||||
const size = this.callbacks.getFontSize?.();
|
||||
if(!size) { throw new Error('somehow font size is undefined still after all the checks'); }
|
||||
|
||||
console.log(size);
|
||||
return size;
|
||||
}
|
||||
|
||||
getCwd(): string {
|
||||
const fs: VirtualFS = this.bash.getFs();
|
||||
console.log(fs.getPathByInode(this.bash.getCwd()));
|
||||
|
||||
@@ -20,11 +20,21 @@
|
||||
if(!e){
|
||||
throw new Error('cant get width of the teminal element. Its null');
|
||||
}
|
||||
//gets an int from padding property value (which is a string) by cutting last 2 letters "px" and parsing to int
|
||||
const padding: number = parseInt(window.getComputedStyle(e, null).getPropertyValue('padding').slice(0, -2));
|
||||
console.log(padding);
|
||||
return e.clientWidth - (padding * 2);
|
||||
}
|
||||
|
||||
function getFontSize() {
|
||||
const e = document.getElementById('cout');
|
||||
if(!e) {
|
||||
throw new Error('cant get font size of the terminal element. its null');
|
||||
}
|
||||
const size: number = parseInt(window.getComputedStyle(e, null).getPropertyValue('font-size').slice(0, -2));
|
||||
return size;
|
||||
}
|
||||
|
||||
function handleInput(e: KeyboardEvent) {
|
||||
switch (e.key) {
|
||||
case 'Enter': {
|
||||
@@ -54,7 +64,8 @@
|
||||
if (!e) return;
|
||||
printOutput(e, data);
|
||||
},
|
||||
getWidth: getWidth
|
||||
getWidth: getWidth,
|
||||
getFontSize: getFontSize
|
||||
};
|
||||
|
||||
//Test user with basic data so the bash can run
|
||||
|
||||
Reference in New Issue
Block a user