Skip to content

Commit

Permalink
cd in prog
Browse files Browse the repository at this point in the history
  • Loading branch information
chinonso098 committed Jul 18, 2024
1 parent 6260b82 commit a4b0646
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { HighlightDirective } from './system-apps/window/window.btn.highlight.di
import { TaskBarEntryHighlightDirective } from './system-apps/taskbarentries/taskbar.entry.highlight.directives';
import { LongPressDirective } from './system-apps/audioplayer/long.press.directive';
import { ColumnResizeDirective } from './system-apps/taskmanager/taskmanager.column-resize.directive';
import { KeyPressCaptureDirective } from './system-apps/terminal/key.press.capture.directive';


@NgModule({
Expand Down Expand Up @@ -78,6 +79,7 @@ import { ColumnResizeDirective } from './system-apps/taskmanager/taskmanager.col
TaskBarEntryHighlightDirective,
LongPressDirective,
ColumnResizeDirective,
KeyPressCaptureDirective,

SafeUrlPipe,
TruncatePipe
Expand Down
36 changes: 36 additions & 0 deletions src/app/system-apps/terminal/key.press.capture.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Directive, ElementRef, Output, EventEmitter, OnInit, OnDestroy } from '@angular/core';
import { fromEvent, Subscription } from 'rxjs';
import { buffer, debounceTime, filter } from 'rxjs/operators';

@Directive({
// eslint-disable-next-line @angular-eslint/directive-selector
selector: '[appKeyPressCapture]'
})
export class KeyPressCaptureDirective implements OnInit, OnDestroy {
@Output() keyDblPressed = new EventEmitter<KeyboardEvent>();
private keyPressSubscription!: Subscription;

constructor(private el: ElementRef) {}

ngOnInit() {
const keyPress$ = fromEvent<KeyboardEvent>(this.el.nativeElement, 'keydown');

this.keyPressSubscription = keyPress$
.pipe(
buffer(keyPress$.pipe(debounceTime(300))),
filter(events => events.length === 2)
)
.subscribe(events => {
//console.log('events-keyPress$:', events );
//this.keyDblPressed.emit(events.length);
if(events[0].key === events[1].key)
this.keyDblPressed.emit(events[0]);
});
}

ngOnDestroy() {
if (this.keyPressSubscription) {
this.keyPressSubscription.unsubscribe();
}
}
}
4 changes: 2 additions & 2 deletions src/app/system-apps/terminal/terminal.commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,11 @@ All commands:

console.log('impliedPath:',impliedPath);
console.log('explicitPath:',explicitPath);
console.log('directory:',directory);
console.log('directory-1:',directory);
}else{
if(!arg0.includes(this.defaultDirectoryPath))
directory = `${this.currentDirectoryPath}/${arg0}`;
console.log('directory:',directory);
console.log('directory-2:',directory);
}

const result = await this._fileService.checkIfFileOrFolderExistsAsync(directory);
Expand Down
2 changes: 2 additions & 0 deletions src/app/system-apps/terminal/terminal.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@
<form [formGroup]="terminalForm" class="terminal-form">
<span class="terminal-prompt">{{terminalPrompt}}</span>
<input
appKeyPressCapture
class="terminal-input"
formControlName="terminalCmd"
(keydown)="onKeyDownInInputBox($event)"
(keyDblPressed)="onKeyDoublePressed($event)"
autofocus ="false"
spellcheck="false"
autocomplete="off"
Expand Down
76 changes: 71 additions & 5 deletions src/app/system-apps/terminal/terminal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,73 @@ export class TerminalComponent implements BaseComponent, OnInit, AfterViewInit,
},this.SECONDS_DELAY[1]);
}

async onKeyDoublePressed(evt: KeyboardEvent): Promise<void> {
console.log(`${evt.key} Key pressed rapidly.`);
// Handle the rapid key presses here
if(evt.key == "Tab"){
const cmdString = this.terminalForm.value.terminalCmd as string;
const cmdStringArr = cmdString.split(" ");

const rootCmd = cmdStringArr[0];
const rootArg = cmdStringArr[1];

console.log('rootCmd:',rootCmd);

/**
* the command part of the command string, can not be undefined, must have a length greater than 0, and cannot contain space
*/
if(rootCmd !== undefined && rootCmd.length > 0 && !rootCmd.includes(" ")){
if(!this.allCommands.includes(rootCmd)){

const autoCmpltReslt = this.getAutoCompelete(rootCmd, this.allCommands);

if(autoCmpltReslt.length <= 1){
this.terminalForm.setValue({terminalCmd: autoCmpltReslt[0]});
}else{
const terminalCommand = new TerminalCommand(cmdString, 0, " ");
terminalCommand.setResponseCode = this.Options;
terminalCommand.setCommandOutput = autoCmpltReslt.join(" ");
this.commandHistory.push(terminalCommand);
}

}
}

if(rootCmd === "cd"){
console.log('rootArg:',rootArg);

const terminalCommand = new TerminalCommand(cmdString, 0, " ");
await this.processCommand(terminalCommand).then(() =>{

const autoCmpltReslt = this.getAutoCompelete(rootArg, this.generatedArguments);

console.log('autoCmpltReslt:',autoCmpltReslt);
console.log('this.generatedArguments:',this.generatedArguments);

if(rootArg){
if(autoCmpltReslt.length === 1){
this.terminalForm.setValue({terminalCmd: `${rootCmd} ${autoCmpltReslt[0]}`});
}else{
terminalCommand.setResponseCode = this.Options;
terminalCommand.setCommandOutput = autoCmpltReslt.join(" ") || this.generatedArguments.join(" ");
this.commandHistory.push(terminalCommand);
}
}else{
terminalCommand.setResponseCode = this.Options;
terminalCommand.setCommandOutput = this.generatedArguments.join(" ");
this.commandHistory.push(terminalCommand);
}


});
}


evt.preventDefault();
}
}


onKeyDownInInputBox(evt:KeyboardEvent):void{

if(evt.key == "Enter"){
Expand Down Expand Up @@ -237,7 +304,7 @@ export class TerminalComponent implements BaseComponent, OnInit, AfterViewInit,

const autoCmpltReslt = this.getAutoCompelete(rootCmd, this.allCommands);

if(autoCmpltReslt.length <= 1){
if(autoCmpltReslt.length === 1){
this.terminalForm.setValue({terminalCmd: autoCmpltReslt[0]});
}else{
const terminalCommand = new TerminalCommand(cmdString, 0, " ");
Expand All @@ -259,9 +326,7 @@ export class TerminalComponent implements BaseComponent, OnInit, AfterViewInit,
// this.terminalForm.setValue({terminalCmd:`${rootCmd} ${this.getAutoCompelete(rootArg, this.generatedArguments)}`});
// }

if(rootCmd == "cd"){

}else if(rootCmd !== "cd" && !this.generatedArguments.includes(rootArg)){
if(!this.generatedArguments.includes(rootArg)){

const autoCmpltReslt = this.getAutoCompelete(rootArg, this.generatedArguments);

Expand Down Expand Up @@ -396,7 +461,7 @@ export class TerminalComponent implements BaseComponent, OnInit, AfterViewInit,

if(result.type === str)
terminalCmd.setCommandOutput = result.result;
else{
else if(result.type === strArr){
this.generatedArguments = [];
this.generatedArguments = [...result.result as string[]];
}
Expand All @@ -408,6 +473,7 @@ export class TerminalComponent implements BaseComponent, OnInit, AfterViewInit,

console.log('ls result:', result)
terminalCmd.setCommandOutput = result.join(' ');
this.generatedArguments = [];
this.generatedArguments = [...result];
}

Expand Down

0 comments on commit a4b0646

Please sign in to comment.