@@ -11,7 +11,7 @@ import {
1111
1212import { IThemeManager , IToolbarWidgetRegistry } from '@jupyterlab/apputils' ;
1313
14- import { ConsolePanel , IConsoleTracker } from '@jupyterlab/console' ;
14+ import { CodeConsole , ConsolePanel , IConsoleTracker } from '@jupyterlab/console' ;
1515
1616import { ITranslator } from '@jupyterlab/translation' ;
1717
@@ -81,7 +81,7 @@ const consolePlugin: JupyterFrontEndPlugin<void> = {
8181 if ( ! tracker ) {
8282 return ;
8383 }
84- const { commands, serviceManager , started } = app ;
84+ const { commands, started } = app ;
8585
8686 const search = window . location . search ;
8787 const urlParams = new URLSearchParams ( search ) ;
@@ -91,33 +91,62 @@ const consolePlugin: JupyterFrontEndPlugin<void> = {
9191 const theme = urlParams . get ( 'theme' ) ?. trim ( ) ;
9292 const toolbar = urlParams . get ( 'toolbar' ) ;
9393
94- Promise . all ( [ started , serviceManager . ready ] ) . then ( async ( ) => {
95- commands . execute ( 'console:create' , { kernelPreference : { name : kernel } } ) ;
94+ // normalize config options
95+ const clearCellsOnExecute =
96+ urlParams . get ( 'clearCellsOnExecute' ) === '1' || undefined ;
97+ const clearCodeContentOnExecute =
98+ urlParams . get ( 'clearCodeContentOnExecute' ) === '0' ? false : undefined ;
99+ const hideCodeInput = urlParams . get ( 'hideCodeInput' ) === '1' || undefined ;
100+ const showBanner = urlParams . get ( 'showBanner' ) === '0' ? false : undefined ;
101+
102+ const position = urlParams . get ( 'promptCellPosition' ) ?? '' ;
103+ const validPositions = [ 'top' , 'bottom' , 'left' , 'right' ] ;
104+ const promptCellPosition = validPositions . includes ( position )
105+ ? ( position as CodeConsole . PromptCellPosition )
106+ : undefined ;
107+
108+ started . then ( async ( ) => {
109+ // create a new console at application startup
110+ void commands . execute ( 'console:create' , {
111+ kernelPreference : { name : kernel } ,
112+ } ) ;
96113 } ) ;
97114
98- if ( theme && themeManager ) {
99- const themeName = decodeURIComponent ( theme ) ;
100- themeManager . setTheme ( themeName ) ;
101- }
102-
103- tracker . widgetAdded . connect ( async ( _ , widget ) => {
104- const { console } = widget ;
105-
115+ tracker . widgetAdded . connect ( async ( _ , panel ) => {
106116 if ( ! toolbar ) {
107117 // hide the toolbar by default if not specified
108- widget . toolbar . dispose ( ) ;
118+ panel . toolbar . dispose ( ) ;
109119 }
110120
111- if ( code ) {
112- await console . sessionContext . ready ;
121+ const { console : widget } = panel ;
122+ const { sessionContext } = widget ;
123+
124+ await sessionContext . ready ;
125+ if ( code . length > 0 ) {
113126 if ( execute === '0' ) {
114127 const codeContent = code . join ( '\n' ) ;
115- console . replaceSelection ( codeContent ) ;
128+ widget . replaceSelection ( codeContent ) ;
116129 } else {
117- code . forEach ( ( line ) => console . inject ( line ) ) ;
130+ code . forEach ( ( line ) => widget . inject ( line ) ) ;
118131 }
119132 }
133+
134+ widget . setConfig ( {
135+ clearCellsOnExecute,
136+ clearCodeContentOnExecute,
137+ hideCodeInput,
138+ promptCellPosition,
139+ // TODO: handling of the showBanner may not work as expected for now
140+ // due to the assumption there should be a banner upstream:
141+ // https://github.com/jupyterlab/jupyterlab/pull/17322
142+ showBanner,
143+ } ) ;
120144 } ) ;
145+
146+ if ( theme && themeManager ) {
147+ const themeName = decodeURIComponent ( theme ) ;
148+ themeManager . setTheme ( themeName ) ;
149+ }
121150 } ,
122151} ;
123152
0 commit comments