talos/internal/pkg/dashboard/components/horizontalline.go
Andrey Smirnov 8dbe2128a9
feat: implement Talos diagnostics
Talos diagnostics analyzes current system state and comes up with detailed
warnings on the system misconfiguration which might be tricky to figure
out other way.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
2024-06-05 22:28:15 +04:00

47 lines
1.2 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"
)
// HorizontalLine is a widget that draws a horizontal line.
type HorizontalLine struct {
tview.TextView
label []rune
}
// NewHorizontalLine initializes HorizontalLine.
func NewHorizontalLine(label string) *HorizontalLine {
widget := &HorizontalLine{
TextView: *tview.NewTextView(),
label: []rune(" " + label + " "),
}
const leftGap = 2
// set the background to be a horizontal line
widget.SetDrawFunc(func(screen tcell.Screen, x, y, width, height int) (int, int, int, int) {
labelLength := len(widget.label)
for i := x; i < x+width; i++ {
for j := y; j < y+height; j++ {
if j == y && i >= leftGap && i-leftGap < labelLength {
screen.SetContent(i, j, widget.label[i-leftGap], nil, tcell.StyleDefault.Foreground(tcell.ColorYellow))
} else {
screen.SetContent(i, j, tview.BoxDrawingsLightHorizontal, nil, tcell.StyleDefault.Foreground(tcell.ColorWhite))
}
}
}
return x, y, width, height
})
return widget
}