mirror of
https://github.com/tw93/Mole.git
synced 2026-03-22 20:15:07 +00:00
feat(status): alert on persistent high-cpu processes (#602)
* feat(status): alert on persistent high-cpu processes * refactor(status): keep high-cpu alerts read-only * fix(status): address lint and sudo test regressions --------- Co-authored-by: Tw93 <hitw93@gmail.com>
This commit is contained in:
@@ -17,7 +17,12 @@ var (
|
||||
okStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#A5D6A7"))
|
||||
lineStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#404040"))
|
||||
|
||||
primaryStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#BD93F9"))
|
||||
primaryStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#BD93F9"))
|
||||
alertBarStyle = lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("#2B1200")).
|
||||
Background(lipgloss.Color("#FFD75F")).
|
||||
Bold(true).
|
||||
Padding(0, 1)
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -234,6 +239,35 @@ func getScoreStyle(score int) lipgloss.Style {
|
||||
}
|
||||
}
|
||||
|
||||
func renderProcessAlertBar(alerts []ProcessAlert, width int) string {
|
||||
active := activeAlerts(alerts)
|
||||
if len(active) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
focus := active[0]
|
||||
|
||||
text := fmt.Sprintf(
|
||||
"ALERT %s at %.1f%% for %s (threshold %.1f%%)",
|
||||
formatProcessLabel(ProcessInfo{PID: focus.PID, Name: focus.Name}),
|
||||
focus.CPU,
|
||||
focus.Window,
|
||||
focus.Threshold,
|
||||
)
|
||||
if len(active) > 1 {
|
||||
text += fmt.Sprintf(" · +%d more", len(active)-1)
|
||||
}
|
||||
|
||||
return renderBanner(alertBarStyle, text, width)
|
||||
}
|
||||
|
||||
func renderBanner(style lipgloss.Style, text string, width int) string {
|
||||
if width > 0 {
|
||||
style = style.MaxWidth(width)
|
||||
}
|
||||
return style.Render(text)
|
||||
}
|
||||
|
||||
func renderCPUCard(cpu CPUStatus, thermal ThermalStatus) cardData {
|
||||
var lines []string
|
||||
|
||||
|
||||
Reference in New Issue
Block a user