feat: migrate lipgloss v1 to v2 (charm.land/lipgloss/v2)
Replace github.com/charmbracelet/lipgloss v1.1.0 with charm.land/lipgloss/v2 v2.0.2. lipgloss.Color changed from a type to a function, so all type signatures now use color.Color from image/color. Local variables named `color` renamed to `clr` to avoid shadowing the package import. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+24
-23
@@ -16,7 +16,8 @@ import (
|
||||
"time"
|
||||
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"image/color"
|
||||
"charm.land/lipgloss/v2"
|
||||
"github.com/creack/pty"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/hinshun/vt10x"
|
||||
@@ -1974,16 +1975,16 @@ var (
|
||||
)
|
||||
|
||||
// colorOr returns the config color if non-empty, otherwise the default
|
||||
func colorOr(cfgColor string, def lipgloss.Color) lipgloss.Color {
|
||||
func colorOr(cfgColor string, def color.Color) color.Color {
|
||||
if cfgColor != "" { return lipgloss.Color(cfgColor) }
|
||||
return def
|
||||
}
|
||||
|
||||
// Resolved colors from config with defaults
|
||||
func (a *App) borderSelected() lipgloss.Color { return colorOr(a.Config.AppColors.Borders.Selected, cBlue) }
|
||||
func (a *App) borderUnselected() lipgloss.Color { return colorOr(a.Config.AppColors.Borders.Unselected, cSurface0) }
|
||||
func (a *App) borderSelected() color.Color { return colorOr(a.Config.AppColors.Borders.Selected, cBlue) }
|
||||
func (a *App) borderUnselected() color.Color { return colorOr(a.Config.AppColors.Borders.Unselected, cSurface0) }
|
||||
|
||||
func (a *App) cmdColorCfg(cmd string) lipgloss.Color {
|
||||
func (a *App) cmdColorCfg(cmd string) color.Color {
|
||||
cc := a.Config.AppColors.Commands
|
||||
switch cmd {
|
||||
case "start": return colorOr(cc.Start, cGreen)
|
||||
@@ -1996,7 +1997,7 @@ func (a *App) cmdColorCfg(cmd string) lipgloss.Color {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) stateColorCfg(s ContainerState) lipgloss.Color {
|
||||
func (a *App) stateColorCfg(s ContainerState) color.Color {
|
||||
cs := a.Config.AppColors.ContainerState
|
||||
switch s {
|
||||
case RunningHealthy: return colorOr(cs.RunningHealthy, cGreen)
|
||||
@@ -2289,11 +2290,11 @@ func (a *App) viewCommands(w, h int) string {
|
||||
|
||||
var sb strings.Builder
|
||||
for i, cmd := range cmds {
|
||||
color := a.cmdColorCfg(cmd)
|
||||
clr := a.cmdColorCfg(cmd)
|
||||
if i == a.CmdSelectedIdx {
|
||||
sb.WriteString(arrow + lipgloss.NewStyle().Foreground(color).Bold(true).Render(cmd) + "\n")
|
||||
sb.WriteString(arrow + lipgloss.NewStyle().Foreground(clr).Bold(true).Render(cmd) + "\n")
|
||||
} else {
|
||||
sb.WriteString(" " + lipgloss.NewStyle().Foreground(color).Bold(true).Render(cmd) + "\n")
|
||||
sb.WriteString(" " + lipgloss.NewStyle().Foreground(clr).Bold(true).Render(cmd) + "\n")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2396,7 +2397,7 @@ func (a *App) viewSparkChart(typ string, w, h int, c *Container) string {
|
||||
bc := a.borderUnselected()
|
||||
var title string
|
||||
var data []float64
|
||||
var color lipgloss.Color
|
||||
var clr color.Color
|
||||
var yLabel string
|
||||
|
||||
if c != nil {
|
||||
@@ -2405,20 +2406,20 @@ func (a *App) viewSparkChart(typ string, w, h int, c *Container) string {
|
||||
case "cpu":
|
||||
title = fmt.Sprintf("cpu %05.2f%%", c.CPUPercent)
|
||||
data = c.CPUHist
|
||||
if isActive { color = cGreen } else { color = cOverlay0 }
|
||||
if isActive { clr = cGreen } else { clr = cOverlay0 }
|
||||
case "memory":
|
||||
title = fmt.Sprintf("memory %s", fmtBytes(c.MemUsage))
|
||||
for _, v := range c.MemHist { data = append(data, float64(v)) }
|
||||
if isActive { color = cBlue } else { color = cOverlay0 }
|
||||
if isActive { clr = cBlue } else { clr = cOverlay0 }
|
||||
}
|
||||
} else {
|
||||
switch typ {
|
||||
case "cpu":
|
||||
title = "cpu 00.00%"
|
||||
color = cGreen
|
||||
clr = cGreen
|
||||
case "memory":
|
||||
title = "memory 0.00 kB"
|
||||
color = cBlue
|
||||
clr = cBlue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2433,7 +2434,7 @@ func (a *App) viewSparkChart(typ string, w, h int, c *Container) string {
|
||||
yLabel = fmtBytes(uint64(maxVal))
|
||||
}
|
||||
|
||||
return a.renderBrailleChart(title, yLabel, data, color, bc, w, h)
|
||||
return a.renderBrailleChart(title, yLabel, data, clr, bc, w, h)
|
||||
}
|
||||
|
||||
func (a *App) viewBWChart(w, h int, c *Container) string {
|
||||
@@ -2459,7 +2460,7 @@ func (a *App) viewBWChart(w, h int, c *Container) string {
|
||||
}
|
||||
|
||||
// renderBrailleChart renders a single-dataset braille chart with Y-axis label and title in border
|
||||
func (a *App) renderBrailleChart(title, yLabel string, data []float64, color, borderColor lipgloss.Color, w, h int) string {
|
||||
func (a *App) renderBrailleChart(title, yLabel string, data []float64, clr, borderColor color.Color, w, h int) string {
|
||||
innerH := h - 2 // border takes 2
|
||||
innerW := w - 2 // border takes 2
|
||||
if innerH < 1 { innerH = 1 }
|
||||
@@ -2472,7 +2473,7 @@ func (a *App) renderBrailleChart(title, yLabel string, data []float64, color, bo
|
||||
chartW := innerW - yLabelW
|
||||
if chartW < 2 { chartW = 2 }
|
||||
|
||||
chart := brailleChart(data, chartW, innerH, color)
|
||||
chart := brailleChart(data, chartW, innerH, clr)
|
||||
chartLines := strings.Split(chart, "\n")
|
||||
if len(chartLines) == 0 {
|
||||
chartLines = []string{""}
|
||||
@@ -2480,7 +2481,7 @@ func (a *App) renderBrailleChart(title, yLabel string, data []float64, color, bo
|
||||
|
||||
// Build content with Y-axis label
|
||||
var sb strings.Builder
|
||||
yStyle := lipgloss.NewStyle().Foreground(color)
|
||||
yStyle := lipgloss.NewStyle().Foreground(clr)
|
||||
for i, line := range chartLines {
|
||||
if i == 0 && yLabel != "" {
|
||||
sb.WriteString(yStyle.Render(padL(yLabel, yLabelW-1)))
|
||||
@@ -2530,7 +2531,7 @@ func (a *App) renderBrailleChart(title, yLabel string, data []float64, color, bo
|
||||
}
|
||||
|
||||
// renderBrailleBWChart renders RX/TX as two braille charts stacked, with title in border
|
||||
func (a *App) renderBrailleBWChart(title string, rxData, txData []float64, rxRate, txRate string, borderColor lipgloss.Color, w, h int) string {
|
||||
func (a *App) renderBrailleBWChart(title string, rxData, txData []float64, rxRate, txRate string, borderColor color.Color, w, h int) string {
|
||||
innerH := h - 2
|
||||
innerW := w - 2
|
||||
if innerH < 2 { innerH = 2 }
|
||||
@@ -2986,7 +2987,7 @@ func (a *App) filtered() []Container {
|
||||
// HELPERS
|
||||
// ============================================================
|
||||
|
||||
func stateStyle(s ContainerState) (string, lipgloss.Color) {
|
||||
func stateStyle(s ContainerState) (string, color.Color) {
|
||||
switch s {
|
||||
case RunningHealthy: return "✓", cGreen
|
||||
case RunningUnhealthy: return "!", cPeach
|
||||
@@ -3021,7 +3022,7 @@ func commandsForState(s ContainerState) []string {
|
||||
}
|
||||
}
|
||||
|
||||
func cmdColor(cmd string) lipgloss.Color {
|
||||
func cmdColor(cmd string) color.Color {
|
||||
switch cmd {
|
||||
case "start":
|
||||
return cGreen
|
||||
@@ -3042,7 +3043,7 @@ func cmdColor(cmd string) lipgloss.Color {
|
||||
|
||||
// brailleChart renders data as a braille dot chart (matching original Rust ratatui style).
|
||||
// Each terminal cell is a 2×4 braille grid, giving (w*2) × (h*4) resolution.
|
||||
func brailleChart(data []float64, w, h int, color lipgloss.Color) string {
|
||||
func brailleChart(data []float64, w, h int, clr color.Color) string {
|
||||
if w <= 0 || h <= 0 { return "" }
|
||||
|
||||
// Braille dot offsets: each char is 2 cols × 4 rows
|
||||
@@ -3081,7 +3082,7 @@ func brailleChart(data []float64, w, h int, color lipgloss.Color) string {
|
||||
}
|
||||
|
||||
// Render braille characters
|
||||
s := lipgloss.NewStyle().Foreground(color)
|
||||
s := lipgloss.NewStyle().Foreground(clr)
|
||||
dimS := lipgloss.NewStyle().Foreground(cSurface1)
|
||||
var lines []string
|
||||
|
||||
|
||||
Reference in New Issue
Block a user