import { Directive, HostListener, EventEmitter, Output } from '@angular/core'; import { KeySet, ForbiddenInput } from './classes'; @Directive({ selector: '[ang-only-ansi-alphabet]' }) export class OnlyAnsiAlphabetDirective { keyset = new KeySet().alphabet().modifiers().interactors(); @Output('ang-only-ansi-alphabet') forbiddenInput = new EventEmitter(); @HostListener('keydown', ['$event']) whileTyping(e: KeyboardEvent){ const forbidden = !this.keyset.has(e.key) if(forbidden){ !e.repeat && this.forbiddenInput.emit(new ForbiddenInput(e)) return false; } } }