66using Microsoft . AspNetCore . Html ;
77using Microsoft . DotNet . Interactive ;
88using Microsoft . DotNet . Interactive . Commands ;
9+ using Microsoft . DotNet . Interactive . Directives ;
910using Microsoft . DotNet . Interactive . Http ;
1011
1112namespace DotLanguage . InteractiveExtension ;
@@ -15,7 +16,6 @@ public class DotLanguageKernel : Kernel,
1516{
1617 private readonly string _cacheBuster ;
1718
18- private ChooseDotLanguageKernelDirective ? _chooseKernelDirective ;
1919
2020 public DotLanguageKernel ( ) : base ( "dot" )
2121 {
@@ -24,25 +24,49 @@ public DotLanguageKernel() : base("dot")
2424 _cacheBuster = Guid . NewGuid ( ) . ToString ( "N" ) ;
2525 }
2626
27+ public override KernelSpecifierDirective KernelSpecifierDirective
28+ {
29+ get
30+ {
31+ var directive = base . KernelSpecifierDirective ;
32+
33+ directive . Parameters . Add ( new ( "--width" ) ) ;
34+ directive . Parameters . Add ( new ( "--height" ) ) ;
35+ var layoutEngineParameter = new KernelDirectiveParameter ( "--layout-engine" ) ;
36+ layoutEngineParameter . AddCompletions ( ( ) => Enum . GetNames ( typeof ( LayoutEngine ) ) ) ;
37+ directive . Parameters . Add ( layoutEngineParameter ) ;
38+
39+ return directive ;
40+ }
41+ }
42+
2743 public Task HandleAsync ( SubmitCode command , KernelInvocationContext context )
2844 {
29- var width = "100%" ;
30- var height = "600px" ;
3145 var layoutEngine = LayoutEngine . dot ;
32- if ( _chooseKernelDirective is { } chooser )
46+ command . Parameters . TryGetValue ( "--width" , out var width ) ;
47+ if ( string . IsNullOrWhiteSpace ( width ) )
48+ {
49+ width = "100%" ;
50+ }
51+ command . Parameters . TryGetValue ( "--height" , out var height ) ;
52+ if ( string . IsNullOrWhiteSpace ( height ) )
3353 {
34- width = command . KernelChooserParseResult ? . GetValueForOption ( chooser . WidthOption ) ;
35- height = command . KernelChooserParseResult ? . GetValueForOption ( chooser . HeightOption ) ;
36- layoutEngine = command . KernelChooserParseResult ? . GetValueForOption ( chooser . LayoutEngineOption ) ?? LayoutEngine . dot ;
54+ height = "600px" ;
3755 }
56+ command . Parameters . TryGetValue ( "--layout-engine" , out var layoutEngineString ) ;
57+ if ( string . IsNullOrWhiteSpace ( layoutEngineString ) )
58+ {
59+ layoutEngineString = "dot" ;
60+ }
61+ layoutEngine = Enum . Parse < LayoutEngine > ( layoutEngineString , true ) ;
62+
3863
3964 var code = GenerateHtml ( command . Code , new Uri ( "https://cdn.jsdelivr.net/npm/@hpcc-js/wasm@1.16.1/dist/index.min.js" , UriKind . Absolute ) , new Uri ( "https://cdn.jsdelivr.net/npm/@hpcc-js/wasm@1.16.1/dist" , UriKind . Absolute ) , "1.16.1" , _cacheBuster , width , height , layoutEngine ) ;
4065 context . Display ( code ) ;
4166 return Task . CompletedTask ;
4267
4368 }
4469
45- public override ChooseKernelDirective ChooseKernelDirective => _chooseKernelDirective ??= new ChooseDotLanguageKernelDirective ( this ) ;
4670
4771 private IHtmlContent GenerateHtml ( string commandCode , Uri libraryUri , Uri wasmFolder , string ? libraryVersion ,
4872 string cacheBuster , string ? width , string ? height , LayoutEngine layoutEngine )
0 commit comments