opencode-usage 0.1.1__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {opencode_usage-0.1.1 → opencode_usage-0.2.0}/PKG-INFO +1 -1
- {opencode_usage-0.1.1 → opencode_usage-0.2.0}/pyproject.toml +1 -1
- opencode_usage-0.2.0/src/opencode_usage/__init__.py +7 -0
- {opencode_usage-0.1.1 → opencode_usage-0.2.0}/src/opencode_usage/render.py +32 -8
- opencode_usage-0.1.1/src/opencode_usage/__init__.py +0 -3
- {opencode_usage-0.1.1 → opencode_usage-0.2.0}/.gitignore +0 -0
- {opencode_usage-0.1.1 → opencode_usage-0.2.0}/LICENSE +0 -0
- {opencode_usage-0.1.1 → opencode_usage-0.2.0}/README.md +0 -0
- {opencode_usage-0.1.1 → opencode_usage-0.2.0}/src/opencode_usage/__main__.py +0 -0
- {opencode_usage-0.1.1 → opencode_usage-0.2.0}/src/opencode_usage/cli.py +0 -0
- {opencode_usage-0.1.1 → opencode_usage-0.2.0}/src/opencode_usage/db.py +0 -0
|
@@ -40,15 +40,20 @@ def _fmt_cost(c: float) -> str:
|
|
|
40
40
|
return f"${c:.2f}"
|
|
41
41
|
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
_BAR_FULL = "█"
|
|
44
|
+
_BAR_EMPTY = "░"
|
|
45
|
+
_BAR_WIDTH_DEFAULT = 8
|
|
44
46
|
|
|
45
47
|
|
|
46
|
-
def _spark_bar(value: int, max_value: int) -> str:
|
|
47
|
-
"""
|
|
48
|
+
def _spark_bar(value: int, max_value: int, width: int = _BAR_WIDTH_DEFAULT) -> str:
|
|
49
|
+
"""Horizontal bar proportional to value/max, fixed *width* characters."""
|
|
50
|
+
if width < 1:
|
|
51
|
+
width = 1
|
|
48
52
|
if max_value <= 0 or value <= 0:
|
|
49
|
-
return
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
return _BAR_EMPTY * width
|
|
54
|
+
filled = max(1, round(value / max_value * width))
|
|
55
|
+
filled = min(filled, width)
|
|
56
|
+
return _BAR_FULL * filled + _BAR_EMPTY * (width - filled)
|
|
52
57
|
|
|
53
58
|
|
|
54
59
|
def _fmt_delta(pct: float) -> str:
|
|
@@ -98,6 +103,25 @@ def _make_table(
|
|
|
98
103
|
|
|
99
104
|
label_max = 24 if show_detail else 30
|
|
100
105
|
detail_max = 18 if show_detail else 0
|
|
106
|
+
|
|
107
|
+
# Estimate fixed column widths (content + padding + borders)
|
|
108
|
+
# Each column has ~3 chars overhead (padding + border).
|
|
109
|
+
col_overhead = 3
|
|
110
|
+
fixed_width = label_max + col_overhead # label
|
|
111
|
+
if show_detail:
|
|
112
|
+
fixed_width += detail_max + col_overhead
|
|
113
|
+
fixed_width += 5 + col_overhead # Calls
|
|
114
|
+
if show_breakdown:
|
|
115
|
+
fixed_width += (6 + col_overhead) * 4 # Input, Output, Cache R, Cache W
|
|
116
|
+
fixed_width += (7 + col_overhead) * 2 # Total, Cost
|
|
117
|
+
if deltas is not None:
|
|
118
|
+
fixed_width += 6 + col_overhead
|
|
119
|
+
fixed_width += 4 # table outer borders + edge padding
|
|
120
|
+
|
|
121
|
+
# Compute trend bar width from remaining terminal space
|
|
122
|
+
term_width = console.width or 80
|
|
123
|
+
bar_width = min(24, max(_BAR_WIDTH_DEFAULT, term_width - fixed_width - col_overhead))
|
|
124
|
+
|
|
101
125
|
table.add_column(label_header, style="bold", no_wrap=True, max_width=label_max)
|
|
102
126
|
if show_detail:
|
|
103
127
|
table.add_column(show_detail, style="dim cyan", no_wrap=True, max_width=detail_max)
|
|
@@ -110,7 +134,7 @@ def _make_table(
|
|
|
110
134
|
table.add_column("Total", justify="right", style="bold white", min_width=7)
|
|
111
135
|
table.add_column("Cost", justify="right", style="bold red", min_width=7)
|
|
112
136
|
if trend_values is not None:
|
|
113
|
-
table.add_column("Trend", justify="
|
|
137
|
+
table.add_column("Trend", justify="left", style="cyan", no_wrap=True, min_width=bar_width)
|
|
114
138
|
if deltas is not None:
|
|
115
139
|
table.add_column("Δ", justify="right", min_width=6)
|
|
116
140
|
|
|
@@ -143,7 +167,7 @@ def _make_table(
|
|
|
143
167
|
cols.extend([_fmt_tokens(r.tokens.total), _fmt_cost(r.cost)])
|
|
144
168
|
if trend_values is not None:
|
|
145
169
|
tv = trend_values[_i] if _i < len(trend_values) else 0
|
|
146
|
-
cols.append(_spark_bar(tv, trend_max))
|
|
170
|
+
cols.append(_spark_bar(tv, trend_max, bar_width))
|
|
147
171
|
if deltas is not None:
|
|
148
172
|
d = deltas[_i] if _i < len(deltas) else None
|
|
149
173
|
cols.append(_fmt_delta(d) if d is not None else "[dim]-[/]")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|