extract captions to const

This commit is contained in:
dimonl 2025-08-20 21:59:27 +02:00
parent 278cc6c03d
commit 68c2d3ad42
2 changed files with 9 additions and 4 deletions

View file

@ -22,6 +22,11 @@ import (
"github.com/jesseduffield/yaml"
)
const (
CPUCaption = "CPU (%)"
MemoryCaption = "Memory (%)"
)
// UserConfig holds all of the user-configurable options
type UserConfig struct {
// Gui is for configuring visual things like colors and whether we show or
@ -460,12 +465,12 @@ func GetDefaultConfig() UserConfig {
MaxDuration: duration,
Graphs: []GraphConfig{
{
Caption: "CPU (%)",
Caption: CPUCaption,
StatPath: "DerivedStats.CPUPercentage",
Color: "cyan",
},
{
Caption: "Memory (%)",
Caption: MemoryCaption,
StatPath: "DerivedStats.MemoryPercentage",
Color: "green",
},

View file

@ -93,14 +93,14 @@ func plotGraph(container *commands.Container, spec config.GraphConfig, width int
memoryLimit := utils.FormatDecimalBytes(int(container.StatHistory[dataLength-1].DerivedStats.MemoryLimit))
var caption string
switch spec.Caption {
case "CPU (%)":
case config.CPUCaption:
caption = fmt.Sprintf(
"%s: %0.2f (%v)",
spec.Caption,
data[dataLength-1],
time.Since(container.StatHistory[0].RecordedAt).Round(time.Second),
)
case "Memory (%)":
case config.MemoryCaption:
caption = fmt.Sprintf(
"%s: %s / %s (%0.2f) (%v)",
spec.Caption,