-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Dashboard view of interactive workflow
Signed-off-by: Anthony Emengo <aemengo@vmware.com>
- Loading branch information
Anthony Emengo
committed
Nov 11, 2021
1 parent
26d8c5c
commit d6a61b8
Showing
9 changed files
with
439 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package termui | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gdamore/tcell/v2" | ||
"github.com/rivo/tview" | ||
|
||
"github.com/buildpacks/pack/pkg/dist" | ||
) | ||
|
||
type Dashboard struct { | ||
app app | ||
appTree *tview.TreeView | ||
builderTree *tview.TreeView | ||
planList *tview.List | ||
logsView *tview.TextView | ||
logs string | ||
} | ||
|
||
func NewDashboard(app app, appName string, bldr buildr, runImageName string, buildpackInfo []dist.BuildpackInfo) *Dashboard { | ||
appTree, builderTree := initTrees(appName, bldr, runImageName) | ||
|
||
planList, logsView := initDashboard(buildpackInfo) | ||
|
||
d := &Dashboard{ | ||
app: app, | ||
appTree: appTree, | ||
builderTree: builderTree, | ||
planList: planList, | ||
logsView: logsView, | ||
} | ||
|
||
imagesView := tview.NewFlex(). | ||
SetDirection(tview.FlexRow). | ||
AddItem(appTree, 0, 1, false). | ||
AddItem(builderTree, 0, 1, true) | ||
|
||
imagesView. | ||
SetBorder(true). | ||
SetTitleAlign(tview.AlignLeft). | ||
SetTitle("| [::b]images[::-] |"). | ||
SetBackgroundColor(backgroundColor) | ||
|
||
leftPane := tview.NewFlex(). | ||
SetDirection(tview.FlexRow). | ||
AddItem(imagesView, 11, 0, false). | ||
AddItem(planList, 0, 1, true) | ||
|
||
screen := tview.NewFlex(). | ||
SetDirection(tview.FlexColumn). | ||
AddItem(leftPane, 0, 1, true). | ||
AddItem(logsView, 0, 1, false) | ||
|
||
d.app.SetRoot(screen, true) | ||
return d | ||
} | ||
|
||
func (d *Dashboard) Handle(txt string) { | ||
d.app.QueueUpdateDraw(func() { | ||
d.logs = d.logs + txt + "\n" | ||
d.logsView.SetText(tview.TranslateANSI(d.logs)) | ||
}) | ||
} | ||
|
||
func (d *Dashboard) Stop() { | ||
// no-op | ||
} | ||
|
||
func initDashboard(buildpackInfos []dist.BuildpackInfo) (*tview.List, *tview.TextView) { | ||
planList := tview.NewList() | ||
planList.SetMainTextColor(tcell.ColorMediumTurquoise). | ||
SetSelectedTextColor(tcell.ColorMediumTurquoise). | ||
SetSelectedBackgroundColor(tcell.ColorDarkSlateGray). | ||
SetSecondaryTextColor(tcell.ColorDimGray). | ||
SetBorder(true). | ||
SetBorderPadding(1, 1, 1, 1). | ||
SetTitle("| [::b]plan[::-] |"). | ||
SetTitleAlign(tview.AlignLeft). | ||
SetBackgroundColor(backgroundColor) | ||
|
||
for _, buildpackInfo := range buildpackInfos { | ||
planList.AddItem( | ||
buildpackInfo.FullName(), | ||
info(buildpackInfo), | ||
'✔', | ||
func() {}, | ||
) | ||
} | ||
|
||
logsView := tview.NewTextView() | ||
logsView.SetDynamicColors(true). | ||
SetTextAlign(tview.AlignLeft). | ||
SetBorderPadding(1, 1, 3, 1). | ||
SetTitleAlign(tview.AlignLeft). | ||
SetBackgroundColor(backgroundColor) | ||
|
||
return planList, logsView | ||
} | ||
|
||
func initTrees(appName string, bldr buildr, runImageName string) (*tview.TreeView, *tview.TreeView) { | ||
var ( | ||
appImage = tview.NewTreeNode(fmt.Sprintf("app: [white::b]%s", appName)).SetColor(tcell.ColorDimGray) | ||
appRunImage = tview.NewTreeNode(fmt.Sprintf(" run: [white::b]%s", runImageName)).SetColor(tcell.ColorDimGray) | ||
builderImage = tview.NewTreeNode(fmt.Sprintf("builder: [white::b]%s", bldr.BaseImageName())).SetColor(tcell.ColorDimGray) | ||
lifecycle = tview.NewTreeNode(fmt.Sprintf(" lifecycle: [white::b]%s", bldr.LifecycleDescriptor().Info.Version.String())).SetColor(tcell.ColorDimGray) | ||
runImage = tview.NewTreeNode(fmt.Sprintf(" run: [white::b]%s", bldr.Stack().RunImage.Image)).SetColor(tcell.ColorDimGray) | ||
buildpacks = tview.NewTreeNode(" [mediumturquoise::b]buildpacks") | ||
) | ||
|
||
appImage.AddChild(appRunImage) | ||
builderImage.AddChild(lifecycle) | ||
builderImage.AddChild(runImage) | ||
builderImage.AddChild(buildpacks) | ||
|
||
appTree := tview.NewTreeView() | ||
appTree. | ||
SetRoot(appImage). | ||
SetGraphics(true). | ||
SetGraphicsColor(tcell.ColorMediumTurquoise). | ||
SetTitleAlign(tview.AlignLeft). | ||
SetBorderPadding(1, 0, 4, 0). | ||
SetBackgroundColor(backgroundColor) | ||
|
||
builderTree := tview.NewTreeView() | ||
builderTree. | ||
SetRoot(builderImage). | ||
SetGraphics(true). | ||
SetGraphicsColor(tcell.ColorMediumTurquoise). | ||
SetTitleAlign(tview.AlignLeft). | ||
SetBorderPadding(0, 0, 4, 0). | ||
SetBackgroundColor(backgroundColor) | ||
|
||
return appTree, builderTree | ||
} | ||
|
||
func info(buildpackInfo dist.BuildpackInfo) string { | ||
if buildpackInfo.Description != "" { | ||
return buildpackInfo.Description | ||
} | ||
|
||
return buildpackInfo.Homepage | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package fakes | ||
|
||
import ( | ||
"github.com/buildpacks/pack/internal/builder" | ||
"github.com/buildpacks/pack/pkg/dist" | ||
) | ||
|
||
type Builder struct { | ||
baseImageName string | ||
buildpacks []dist.BuildpackInfo | ||
lifecycleDescriptor builder.LifecycleDescriptor | ||
stack builder.StackMetadata | ||
} | ||
|
||
func NewBuilder(baseImageName string, buildpacks []dist.BuildpackInfo, lifecycleDescriptor builder.LifecycleDescriptor, stack builder.StackMetadata) *Builder { | ||
return &Builder{ | ||
baseImageName: baseImageName, | ||
buildpacks: buildpacks, | ||
lifecycleDescriptor: lifecycleDescriptor, | ||
stack: stack, | ||
} | ||
} | ||
|
||
func (b *Builder) BaseImageName() string { | ||
return b.baseImageName | ||
} | ||
|
||
func (b *Builder) Buildpacks() []dist.BuildpackInfo { | ||
return b.buildpacks | ||
} | ||
|
||
func (b *Builder) LifecycleDescriptor() builder.LifecycleDescriptor { | ||
return b.lifecycleDescriptor | ||
} | ||
|
||
func (b *Builder) Stack() builder.StackMetadata { | ||
return b.stack | ||
} |
Oops, something went wrong.