import { inject , injectable } from 'inversify' ; import { Uri } from 'vscode' ; import { IServiceContainer } from '../../ioc/types' ; import { IWorkspaceService } from '../application/types' ; import { TerminalService } from './service' ; import { ITerminalService , ITerminalServiceFactory } from './types' ; @ injectable ( ) export class TerminalServiceFactory implements ITerminalServiceFactory { private terminalServices : Map < string , ITerminalService > ; constructor ( @ inject ( IServiceContainer ) private serviceContainer ) { this . terminalServices = new Map < string , ITerminalService > ( ) ; } public getTerminalService ( resource ? , title ? ) { const terminalTitle = typeof title === 'string' && title . trim ( ) . length > 0 ? title . trim ( ) : 'Python' ; const id = this . getTerminalId ( terminalTitle , resource ) ; if ( ! this . terminalServices . has ( id ) ) { const terminalService = new TerminalService ( this . serviceContainer , terminalTitle ) ; this . terminalServices . set ( id , terminalService ) ; } return this . terminalServices . get ( id ) ! ; } public createTerminalService ( _resource ? , title ? ) { const terminalTitle = typeof title === 'string' && title . trim ( ) . length > 0 ? title . trim ( ) : 'Python' ; return new TerminalService ( this . serviceContainer , terminalTitle ) ; } private getTerminalId ( title , resource ? ) { if ( ! resource ) { return title ; } const workspaceFolder = this . serviceContainer . get < IWorkspaceService > ( IWorkspaceService ) . getWorkspaceFolder ( resource ! ) ; return workspaceFolder ? `${ title }:${ workspaceFolder . uri . fsPath }` : title ; } }