@@ -25,10 +25,6 @@ import { createCodeCell, createMarkdownCell } from '../../../datascience-ui/comm
25
25
import { MARKDOWN_LANGUAGE , PYTHON_LANGUAGE } from '../../common/constants' ;
26
26
import { traceError , traceWarning } from '../../logging' ;
27
27
import { CellState , ICell , INotebookModel } from '../types' ;
28
- // tslint:disable-next-line: no-var-requires no-require-imports
29
- const ansiToHtml = require ( 'ansi-to-html' ) ;
30
- // tslint:disable-next-line: no-var-requires no-require-imports
31
- const ansiRegex = require ( 'ansi-regex' ) ;
32
28
33
29
/**
34
30
* Converts a NotebookModel into VSCode friendly format.
@@ -200,43 +196,14 @@ function isImagePngOrJpegMimeType(mimeType: string) {
200
196
return mimeType === 'image/png' || mimeType === 'image/jpeg' ;
201
197
}
202
198
function translateStreamOutput ( output : nbformat . IStream ) : CellStreamOutput | CellDisplayOutput {
203
- const text = concatMultilineStringOutput ( output . text ) ;
204
- const hasAngleBrackets = text . includes ( '<' ) ;
205
- const hasAnsiChars = ansiRegex ( ) . test ( text ) ;
206
-
207
- if ( ! hasAngleBrackets && ! hasAnsiChars ) {
208
- // Plain text output.
209
- return {
210
- outputKind : vscodeNotebookEnums . CellOutputKind . Text ,
211
- text
212
- } ;
213
- }
214
-
215
- // Format the output, but ensure we have the plain text output as well.
216
- const richOutput : CellDisplayOutput = {
199
+ // Do not return as `CellOutputKind.Text`. VSC will not translate ascii output correctly.
200
+ // Instead format the output as rich.
201
+ return {
217
202
outputKind : vscodeNotebookEnums . CellOutputKind . Rich ,
218
203
data : {
219
- [ 'text/plain' ] : text
204
+ [ 'text/plain' ] : concatMultilineStringOutput ( output . text )
220
205
}
221
206
} ;
222
-
223
- if ( hasAngleBrackets ) {
224
- // Stream output needs to be wrapped in xmp so it
225
- // show literally. Otherwise < chars start a new html element.
226
- richOutput . data [ 'text/html' ] = `<xmp>${ text } </xmp>` ;
227
- }
228
- if ( hasAnsiChars ) {
229
- // ansiToHtml is different between the tests running and webpack. figure out which one
230
- try {
231
- const ctor = ansiToHtml instanceof Function ? ansiToHtml : ansiToHtml . default ;
232
- const converter = new ctor ( getAnsiToHtmlOptions ( ) ) ;
233
- richOutput . data [ 'text/html' ] = converter . toHtml ( text ) ;
234
- } catch ( ex ) {
235
- traceError ( `Failed to convert Ansi text to HTML, ${ text } ` , ex ) ;
236
- }
237
- }
238
-
239
- return richOutput ;
240
207
}
241
208
export function translateErrorOutput ( output : nbformat . IError ) : CellErrorOutput {
242
209
return {
@@ -246,48 +213,3 @@ export function translateErrorOutput(output: nbformat.IError): CellErrorOutput {
246
213
traceback : output . traceback
247
214
} ;
248
215
}
249
-
250
- function getAnsiToHtmlOptions ( ) : { fg : string ; bg : string ; colors : string [ ] } {
251
- // Here's the default colors for ansiToHtml. We need to use the
252
- // colors from our current theme.
253
- // const colors = {
254
- // 0: '#000',
255
- // 1: '#A00',
256
- // 2: '#0A0',
257
- // 3: '#A50',
258
- // 4: '#00A',
259
- // 5: '#A0A',
260
- // 6: '#0AA',
261
- // 7: '#AAA',
262
- // 8: '#555',
263
- // 9: '#F55',
264
- // 10: '#5F5',
265
- // 11: '#FF5',
266
- // 12: '#55F',
267
- // 13: '#F5F',
268
- // 14: '#5FF',
269
- // 15: '#FFF'
270
- // };
271
- return {
272
- fg : 'var(--vscode-terminal-foreground)' ,
273
- bg : 'var(--vscode-terminal-background)' ,
274
- colors : [
275
- 'var(--vscode-terminal-ansiBlack)' , // 0
276
- 'var(--vscode-terminal-ansiBrightRed)' , // 1
277
- 'var(--vscode-terminal-ansiGreen)' , // 2
278
- 'var(--vscode-terminal-ansiYellow)' , // 3
279
- 'var(--vscode-terminal-ansiBrightBlue)' , // 4
280
- 'var(--vscode-terminal-ansiMagenta)' , // 5
281
- 'var(--vscode-terminal-ansiCyan)' , // 6
282
- 'var(--vscode-terminal-ansiBrightBlack)' , // 7
283
- 'var(--vscode-terminal-ansiWhite)' , // 8
284
- 'var(--vscode-terminal-ansiRed)' , // 9
285
- 'var(--vscode-terminal-ansiBrightGreen)' , // 10
286
- 'var(--vscode-terminal-ansiBrightYellow)' , // 11
287
- 'var(--vscode-terminal-ansiBlue)' , // 12
288
- 'var(--vscode-terminal-ansiBrightMagenta)' , // 13
289
- 'var(--vscode-terminal-ansiBrightCyan)' , // 14
290
- 'var(--vscode-terminal-ansiBrightWhite)' // 15
291
- ]
292
- } ;
293
- }
0 commit comments