diff --git a/src/app/app.module.ts b/src/app/app.module.ts index af8ab963..e27d8137 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -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({ @@ -78,6 +79,7 @@ import { ColumnResizeDirective } from './system-apps/taskmanager/taskmanager.col TaskBarEntryHighlightDirective, LongPressDirective, ColumnResizeDirective, + KeyPressCaptureDirective, SafeUrlPipe, TruncatePipe diff --git a/src/app/system-apps/terminal/key.press.capture.directive.ts b/src/app/system-apps/terminal/key.press.capture.directive.ts new file mode 100644 index 00000000..66b11831 --- /dev/null +++ b/src/app/system-apps/terminal/key.press.capture.directive.ts @@ -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(); + private keyPressSubscription!: Subscription; + + constructor(private el: ElementRef) {} + + ngOnInit() { + const keyPress$ = fromEvent(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(); + } + } +} diff --git a/src/app/system-apps/terminal/terminal.commands.ts b/src/app/system-apps/terminal/terminal.commands.ts index 55215d7a..c3cf21b4 100644 --- a/src/app/system-apps/terminal/terminal.commands.ts +++ b/src/app/system-apps/terminal/terminal.commands.ts @@ -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); diff --git a/src/app/system-apps/terminal/terminal.component.html b/src/app/system-apps/terminal/terminal.component.html index 64f27a25..3f96c1c8 100644 --- a/src/app/system-apps/terminal/terminal.component.html +++ b/src/app/system-apps/terminal/terminal.component.html @@ -50,9 +50,11 @@
{{terminalPrompt}} { + 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"){ @@ -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, " "); @@ -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); @@ -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[]]; } @@ -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]; }