@@ -43,6 +43,9 @@ import { Key } from '@theia/core/lib/browser/keys';
43
43
import { nls } from '@theia/core/lib/common/nls' ;
44
44
import { TerminalMenus } from './terminal-frontend-contribution' ;
45
45
import debounce = require( 'p-debounce' ) ;
46
+ import { MarkdownString , MarkdownStringImpl } from '@theia/core/lib/common/markdown-rendering/markdown-string' ;
47
+ import { EnhancedPreviewWidget } from '@theia/core/lib/browser/widgets/enhanced-preview-widget' ;
48
+ import { MarkdownRenderer , MarkdownRendererFactory } from '@theia/core/lib/browser/markdown-rendering/markdown-renderer' ;
46
49
47
50
export const TERMINAL_WIDGET_FACTORY_ID = 'terminal' ;
48
51
@@ -57,7 +60,7 @@ export interface TerminalContribution {
57
60
}
58
61
59
62
@injectable ( )
60
- export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget , ExtractableWidget {
63
+ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget , ExtractableWidget , EnhancedPreviewWidget {
61
64
readonly isExtractable : boolean = true ;
62
65
secondaryWindow : Window | undefined ;
63
66
location : TerminalLocationOptions ;
@@ -81,6 +84,7 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
81
84
protected lastMousePosition : { x : number , y : number } | undefined ;
82
85
protected isAttachedCloseListener : boolean = false ;
83
86
protected shown = false ;
87
+ protected enhancedPreviewNode : Node | undefined ;
84
88
override lastCwd = new URI ( ) ;
85
89
86
90
@inject ( WorkspaceService ) protected readonly workspaceService : WorkspaceService ;
@@ -98,6 +102,13 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
98
102
@inject ( TerminalThemeService ) protected readonly themeService : TerminalThemeService ;
99
103
@inject ( ShellCommandBuilder ) protected readonly shellCommandBuilder : ShellCommandBuilder ;
100
104
@inject ( ContextMenuRenderer ) protected readonly contextMenuRenderer : ContextMenuRenderer ;
105
+ @inject ( MarkdownRendererFactory ) protected readonly markdownRendererFactory : MarkdownRendererFactory ;
106
+
107
+ protected _markdownRenderer : MarkdownRenderer | undefined ;
108
+ protected get markdownRenderer ( ) : MarkdownRenderer {
109
+ this . _markdownRenderer ||= this . markdownRendererFactory ( ) ;
110
+ return this . _markdownRenderer ;
111
+ }
101
112
102
113
protected readonly onDidOpenEmitter = new Emitter < void > ( ) ;
103
114
readonly onDidOpen : Event < void > = this . onDidOpenEmitter . event ;
@@ -426,6 +437,13 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
426
437
return this . shellTerminalServer . getProcessInfo ( this . terminalId ) ;
427
438
}
428
439
440
+ get envVarCollectionDescriptionsByExtension ( ) : Promise < Map < string , string | MarkdownString | undefined > > {
441
+ if ( ! IBaseTerminalServer . validateId ( this . terminalId ) ) {
442
+ return Promise . reject ( new Error ( 'terminal is not started' ) ) ;
443
+ }
444
+ return this . shellTerminalServer . getEnvVarCollectionDescriptionsByExtension ( this . terminalId ) ;
445
+ }
446
+
429
447
get terminalId ( ) : number {
430
448
return this . _terminalId ;
431
449
}
@@ -762,6 +780,10 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
762
780
if ( this . exitStatus ) {
763
781
this . onTermDidClose . fire ( this ) ;
764
782
}
783
+ if ( this . enhancedPreviewNode ) {
784
+ // don't use preview node anymore. rendered markdown will be disposed on super call
785
+ this . enhancedPreviewNode = undefined ;
786
+ }
765
787
super . dispose ( ) ;
766
788
}
767
789
@@ -867,4 +889,46 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
867
889
private disableEnterWhenAttachCloseListener ( ) : boolean {
868
890
return this . isAttachedCloseListener ;
869
891
}
892
+
893
+ getEnhancedPreviewNode ( ) : Node | undefined {
894
+ if ( this . enhancedPreviewNode ) {
895
+ return this . enhancedPreviewNode ;
896
+ }
897
+
898
+ this . enhancedPreviewNode = document . createElement ( 'div' ) ;
899
+
900
+ Promise . all ( [ this . envVarCollectionDescriptionsByExtension , this . processId , this . processInfo ] )
901
+ . then ( ( values : [ Map < string , string | MarkdownString | undefined > , number , TerminalProcessInfo ] ) => {
902
+ const extensions = values [ 0 ] ;
903
+ const processId = values [ 1 ] ;
904
+ const processInfo = values [ 2 ] ;
905
+
906
+ const markdown = new MarkdownStringImpl ( ) ;
907
+ markdown . appendMarkdown ( 'Process ID: ' + processId + '\\\n' ) ;
908
+ markdown . appendMarkdown ( 'Command line: ' +
909
+ processInfo . executable +
910
+ ' ' +
911
+ processInfo . arguments . join ( ' ' ) +
912
+ '\n\n---\n\n' ) ;
913
+ markdown . appendMarkdown ( 'The following extensions have contributed to this terminal\'s environment:\n' ) ;
914
+ extensions . forEach ( ( value , key ) => {
915
+ if ( value === undefined ) {
916
+ markdown . appendMarkdown ( '* ' + key + '\n' ) ;
917
+ } else if ( typeof value === 'string' ) {
918
+ markdown . appendMarkdown ( '* ' + key + ': ' + value + '\n' ) ;
919
+ } else {
920
+ markdown . appendMarkdown ( '* ' + key + ': ' + value . value + '\n' ) ;
921
+ }
922
+ } ) ;
923
+
924
+ const enhancedPreviewNode = this . enhancedPreviewNode ;
925
+ if ( ! this . isDisposed && enhancedPreviewNode ) {
926
+ const result = this . markdownRenderer . render ( markdown ) ;
927
+ this . toDispose . push ( result ) ;
928
+ enhancedPreviewNode . appendChild ( result . element ) ;
929
+ }
930
+ } ) ;
931
+
932
+ return this . enhancedPreviewNode ;
933
+ }
870
934
}
0 commit comments