@@ -73,19 +73,42 @@ function displayWidth(s: string): number {
7373const BAR_WIDTH = 16 ;
7474const COMPACT_BAR_WIDTH = 10 ;
7575
76+ // Display ceiling. Server returns base percent (0–100) plus a `weekly_boost_permille`
77+ // multiplier; a typical boosted plan shows up to 150%, so cap the rendered value
78+ // at 200% to leave headroom and keep the bar/text readable.
79+ const MAX_DISPLAY_PCT = 200 ;
80+
81+ // Weekly quota is unlimited when the server reports `current_weekly_status: 3`
82+ // (per the status enum: 1=normal, 2=exhausted, 3=unlimited).
83+ function isUnweekly ( status : number | undefined | null ) : boolean {
84+ return status === 3 ;
85+ }
86+
7687function clampPct ( value : number ) : number {
77- return Math . max ( 0 , Math . min ( 100 , Math . round ( value ) ) ) ;
88+ return Math . max ( 0 , Math . min ( MAX_DISPLAY_PCT , Math . round ( value ) ) ) ;
7889}
7990
80- function remainingPct ( percent : number | undefined | null , remaining : number , total : number ) : number {
81- return percent !== undefined && percent !== null
82- ? clampPct ( percent )
83- : total > 0 ? clampPct ( ( remaining / total ) * 100 ) : 0 ;
91+ function boostFactor ( boostPermille : number | undefined | null ) : number {
92+ if ( boostPermille === undefined || boostPermille === null ) return 1 ;
93+ return Math . max ( 0 , boostPermille ) / 1000 ;
94+ }
95+
96+ function remainingPct (
97+ percent : number | undefined | null ,
98+ remaining : number ,
99+ total : number ,
100+ boostPermille ?: number | null ,
101+ ) : number {
102+ const factor = boostFactor ( boostPermille ) ;
103+ if ( percent !== undefined && percent !== null ) {
104+ return clampPct ( percent * factor ) ;
105+ }
106+ return total > 0 ? clampPct ( ( remaining / total ) * 100 * factor ) : 0 ;
84107}
85108
86109function renderBar ( remainingPct : number , color : boolean , barWidth : number = BAR_WIDTH , showPct : boolean = true ) : string {
87110 const pct = clampPct ( remainingPct ) ;
88- const ratio = pct / 100 ;
111+ const ratio = Math . min ( 1 , pct / 100 ) ;
89112 const filled = Math . round ( barWidth * ratio ) ;
90113 const empty = barWidth - filled ;
91114 const pctStr = `${ pct } %` . padStart ( 4 ) ;
@@ -98,14 +121,31 @@ function renderBar(remainingPct: number, color: boolean, barWidth: number = BAR_
98121 return showPct ? `${ bar } ${ fg } ${ B } ${ pctStr } ${ R } ` : bar ;
99122}
100123
124+ const UNLIMITED_SYMBOL = '∞' ;
125+ const UNLIMITED_LABEL_CN = '无限' ;
126+ const UNLIMITED_LABEL_EN = 'unlimited' ;
127+
101128function renderMetric (
102129 label : string ,
103130 remaining : number ,
104131 total : number ,
105132 percent : number | undefined | null ,
106133 color : boolean ,
134+ boostPermille ?: number | null ,
135+ unlimited ?: boolean ,
136+ unlimitedLabel ?: string ,
107137) : string {
108- const pct = remainingPct ( percent , remaining , total ) ;
138+ if ( unlimited ) {
139+ const ul = unlimitedLabel ?? UNLIMITED_SYMBOL ;
140+ const ulStr = ul . padStart ( 4 ) ;
141+ if ( color ) {
142+ const bar = `${ BG_GREEN } ${ ' ' . repeat ( COMPACT_BAR_WIDTH ) } ${ R } ` ;
143+ return `${ D } ${ label } ${ R } ${ bar } ${ FG_GREEN } ${ B } ${ ulStr } ${ R } ` ;
144+ }
145+ const bar = `[${ '█' . repeat ( COMPACT_BAR_WIDTH ) } ]` ;
146+ return `${ label } ${ bar } ${ ulStr } ` ;
147+ }
148+ const pct = remainingPct ( percent , remaining , total , boostPermille ) ;
109149 const bar = renderBar ( pct , color , COMPACT_BAR_WIDTH , total <= 0 ) ;
110150 if ( total > 0 ) {
111151 const count = `${ remaining . toLocaleString ( ) } / ${ total . toLocaleString ( ) } ` ;
@@ -142,6 +182,9 @@ export function renderQuotaTable(models: QuotaModelRemain[], config: Config): vo
142182 m . current_weekly_total_count ,
143183 m . current_weekly_remaining_percent ,
144184 useColor ,
185+ m . weekly_boost_permille ,
186+ isUnweekly ( m . current_weekly_status ) ,
187+ config . region === 'cn' ? UNLIMITED_LABEL_CN : UNLIMITED_LABEL_EN ,
145188 ) ;
146189 const reset = `${ L . resetsIn } ${ formatDuration ( m . remains_time , L . now ) } ` ;
147190 return { displayName, current, weekly, reset } ;
0 commit comments