|
|
@@ -17,7 +17,6 @@ const (
|
|
|
barWidth = 30
|
|
|
barFilled = "█"
|
|
|
barEmpty = "░"
|
|
|
- emDash = "—"
|
|
|
)
|
|
|
|
|
|
// AccountResult bundles a single account's fetch outcome for RenderAll.
|
|
|
@@ -79,9 +78,9 @@ func setGlobalColor(useColor bool) {
|
|
|
color.NoColor = !useColor
|
|
|
}
|
|
|
|
|
|
-// RenderAccount writes the header + three quota rows + token summary for a
|
|
|
-// single account. Caller must have already called setGlobalColor via RenderAll,
|
|
|
-// or set color.NoColor directly.
|
|
|
+// RenderAccount writes the header + two quota rows + token summary + monthly
|
|
|
+// cap line for a single account. Caller must have already called
|
|
|
+// setGlobalColor via RenderAll, or set color.NoColor directly.
|
|
|
func RenderAccount(w io.Writer, name string, resp *api.Response, useColor bool) {
|
|
|
writeHeader(w, name)
|
|
|
writePlanLine(w, resp)
|
|
|
@@ -89,16 +88,11 @@ func RenderAccount(w io.Writer, name string, resp *api.Response, useColor bool)
|
|
|
|
|
|
d := resp.Data
|
|
|
rows := []struct {
|
|
|
- label string
|
|
|
- window api.QuotaWindow
|
|
|
- monthly bool
|
|
|
+ label string
|
|
|
+ window api.QuotaWindow
|
|
|
}{
|
|
|
- {"5 hour", d.Quota5Hour, false},
|
|
|
- {"7 day", d.Quota7Day, false},
|
|
|
- {"month", api.QuotaWindow{
|
|
|
- MaxFlows: d.QuotaMonthly.MaxFlows,
|
|
|
- MaxValueUSD: d.QuotaMonthly.MaxValueUSD,
|
|
|
- }, true},
|
|
|
+ {"5 hour", d.Quota5Hour},
|
|
|
+ {"7 day", d.Quota7Day},
|
|
|
}
|
|
|
|
|
|
// Pre-format each row's segments so we can align by max width.
|
|
|
@@ -109,19 +103,11 @@ func RenderAccount(w io.Writer, name string, resp *api.Response, useColor bool)
|
|
|
fmts := make([]formatted, len(rows))
|
|
|
for i, r := range rows {
|
|
|
f := formatted{label: r.label}
|
|
|
- if r.monthly {
|
|
|
- f.bar = ProgressBar(0, barWidth) // no used data available
|
|
|
- f.pct = " n/a "
|
|
|
- f.pctAttr = color.FgWhite
|
|
|
- f.flows = fmt.Sprintf("%s / %s flows", emDash, fmtFlow(r.window.MaxFlows))
|
|
|
- f.dollars = fmt.Sprintf("%s / %s", emDash, fmtUSD(r.window.MaxValueUSD))
|
|
|
- } else {
|
|
|
- f.bar = ProgressBar(r.window.UsagePercentage, barWidth)
|
|
|
- f.pct = fmt.Sprintf("%6.2f%%", r.window.UsagePercentage*100)
|
|
|
- f.pctAttr = BandColor(r.window.UsagePercentage)
|
|
|
- f.flows = fmt.Sprintf("%s / %s flows", fmtFlow(r.window.UsedFlows), fmtFlow(r.window.MaxFlows))
|
|
|
- f.dollars = fmt.Sprintf("%s / %s", fmtUSD(r.window.UsedValueUSD), fmtUSD(r.window.MaxValueUSD))
|
|
|
- }
|
|
|
+ f.bar = ProgressBar(r.window.UsagePercentage, barWidth)
|
|
|
+ f.pct = fmt.Sprintf("%6.2f%%", r.window.UsagePercentage*100)
|
|
|
+ f.pctAttr = BandColor(r.window.UsagePercentage)
|
|
|
+ f.flows = fmt.Sprintf("%s / %s flows", fmtFlow(r.window.UsedFlows), fmtFlow(r.window.MaxFlows))
|
|
|
+ f.dollars = fmt.Sprintf("%s / %s", fmtUSD(r.window.UsedValueUSD), fmtUSD(r.window.MaxValueUSD))
|
|
|
fmts[i] = f
|
|
|
}
|
|
|
flowsW, dollarsW := 0, 0
|
|
|
@@ -142,8 +128,9 @@ func RenderAccount(w io.Writer, name string, resp *api.Response, useColor bool)
|
|
|
}
|
|
|
|
|
|
fmt.Fprintln(w)
|
|
|
- tokens := fmtUSD(d.Quota7Day.UsedValueUSD)
|
|
|
- fmt.Fprintf(w, " Tokens consumed (estimated USD value): %s\n", tokens)
|
|
|
+ fmt.Fprintf(w, " Tokens consumed (estimated USD value): %s\n", fmtUSD(d.Quota7Day.UsedValueUSD))
|
|
|
+ fmt.Fprintf(w, " Monthly cap: %s flows · %s\n",
|
|
|
+ fmtFlow(d.QuotaMonthly.MaxFlows), fmtUSD(d.QuotaMonthly.MaxValueUSD))
|
|
|
|
|
|
resets := resetsLine(d.Quota5Hour.ResetsAt, d.Quota7Day.ResetsAt)
|
|
|
if resets != "" {
|