Bug Description
The PRINT_DATA function in machine_report.sh has a truncation bug that causes the right │ border to appear too far to the left when data is truncated with ....
Root Cause
Two issues in PRINT_DATA (around line 146):
if (( data_len >= MAX_DATA_LEN || data_len == MAX_DATA_LEN-1 )); then
data=$(echo "$data" | cut -c 1-$((MAX_DATA_LEN-3-2)))...
else
data=$(printf "%-${max_data_len}s" "$data")
fi
1. Missing padding after truncation: When data is truncated, the result is MAX_DATA_LEN-3-2 + ... = 30 characters, but it's never padded back to CURRENT_LEN. The else branch pads, but the if branch doesn't. This causes the right │ to shift left by CURRENT_LEN - 30 characters.
2. Over-eager truncation threshold: The condition data_len >= MAX_DATA_LEN || data_len == MAX_DATA_LEN-1 (effectively >= 31) uses the constant MAX_DATA_LEN instead of the dynamic max_data_len (which is CURRENT_LEN). This incorrectly truncates data that fits perfectly in the column — notably bar graphs, which are generated at exactly CURRENT_LEN width.
Visual Example
│ LOAD 1m │ ██░░░░░░░... │ ← border shifted left
│ LOAD 5m │ ██░░░░░░░... │
│ DISK USAGE │ █████████... │
│ USAGE │ █████████... │
│ HOSTNAME │ framework-laptop │ ← correct alignment
Suggested Fix
# Truncate or pad data
local data_len=${#data}
if (( data_len > max_data_len )); then
data=$(echo "$data" | cut -c 1-$((max_data_len-3)))...
fi
data=$(printf "%-${max_data_len}s" "$data")
Changes:
- Compare against
max_data_len (dynamic) instead of MAX_DATA_LEN (constant)
- Use
> instead of >= so data that fits exactly isn't truncated
- Always pad to
max_data_len, regardless of whether truncation occurred
Bug Description
The
PRINT_DATAfunction inmachine_report.shhas a truncation bug that causes the right│border to appear too far to the left when data is truncated with....Root Cause
Two issues in
PRINT_DATA(around line 146):1. Missing padding after truncation: When data is truncated, the result is
MAX_DATA_LEN-3-2+...= 30 characters, but it's never padded back toCURRENT_LEN. Theelsebranch pads, but theifbranch doesn't. This causes the right│to shift left byCURRENT_LEN - 30characters.2. Over-eager truncation threshold: The condition
data_len >= MAX_DATA_LEN || data_len == MAX_DATA_LEN-1(effectively>= 31) uses the constantMAX_DATA_LENinstead of the dynamicmax_data_len(which isCURRENT_LEN). This incorrectly truncates data that fits perfectly in the column — notably bar graphs, which are generated at exactlyCURRENT_LENwidth.Visual Example
Suggested Fix
Changes:
max_data_len(dynamic) instead ofMAX_DATA_LEN(constant)>instead of>=so data that fits exactly isn't truncatedmax_data_len, regardless of whether truncation occurred