Skip to content

Commit 1b45294

Browse files
authored
Merge pull request #48 from Paliak/gui-tweaks
Implement a few gui tweaks to the details panel so that it looks better on small width terminals
2 parents 2640dbb + fb462fd commit 1b45294

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

src/pingtop/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from typing import Protocol
88

99
HostId = str
10-
MAX_HISTORY = 60
10+
MAX_HISTORY = 64
1111
TREND_BLOCKS = "▁▂▃▄▅▆▇█"
1212
TIMEOUT_MARKER = "╳"
1313

src/pingtop/widgets/details_panel.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from rich.text import Text
66
from textual.widgets import Static
7+
import pingtop.models
78

89
from pingtop.widgets.trend import render_detailed_trend_graph
910

@@ -33,11 +34,11 @@ def _fmt(value: object) -> str:
3334
def _graph_width(self, left_width: int) -> int:
3435
if self.size.width <= 0:
3536
return 32
36-
available = self.size.width - left_width - self.COLUMN_GAP - 6
37-
return max(16, min(72, available))
37+
available = self.size.width - left_width - self.COLUMN_GAP - 8
38+
return max(16, min(pingtop.models.MAX_HISTORY, available))
3839

3940
def _left_column_lines(self, row: dict[str, object]) -> list[str]:
40-
return [
41+
lines = [
4142
f"Host: {row['target']}",
4243
f"IP: {row['resolved_ip'] or '-'}",
4344
f"State: {row['state']}",
@@ -48,9 +49,14 @@ def _left_column_lines(self, row: dict[str, object]) -> list[str]:
4849
f"StdDev: {self._fmt(row['stddev_ms'])}",
4950
f"Sent: {row['seq']}",
5051
f"Loss: {row['lost']} ({float(cast(float, row['loss_percent'])):.1f}%)",
51-
f"Error: {self._truncate(str(row['last_error'] or '-'))}",
5252
]
5353

54+
last_err = row.get('last_error')
55+
if last_err not in (None, '', b''):
56+
lines.append(f"Error: {self._truncate(str(last_err))}")
57+
58+
return lines
59+
5460
def _left_column_width(self, lines: list[str]) -> int:
5561
if not lines:
5662
return 0

src/pingtop/widgets/trend.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,8 @@ def render_detailed_trend_graph(
105105

106106
low = min(samples)
107107
high = max(samples)
108-
avg = sum(samples) / len(samples)
109108
span = max(high - low, 1.0)
110109
label_width = max(len(f"{low:.1f}"), len(f"{high:.1f}"))
111-
header.append(f" {low:.1f}..{high:.1f} ms", style=DETAIL_GRAPH_AXIS_STYLE)
112-
header.append(f" avg {avg:.1f}", style=DETAIL_GRAPH_AXIS_STYLE)
113110

114111
lines = [header]
115112
for level in range(height, 0, -1):
@@ -128,10 +125,11 @@ def render_detailed_trend_graph(
128125
line.append("█", style=TREND_STYLES[bucket])
129126
else:
130127
line.append("·", style=DETAIL_GRAPH_EMPTY_STYLE)
128+
for _ in range(width - len(cells)):
129+
line.append("·", style=DETAIL_GRAPH_EMPTY_STYLE)
131130
lines.append(line)
132131

133-
lines.append(_render_graph_axis(len(cells), label_width))
134-
lines.append(Text(" " * (label_width + 3) + "oldest -> newest", style=DETAIL_GRAPH_AXIS_STYLE))
132+
lines.append(_render_graph_axis(width, label_width))
135133
return lines
136134

137135

0 commit comments

Comments
 (0)