Newest Commit - code same as last commit
This commit is contained in:
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
+12
-12
@@ -65,6 +65,16 @@ export class Bash {
|
|||||||
this.vfs = new VirtualFS({ fs: args.fs, user: args.user });
|
this.vfs = new VirtualFS({ fs: args.fs, user: args.user });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _appendNewResult(inode: number, output: any, cmd: string) {
|
||||||
|
const data: PrintData = {
|
||||||
|
path: this.vfs.formatPath(this.vfs.getPathByInode(inode)),
|
||||||
|
output: output,
|
||||||
|
cmd: cmd
|
||||||
|
};
|
||||||
|
console.log(data);
|
||||||
|
this._terminal.PrintOutput(data);
|
||||||
|
}
|
||||||
|
|
||||||
updateHistory(input: string): void {
|
updateHistory(input: string): void {
|
||||||
if ((this.user.history.length = 255)) {
|
if ((this.user.history.length = 255)) {
|
||||||
this.user.history.unshift(...this.user.history.splice(-1));
|
this.user.history.unshift(...this.user.history.splice(-1));
|
||||||
@@ -107,14 +117,14 @@ export class Bash {
|
|||||||
if (command.root) {
|
if (command.root) {
|
||||||
if (this.hasSudoPerms(this.user.uid)) {
|
if (this.hasSudoPerms(this.user.uid)) {
|
||||||
let out: Result = command.method.call(this, args);
|
let out: Result = command.method.call(this, args);
|
||||||
this.appendNewResult(this.getCwd(), out, this.user.history[0]);
|
this._appendNewResult(this.getCwd(), out, this.user.history[0]);
|
||||||
}
|
}
|
||||||
this.throwError(result);
|
this.throwError(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
let out: Result = command.method.call(this, args);
|
let out: Result = command.method.call(this, args);
|
||||||
console.log(out);
|
console.log(out);
|
||||||
this.appendNewResult(out.path, out.data?.data, this.user.history[0]);
|
this._appendNewResult(out.path, out.data?.data, this.user.history[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
throwError(result: Result): void {
|
throwError(result: Result): void {
|
||||||
@@ -134,16 +144,6 @@ export class Bash {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private appendNewResult(inode: number, output: any, cmd: string) {
|
|
||||||
const data: PrintData = {
|
|
||||||
path: this.vfs.formatPath(this.vfs.getPathByInode(inode)),
|
|
||||||
output: output,
|
|
||||||
cmd: cmd
|
|
||||||
};
|
|
||||||
console.log(data);
|
|
||||||
this._terminal.PrintOutput(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
formatBytes(bytes: number, dPoint?: number, pow: 1024 | 1000 = 1024): string {
|
formatBytes(bytes: number, dPoint?: number, pow: 1024 | 1000 = 1024): string {
|
||||||
if (!+bytes) return '0';
|
if (!+bytes) return '0';
|
||||||
|
|
||||||
|
|||||||
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
+8
@@ -110,6 +110,14 @@ export class Terminal {
|
|||||||
return this.bash.getUser();
|
return this.bash.getUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
getCwd(): string {
|
getCwd(): string {
|
||||||
const fs: VirtualFS = this.bash.getFs();
|
const fs: VirtualFS = this.bash.getFs();
|
||||||
console.log(fs.getPathByInode(this.bash.getCwd()));
|
console.log(fs.getPathByInode(this.bash.getCwd()));
|
||||||
|
|||||||
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
+15
-2
@@ -10,6 +10,16 @@
|
|||||||
|
|
||||||
const printOutput = (e: HTMLElement, d: PrintData): void => print(e, d);
|
const printOutput = (e: HTMLElement, d: PrintData): void => print(e, d);
|
||||||
|
|
||||||
|
function getWidth() {
|
||||||
|
const e = document.getElementById('cout');
|
||||||
|
if(!e){
|
||||||
|
throw new Error('cant get width of the teminal element. Its null');
|
||||||
|
}
|
||||||
|
const padding: number = parseInt(window.getComputedStyle(e, null).getPropertyValue('padding').slice(0, -2));
|
||||||
|
console.log(padding);
|
||||||
|
return e.clientWidth - (padding * 2);
|
||||||
|
}
|
||||||
|
|
||||||
function updateTerminal() {
|
function updateTerminal() {
|
||||||
username = terminal!.getUser().username;
|
username = terminal!.getUser().username;
|
||||||
cwd = terminal!.getCwd();
|
cwd = terminal!.getCwd();
|
||||||
@@ -47,7 +57,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let callbackInit = {
|
//Callback initializer
|
||||||
|
const callbackInit = {
|
||||||
print: (data: any) => {
|
print: (data: any) => {
|
||||||
const e = document.getElementById('outputWrapper');
|
const e = document.getElementById('outputWrapper');
|
||||||
if (!e) return;
|
if (!e) return;
|
||||||
@@ -56,6 +67,7 @@
|
|||||||
getWidth: getWidth
|
getWidth: getWidth
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//Test user with basic data so the bash can run
|
||||||
let testUser: User = {
|
let testUser: User = {
|
||||||
username: 'kamil',
|
username: 'kamil',
|
||||||
passwd: '123',
|
passwd: '123',
|
||||||
@@ -65,6 +77,7 @@
|
|||||||
history: []
|
history: []
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//Empty terminal variable where the terminal class instance will be stored
|
||||||
let terminal: Terminal;
|
let terminal: Terminal;
|
||||||
let username: string = $state(testUser.username);
|
let username: string = $state(testUser.username);
|
||||||
let cwd: string = $state(testUser.home);
|
let cwd: string = $state(testUser.home);
|
||||||
@@ -82,7 +95,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<label for="input" onkeydowncapture={(e) => handleInput(e)}>
|
<label for="input" onkeydowncapture={(e) => handleInput(e)}>
|
||||||
<div id="terminal" class="terminal-window shadow-() size-full resize rounded-md shadow-bg">
|
<div id="terminal" class="terminal-window shadow-() size-full rounded-md shadow-bg">
|
||||||
<div
|
<div
|
||||||
class="terminal-bar flex h-9 w-full flex-row items-center rounded-t-md bg-bg-dark text-center font-terminal text-sm font-bold text-primary-dark light:bg-bg-dark-light light:text-primary-light"
|
class="terminal-bar flex h-9 w-full flex-row items-center rounded-t-md bg-bg-dark text-center font-terminal text-sm font-bold text-primary-dark light:bg-bg-dark-light light:text-primary-light"
|
||||||
>
|
>
|
||||||
|
|||||||
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Reference in New Issue
Block a user