refactor log view

mine
derailed 2019-06-20 10:24:27 -06:00
parent ddc1f74a41
commit d0ca931d9d
2 changed files with 52 additions and 25 deletions

View File

@ -92,9 +92,10 @@ func (v *clusterInfoView) infoCell(t string) *tview.TableCell {
} }
func (v *clusterInfoView) refresh() { func (v *clusterInfoView) refresh() {
cluster := resource.NewCluster(v.app.conn(), &log.Logger, v.mxs) var (
cluster = resource.NewCluster(v.app.conn(), &log.Logger, v.mxs)
var row int row int
)
v.GetCell(row, 1).SetText(cluster.ContextName()) v.GetCell(row, 1).SetText(cluster.ContextName())
row++ row++
v.GetCell(row, 1).SetText(cluster.ClusterName()) v.GetCell(row, 1).SetText(cluster.ClusterName())
@ -109,6 +110,10 @@ func (v *clusterInfoView) refresh() {
c = v.GetCell(row+1, 1) c = v.GetCell(row+1, 1)
c.SetText(resource.NAValue) c.SetText(resource.NAValue)
v.refreshMetrics(cluster, row)
}
func (v *clusterInfoView) refreshMetrics(cluster *resource.Cluster, row int) {
nos, err := v.app.informer.List(watch.NodeIndex, "", metav1.ListOptions{}) nos, err := v.app.informer.List(watch.NodeIndex, "", metav1.ListOptions{})
if err != nil { if err != nil {
log.Warn().Err(err).Msg("ListNodes") log.Warn().Err(err).Msg("ListNodes")
@ -122,7 +127,7 @@ func (v *clusterInfoView) refresh() {
var cmx k8s.ClusterMetrics var cmx k8s.ClusterMetrics
cluster.Metrics(nos, nmx, &cmx) cluster.Metrics(nos, nmx, &cmx)
c = v.GetCell(row, 1) c := v.GetCell(row, 1)
cpu := resource.AsPerc(cmx.PercCPU) cpu := resource.AsPerc(cmx.PercCPU)
if cpu == "0" { if cpu == "0" {
cpu = resource.NAValue cpu = resource.NAValue

View File

@ -15,26 +15,45 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
type logView struct { type (
*tview.Flex logFrame struct {
*tview.Flex
app *appView
actions keyActions
backFn actionHandler
}
app *appView logView struct {
backFn actionHandler *logFrame
logs *detailsView logs *detailsView
status *statusView status *statusView
ansiWriter io.Writer ansiWriter io.Writer
autoScroll int32 autoScroll int32
actions keyActions path string
path string }
)
func newLogFrame(app *appView, backFn actionHandler) *logFrame {
f := logFrame{
Flex: tview.NewFlex(),
app: app,
backFn: backFn,
actions: make(keyActions),
}
f.SetBorder(true)
f.SetBackgroundColor(config.AsColor(app.styles.Views().Log.BgColor))
f.SetBorderPadding(0, 0, 1, 1)
f.SetDirection(tview.FlexRow)
return &f
} }
func newLogView(title string, app *appView, backFn actionHandler) *logView { func newLogView(_ string, app *appView, backFn actionHandler) *logView {
v := logView{Flex: tview.NewFlex(), app: app} v := logView{
v.autoScroll = 1 logFrame: newLogFrame(app, backFn),
v.backFn = backFn autoScroll: 1,
v.SetBorder(true) }
v.SetBackgroundColor(config.AsColor(app.styles.Views().Log.BgColor))
v.SetBorderPadding(0, 0, 1, 1)
v.logs = newDetailsView(app, backFn) v.logs = newDetailsView(app, backFn)
{ {
v.logs.SetBorder(false) v.logs.SetBorder(false)
@ -47,10 +66,16 @@ func newLogView(title string, app *appView, backFn actionHandler) *logView {
} }
v.ansiWriter = tview.ANSIWriter(v.logs) v.ansiWriter = tview.ANSIWriter(v.logs)
v.status = newStatusView(app.styles) v.status = newStatusView(app.styles)
v.SetDirection(tview.FlexRow)
v.AddItem(v.status, 1, 1, false) v.AddItem(v.status, 1, 1, false)
v.AddItem(v.logs, 0, 1, true) v.AddItem(v.logs, 0, 1, true)
v.bindKeys()
v.logs.SetInputCapture(v.keyboard)
return &v
}
func (v *logView) bindKeys() {
v.actions = keyActions{ v.actions = keyActions{
tcell.KeyEscape: newKeyAction("Back", v.backCmd, true), tcell.KeyEscape: newKeyAction("Back", v.backCmd, true),
KeyC: newKeyAction("Clear", v.clearCmd, true), KeyC: newKeyAction("Clear", v.clearCmd, true),
@ -61,9 +86,6 @@ func newLogView(title string, app *appView, backFn actionHandler) *logView {
KeyB: newKeyAction("Down", v.pageDownCmd, false), KeyB: newKeyAction("Down", v.pageDownCmd, false),
tcell.KeyCtrlS: newKeyAction("Save", v.saveCmd, true), tcell.KeyCtrlS: newKeyAction("Save", v.saveCmd, true),
} }
v.logs.SetInputCapture(v.keyboard)
return &v
} }
// Hints show action hints // Hints show action hints