Files
ctop/cwidgets/single/net.go
T
ahp 78e85dc4df feat(theme): add catppuccin themes with transparency and 256-color support
Add a theme package providing all four catppuccin flavors (mocha,
frappe, macchiato, latte) mapped to the xterm-256 palette. Themes are
selected with -theme or the CTOP_THEME environment variable; -i inverts
the flavor. Background slots use the terminal's native color for
transparency (opt out with -solid / CTOP_SOLID), and termbox is switched
to Output256 so colors render correctly. Replace hardcoded colors in the
compact and single views with ctheme portrait slots.
2026-09-14 14:06:49 +03:30

53 lines
1.0 KiB
Go

package single
import (
"fmt"
"strings"
"github.com/bcicen/ctop/cwidgets"
"github.com/bcicen/ctop/theme"
ui "github.com/gizak/termui"
)
type Net struct {
*ui.Sparklines
rxHist *DiffHist
txHist *DiffHist
}
func NewNet() *Net {
net := &Net{ui.NewSparklines(), NewDiffHist(60), NewDiffHist(60)}
net.BorderLabel = "NET"
net.Height = 6
net.Width = colWidth[0]
net.X = 0
net.Y = 24
rx := ui.NewSparkline()
rx.Title = "RX"
rx.Height = 1
rx.Data = net.rxHist.Data
rx.LineColor = theme.Attr("net.rx")
tx := ui.NewSparkline()
tx.Title = "TX"
tx.Height = 1
tx.Data = net.txHist.Data
tx.LineColor = theme.Attr("net.tx")
net.Lines = []ui.Sparkline{rx, tx}
return net
}
func (w *Net) Update(rx int64, tx int64) {
var rate string
w.rxHist.Append(int(rx))
rate = strings.ToLower(cwidgets.ByteFormat(w.rxHist.Val))
w.Lines[0].Title = fmt.Sprintf("RX [%s/s]", rate)
w.txHist.Append(int(tx))
rate = strings.ToLower(cwidgets.ByteFormat(w.txHist.Val))
w.Lines[1].Title = fmt.Sprintf("TX [%s/s]", rate)
}