@@ -2,6 +2,7 @@ package engine
2
2
3
3
import (
4
4
"fmt"
5
+ "strings"
5
6
"time"
6
7
7
8
"github.com/Azure/InnovationEngine/internal/az"
@@ -41,9 +42,10 @@ type CodeBlockState struct {
41
42
}
42
43
43
44
type interactiveModeComponents struct {
44
- paginator paginator.Model
45
- stepViewport viewport.Model
46
- outputViewport viewport.Model
45
+ paginator paginator.Model
46
+ stepViewport viewport.Model
47
+ outputViewport viewport.Model
48
+ azureCLIViewport viewport.Model
47
49
}
48
50
49
51
type InteractiveModeModel struct {
@@ -62,6 +64,7 @@ type InteractiveModeModel struct {
62
64
scenarioCompleted bool
63
65
components interactiveModeComponents
64
66
ready bool
67
+ commandLines []string
65
68
}
66
69
67
70
// Initialize the intractive mode model
@@ -91,11 +94,13 @@ func initializeComponents(model InteractiveModeModel, width, height int) interac
91
94
92
95
stepViewport := viewport .New (width , 4 )
93
96
outputViewport := viewport .New (width , 2 )
97
+ azureCLIViewport := viewport .New (width , height )
94
98
95
99
components := interactiveModeComponents {
96
- paginator : p ,
97
- stepViewport : stepViewport ,
98
- outputViewport : outputViewport ,
100
+ paginator : p ,
101
+ stepViewport : stepViewport ,
102
+ outputViewport : outputViewport ,
103
+ azureCLIViewport : azureCLIViewport ,
99
104
}
100
105
101
106
components .updateViewportHeight (height )
@@ -207,6 +212,7 @@ func (components *interactiveModeComponents) updateViewportHeight(terminalHeight
207
212
208
213
components .stepViewport .Height = stepViewportHeight
209
214
components .outputViewport .Height = outputViewportHeight
215
+ components .azureCLIViewport .Height = terminalHeight - 1
210
216
}
211
217
212
218
// Updates the intractive mode model
@@ -225,6 +231,7 @@ func (model InteractiveModeModel) Update(message tea.Msg) (tea.Model, tea.Cmd) {
225
231
} else {
226
232
model .components .stepViewport .Width = message .Width
227
233
model .components .outputViewport .Width = message .Width
234
+ model .components .azureCLIViewport .Width = message .Width
228
235
model .components .updateViewportHeight (message .Height )
229
236
}
230
237
@@ -255,10 +262,18 @@ func (model InteractiveModeModel) Update(message tea.Msg) (tea.Model, tea.Cmd) {
255
262
model .resourceGroupName = tmpResourceGroup
256
263
}
257
264
}
265
+ model .commandLines = append (model .commandLines , codeBlockState .StdOut )
258
266
259
267
// Increment the codeblock and update the viewport content.
260
268
model .currentCodeBlock ++
261
269
270
+ if model .currentCodeBlock < len (model .codeBlockState ) {
271
+ nextCommand := model .codeBlockState [model .currentCodeBlock ].CodeBlock .Content
272
+ nextLanguage := model .codeBlockState [model .currentCodeBlock ].CodeBlock .Language
273
+
274
+ model .commandLines = append (model .commandLines , ui .CommandPrompt (nextLanguage )+ nextCommand )
275
+ }
276
+
262
277
// Only increment the step for azure if the step name has changed.
263
278
nextCodeBlockState := model .codeBlockState [model .currentCodeBlock ]
264
279
@@ -301,6 +316,7 @@ func (model InteractiveModeModel) Update(message tea.Msg) (tea.Model, tea.Cmd) {
301
316
codeBlockState .Success = false
302
317
303
318
model .codeBlockState [step ] = codeBlockState
319
+ model .commandLines = append (model .commandLines , codeBlockState .StdErr )
304
320
305
321
// Report the error
306
322
model .executingCommand = false
@@ -381,6 +397,8 @@ func (model InteractiveModeModel) Update(message tea.Msg) (tea.Model, tea.Cmd) {
381
397
model .components .outputViewport .SetContent (block .StdErr )
382
398
}
383
399
400
+ model .components .azureCLIViewport .SetContent (strings .Join (model .commandLines , "\n " ))
401
+
384
402
// Update all the viewports and append resulting commands.
385
403
var command tea.Cmd
386
404
@@ -392,6 +410,9 @@ func (model InteractiveModeModel) Update(message tea.Msg) (tea.Model, tea.Cmd) {
392
410
model .components .outputViewport , command = model .components .outputViewport .Update (message )
393
411
commands = append (commands , command )
394
412
413
+ model .components .azureCLIViewport , command = model .components .azureCLIViewport .Update (message )
414
+ commands = append (commands , command )
415
+
395
416
return model , tea .Batch (commands ... )
396
417
}
397
418
@@ -419,44 +440,33 @@ func (model InteractiveModeModel) helpView() string {
419
440
420
441
// Renders the interactive mode model.
421
442
func (model InteractiveModeModel ) View () string {
443
+ // When running in the portal, we only want to show the Azure CLI viewport
444
+ // which mimics a command line interface during execution.
445
+ if model .environment == "azure" {
446
+ return model .components .azureCLIViewport .View ()
447
+ }
448
+
422
449
scenarioTitle := ui .ScenarioTitleStyle .Width (model .width ).
423
450
Align (lipgloss .Center ).
424
451
Render (model .scenarioTitle )
425
- var stepTitle string
426
- var stepView string
427
- var stepSection string
428
- stepTitle = ui .StepTitleStyle .Render (
452
+
453
+ border := lipgloss .NewStyle ().
454
+ Width (model .components .stepViewport .Width - 2 ).
455
+ Border (lipgloss .NormalBorder ())
456
+
457
+ stepTitle := ui .StepTitleStyle .Render (
429
458
fmt .Sprintf (
430
459
"Step %d - %s" ,
431
460
model .currentCodeBlock + 1 ,
432
461
model .codeBlockState [model .currentCodeBlock ].StepName ,
433
462
),
434
463
)
464
+ stepView := border .Render (model .components .stepViewport .View ())
465
+ stepSection := fmt .Sprintf ("%s\n %s\n \n " , stepTitle , stepView )
435
466
436
- border := lipgloss .NewStyle ().
437
- Width (model .components .stepViewport .Width - 2 )
438
- // Border(lipgloss.NormalBorder())
439
-
440
- stepView = border .Render (model .components .stepViewport .View ())
441
-
442
- if model .environment != "azure" {
443
- stepSection = fmt .Sprintf ("%s\n %s\n \n " , stepTitle , stepView )
444
- } else {
445
- stepSection = fmt .Sprintf ("%s\n %s\n " , stepTitle , stepView )
446
- }
447
-
448
- var outputTitle string
449
- var outputView string
450
- var outputSection string
451
- if model .environment != "azure" {
452
- outputTitle = ui .StepTitleStyle .Render ("Output" )
453
- outputView = border .Render (model .components .outputViewport .View ())
454
- outputSection = fmt .Sprintf ("%s\n %s\n \n " , outputTitle , outputView )
455
- } else {
456
- outputTitle = ""
457
- outputView = ""
458
- outputSection = ""
459
- }
467
+ outputTitle := ui .StepTitleStyle .Render ("Output" )
468
+ outputView := border .Render (model .components .outputViewport .View ())
469
+ outputSection := fmt .Sprintf ("%s\n %s\n \n " , outputTitle , outputView )
460
470
461
471
paginator := lipgloss .NewStyle ().
462
472
Width (model .width ).
@@ -532,6 +542,11 @@ func NewInteractiveModeModel(
532
542
azureStatus .AddStep (fmt .Sprintf ("%d. %s" , stepNumber + 1 , step .Name ), azureCodeBlocks )
533
543
}
534
544
545
+ language := codeBlockState [0 ].CodeBlock .Language
546
+ commandLines := []string {
547
+ ui .CommandPrompt (language ) + codeBlockState [0 ].CodeBlock .Content ,
548
+ }
549
+
535
550
return InteractiveModeModel {
536
551
scenarioTitle : title ,
537
552
commands : InteractiveModeCommands {
@@ -562,5 +577,6 @@ func NewInteractiveModeModel(
562
577
environment : engine .Configuration .Environment ,
563
578
scenarioCompleted : false ,
564
579
ready : false ,
580
+ commandLines : commandLines ,
565
581
}, nil
566
582
}
0 commit comments