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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: opencode-usage
3
- Version: 0.1.1
3
+ Version: 0.2.0
4
4
  Summary: CLI tool to track and display OpenCode token usage statistics
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "opencode-usage"
3
- version = "0.1.1"
3
+ version = "0.2.0"
4
4
  description = "CLI tool to track and display OpenCode token usage statistics"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -0,0 +1,7 @@
1
+ """OpenCode usage statistics CLI."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from importlib.metadata import version
6
+
7
+ __version__ = version("opencode-usage")
@@ -40,15 +40,20 @@ def _fmt_cost(c: float) -> str:
40
40
  return f"${c:.2f}"
41
41
 
42
42
 
43
- _SPARK_CHARS = "▁▂▃▄▅▆▇█"
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
- """Single-character bar proportional to value/max."""
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
- level = min(int(value / max_value * 7), 7)
51
- return _SPARK_CHARS[level]
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="center", style="cyan", no_wrap=True)
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]-[/]")
@@ -1,3 +0,0 @@
1
- """OpenCode usage statistics CLI."""
2
-
3
- __version__ = "0.1.0"
File without changes
File without changes