Skip to content

Commit cf90a24

Browse files
committed
fix missing colorization
1 parent f07d2aa commit cf90a24

1 file changed

Lines changed: 49 additions & 3 deletions

File tree

internal/ui/dataset_info/dataset_info.go

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import (
66
"sort"
77
"strings"
88
"zfs-file-history/internal/ui/theme"
9+
"zfs-file-history/internal/ui/txwidgets"
910
uiutil "zfs-file-history/internal/ui/util"
1011
"zfs-file-history/internal/zfs"
1112

13+
"github.com/gdamore/tcell/v2"
1214
"github.com/rivo/tview"
1315
)
1416

@@ -142,18 +144,62 @@ func (datasetInfo *DatasetInfoComponent) updateUi() {
142144
return properties[i].Name < properties[j].Name
143145
})
144146

147+
keyColorTag := txwidgets.ColorTag(theme.Colors.Layout.Table.Header)
145148
var out strings.Builder
146149
for _, prop := range properties {
147-
out.WriteString(fmt.Sprintf(" [gray]%*s:[-] %s\n",
150+
valueColor := resolveValueColor(prop.Name, prop.Value)
151+
valueColorTag := txwidgets.ColorTag(valueColor)
152+
153+
out.WriteString(fmt.Sprintf(" %s%*s:[-] %s%s[-]\n",
154+
keyColorTag,
148155
maxKeyLen,
149-
prop.Name,
150-
prop.Value,
156+
tview.Escape(prop.Name),
157+
valueColorTag,
158+
tview.Escape(prop.Value),
151159
))
152160
}
153161

154162
datasetInfo.textView.SetText(out.String())
155163
}
156164

165+
func resolveValueColor(name, value string) tcell.Color {
166+
if value == "" || value == "-" || strings.EqualFold(value, "none") {
167+
return tcell.ColorGray
168+
}
169+
170+
lowerName := strings.ToLower(name)
171+
lowerValue := strings.ToLower(value)
172+
173+
// Warning / Restrictive States
174+
if lowerName == "readonly" && lowerValue == "on" {
175+
return tcell.ColorOrange // Visual cue that writes/restores are blocked
176+
}
177+
if strings.Contains(lowerValue, "unavailable") {
178+
return tcell.ColorRed // Key is missing/locked
179+
}
180+
181+
// Paths / Mountpoints
182+
if strings.HasPrefix(value, "/") || lowerName == "mount point" || lowerName == "origin" {
183+
return tcell.ColorLightBlue
184+
}
185+
186+
// Booleans / Positive Flags
187+
if lowerValue == "yes" || lowerValue == "true" || lowerValue == "on" || lowerValue == "visible" || lowerValue == "mounted" || (lowerName == "compression" && lowerValue != "off") {
188+
return tcell.ColorGreen
189+
}
190+
if lowerValue == "no" || lowerValue == "false" || lowerValue == "off" || lowerValue == "hidden" {
191+
return tcell.ColorRed
192+
}
193+
194+
// File Sizes & Ratios
195+
if lowerName == "vol size" || lowerName == "available" || lowerName == "used" || lowerName == "snapshots" || strings.Contains(lowerValue, "x") {
196+
return tcell.ColorYellow
197+
}
198+
199+
// Fallback Default String Color
200+
return tcell.ColorWhite
201+
}
202+
157203
func (datasetInfo *DatasetInfoComponent) HasFocus() bool {
158204
return datasetInfo.container.HasFocus()
159205
}

0 commit comments

Comments
 (0)