@@ -651,7 +651,7 @@ function installCLIProxy(context: vscode.ExtensionContext, output: vscode.Output
651651
652652type TerminalOpenMode = 'tab-before' | 'tab-after' | 'split-left' | 'split-right' | 'split-top' | 'split-bottom' ;
653653
654- export async function registerTasks ( context : GitpodExtensionContext ) : Promise < void > {
654+ export async function registerTasks ( context : GitpodExtensionContext , createTerminal : ( options : vscode . ExtensionTerminalOptions , parent : vscode . Terminal | undefined ) => vscode . Terminal ) : Promise < void > {
655655 const tokenSource = new vscode . CancellationTokenSource ( ) ;
656656 const token = tokenSource . token ;
657657 context . subscriptions . push ( {
@@ -698,30 +698,42 @@ export async function registerTasks(context: GitpodExtensionContext): Promise<vo
698698 return ;
699699 }
700700
701- const terminals = new Map < string , SupervisorTerminal > ( ) ;
701+ const taskTerminals = new Map < string , SupervisorTerminal > ( ) ;
702702 try {
703703 const response = await util . promisify ( context . supervisor . terminal . list . bind ( context . supervisor . terminal , new ListTerminalsRequest ( ) , context . supervisor . metadata , {
704704 deadline : Date . now ( ) + context . supervisor . deadlines . long
705705 } ) ) ( ) ;
706- for ( const terminal of response . getTerminalsList ( ) ) {
707- terminals . set ( terminal . getAlias ( ) , terminal ) ;
706+ for ( const term of response . getTerminalsList ( ) ) {
707+ taskTerminals . set ( term . getAlias ( ) , term ) ;
708708 }
709709 } catch ( e ) {
710- console . error ( 'failed to list terminals:' , e ) ;
710+ console . error ( 'failed to list task terminals:' , e ) ;
711711 }
712712
713713 let prevTerminal : vscode . Terminal | undefined ;
714714 for ( const [ alias , taskStatus ] of tasks . entries ( ) ) {
715- const terminal = terminals . get ( alias ) ;
716- if ( terminal ) {
715+ const taskTerminal = taskTerminals . get ( alias ) ;
716+ if ( taskTerminal ) {
717717 const openMode : TerminalOpenMode | undefined = taskStatus . getPresentation ( ) ?. getOpenMode ( ) as TerminalOpenMode ;
718- let parentTerminal = ( openMode && openMode !== 'tab-before' && openMode !== 'tab-after' ) ? prevTerminal : undefined ;
719- prevTerminal = registerTask ( alias , terminal . getTitle ( ) , context , token , parentTerminal ) ;
718+ const parentTerminal = ( openMode && openMode !== 'tab-before' && openMode !== 'tab-after' ) ? prevTerminal : undefined ;
719+ const pty = createTaskPty ( alias , context , token ) ;
720+
721+ // Delegate creation of the terminal to the extension caller
722+ // if proposed API usage is required.
723+ const terminal = createTerminal (
724+ {
725+ name : taskTerminal . getTitle ( ) ,
726+ pty
727+ } ,
728+ parentTerminal
729+ ) ;
730+ terminal . show ( ) ;
731+ prevTerminal = terminal ;
720732 }
721733 }
722734}
723735
724- function registerTask ( alias : string , initialTitle : string , context : GitpodExtensionContext , contextToken : vscode . CancellationToken , parentTerminal ?: vscode . Terminal ) : vscode . Terminal {
736+ function createTaskPty ( alias : string , context : GitpodExtensionContext , contextToken : vscode . CancellationToken ) : vscode . Pseudoterminal {
725737 const tokenSource = new vscode . CancellationTokenSource ( ) ;
726738 contextToken . onCancellationRequested ( ( ) => tokenSource . cancel ( ) ) ;
727739 const token = tokenSource . token ;
@@ -876,16 +888,5 @@ function registerTask(alias: string, initialTitle: string, context: GitpodExtens
876888 }
877889 } ;
878890
879- let proposedOptions = vscode . env . uiKind === vscode . UIKind . Web ? {
880- location : parentTerminal ? { parentTerminal } : 1 /* vscode.TerminalLocation.Panel */
881- } : { } ;
882- proposedOptions = { } ; // TODO: enable this
883- const terminal = vscode . window . createTerminal ( {
884- name : initialTitle ,
885- pty,
886- ...proposedOptions
887- } ) ;
888- terminal . show ( ) ;
889-
890- return terminal ;
891+ return pty ;
891892}
0 commit comments