-
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.
Signed-off-by: Anthony Emengo <aemengo@vmware.com>
- Loading branch information
Anthony Emengo
committed
Sep 13, 2021
1 parent
a7487c9
commit 229092a
Showing
5 changed files
with
245 additions
and
29 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,139 @@ | ||
package termui | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gdamore/tcell/v2" | ||
"github.com/rivo/tview" | ||
|
||
"github.com/buildpacks/pack/internal/builder" | ||
"github.com/buildpacks/pack/internal/dist" | ||
) | ||
|
||
type Dashboard struct { | ||
app app | ||
imagesView *tview.Flex | ||
planList *tview.List | ||
logsView *tview.TextView | ||
logs string | ||
} | ||
|
||
func NewDashboard(app app, appName string, bldr *builder.Builder, runImageName string, buildpackInfo []dist.BuildpackInfo) *Dashboard { | ||
imagesView, planList, logsView := initDashboard(appName, bldr, runImageName, buildpackInfo) | ||
|
||
d := &Dashboard{ | ||
app: app, | ||
imagesView: imagesView, | ||
planList: planList, | ||
logsView: logsView, | ||
} | ||
|
||
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() { | ||
panic("implement me") | ||
} | ||
|
||
func initDashboard(appName string, bldr *builder.Builder, runImageName string, buildpackInfos []dist.BuildpackInfo) (*tview.Flex, *tview.List, *tview.TextView) { | ||
appTree, builderTree := initTrees(appName, bldr, runImageName) | ||
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) | ||
|
||
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 imagesView, planList, logsView | ||
} | ||
|
||
func initTrees(appName string, bldr *builder.Builder, 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