import { Inject , Injectable } from '@angular/core' ; import { ConfigService , PlatformService } from 'tabby-core' ; import { TerminalDecorator , BaseTerminalTabComponent } from 'tabby-terminal' ; import { LinkHandler } from './api' ; @ Injectable ( ) export class LinkHighlighterDecorator extends TerminalDecorator { constructor ( private config , private platform , @ Inject ( LinkHandler ) private handlers ) { super ( ) ; } attach ( tab ) { if ( ! ( tab . frontend as any ) . xterm ) { return ; } for ( let handler of this . handlers ) { const getLink = async ( uri ) => handler . convert ( uri , tab ) ; const openLink = async ( uri ) => handler . handle ( await getLink ( uri ) , tab ) ; ( tab . frontend as any ) . xterm . registerLinkMatcher ( handler . regex , ( event , uri ) => { if ( ! this . willHandleEvent ( event ) ) { return ; } openLink ( uri ) ; } , { priority : handler . priority , validationCallback : async ( uri , callback ) => { callback ( await handler . verify ( await handler . convert ( uri , tab ) , tab ) ) ; } , willLinkActivate : ( event , uri ) => { if ( event . button === 2 ) { this . platform . popupContextMenu ( [ { click : ( ) => openLink ( uri ) , label : 'Open' , } , { click : async ( ) => { this . platform . setClipboard ( { text : await getLink ( uri ) } ) ; } , label : 'Copy' , } , ] ) ; return false ; } return this . willHandleEvent ( event ) ; } , } ) ; } } private willHandleEvent ( event ) { const modifier = this . config . store . clickableLinks . modifier ; return ! modifier || event [ modifier ] ; } }