refactor(shared): consolidate coverage, priority, and severity styles
Add reusable styles and helpers to shared package: - Coverage styles (high/med/low) with FormatCoverage() helper - Priority styles (high/medium/low) with FormatPriority() helper - Severity styles (critical/high/medium/low) with FormatSeverity() helper Update packages to use shared styles: - cmd/test: use shared coverage styles and FormatCoverage() - cmd/php: use shared status, QA, and severity styles Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
27a5b948a3
commit
1b76d4c145
4 changed files with 137 additions and 83 deletions
|
|
@ -15,66 +15,36 @@ var (
|
||||||
linkStyle = shared.LinkStyle
|
linkStyle = shared.LinkStyle
|
||||||
)
|
)
|
||||||
|
|
||||||
// Service colors for log output
|
// Service colors for log output (domain-specific, keep local)
|
||||||
var (
|
var (
|
||||||
phpFrankenPHPStyle = lipgloss.NewStyle().
|
phpFrankenPHPStyle = lipgloss.NewStyle().Foreground(shared.ColourIndigo500)
|
||||||
Foreground(lipgloss.Color("#6366f1")) // indigo-500
|
phpViteStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#eab308")) // yellow-500
|
||||||
|
phpHorizonStyle = lipgloss.NewStyle().Foreground(shared.ColourOrange500)
|
||||||
phpViteStyle = lipgloss.NewStyle().
|
phpReverbStyle = lipgloss.NewStyle().Foreground(shared.ColourViolet500)
|
||||||
Foreground(lipgloss.Color("#eab308")) // yellow-500
|
phpRedisStyle = lipgloss.NewStyle().Foreground(shared.ColourRed500)
|
||||||
|
|
||||||
phpHorizonStyle = lipgloss.NewStyle().
|
|
||||||
Foreground(lipgloss.Color("#f97316")) // orange-500
|
|
||||||
|
|
||||||
phpReverbStyle = lipgloss.NewStyle().
|
|
||||||
Foreground(lipgloss.Color("#8b5cf6")) // violet-500
|
|
||||||
|
|
||||||
phpRedisStyle = lipgloss.NewStyle().
|
|
||||||
Foreground(lipgloss.Color("#ef4444")) // red-500
|
|
||||||
|
|
||||||
phpStatusRunning = lipgloss.NewStyle().
|
|
||||||
Foreground(lipgloss.Color("#22c55e")). // green-500
|
|
||||||
Bold(true)
|
|
||||||
|
|
||||||
phpStatusStopped = lipgloss.NewStyle().
|
|
||||||
Foreground(lipgloss.Color("#6b7280")) // gray-500
|
|
||||||
|
|
||||||
phpStatusError = lipgloss.NewStyle().
|
|
||||||
Foreground(lipgloss.Color("#ef4444")). // red-500
|
|
||||||
Bold(true)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// QA command styles
|
// Status styles (from shared)
|
||||||
var (
|
var (
|
||||||
phpQAPassedStyle = lipgloss.NewStyle().
|
phpStatusRunning = shared.SuccessStyle
|
||||||
Foreground(lipgloss.Color("#22c55e")). // green-500
|
phpStatusStopped = shared.StatusPendingStyle
|
||||||
Bold(true)
|
phpStatusError = shared.ErrorStyle
|
||||||
|
)
|
||||||
|
|
||||||
phpQAFailedStyle = lipgloss.NewStyle().
|
// QA command styles (from shared)
|
||||||
Foreground(lipgloss.Color("#ef4444")). // red-500
|
var (
|
||||||
Bold(true)
|
phpQAPassedStyle = shared.SuccessStyle
|
||||||
|
phpQAFailedStyle = shared.ErrorStyle
|
||||||
|
phpQAWarningStyle = shared.WarningStyle
|
||||||
|
phpQAStageStyle = lipgloss.NewStyle().Bold(true).Foreground(shared.ColourIndigo500)
|
||||||
|
)
|
||||||
|
|
||||||
phpQAWarningStyle = lipgloss.NewStyle().
|
// Security severity styles (from shared)
|
||||||
Foreground(lipgloss.Color("#f59e0b")). // amber-500
|
var (
|
||||||
Bold(true)
|
phpSecurityCriticalStyle = shared.SeverityCriticalStyle
|
||||||
|
phpSecurityHighStyle = shared.SeverityHighStyle
|
||||||
phpQAStageStyle = lipgloss.NewStyle().
|
phpSecurityMediumStyle = shared.SeverityMediumStyle
|
||||||
Foreground(lipgloss.Color("#6366f1")). // indigo-500
|
phpSecurityLowStyle = shared.SeverityLowStyle
|
||||||
Bold(true)
|
|
||||||
|
|
||||||
phpSecurityCriticalStyle = lipgloss.NewStyle().
|
|
||||||
Foreground(lipgloss.Color("#ef4444")). // red-500
|
|
||||||
Bold(true)
|
|
||||||
|
|
||||||
phpSecurityHighStyle = lipgloss.NewStyle().
|
|
||||||
Foreground(lipgloss.Color("#f97316")). // orange-500
|
|
||||||
Bold(true)
|
|
||||||
|
|
||||||
phpSecurityMediumStyle = lipgloss.NewStyle().
|
|
||||||
Foreground(lipgloss.Color("#f59e0b")) // amber-500
|
|
||||||
|
|
||||||
phpSecurityLowStyle = lipgloss.NewStyle().
|
|
||||||
Foreground(lipgloss.Color("#6b7280")) // gray-500
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddPHPCommands adds PHP/Laravel development commands.
|
// AddPHPCommands adds PHP/Laravel development commands.
|
||||||
|
|
|
||||||
|
|
@ -192,6 +192,54 @@ var (
|
||||||
StatusWarningStyle = lipgloss.NewStyle().Foreground(ColourAmber500)
|
StatusWarningStyle = lipgloss.NewStyle().Foreground(ColourAmber500)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ─────────────────────────────────────────────────────────────────────────────
|
||||||
|
// Coverage Styles (for test/code coverage display)
|
||||||
|
// ─────────────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
var (
|
||||||
|
// CoverageHighStyle for good coverage (80%+).
|
||||||
|
CoverageHighStyle = lipgloss.NewStyle().Foreground(ColourGreen500)
|
||||||
|
|
||||||
|
// CoverageMedStyle for moderate coverage (50-79%).
|
||||||
|
CoverageMedStyle = lipgloss.NewStyle().Foreground(ColourAmber500)
|
||||||
|
|
||||||
|
// CoverageLowStyle for low coverage (<50%).
|
||||||
|
CoverageLowStyle = lipgloss.NewStyle().Foreground(ColourRed500)
|
||||||
|
)
|
||||||
|
|
||||||
|
// ─────────────────────────────────────────────────────────────────────────────
|
||||||
|
// Priority Styles (for task/issue priority levels)
|
||||||
|
// ─────────────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
var (
|
||||||
|
// PriorityHighStyle for high/critical priority (red, bold).
|
||||||
|
PriorityHighStyle = lipgloss.NewStyle().Bold(true).Foreground(ColourRed500)
|
||||||
|
|
||||||
|
// PriorityMediumStyle for medium priority (amber).
|
||||||
|
PriorityMediumStyle = lipgloss.NewStyle().Foreground(ColourAmber500)
|
||||||
|
|
||||||
|
// PriorityLowStyle for low priority (green).
|
||||||
|
PriorityLowStyle = lipgloss.NewStyle().Foreground(ColourGreen500)
|
||||||
|
)
|
||||||
|
|
||||||
|
// ─────────────────────────────────────────────────────────────────────────────
|
||||||
|
// Severity Styles (for security/QA severity levels)
|
||||||
|
// ─────────────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
var (
|
||||||
|
// SeverityCriticalStyle for critical issues (red, bold).
|
||||||
|
SeverityCriticalStyle = lipgloss.NewStyle().Bold(true).Foreground(ColourRed500)
|
||||||
|
|
||||||
|
// SeverityHighStyle for high severity issues (orange, bold).
|
||||||
|
SeverityHighStyle = lipgloss.NewStyle().Bold(true).Foreground(ColourOrange500)
|
||||||
|
|
||||||
|
// SeverityMediumStyle for medium severity issues (amber).
|
||||||
|
SeverityMediumStyle = lipgloss.NewStyle().Foreground(ColourAmber500)
|
||||||
|
|
||||||
|
// SeverityLowStyle for low severity issues (gray).
|
||||||
|
SeverityLowStyle = lipgloss.NewStyle().Foreground(ColourGray500)
|
||||||
|
)
|
||||||
|
|
||||||
// ─────────────────────────────────────────────────────────────────────────────
|
// ─────────────────────────────────────────────────────────────────────────────
|
||||||
// Box Styles (for bordered content)
|
// Box Styles (for bordered content)
|
||||||
// ─────────────────────────────────────────────────────────────────────────────
|
// ─────────────────────────────────────────────────────────────────────────────
|
||||||
|
|
@ -351,6 +399,61 @@ func Number(n int) string {
|
||||||
return NumberStyle.Render(fmt.Sprintf("%d", n))
|
return NumberStyle.Render(fmt.Sprintf("%d", n))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FormatCoverage formats a coverage percentage with colour based on thresholds.
|
||||||
|
// High (green) >= 80%, Medium (amber) >= 50%, Low (red) < 50%.
|
||||||
|
func FormatCoverage(percent float64) string {
|
||||||
|
var style lipgloss.Style
|
||||||
|
switch {
|
||||||
|
case percent >= 80:
|
||||||
|
style = CoverageHighStyle
|
||||||
|
case percent >= 50:
|
||||||
|
style = CoverageMedStyle
|
||||||
|
default:
|
||||||
|
style = CoverageLowStyle
|
||||||
|
}
|
||||||
|
return style.Render(fmt.Sprintf("%.1f%%", percent))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FormatCoverageCustom formats coverage with custom thresholds.
|
||||||
|
func FormatCoverageCustom(percent, highThreshold, medThreshold float64) string {
|
||||||
|
var style lipgloss.Style
|
||||||
|
switch {
|
||||||
|
case percent >= highThreshold:
|
||||||
|
style = CoverageHighStyle
|
||||||
|
case percent >= medThreshold:
|
||||||
|
style = CoverageMedStyle
|
||||||
|
default:
|
||||||
|
style = CoverageLowStyle
|
||||||
|
}
|
||||||
|
return style.Render(fmt.Sprintf("%.1f%%", percent))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FormatSeverity returns styled text for a severity level.
|
||||||
|
func FormatSeverity(level string) string {
|
||||||
|
switch strings.ToLower(level) {
|
||||||
|
case "critical":
|
||||||
|
return SeverityCriticalStyle.Render(level)
|
||||||
|
case "high":
|
||||||
|
return SeverityHighStyle.Render(level)
|
||||||
|
case "medium", "med":
|
||||||
|
return SeverityMediumStyle.Render(level)
|
||||||
|
default:
|
||||||
|
return SeverityLowStyle.Render(level)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FormatPriority returns styled text for a priority level.
|
||||||
|
func FormatPriority(level string) string {
|
||||||
|
switch strings.ToLower(level) {
|
||||||
|
case "high", "critical", "urgent":
|
||||||
|
return PriorityHighStyle.Render(level)
|
||||||
|
case "medium", "med", "normal":
|
||||||
|
return PriorityMediumStyle.Render(level)
|
||||||
|
default:
|
||||||
|
return PriorityLowStyle.Render(level)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ─────────────────────────────────────────────────────────────────────────────
|
// ─────────────────────────────────────────────────────────────────────────────
|
||||||
// Table Helpers
|
// Table Helpers
|
||||||
// ─────────────────────────────────────────────────────────────────────────────
|
// ─────────────────────────────────────────────────────────────────────────────
|
||||||
|
|
|
||||||
|
|
@ -4,30 +4,20 @@
|
||||||
package testcmd
|
package testcmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/charmbracelet/lipgloss"
|
|
||||||
"github.com/host-uk/core/cmd/shared"
|
"github.com/host-uk/core/cmd/shared"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Style aliases from shared
|
// Style aliases from shared
|
||||||
var (
|
var (
|
||||||
testHeaderStyle = shared.RepoNameStyle
|
testHeaderStyle = shared.RepoNameStyle
|
||||||
testPassStyle = shared.SuccessStyle
|
testPassStyle = shared.SuccessStyle
|
||||||
testFailStyle = shared.ErrorStyle
|
testFailStyle = shared.ErrorStyle
|
||||||
testSkipStyle = shared.WarningStyle
|
testSkipStyle = shared.WarningStyle
|
||||||
testDimStyle = shared.DimStyle
|
testDimStyle = shared.DimStyle
|
||||||
)
|
testCovHighStyle = shared.CoverageHighStyle
|
||||||
|
testCovMedStyle = shared.CoverageMedStyle
|
||||||
// Coverage-specific styles
|
testCovLowStyle = shared.CoverageLowStyle
|
||||||
var (
|
|
||||||
testCovHighStyle = lipgloss.NewStyle().
|
|
||||||
Foreground(lipgloss.Color("#22c55e")) // green-500
|
|
||||||
|
|
||||||
testCovMedStyle = lipgloss.NewStyle().
|
|
||||||
Foreground(lipgloss.Color("#f59e0b")) // amber-500
|
|
||||||
|
|
||||||
testCovLowStyle = lipgloss.NewStyle().
|
|
||||||
Foreground(lipgloss.Color("#ef4444")) // red-500
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Flag variables for test command
|
// Flag variables for test command
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/host-uk/core/cmd/shared"
|
||||||
)
|
)
|
||||||
|
|
||||||
type packageCoverage struct {
|
type packageCoverage struct {
|
||||||
|
|
@ -151,16 +151,7 @@ func printCoverageSummary(results testResults) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatCoverage(cov float64) string {
|
func formatCoverage(cov float64) string {
|
||||||
var style lipgloss.Style
|
return shared.FormatCoverage(cov)
|
||||||
switch {
|
|
||||||
case cov >= 80:
|
|
||||||
style = testCovHighStyle
|
|
||||||
case cov >= 50:
|
|
||||||
style = testCovMedStyle
|
|
||||||
default:
|
|
||||||
style = testCovLowStyle
|
|
||||||
}
|
|
||||||
return style.Render(fmt.Sprintf("%.1f%%", cov))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func shortenPackageName(name string) string {
|
func shortenPackageName(name string) string {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue