Utku Ozdemir 9e07832db9
feat: implement summary dashboard
Implement the new summary dashboard with node info and logs.
Replace the previous metrics dashboard with the new dashboard which has multiple screens for node summary, metrics and editing network config.

Port the old metrics dashboard to the tview library and assign it to be a screen in the new dashboard, accessible by F2 key.

Add a new resource, infos.cluster.talos.dev which contains the cluster name and id of a node.

Disable the network config editor screen in the new dashboard until it is fully implemented with its backend.

Closes siderolabs/talos#4790.

Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com>
2023-03-15 13:13:28 +01:00

61 lines
1.5 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package components
import (
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
// LogViewer represents the logs widget.
type LogViewer struct {
tview.Grid
logs tview.TextView
}
// NewLogViewer initializes LogViewer.
func NewLogViewer() *LogViewer {
widget := &LogViewer{
Grid: *tview.NewGrid(),
logs: *tview.NewTextView(),
}
widget.logs.ScrollToEnd().
SetMaxLines(maxLogLines).
SetText(noData).
SetBorderPadding(0, 0, 1, 1).
SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
_, _, _, pageSize := widget.logs.GetInnerRect()
lineOffset, columnOffset := widget.logs.GetScrollOffset()
//nolint:exhaustive
switch event.Key() {
case tcell.KeyCtrlD:
widget.logs.ScrollTo(lineOffset+(pageSize/2), columnOffset)
return nil
case tcell.KeyCtrlU:
widget.logs.ScrollTo(lineOffset-(pageSize/2), columnOffset)
return nil
}
return event
})
widget.SetRows(1, 0).SetColumns(0)
widget.AddItem(NewHorizontalLine(), 0, 0, 1, 1, 0, 0, false)
widget.AddItem(&widget.logs, 1, 0, 1, 1, 0, 0, true)
return widget
}
// WriteLog writes the log line to the widget.
func (widget *LogViewer) WriteLog(logLine string) {
widget.logs.Write([]byte(logLine)) //nolint:errcheck
widget.logs.Write([]byte("\n")) //nolint:errcheck
}