mirror of
https://github.com/tw93/Mole.git
synced 2026-02-11 13:34:23 +00:00
Merge pull request #312 from Copper-Eye/dev
Feature: Add cpu temp, top consumers, and visual improvements
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
<!-- {"contributors":["tw93","bhadraagada","JackPhallen","amanthanvi","alexandear","rubnogueira","biplavbarua","bsisduck","jimmystridh","fte-jjmartres","Else00","carolyn-sun","MohammedEsafi","ndbroadbent","Sizk","thijsvanhal","yuzeguitarist","zeldrisho","bunizao","frozturk","huyixi","purofle","Schlauer-Hax","anonymort","khipu-luke","LmanTW","kwakubiney","kowyo","jalen0x","Hensell","ClathW","andmev"],"collaborators":["tw93"],"bots":["github-actions[bot]","dependabot[bot]"]} -->
|
<!-- {"contributors":["tw93","bhadraagada","JackPhallen","amanthanvi","alexandear","rubnogueira","biplavbarua","bsisduck","jimmystridh","fte-jjmartres","Else00","carolyn-sun","MohammedEsafi","ndbroadbent","Sizk","thijsvanhal","yuzeguitarist","zeldrisho","bunizao","frozturk","huyixi","purofle","Schlauer-Hax","anonymort","khipu-luke","LmanTW","kwakubiney","kowyo","jalen0x","Hensell","ClathW","andmev"],"collaborators":["Copper-Eye"],"bots":["github-actions[bot]","dependabot[bot]"]} -->
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="1000" height="548">
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="1000" height="548">
|
||||||
<style>.contributor-link { cursor: pointer; }</style>
|
<style>.contributor-link { cursor: pointer; }</style>
|
||||||
<g transform="translate(45, 45)">
|
<g transform="translate(45, 45)">
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 309 KiB After Width: | Height: | Size: 309 KiB |
10
bin/purge.sh
10
bin/purge.sh
@@ -98,12 +98,7 @@ perform_purge() {
|
|||||||
# Function to truncate path in the middle
|
# Function to truncate path in the middle
|
||||||
truncate_path() {
|
truncate_path() {
|
||||||
local path="$1"
|
local path="$1"
|
||||||
local term_width=$(tput cols 2> /dev/null || echo 80)
|
local max_len=80
|
||||||
# Reserve space: "| Scanning " = 12 chars, spinner = 2 chars, margins = 4 chars
|
|
||||||
local max_len=$((term_width - 18))
|
|
||||||
|
|
||||||
# Minimum length to avoid too short
|
|
||||||
[[ $max_len -lt 40 ]] && max_len=40
|
|
||||||
|
|
||||||
if [[ ${#path} -le $max_len ]]; then
|
if [[ ${#path} -le $max_len ]]; then
|
||||||
echo "$path"
|
echo "$path"
|
||||||
@@ -133,8 +128,7 @@ perform_purge() {
|
|||||||
local spin_char="${spinner_chars:$spinner_idx:1}"
|
local spin_char="${spinner_chars:$spinner_idx:1}"
|
||||||
spinner_idx=$(((spinner_idx + 1) % ${#spinner_chars}))
|
spinner_idx=$(((spinner_idx + 1) % ${#spinner_chars}))
|
||||||
|
|
||||||
# Clear previous output and redraw
|
# Show title on first line, spinner and scanning info on second line
|
||||||
# Important: Must move up THEN to start of line to avoid column offset
|
|
||||||
if [[ -n "$display_path" ]]; then
|
if [[ -n "$display_path" ]]; then
|
||||||
# Line 1: Move to start, clear, print title
|
# Line 1: Move to start, clear, print title
|
||||||
printf '\r\033[K%s\n' "${PURPLE_BOLD}Purge Project Artifacts${NC}"
|
printf '\r\033[K%s\n' "${PURPLE_BOLD}Purge Project Artifacts${NC}"
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ func getScoreStyle(score int) lipgloss.Style {
|
|||||||
|
|
||||||
func buildCards(m MetricsSnapshot, _ int) []cardData {
|
func buildCards(m MetricsSnapshot, _ int) []cardData {
|
||||||
cards := []cardData{
|
cards := []cardData{
|
||||||
renderCPUCard(m.CPU),
|
renderCPUCard(m.CPU, m.Thermal),
|
||||||
renderMemoryCard(m.Memory),
|
renderMemoryCard(m.Memory),
|
||||||
renderDiskCard(m.Disks, m.DiskIO),
|
renderDiskCard(m.Disks, m.DiskIO),
|
||||||
renderBatteryCard(m.Batteries, m.Thermal),
|
renderBatteryCard(m.Batteries, m.Thermal),
|
||||||
@@ -225,9 +225,18 @@ func hasSensorData(sensors []SensorReading) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderCPUCard(cpu CPUStatus) cardData {
|
func renderCPUCard(cpu CPUStatus, thermal ThermalStatus) cardData {
|
||||||
var lines []string
|
var lines []string
|
||||||
lines = append(lines, fmt.Sprintf("Total %s %5.1f%%", progressBar(cpu.Usage), cpu.Usage))
|
|
||||||
|
// Line 1: Usage + Temp (Format: 15% @ 30.4°C)
|
||||||
|
usageBar := progressBar(cpu.Usage)
|
||||||
|
|
||||||
|
headerText := fmt.Sprintf("%5.1f%%", cpu.Usage)
|
||||||
|
if thermal.CPUTemp > 0 {
|
||||||
|
headerText += fmt.Sprintf(" @ %s°C", colorizeTemp(thermal.CPUTemp))
|
||||||
|
}
|
||||||
|
|
||||||
|
lines = append(lines, fmt.Sprintf("Total %s %s", usageBar, headerText))
|
||||||
|
|
||||||
if cpu.PerCoreEstimated {
|
if cpu.PerCoreEstimated {
|
||||||
lines = append(lines, subtleStyle.Render("Per-core data unavailable (using averaged load)"))
|
lines = append(lines, subtleStyle.Render("Per-core data unavailable (using averaged load)"))
|
||||||
@@ -527,12 +536,7 @@ func renderBatteryCard(batts []BatteryStatus, thermal ThermalStatus) cardData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if thermal.CPUTemp > 0 {
|
if thermal.CPUTemp > 0 {
|
||||||
tempText := fmt.Sprintf("%.0f°C", thermal.CPUTemp)
|
tempText := colorizeTemp(thermal.CPUTemp) + "°C" // Reuse common color logic
|
||||||
if thermal.CPUTemp > 80 {
|
|
||||||
tempText = dangerStyle.Render(tempText)
|
|
||||||
} else if thermal.CPUTemp > 60 {
|
|
||||||
tempText = warnStyle.Render(tempText)
|
|
||||||
}
|
|
||||||
healthParts = append(healthParts, tempText)
|
healthParts = append(healthParts, tempText)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -641,12 +645,12 @@ func colorizeBattery(percent float64, s string) string {
|
|||||||
|
|
||||||
func colorizeTemp(t float64) string {
|
func colorizeTemp(t float64) string {
|
||||||
switch {
|
switch {
|
||||||
case t >= 85:
|
case t >= 76:
|
||||||
return dangerStyle.Render(fmt.Sprintf("%.1f", t))
|
return dangerStyle.Render(fmt.Sprintf("%.1f", t))
|
||||||
case t >= 70:
|
case t >= 56:
|
||||||
return warnStyle.Render(fmt.Sprintf("%.1f", t))
|
return warnStyle.Render(fmt.Sprintf("%.1f", t))
|
||||||
default:
|
default:
|
||||||
return subtleStyle.Render(fmt.Sprintf("%.1f", t))
|
return okStyle.Render(fmt.Sprintf("%.1f", t))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -260,11 +260,20 @@ get_user_home() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get_invoking_user() {
|
get_invoking_user() {
|
||||||
if [[ -n "${SUDO_USER:-}" && "${SUDO_USER:-}" != "root" ]]; then
|
if [[ -n "${_MOLE_INVOKING_USER_CACHE:-}" ]]; then
|
||||||
echo "$SUDO_USER"
|
echo "$_MOLE_INVOKING_USER_CACHE"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
echo "${USER:-}"
|
|
||||||
|
local user
|
||||||
|
if [[ -n "${SUDO_USER:-}" && "${SUDO_USER:-}" != "root" ]]; then
|
||||||
|
user="$SUDO_USER"
|
||||||
|
else
|
||||||
|
user="${USER:-}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
export _MOLE_INVOKING_USER_CACHE="$user"
|
||||||
|
echo "$user"
|
||||||
}
|
}
|
||||||
|
|
||||||
get_invoking_uid() {
|
get_invoking_uid() {
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ setup() {
|
|||||||
|
|
||||||
elapsed=$(( (end - start) / 1000000 ))
|
elapsed=$(( (end - start) / 1000000 ))
|
||||||
|
|
||||||
[ "$elapsed" -lt 200 ]
|
[ "$elapsed" -lt 500 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "get_darwin_major caches correctly" {
|
@test "get_darwin_major caches correctly" {
|
||||||
|
|||||||
Reference in New Issue
Block a user