-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b4b03c
commit 80253a1
Showing
10 changed files
with
182 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
|
||
ui "github.com/gizak/termui/v3" | ||
"github.com/gizak/termui/v3/widgets" | ||
analyzerunner "github.com/replicatedhq/troubleshoot/pkg/analyze" | ||
) | ||
|
||
type nodeValue string | ||
|
||
func (nv nodeValue) String() string { | ||
return string(nv) | ||
} | ||
|
||
func showInteractiveResults(analyzeResults []*analyzerunner.AnalyzeResult) error { | ||
if err := ui.Init(); err != nil { | ||
return err | ||
} | ||
defer ui.Close() | ||
|
||
selectedResult := 0 | ||
|
||
preflightTable := getPreflightTable(analyzeResults) | ||
details := getDetails(analyzeResults[selectedResult]) | ||
|
||
grid := ui.NewGrid() | ||
termWidth, termHeight := ui.TerminalDimensions() | ||
grid.SetRect(0, 0, termWidth, termHeight) | ||
|
||
grid.Set( | ||
ui.NewRow(1.0, | ||
ui.NewCol(1.0/2, preflightTable), | ||
ui.NewCol(1.0/2, details), | ||
), | ||
) | ||
|
||
ui.Render(grid) | ||
|
||
uiEvents := ui.PollEvents() | ||
for { | ||
select { | ||
case e := <-uiEvents: | ||
switch e.ID { | ||
case "q", "<C-c>": | ||
return nil | ||
case "<Resize>": | ||
payload := e.Payload.(ui.Resize) | ||
grid.SetRect(0, 0, payload.Width, payload.Height) | ||
ui.Clear() | ||
ui.Render(grid) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func getPreflightTable(analyzeResults []*analyzerunner.AnalyzeResult) *widgets.Table { | ||
table := widgets.NewTable() | ||
table.Border = true | ||
table.Rows = [][]string{} | ||
|
||
for i, analyzeResult := range analyzeResults { | ||
table.Rows = append(table.Rows, []string{ | ||
analyzeResult.Title, | ||
}) | ||
|
||
if analyzeResult.IsPass { | ||
table.RowStyles[i] = ui.NewStyle(ui.ColorGreen, ui.ColorClear, ui.ModifierBold) | ||
} else if analyzeResult.IsWarn { | ||
table.RowStyles[i] = ui.NewStyle(ui.ColorYellow, ui.ColorClear, ui.ModifierBold) | ||
} else if analyzeResult.IsFail { | ||
table.RowStyles[i] = ui.NewStyle(ui.ColorRed, ui.ColorClear) | ||
} | ||
} | ||
|
||
return table | ||
} | ||
|
||
func getDetails(analysisResult *analyzerunner.AnalyzeResult) *ui.Grid { | ||
grid := ui.NewGrid() | ||
|
||
entries := []interface{}{} | ||
|
||
title := widgets.NewParagraph() | ||
title.Text = analysisResult.Title | ||
title.Border = false | ||
entries = append(entries, ui.NewRow(0.2, ui.NewCol(1.0, title))) | ||
|
||
message := widgets.NewParagraph() | ||
message.Text = analysisResult.Message | ||
message.Border = false | ||
entries = append(entries, ui.NewRow(0.2, ui.NewCol(1.0, message))) | ||
|
||
if analysisResult.URI != "" { | ||
uri := widgets.NewParagraph() | ||
uri.Text = fmt.Sprintf("For more information: %s", analysisResult.URI) | ||
uri.Border = false | ||
entries = append(entries, ui.NewRow(0.2, ui.NewCol(1.0, uri))) | ||
} | ||
|
||
grid.Set(entries...) | ||
return grid | ||
} |
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
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ type AnalyzeResult struct { | |
IsFail bool | ||
IsWarn bool | ||
|
||
Title string | ||
Message string | ||
URI string | ||
} | ||
|
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