Skip to content

Commit

Permalink
Now correctly changing focus at the application level, which unfocuse…
Browse files Browse the repository at this point in the history
…s the currently selected element; moved the application.Run() event loop to the main Entrypoint() function so it's clear what is going on in this app; cluster details tables now have a different border color than the cluster table to make distinguishing which one has focus easier.
  • Loading branch information
swartzja committed Dec 19, 2020
1 parent f2abc84 commit a29e36f
Showing 1 changed file with 13 additions and 29 deletions.
42 changes: 13 additions & 29 deletions cmd/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ var progressFooterBar *tview.TextView

// Entrypoint for the ecsview application
func Entrypoint() {
fmt.Println("Loading information about your AWS ECS clusters and container instances...")
buildUIElements()
if err := tviewApp.Run(); err != nil {
panic(err)
}
}

// Select a cluster details page with a single key shortcut
Expand Down Expand Up @@ -56,8 +60,7 @@ func showPage(selectedPage *pages.ClusterDetailsPage, key int32) {

// If the page about to be hidden has focus, switch focus to the new page
if frontPageView != nil && frontPageView.HasFocus() {
RemoveFocus(frontPageView)
AddFocus(selectedPage.GetTable())
tviewApp.SetFocus(selectedPage.GetTable())
}
}

Expand All @@ -78,25 +81,9 @@ func changeFocus() {
return
}
if clusterTable.HasFocus() {
RemoveFocus(clusterTable)
AddFocus(pageView)
tviewApp.SetFocus(pageView)
} else {
RemoveFocus(pageView)
AddFocus(clusterTable)
}
}

func AddFocus(p tview.Primitive) {
if table, ok := p.(*tview.Table); ok {
table.Focus(nil)
table.SetBorderColor(tcell.ColorGoldenrod)
}
}

func RemoveFocus(p tview.Primitive) {
if table, ok := p.(*tview.Table); ok {
table.Blur()
table.SetBorderColor(tcell.ColorGray)
tviewApp.SetFocus(clusterTable)
}
}

Expand Down Expand Up @@ -148,7 +135,7 @@ func showRefreshTime(what string, when time.Time) {
fmt.Fprintf(progressFooterBar, "%s refreshed at %s", what, utils.FormatLocalTimeAmPmSecs(when))
}

// Build the UI elements for this application
// Build the UI elements and configures the application
func buildUIElements() {

clusterTable = buildClusterTable()
Expand All @@ -159,6 +146,7 @@ func buildUIElements() {
clusterDetailsPageMap['3'] = pages.NewInstancesPage()
clusterDetailsPages = tview.NewPages()
for _, page := range clusterDetailsPageMap {
page.GetTable().SetBorderColor(tcell.ColorGoldenrod)
clusterDetailsPages.AddPage(page.Name, page.GetTable(), true, false)
}

Expand Down Expand Up @@ -186,17 +174,12 @@ func buildUIElements() {
AddItem(footer, 1, 1, false)

tviewApp = tview.NewApplication().
SetRoot(flex, true).
SetInputCapture(handleAppInput).
EnableMouse(true)

// Show the services page
// Show the services page, but start with the cluster table selected
selectClusterDetailsPageByKey('1')
changeFocus()

if err := tviewApp.SetRoot(flex, true).Run(); err != nil {
panic(err)
}

}

// Load the ECS clusters and create the cluster table
Expand All @@ -208,7 +191,8 @@ func buildClusterTable() *tview.Table {
table.
SetBorder(true).
SetTitle(" ✨ ECS Clusters ").
SetBorderPadding(0, 0, 1, 1)
SetBorderPadding(0, 0, 1, 1).
SetBorderColor(tcell.ColorDarkCyan)

table.SetSelectionChangedFunc(func(row, column int) {
renderCurrentClusterDetailsPage()
Expand Down

0 comments on commit a29e36f

Please sign in to comment.