5
5
6
6
import { handleANSIOutput } from './ansi' ;
7
7
8
- function generateViewMoreElement ( outputId : string ) {
8
+ function generateViewMoreElement ( outputId : string , adjustableSize : boolean ) {
9
9
const container = document . createElement ( 'span' ) ;
10
10
const first = document . createElement ( 'span' ) ;
11
- first . textContent = 'Output exceeds the ' ;
12
- const second = document . createElement ( 'a' ) ;
13
- second . textContent = 'size limit' ;
14
- second . href = `command:workbench.action.openSettings?%5B%22notebook.output.textLineLimit%22%5D` ;
11
+
12
+ if ( adjustableSize ) {
13
+ first . textContent = 'Output exceeds the ' ;
14
+ const second = document . createElement ( 'a' ) ;
15
+ second . textContent = 'size limit' ;
16
+ second . href = `command:workbench.action.openSettings?%5B%22notebook.output.textLineLimit%22%5D` ;
17
+ container . appendChild ( first ) ;
18
+ container . appendChild ( second ) ;
19
+ } else {
20
+ first . textContent = 'Output exceeds the maximium size limit' ;
21
+ container . appendChild ( first ) ;
22
+ }
23
+
15
24
const third = document . createElement ( 'span' ) ;
16
- third . textContent = '. Enable scrolling in the settings, or open the full output data ' ;
25
+ third . textContent = '. Open the full output data ' ;
17
26
const forth = document . createElement ( 'a' ) ;
18
27
forth . textContent = 'in a text editor' ;
19
28
forth . href = `command:workbench.action.openLargeOutput?${ outputId } ` ;
20
- container . appendChild ( first ) ;
21
- container . appendChild ( second ) ;
22
29
container . appendChild ( third ) ;
23
30
container . appendChild ( forth ) ;
24
31
return container ;
25
32
}
26
33
27
- export function truncatedArrayOfString ( id : string , outputs : string [ ] , linesLimit : number , container : HTMLElement ) {
28
- const buffer = outputs . join ( '\n' ) . split ( / \r \n | \r | \n / g) ;
34
+ export function truncatedArrayOfString ( id : string , buffer : string [ ] , linesLimit : number , container : HTMLElement ) {
29
35
const lineCount = buffer . length ;
30
-
31
- if ( lineCount < linesLimit ) {
32
- const spanElement = handleANSIOutput ( buffer . slice ( 0 , linesLimit ) . join ( '\n' ) ) ;
33
- container . appendChild ( spanElement ) ;
34
- return ;
35
- }
36
-
37
- container . appendChild ( generateViewMoreElement ( id ) ) ;
36
+ container . appendChild ( generateViewMoreElement ( id , true ) ) ;
38
37
39
38
const div = document . createElement ( 'div' ) ;
40
39
container . appendChild ( div ) ;
@@ -50,9 +49,11 @@ export function truncatedArrayOfString(id: string, outputs: string[], linesLimit
50
49
div2 . appendChild ( handleANSIOutput ( buffer . slice ( lineCount - 5 ) . join ( '\n' ) ) ) ;
51
50
}
52
51
53
- function scrollableArrayOfString ( outputs : string [ ] , container : HTMLElement ) {
52
+ function scrollableArrayOfString ( id : string , buffer : string [ ] , container : HTMLElement ) {
54
53
container . classList . add ( 'scrollable' ) ;
54
+ container . classList . add ( 'more-below' ) ;
55
55
56
+ // disposable?
56
57
container . onscroll = ( e ) => {
57
58
const target = e . target as HTMLElement ;
58
59
if ( target . scrollTop === 0 ) {
@@ -68,15 +69,27 @@ function scrollableArrayOfString(outputs: string[], container: HTMLElement) {
68
69
}
69
70
} ;
70
71
71
- const buffer = outputs . join ( '\n' ) . split ( / \r \n | \r | \n / g) ;
72
- const spanElement = handleANSIOutput ( buffer . slice ( 0 , 5000 ) . join ( '\n' ) ) ;
73
- container . appendChild ( spanElement ) ;
72
+ if ( buffer . length > 5000 ) {
73
+ container . appendChild ( generateViewMoreElement ( id , false ) ) ;
74
+ }
75
+ const div = document . createElement ( 'div' ) ;
76
+ container . appendChild ( div ) ;
77
+ div . appendChild ( handleANSIOutput ( buffer . slice ( 0 , 5000 ) . join ( '\n' ) ) ) ;
74
78
}
75
79
76
80
export function insertOutput ( id : string , outputs : string [ ] , linesLimit : number , scrollable : boolean , container : HTMLElement ) {
81
+ const buffer = outputs . join ( '\n' ) . split ( / \r \n | \r | \n / g) ;
82
+ const lineCount = buffer . length ;
83
+
84
+ if ( lineCount < linesLimit ) {
85
+ const spanElement = handleANSIOutput ( buffer . join ( '\n' ) ) ;
86
+ container . appendChild ( spanElement ) ;
87
+ return ;
88
+ }
89
+
77
90
if ( scrollable ) {
78
- scrollableArrayOfString ( outputs , container ) ;
91
+ scrollableArrayOfString ( id , buffer , container ) ;
79
92
} else {
80
- truncatedArrayOfString ( id , outputs , linesLimit , container ) ;
93
+ truncatedArrayOfString ( id , buffer , linesLimit , container ) ;
81
94
}
82
95
}
0 commit comments