7:`).filter(e=>e.trim()),r=[];for(let e of n)try{let t=JSON.parse(e);if(t.isSidechain===!0)continue;r.push(t)}catch(e){O(`Failed to parse JSONL line: ${e}`);continue}return O(`Loaded ${r.length} transcript entries`),r}catch(t){return O(`Error loading transcript for ${e}:`,t),[]}}calculateMessageCount(e){return e.filter(e=>{let t=e.type||e.message?.role||e.message?.type,n=e.type===`user`&&e.message?.content?.[0]?.type===`tool_result`;return t===`user`&&!n}).length}calculateLastResponseTime(e){if(e.length===0)return null;let t=e.slice(-20),n=null,r=null;for(let e of t)if(e.timestamp)try{let t=new Date(e.timestamp),i=e.type||e.message?.role||e.message?.type,a=e.type===`user`&&e.message?.content?.[0]?.type===`tool_result`;if(i===`user`&&!a)n=t;else if(i===`assistant`&&n){let e=(t.getTime()-n.getTime())/1e3;e>.1&&e<300&&(r=e)}}catch{continue}return r}async getMetricsInfo(e,t){try{if(O(`Getting metrics from hook data for session: ${e}`),!t.cost)return O(`No cost data available in hook data`),{responseTime:null,lastResponseTime:null,sessionDuration:null,messageCount:null,linesAdded:null,linesRemoved:null};let n=await this.loadTranscriptEntries(e),r=this.calculateMessageCount(n),i=this.calculateLastResponseTime(n);return{responseTime:t.cost.total_api_duration_ms/1e3,lastResponseTime:i,sessionDuration:t.cost.total_duration_ms/1e3,messageCount:r,linesAdded:t.cost.total_lines_added,linesRemoved:t.cost.total_lines_removed}}catch(t){return O(`Error getting metrics from hook data for session ${e}:`,t),{responseTime:null,lastResponseTime:null,sessionDuration:null,messageCount:null,linesAdded:null,linesRemoved:null}}}};function M(e){return e===null?`$0.00`:e<.01?`<$0.01`:`$${e.toFixed(2)}`}function Ve(e){return e===null||e===0?`0 tokens`:e>=1e6?`${(e/1e6).toFixed(1)}M tokens`:e>=1e3?`${(e/1e3).toFixed(1)}K tokens`:`${e} tokens`}function He(e){if(!e)return`0 tokens`;let t=[];if(e.input>0&&t.push(`${N(e.input)} in`),e.output>0&&t.push(`${N(e.output)} out`),e.cacheCreation>0||e.cacheRead>0){let n=e.cacheCreation+e.cacheRead;t.push(`${N(n)} cached`)}return t.length>0?t.join(` + `):`0 tokens`}function Ue(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m`:e<86400?`${Math.floor(e/3600)}h`:e<604800?`${Math.floor(e/86400)}d`:`${Math.floor(e/604800)}w`}function We(e){return e<60?`${e.toFixed(0)}s`:e<3600?`${(e/60).toFixed(0)}m`:e<86400?`${(e/3600).toFixed(1)}h`:`${(e/86400).toFixed(1)}d`}const Ge=/^(?:(?:global|apac|au|eu|us|us-east-\d|us-west-\d|eu-west-\d|eu-central-\d)\.)?(?:anthropic\.|azure_ai\/|bedrock\/|vertex_ai\/)?claude-(?:(?<family>opus|sonnet|haiku)-(?<newMajor>\d+)(?:-(?<newMinor>\d))?|(?<oldMajor>\d+)(?:-(?<oldMinor>\d))?-(?<oldFamily>opus|sonnet|haiku))(?:[-@]\d{8})?(?:-v\d+:\d+)?(?:-latest)?$/i;function Ke(e){if(!e)return`Claude`;let t=e.trim().match(Ge);if(!t?.groups)return e;let{family:n,newMajor:r,newMinor:i,oldMajor:a,oldMinor:o,oldFamily:s}=t.groups,c=n||s,l=r||a,u=i||o;return c&&l?`${c.charAt(0).toUpperCase()+c.slice(1).toLowerCase()} ${u?`${l}.${u}`:l}`:e}function qe(e){let t=e.includes(`/`)?`/`:`\\`,n=e.split(t);return n.map((e,t)=>t===n.length-1||e===`~`||e===``?e:e.charAt(0)).join(t)}function Je(e){return e<60?`${e.toFixed(1)}s`:`${(e/60).toFixed(1)}m`}function N(e){return Ve(e).replace(` tokens`,``)}function Ye(e,t){let n=t??globalThis.process?.env?.HOME??globalThis.process?.env?.USERPROFILE;return n&&e.startsWith(n)?e.replace(n,`~`):e}function Xe(e){let t=Math.floor(e/60),n=e%60;return t>0?`${t}h ${n}m left`:`${n}m left`}function Ze(e){if(e>=1440){let t=Math.floor(e/1440),n=Math.floor(e%1440/60);return n>0?`${t}d ${n}h`:`${t}d`}else if(e>=60){let t=Math.floor(e/60),n=e%60;return n>0?`${t}h ${n}m`:`${t}h`}return`${e}m`}function Qe(e){return Math.round(Math.max(0,e*1e3-Date.now())/6e4)}function $e(e,t){return!t||t<=0||e<0?null:Math.min(100,e/t*100)}function P(e,t,n=80){let r=$e(e,t);if(r===null)return{percentage:null,isWarning:!1,displayText:``};let i=`${r.toFixed(0)}%`,a=r>=n,o=``;return o=a?` !${i}`:r>=50?` +${i}`:` ${i}`,{percentage:r,isWarning:a,displayText:o}}const et={ball:{filled:`─`,empty:`─`,marker:`●`},blocks:{filled:`█`,empty:`░`},"blocks-line":{filled:`█`,empty:`─`},capped:{filled:`━`,empty:`┄`,cap:`╸`},dots:{filled:`●`,empty:`○`},filled:{filled:`■`,empty:`□`},geometric:{filled:`▰`,empty:`▱`},line:{filled:`━`,empty:`┄`},squares:{filled:`◼`,empty:`◻`}};var tt=class{constructor(e,t){this.config=e,this.symbols=t}renderDirectory(e,t,n){let r=e.workspace?.current_dir||e.cwd||`/`,i=e.workspace?.project_dir,a=n?.style??(n?.showBasename?`basename`:`full`);if(a===`basename`)return{text:r.split(/[\\/]/).pop()||`root`,bgColor:t.modeBg,fgColor:t.modeFg};let o=Ye(r),s=i&&Ye(i),c=this.getDisplayDirectoryName(o,s);return a===`fish`&&(c=qe(c)),{text:c,bgColor:t.modeBg,fgColor:t.modeFg}}renderGit(e,t,n){if(!e)return null;let r=[];if(n?.showRepoName&&e.repoName&&(r.push(e.repoName),e.isWorktree&&r.push(this.symbols.git_worktree)),n?.showOperation&&e.operation&&r.push(`[${e.operation}]`),r.push(`${this.symbols.branch} ${e.branch}`),n?.showTag&&e.tag&&r.push(`${this.symbols.git_tag} ${e.tag}`),n?.showSha&&e.sha&&r.push(`${this.symbols.git_sha} ${e.sha}`),n?.showAheadBehind!==!1&&(e.ahead>0&&e.behind>0?r.push(`${this.symbols.git_ahead}${e.ahead}${this.symbols.git_behind}${e.behind}`):e.ahead>0?r.push(`${this.symbols.git_ahead}${e.ahead}`):e.behind>0&&r.push(`${this.symbols.git_behind}${e.behind}`)),n?.showWorkingTree){let t=[];e.staged&&e.staged>0&&t.push(`+${e.staged}`),e.unstaged&&e.unstaged>0&&t.push(`~${e.unstaged}`),e.untracked&&e.untracked>0&&t.push(`?${e.untracked}`),e.conflicts&&e.conflicts>0&&t.push(`!${e.conflicts}`),t.length>0&&r.push(`(${t.join(` `)})`)}if(n?.showUpstream&&e.upstream&&r.push(`${this.symbols.git_upstream}${e.upstream}`),n?.showStashCount&&e.stashCount&&e.stashCount>0&&r.push(`${this.symbols.git_stash} ${e.stashCount}`),n?.showTimeSinceCommit&&e.timeSinceCommit!==void 0){let t=Ue(e.timeSinceCommit);r.push(`${this.symbols.git_time} ${t}`)}let i=this.symbols.git_clean;return e.status===`conflicts`?i=this.symbols.git_conflicts:e.status===`dirty`&&(i=this.symbols.git_dirty),r.push(i),{text:r.join(` `),bgColor:t.gitBg,fgColor:t.gitFg}}renderModel(e,t){let n=Ke(e.model?.display_name||`Claude`);return{text:`${this.symbols.model} ${n}`,bgColor:t.modelBg,fgColor:t.modelFg}}renderSession(e,t,n){let r=n?.type||`cost`,i=n?.costSource,a=this.config.budget?.session,o=this.formatUsageWithBudget(i===`calculated`?e.session.calculatedCost:i===`official`?e.session.officialCost:e.session.cost,e.session.tokens,e.session.tokenBreakdown,r,a?.amount,a?.warningThreshold||80,a?.type);return{text:`${this.symbols.session_cost} ${o}`,bgColor:t.sessionBg,fgColor:t.sessionFg}}renderSessionId(e,t,n){return{text:n?.showIdLabel===!1?e:`${this.symbols.session_id} ${e}`,bgColor:t.sessionBg,fgColor:t.sessionFg}}renderTmux(e,t){return e?{text:`tmux:${e}`,bgColor:t.tmuxBg,fgColor:t.tmuxFg}:{text:`tmux:none`,bgColor:t.tmuxBg,fgColor:t.tmuxFg}}renderContext(e,t,n){let r=n?.displayStyle??`text`,i=r===`text`?`remaining`:`used`,a=n?.percentageMode??i,o=this.resolveBarStyleDef(r),s=a===`remaining`?`100%`:`0%`;if(!e)return o?{text:`${o.empty.repeat(10)} ${s}`,bgColor:t.contextBg,fgColor:t.contextFg}:{text:`${this.symbols.context_time} 0 (${s})`,bgColor:t.contextBg,fgColor:t.contextFg};let c=t.contextBg,l=t.contextFg;e.contextLeftPercentage<=20?(c=t.contextCriticalBg,l=t.contextCriticalFg):e.contextLeftPercentage<=40&&(c=t.contextWarningBg,l=t.contextWarningFg);let u=a===`remaining`?e.contextLeftPercentage:e.usablePercentage,d=Math.round(e.usablePercentage/100*10),f=10-d;if(o){let t=this.buildBar(o,d,f,10);return{text:n?.showPercentageOnly?`${t} ${u}%`:`${t} ${e.totalTokens.toLocaleString()} (${u}%)`,bgColor:c,fgColor:l}}return{text:n?.showPercentageOnly?`${this.symbols.context_time} ${u}%`:`${this.symbols.context_time} ${e.totalTokens.toLocaleString()} (${u}%)`,bgColor:c,fgColor:l}}buildBar(e,t,n,r){if(e.marker){let n=Math.min(t,r-1);return e.filled.repeat(n)+e.marker+e.empty.repeat(r-n-1)}return e.cap?t===0?e.cap+e.empty.repeat(r-1):t>=r?e.filled.repeat(r):e.filled.repeat(t-1)+e.cap+e.empty.repeat(n):e.filled.repeat(t)+e.empty.repeat(n)}resolveBarStyleDef(e){return e===`bar`?{filled:this.symbols.bar_filled,empty:this.symbols.bar_empty}:et[e]??null}formatPercentageWithBar(e,t,n){let r=t??`text`,i=this.resolveBarStyleDef(r);if(i){let t=Math.round(e/100*10),r=10-t,a=this.buildBar(i,t,r,10);return n?`${a} ${e}% (${n})`:`${a} ${e}%`}return n?`${e}% (${n})`:`${e}%`}renderMetrics(e,t,n){if(!e)return{text:`${this.symbols.metrics_response} new`,bgColor:t.metricsBg,fgColor:t.metricsFg};let r=[];if(n?.showLastResponseTime&&e.lastResponseTime!==null){let t=e.lastResponseTime<60?`${e.lastResponseTime.toFixed(1)}s`:`${(e.lastResponseTime/60).toFixed(1)}m`;r.push(`${this.symbols.metrics_last_response} ${t}`)}if(n?.showResponseTime!==!1&&e.responseTime!==null){let t=e.responseTime<60?`${e.responseTime.toFixed(1)}s`:`${(e.responseTime/60).toFixed(1)}m`;r.push(`${this.symbols.metrics_response} ${t}`)}if(n?.showDuration!==!1&&e.sessionDuration!==null){let t=We(e.sessionDuration);r.push(`${this.symbols.metrics_duration} ${t}`)}return n?.showMessageCount!==!1&&e.messageCount!==null&&r.push(`${this.symbols.metrics_messages} ${e.messageCount}`),n?.showLinesAdded!==!1&&e.linesAdded!==null&&e.linesAdded>0&&r.push(`${this.symbols.metrics_lines_added} ${e.linesAdded}`),n?.showLinesRemoved!==!1&&e.linesRemoved!==null&&e.linesRemoved>0&&r.push(`${this.symbols.metrics_lines_removed} ${e.linesRemoved}`),r.length===0?{text:`${this.symbols.metrics_response} active`,bgColor:t.metricsBg,fgColor:t.metricsFg}:{text:r.join(` `),bgColor:t.metricsBg,fgColor:t.metricsFg}}renderBlock(e,t,n){let r=Math.round(e.nativeUtilization),i=Ze(e.timeRemaining),a=this.config.budget?.block?.warningThreshold??80,o=t.blockBg,s=t.blockFg;return r>=a?(o=t.contextCriticalBg,s=t.contextCriticalFg):r>=50&&(o=t.contextWarningBg,s=t.contextWarningFg),{text:`${this.symbols.block_cost} ${this.formatPercentageWithBar(r,n?.displayStyle,i)}`,bgColor:o,fgColor:s}}renderWeekly(e,t,n){let r=e.rate_limits?.seven_day;if(!r)return null;let i=Math.round(r.used_percentage),a=Ze(Qe(r.resets_at)),o=t.weeklyBg,s=t.weeklyFg;return i>=80?(o=t.contextCriticalBg,s=t.contextCriticalFg):i>=50&&(o=t.contextWarningBg,s=t.contextWarningFg),{text:`${this.symbols.weekly_cost} ${this.formatPercentageWithBar(i,n?.displayStyle,a)}`,bgColor:o,fgColor:s}}renderToday(e,t,n=`cost`){let r=this.config.budget?.today;return{text:`${this.symbols.today_cost} ${this.formatUsageWithBudget(e.cost,e.tokens,e.tokenBreakdown,n,r?.amount,r?.warningThreshold,r?.type)}`,bgColor:t.todayBg,fgColor:t.todayFg}}getDisplayDirectoryName(e,t){return e.startsWith(`~`)?e:t&&t!==e&&e.startsWith(t)?e.slice(t.length+1)||t.split(/[\\/]/).pop()||`project`:e}formatUsageDisplay(e,t,n,r){switch(r){case`cost`:return M(e);case`tokens`:return Ve(t);case`both`:return`${M(e)} (${Ve(t)})`;case`breakdown`:return He(n);default:return M(e)}}formatUsageWithBudget(e,t,n,r,i,a=80,o){let s=this.formatUsageDisplay(e,t,n,r);if(i&&i>0){let n=null;if(o===`tokens`&&t!==null?n=t:(o===`cost`&&e!==null||!o&&e!==null)&&(n=e),n!==null)return s+P(n,i,a).displayText}return s}renderVersion(e,t,n){return e.version?{text:`${this.symbols.version} v${e.version}`,bgColor:t.versionBg,fgColor:t.versionFg}:null}renderEnv(e,t){let n=globalThis.process?.env?.[t.variable];if(!n)return null;let r=t.prefix??t.variable;return{text:r?`${this.symbols.env} ${r}: ${n}`:`${this.symbols.env} ${n}`,bgColor:e.envBg,fgColor:e.envFg}}},nt=class{async getActiveBlockInfo(e){let t=e?.rate_limits?.five_hour;if(!t)return O(`Block segment: No native rate_limits data available`),null;let n=Qe(t.resets_at);return O(`Block segment: Using native rate_limits: ${t.used_percentage}%, resets in ${n}m`),{nativeUtilization:t.used_percentage,timeRemaining:n}}};function F(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function rt(e){return e.inputTokens+e.outputTokens+e.cacheCreationInputTokens+e.cacheReadInputTokens}function it(e){return{timestamp:e.timestamp,usage:{inputTokens:e.message?.usage?.input_tokens||0,outputTokens:e.message?.usage?.output_tokens||0,cacheCreationInputTokens:e.message?.usage?.cache_creation_input_tokens||0,cacheReadInputTokens:e.message?.usage?.cache_read_input_tokens||0},costUSD:e.costUSD||0,model:e.message?.model||`unknown`}}var at=class{async loadTodayEntries(){let e=F(new Date);O(`Today segment: Loading entries for date ${e}`);let t=await A.getLatestTranscriptMtime(),n=await A.getUsageCache(`today`,t);if(n)return O(`Using shared today usage cache`),n;let r=new Date;r.setDate(r.getDate()-1),r.setHours(0,0,0,0);let i=(e,t)=>t>=r,a=new Date;a.setHours(0,0,0,0);let o=await Pe(e=>e.timestamp>=a,i,!0),s=[],c=0;for(let t of o)if(F(t.timestamp)===e&&t.message?.usage){let e=it(t);!e.costUSD&&t.raw&&(e.costUSD=await Fe.calculateCostForEntry(t.raw)),s.push(e),c++}return O(`Today segment: Found ${c} entries for today (${e})`),await A.setUsageCache(`today`,s,t),s}async getTodayEntries(){try{return await this.loadTodayEntries()}catch(e){return O(`Error loading today's entries:`,e),[]}}async getTodayInfo(){try{let e=await this.getTodayEntries();if(e.length===0)return{cost:null,tokens:null,tokenBreakdown:null,date:F(new Date)};let t=e.reduce((e,t)=>e+t.costUSD,0),n=e.reduce((e,t)=>e+rt(t.usage),0),r=e.reduce((e,t)=>({input:e.input+t.usage.inputTokens,output:e.output+t.usage.outputTokens,cacheCreation:e.cacheCreation+t.usage.cacheCreationInputTokens,cacheRead:e.cacheRead+t.usage.cacheReadInputTokens}),{input:0,output:0,cacheCreation:0,cacheRead:0});return O(`Today segment: $${t.toFixed(2)}, ${n} tokens total`),{cost:t,tokens:n,tokenBreakdown:r,date:F(new Date)}}catch(e){return O(`Error getting today's info:`,e),{cost:null,tokens:null,tokenBreakdown:null,date:F(new Date)}}}};const ot={right:``,left_rounded:``,right_rounded:``,branch:`⎇`,model:`✱`,git_clean:`✓`,git_dirty:`●`,git_conflicts:`⚠`,git_ahead:`↑`,git_behind:`↓`,git_worktree:`⧉`,git_tag:`⌂`,git_sha:`♯`,git_upstream:`→`,git_stash:`⧇`,git_time:`◷`,session_cost:`§`,block_cost:`◱`,today_cost:`☉`,context_time:`◔`,metrics_response:`⧖`,metrics_last_response:`Δ`,metrics_duration:`⧗`,metrics_messages:`◆`,metrics_lines_added:`+`,metrics_lines_removed:`-`,metrics_burn:`↗`,version:`◈`,bar_filled:`▪`,bar_empty:`▫`,env:`⚙`,session_id:`⌗`,weekly_cost:`◑`,dir:`📁`,activity:`⚡`},st={topLeft:`╭`,topRight:`╮`,bottomLeft:`╰`,bottomRight:`╯`,horizontal:`─`,vertical:`│`,teeLeft:`├`,teeRight:`┤`},ct={topLeft:`+`,topRight:`+`,bottomLeft:`+`,bottomRight:`+`,horizontal:`-`,vertical:`|`,teeLeft:`+`,teeRight:`+`},I={rounded:st,square:{topLeft:`┌`,topRight:`┐`,bottomLeft:`└`,bottomRight:`┘`,horizontal:`─`,vertical:`│`,teeLeft:`├`,teeRight:`┤`},heavy:{topLeft:`┏`,topRight:`┓`,bottomLeft:`┗`,bottomRight:`┛`,horizontal:`━`,vertical:`┃`,teeLeft:`┣`,teeRight:`┫`},double:{topLeft:`╔`,topRight:`╗`,bottomLeft:`╚`,bottomRight:`╝`,horizontal:`═`,vertical:`║`,teeLeft:`╠`,teeRight:`╣`},dashed:{topLeft:`╭`,topRight:`╮`,bottomLeft:`╰`,bottomRight:`╯`,horizontal:`┄`,vertical:`┊`,teeLeft:`├`,teeRight:`┤`},"heavy-dashed":{topLeft:`┏`,topRight:`┓`,bottomLeft:`┗`,bottomRight:`┛`,horizontal:`┅`,vertical:`┇`,teeLeft:`┣`,teeRight:`┫`},mixed:{topLeft:`┍`,topRight:`┑`,bottomLeft:`┕`,bottomRight:`┙`,horizontal:`━`,vertical:`│`,teeLeft:`┝`,teeRight:`┥`},ascii:ct,invisible:{topLeft:` `,topRight:` `,bottomLeft:` `,bottomRight:` `,horizontal:` `,vertical:` `,teeLeft:` `,teeRight:` `}},lt={right:``,left_rounded:``,right_rounded:``,branch:`~`,model:`M`,git_clean:`=`,git_dirty:`*`,git_conflicts:`!`,git_ahead:`^`,git_behind:`v`,git_worktree:`W`,git_tag:`T`,git_sha:`#`,git_upstream:`>>`,git_stash:`S`,git_time:`@`,session_cost:`S`,block_cost:`B`,today_cost:`D`,context_time:`C`,metrics_response:`R`,metrics_last_response:`L`,metrics_duration:`T`,metrics_messages:`#`,metrics_lines_added:`+`,metrics_lines_removed:`-`,metrics_burn:`~/h`,version:`V`,bar_filled:`=`,bar_empty:`-`,env:`$`,session_id:`#`,weekly_cost:`W`,dir:`D`,activity:`A`},ut=RegExp(`\x1B\\[[0-9;]*m`,`g`),dt=RegExp(`(\x1B\\[[0-9;]*m)`);function ft(e){return e.replace(ut,``)}function L(e){return ft(e).length}const pt=/^[a-zA-Z0-9/]+$/;function mt(){if(process.platform===`win32`)return null;let e=process.pid.toString();for(let t=0;t<10;t++)try{let t=i(`ps -o ppid=,tty= -p ${e}`,{encoding:`utf8`,stdio:[`pipe`,`pipe`,`ignore`]}).trim().split(/\s+/),n=t[0],r=t[1];if(r&&r!==`?`&&r!==`??`&&pt.test(r))return r;if(!n||n===`1`||n===`0`)break;e=n}catch{break}return null}function ht(){try{let e=i(`mode con`,{encoding:`utf8`,stdio:[`pipe`,`pipe`,`ignore`],windowsHide:!0}).match(/Columns:\s*(\d+)/i);if(e?.[1]){let t=parseInt(e[1],10);if(!isNaN(t)&&t>0)return t}}catch{}return null}function gt(){let e=mt();if(e)try{let t=i(`stty size < /dev/${e}`,{encoding:`utf8`,stdio:[`pipe`,`pipe`,`ignore`],shell:`/bin/sh`}).trim().split(` `)[1];if(t){let e=parseInt(t,10);if(!isNaN(e)&&e>0)return e}}catch{}try{let e=i(`tput cols 2>/dev/null`,{encoding:`utf8`,stdio:[`pipe`,`pipe`,`ignore`]}).trim(),t=parseInt(e,10);if(!isNaN(t)&&t>0)return t}catch{}return null}function _t(){let e=e=>Math.max(1,e-45),t=process.env.COLUMNS;if(t){let n=parseInt(t,10);if(!isNaN(n)&&n>0)return e(n)}if(process.stdout.columns&&process.stdout.columns>0)return e(process.stdout.columns);if(process.platform===`win32`){let t=ht();if(t)return e(t)}let n=gt();return n?e(n):null}function vt(){return process.platform===`win32`?ht():gt()}function R(e,t,n){return t?`${t}${e}${n}`:e}function z(e,t){let n=L(e);return n>=t?e:e+` `.repeat(t-n)}function yt(e,t){let n=L(e);return n>=t?e:` `.repeat(t-n)+e}function bt(e,t){let n=L(e);if(n>=t)return e;let r=t-n,i=Math.floor(r/2),a=r-i;return` `.repeat(i)+e+` `.repeat(a)}function B(e,t){if(ft(e).length<=t)return e;let n=0,r=``,i=e.split(dt);for(let e of i){if(e.startsWith(`\x1B`)){r+=e;continue}for(let i of e){if(n>=t-1)return r+=`…\x1B[0m`,r;r+=i,n++}}return r}function V(e,t,n){let r=n-2,i=z(B(t,r),r);return e.vertical+` `+i+` `+e.vertical}function H(e,t){return e.teeLeft+e.horizontal.repeat(t)+e.teeRight}function xt(e,t,n,r){if(!n&&!r)return e.bottomLeft+e.horizontal.repeat(t)+e.bottomRight;let i=n?` ${n} `:``,a=r?` ${r} `:``,o=L(i),s=L(a);if(o+s>t){let e=Math.max(0,t-s);if(o>e&&(i=B(i,e),o=L(i)),o+s>t){let e=Math.max(0,t-o);a=B(a,e),s=L(a)}}let c=t-o-s;return e.bottomLeft+i+e.horizontal.repeat(Math.max(0,c))+a+e.bottomRight}function St(e,t){if(e.length===0)return``;if(e.length===1)return e[0]??``;let n=e.map(e=>L(e)),r=t-n.reduce((e,t)=>e+t,0),i=Math.max(2,Math.floor(r/(e.length-1))),a=Array.from({length:e.length});a[e.length-1]=n[e.length-1]??0;for(let t=e.length-2;t>=0;t--)a[t]=(a[t+1]??0)+(n[t]??0);let o=e[0]??``,s=n[0]??0;for(let r=1;r<e.length;r++){let c=t-s-(a[r]??0)-(e.length-1-r)*2,l=Math.max(2,Math.min(i,c));o+=` `.repeat(l)+(e[r]??``),s+=l+(n[r]??0)}return o}function U(e,t,n){if(!t)return e;if(!e)return t;let r=L(e),i=L(t),a=n-r-i;return a<2?`${e}  ${t}`:e+` `.repeat(a)+t}function W(e,t,n){let r=Ke(t.hookData.model?.display_name||`Claude`).toLowerCase();return e.replace(/\{([^}]+)\}/g,(e,t)=>{if(n){let e=n[t];if(e!==void 0)return e}return t===`model`?r:``})}function Ct(e,t,n,r,i){let a=r?.left??`{model}`,o=r?.right,s=W(a,e,i),c=s?` ${s} `:``,l=L(c);if(!o){let e=n-l;return t.topLeft+c+t.horizontal.repeat(Math.max(0,e))+t.topRight}let u=W(o,e,i),d=u?` ${u} `:``,f=L(d),p=c,m=l,h=d,g=f;if(m+g>n){let e=Math.max(0,n-g);if(m>e&&(p=B(p,e),m=L(p)),m+g>n){let e=Math.max(0,n-m);h=B(h,e),g=L(h)}}let _=n-m-g;if(_<2){let e=n-m;return t.topLeft+p+t.horizontal.repeat(Math.max(0,e))+t.topRight}return t.topLeft+p+t.horizontal.repeat(_)+h+t.topRight}function G(e,t,n,r=60,i=80){return e>=i?n.contextCriticalFg:e>=r?n.contextWarningFg:t}function K(e,t,n,r,i){t=Math.max(5,t);let a=Math.max(0,Math.min(t,Math.round(e/100*t))),o=t-a;return R(n.bar_filled.repeat(a)+n.bar_empty.repeat(o),i,r)}function wt(e,t){if(!e.contextInfo)return{icon:``,label:`context`,bar:``,pct:``,tokens:``};let n=e.contextInfo.usablePercentage,r=N(e.contextInfo.totalTokens),i=N(e.contextInfo.maxTokens);return{icon:t.context_time,label:`context`,bar:` `,pct:`${n}%`,tokens:`${r}/${i}`}}function Tt(e,t,n,r,i,a){if(!e.contextInfo)return``;let o=e.contextInfo.usablePercentage;return K(o,t,n,r,G(o,a?.[`context.bar`]??a?.context??i.contextFg,i))}function Et(e,t,n,r,i,a,o){if(!e.blockInfo)return``;let s=e.blockInfo.nativeUtilization,c=a.budget?.block?.warningThreshold??80;return K(s,t,n,r,G(s,o?.[`block.bar`]??o?.block??i.blockFg,i,50,c))}function Dt(e,t,n,r,i,a){let o=e.hookData.rate_limits?.seven_day;if(!o)return``;let s=o.used_percentage;return K(s,t,n,r,G(s,a?.[`weekly.bar`]??a?.weekly??i.weeklyFg,i))}function Ot(e,t,n,r,i){if(!e.contextInfo)return null;let a=e.contextInfo.usablePercentage,o=`  ${a}%  ${N(e.contextInfo.totalTokens)}/${N(e.contextInfo.maxTokens)}`,s=Math.max(5,t-o.length),c=Math.max(0,Math.min(s,Math.round(a/100*s))),l=s-c,u=n.bar_filled.repeat(c)+n.bar_empty.repeat(l),d=G(a,i.contextFg,i);return R(`${u}${o}`,d,r)}function kt(e){return Ye(e.workspace?.current_dir||e.cwd||`/`)}function At(e,t,n,r,i){let a=[];e.blockInfo&&a.push(R(q(e.blockInfo,t,n),i.blockFg,r));let o=e.hookData.rate_limits?.seven_day;o&&a.push(R(J(o,t),i.weeklyFg,r)),e.usageInfo&&a.push(R(Lt(e.usageInfo,t,n),i.sessionFg,r)),e.todayInfo&&a.push(R(zt(e.todayInfo,t,n),i.todayFg,r));let s=jt(e,t);return s.length>0&&a.push(R(s.join(` · `),i.metricsFg,r)),a}function jt(e,t){let n=[];return e.metricsInfo&&(e.metricsInfo.sessionDuration!==null&&e.metricsInfo.sessionDuration>0&&n.push(`${t.metrics_duration} ${We(e.metricsInfo.sessionDuration)}`),e.metricsInfo.messageCount!==null&&e.metricsInfo.messageCount>0&&n.push(`${t.metrics_messages} ${e.metricsInfo.messageCount}`)),n}function Mt(e,t,n,r){let i=[],a=Gt(e,t);a&&i.push(R(a,r.gitFg,n));let o=qe(kt(e.hookData));return i.push(R(o,r.modeFg,n)),i}function Nt(e,t,n,r,i){let a=[];if(e.hookData.version&&a.push(R(`${t.version} v${e.hookData.version}`,i.versionFg,r)),e.tmuxSessionId&&a.push(R(`tmux:${e.tmuxSessionId}`,i.tmuxFg,r)),e.metricsInfo){let n=[];e.metricsInfo.responseTime!==null&&!isNaN(e.metricsInfo.responseTime)&&e.metricsInfo.responseTime>0&&n.push(`${t.metrics_response} ${Je(e.metricsInfo.responseTime)}`),e.metricsInfo.linesAdded!==null&&e.metricsInfo.linesAdded>0&&n.push(`${t.metrics_lines_added}${e.metricsInfo.linesAdded}`),e.metricsInfo.linesRemoved!==null&&e.metricsInfo.linesRemoved>0&&n.push(`${t.metrics_lines_removed}${e.metricsInfo.linesRemoved}`),n.length>0&&a.push(R(n.join(` · `),i.metricsFg,r))}let o=n.display.lines.map(e=>e.segments.env).find(e=>e?.enabled);if(o&&o.variable){let e=globalThis.process?.env?.[o.variable];if(e){let t=o.prefix??o.variable;a.push(R(t?`${t}:${e}`:e,i.envFg,r))}}return a}function Pt(e,t,n){let r=`${Math.round(e.nativeUtilization)}%`,i=Xe(e.timeRemaining);return{icon:t.block_cost,label:`block`,value:r,time:i,budget:``,bar:` `}}function q(e,t,n){let r=Pt(e,t,n),i=`${r.icon} ${r.value}`;return r.time&&(i+=` · ${r.time}`),r.budget&&(i+=r.budget),i}function Ft(e,t){let n=`${Math.round(e.used_percentage)}%`,r=Ze(Qe(e.resets_at));return{icon:t.weekly_cost,label:`weekly`,pct:n,time:r,bar:` `}}function J(e,t){let n=Ft(e,t),r=`${n.icon} ${n.pct}`;return n.time&&(r+=` · ${n.time}`),r}function It(e,t,n){let r=e.session.tokens,i=r!==null&&r>0?N(r):``,a=``,o=n.budget?.session;return o?.amount&&e.session.cost!==null&&(a=P(e.session.cost,o.amount,o.warningThreshold||80).displayText),{icon:t.session_cost,label:`session`,cost:M(e.session.cost),tokens:i,budget:a}}function Lt(e,t,n){let r=It(e,t,n),i=`${r.icon} ${r.cost}`;return r.tokens&&(i+=` · ${r.tokens}`),r.budget&&(i+=r.budget),i}function Rt(e,t,n){let r=``,i=n.budget?.today;return i?.amount&&e.cost!==null&&(r=P(e.cost,i.amount,i.warningThreshold||80).displayText),{icon:t.today_cost,cost:M(e.cost),label:`today`,budget:r}}function zt(e,t,n){let r=Rt(e,t,n),i=`${r.icon} ${r.cost} ${r.label}`;return r.budget&&(i+=r.budget),i}function Bt(e,t){let n={response:``,responseIcon:``,responseVal:``,lastResponse:``,lastResponseIcon:``,lastResponseVal:``,added:``,addedIcon:``,addedVal:``,removed:``,removedIcon:``,removedVal:``};if(!e.metricsInfo)return n;let r=e.metricsInfo.responseTime!==null&&!isNaN(e.metricsInfo.responseTime)&&e.metricsInfo.responseTime>0,i=r?Je(e.metricsInfo.responseTime):``,a=e.metricsInfo.lastResponseTime!==null&&!isNaN(e.metricsInfo.lastResponseTime)&&e.metricsInfo.lastResponseTime>0,o=a?Je(e.metricsInfo.lastResponseTime):``,s=e.metricsInfo.linesAdded!==null&&e.metricsInfo.linesAdded>0,c=s?`${e.metricsInfo.linesAdded}`:``,l=e.metricsInfo.linesRemoved!==null&&e.metricsInfo.linesRemoved>0,u=l?`${e.metricsInfo.linesRemoved}`:``;return{response:r?`${t.metrics_response} ${i}`:``,responseIcon:r?t.metrics_response:``,responseVal:i,lastResponse:a?`${t.metrics_last_response} ${o}`:`${t.metrics_last_response} --`,lastResponseIcon:t.metrics_last_response,lastResponseVal:a?o:`--`,added:s?`${t.metrics_lines_added}${c}`:``,addedIcon:s?t.metrics_lines_added:``,addedVal:c,removed:l?`${t.metrics_lines_removed}${u}`:``,removedIcon:l?t.metrics_lines_removed:``,removedVal:u}}function Vt(e,t){let n=Bt(e,t),r=[n.response,n.lastResponse,n.added,n.removed].filter(Boolean);return r.length>0?r.join(` · `):``}function Ht(e,t){let n={icon:``,duration:``,durationIcon:``,durationVal:``,messages:``,messagesIcon:``,messagesVal:``};if(!e.metricsInfo)return n;let r=e.metricsInfo.sessionDuration!==null&&e.metricsInfo.sessionDuration>0,i=r?We(e.metricsInfo.sessionDuration):``,a=e.metricsInfo.messageCount!==null&&e.metricsInfo.messageCount>0,o=a?`${e.metricsInfo.messageCount}`:``;return{icon:t.activity,duration:r?`${t.metrics_duration} ${i}`:``,durationIcon:r?t.metrics_duration:``,durationVal:i,messages:a?`${t.metrics_messages} ${o}`:``,messagesIcon:a?t.metrics_messages:``,messagesVal:o}}function Ut(e,t){let n=Ht(e,t),r=[n.duration,n.messages].filter(Boolean);return r.length>0?r.join(` · `):``}function Wt(e,t){if(!e.gitInfo)return{icon:``,headVal:``,branch:``,status:``,ahead:``,behind:``,working:``,head:``};let n;n=e.gitInfo.status===`conflicts`?t.git_conflicts:e.gitInfo.status===`dirty`?t.git_dirty:t.git_clean;let r=e.gitInfo.ahead>0?`${t.git_ahead}${e.gitInfo.ahead}`:``,i=e.gitInfo.behind>0?`${t.git_behind}${e.gitInfo.behind}`:``,a=[];e.gitInfo.staged&&e.gitInfo.staged>0&&a.push(`+${e.gitInfo.staged}`),e.gitInfo.unstaged&&e.gitInfo.unstaged>0&&a.push(`~${e.gitInfo.unstaged}`),e.gitInfo.untracked&&e.gitInfo.untracked>0&&a.push(`?${e.gitInfo.untracked}`);let o=a.length>0?`(${a.join(` `)})`:``,s=[t.branch,e.gitInfo.branch,n];r&&s.push(r),i&&s.push(i);let c=[e.gitInfo.branch,n];return r&&c.push(r),i&&c.push(i),{icon:t.branch,headVal:c.join(` `),branch:e.gitInfo.branch,status:n,ahead:r,behind:i,working:o,head:s.join(` `)}}function Gt(e,t){let n=Wt(e,t);if(!n.icon)return``;let r=`${n.icon} ${n.branch} ${n.status}`;return n.ahead&&(r+=` ${n.ahead}`),n.behind&&(r+=`${n.behind}`),n.working&&(r+=` ${n.working}`),r}function Kt(e,t,n){return{icon:n.dir,value:qt(e,t)}}function qt(e,t){let n=kt(e.hookData),r=t.display.lines.map(e=>e.segments.directory).find(e=>e?.enabled),i=r?.style??(r?.showBasename?`basename`:`fish`);if(i===`basename`){let e=n.includes(`/`)?`/`:`\\`;return n.split(e).pop()||n}return i===`full`?n:qe(n)}function Jt(e,t){return e.hookData.version?{icon:t.version,value:`v${e.hookData.version}`}:{icon:``,value:``}}function Yt(e,t){let n=Jt(e,t);return n.icon?`${n.icon} ${n.value}`:``}function Xt(e){return e.tmuxSessionId?{label:`tmux`,value:e.tmuxSessionId}:{label:``,value:``}}function Zt(e){let t=Xt(e);return t.label?`${t.label}:${t.value}`:``}function Qt(e){let t=e.display.lines.map(e=>e.segments.env).find(e=>e?.enabled);if(!t||!t.variable)return{prefix:``,value:``};let n=globalThis.process?.env?.[t.variable];return n?{prefix:(t.prefix??t.variable)||``,value:n}:{prefix:``,value:``}}function $t(e){let t=Qt(e);return t.value?t.prefix?`${t.prefix}:${t.value}`:t.value:``}function Y(e,t,n,r,i,a){for(let[o,s]of Object.entries(n)){let n=`${t}.${o}`,c=a?.[n]??a?.[t]??r;e[n]=s?R(s,c,i):``}}function en(e,t,n){let r=t.indexOf(`.`),i=r===-1?t:t.slice(0,r);return e.items.map(e=>{let t=e.match(/^\{(.+)\}$/);return t?n[`${i}.${t[1]}`]??``:e?R(e,``,``):``}).filter(Boolean)}function tn(e,t,n,r){if(e.length===0)return``;if(n===`between`&&r!==void 0&&e.length>1){let n=e.reduce((e,t)=>e+L(t),0),i=Math.max(t*(e.length-1),r-n),a=Math.floor(i/(e.length-1)),o=i%(e.length-1),s=e[0];for(let t=1;t<e.length;t++)s+=` `.repeat(a+(t<=o?1:0))+e[t];return s}return e.join(` `.repeat(t))}function nn(e,t){let{sym:n,config:r,reset:i,colors:a}=t,o=a.partFg,s=(e,t)=>e?R(e,t,i):``,c={},l=Ke(e.hookData.model?.display_name||`Claude`).toLowerCase(),u=o?.model??a.modelFg;if(c.model=s(`${n.model} ${l}`,u),Y(c,`model`,{icon:n.model,value:l},a.modelFg,i,o),c.context=Ot(e,t.contentWidth,n,i,a)??``,Y(c,`context`,wt(e,n),e.contextInfo?G(e.contextInfo.usablePercentage,a.contextFg,a):a.contextFg,i,o),e.blockInfo){let t=o?.block??a.blockFg;c.block=s(q(e.blockInfo,n,r),t),Y(c,`block`,Pt(e.blockInfo,n,r),a.blockFg,i,o)}else c.block=``;if(e.usageInfo){let t=o?.session??a.sessionFg;c.session=s(Lt(e.usageInfo,n,r),t),Y(c,`session`,It(e.usageInfo,n,r),a.sessionFg,i,o)}else c.session=``;if(e.todayInfo){let t=o?.today??a.todayFg;c.today=s(zt(e.todayInfo,n,r),t),Y(c,`today`,Rt(e.todayInfo,n,r),a.todayFg,i,o)}else c.today=``;let d=e.hookData.rate_limits?.seven_day;if(d){let e=o?.weekly??a.weeklyFg;c.weekly=s(J(d,n),e),Y(c,`weekly`,Ft(d,n),a.weeklyFg,i,o)}else c.weekly=``;let f=o?.git??a.gitFg;c.git=s(Gt(e,n),f),Y(c,`git`,Wt(e,n),a.gitFg,i,o);let p=o?.dir??a.modeFg;c.dir=s(qt(e,r),p),Y(c,`dir`,Kt(e,r,n),a.modeFg,i,o);let m=o?.version??a.versionFg;c.version=s(Yt(e,n),m),Y(c,`version`,Jt(e,n),a.versionFg,i,o);let h=o?.tmux??a.tmuxFg;c.tmux=s(Zt(e),h),Y(c,`tmux`,Xt(e),a.tmuxFg,i,o);let g=o?.metrics??a.metricsFg;c.metrics=s(Vt(e,n),g),Y(c,`metrics`,Bt(e,n),a.metricsFg,i,o);let _=o?.activity??a.metricsFg;c.activity=s(Ut(e,n),_),Y(c,`activity`,Ht(e,n),a.metricsFg,i,o);let v=o?.env??a.envFg;c.env=s($t(r),v),Y(c,`env`,Qt(r),a.envFg,i,o);let y={},b=r.display.tui?.segments;if(b)for(let[e,t]of Object.entries(b)){let n=en(t,e,c),r=t.gap??1,i=t.justify??`start`;y[e]={items:n,gap:r,justify:i},c[e]=tn(n,r,i===`between`?`start`:i)}return{data:c,templates:y}}function rn(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=At(n,o,s,c,l);u.length>0&&t.push(V(r,St(u,i),a))}function an(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=Mt(n,o,c,l),d=Nt(n,o,s,c,l),f=u.join(`  `),p=d.join(` · `);(f||p)&&(t.push(H(r,a)),t.push(V(r,U(f,p,i),a)))}function on(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=[],d=[];n.blockInfo&&u.push(R(q(n.blockInfo,o,s),l.blockFg,c));let f=n.hookData.rate_limits?.seven_day;f&&u.push(R(J(f,o),l.weeklyFg,c)),n.todayInfo&&u.push(R(zt(n.todayInfo,o,s),l.todayFg,c)),n.usageInfo&&d.push(R(Lt(n.usageInfo,o,s),l.sessionFg,c));let p=jt(n,o);p.length>0&&d.push(R(p.join(` · `),l.metricsFg,c)),u.length>0&&t.push(V(r,St(u,i),a)),d.length>0&&t.push(V(r,U(d[0]??``,d[1]??``,i),a))}function sn(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=Mt(n,o,c,l);u.length>0&&(t.push(H(r,a)),t.push(V(r,U(u[0]??``,u[1]??``,i),a)));let d=Nt(n,o,s,c,l);d.length>0&&(t.push(H(r,a)),t.push(V(r,d.join(` · `),a)))}function cn(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e;n.blockInfo&&t.push(V(r,R(q(n.blockInfo,o,s),l.blockFg,c),a));let u=n.hookData.rate_limits?.seven_day;u&&t.push(V(r,R(J(u,o),l.weeklyFg,c),a));let d=[];n.usageInfo&&d.push(R(`${o.session_cost} ${M(n.usageInfo.session.cost)}`,l.sessionFg,c)),n.todayInfo&&d.push(R(`${o.today_cost} ${M(n.todayInfo.cost)} today`,l.todayFg,c)),d.length>0&&t.push(V(r,U(d[0]??``,d[1]??``,i),a))}function ln(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=Mt(n,o,c,l);u.length>0&&(t.push(H(r,a)),t.push(V(r,U(u[0]??``,u[1]??``,i),a)));let d=Nt(n,o,s,c,l);d.length>0&&t.push(V(r,d.join(` · `),a))}const un=new Set([`context`,`context.bar`,`block.bar`,`weekly.bar`]);function X(e){return e.length===1&&e[0].segment===`---`}function Z(e){if(!e.endsWith(`fr`))return 0;let t=parseInt(e.replace(`fr`,``),10);return!isNaN(t)&&t>0?t:0}function dn(e,t,n){let r=Math.floor(e/t.length),i=e-r*t.length;for(let e of t)n[e]=n[e]+r+(i>0?1:0),i>0&&i--}function fn(e,t,n,r){let i=0;for(let r=0;r<n;r++)i+=e[t+r]??0;return n>1&&(i+=(n-1)*r),i}function pn(e,t){let n;for(let r of e)t>=r.minWidth&&(!n||r.minWidth>n.minWidth)&&(n=r);if(n)return n;let r=e[0];for(let t=1;t<e.length;t++)e[t].minWidth<r.minWidth&&(r=e[t]);return r}function mn(e){let t=[];for(let n of e){let e=n.trim();if(e===`---`){t.push([{segment:`---`,spanStart:!0,spanSize:1}]);continue}let r=e.split(/\s+/),i=[],a=0;for(;a<r.length;){let e=r[a],t=1;for(;a+t<r.length&&r[a+t]===e;)t++;i.push({segment:e,spanStart:!0,spanSize:t});for(let n=1;n<t;n++)i.push({segment:e,spanStart:!1,spanSize:0});a+=t}t.push(i)}return t}function hn(e,t){let n=e.map(e=>X(e)?e:e.map(e=>e.segment===`.`||e.segment===`---`||t[e.segment]?e:{segment:`.`,spanStart:!0,spanSize:1})).map(e=>{if(X(e))return e;let t=e.map(e=>e.segment),n=[],r=0;for(;r<t.length;){let e=t[r],i=1;for(;r+i<t.length&&t[r+i]===e;)i++;n.push({segment:e,spanStart:!0,spanSize:i});for(let t=1;t<i;t++)n.push({segment:e,spanStart:!1,spanSize:0});r+=i}return n}).filter(e=>X(e)?!0:e.some(e=>e.segment!==`.`)),r=[];for(let e=0;e<n.length;e++){let t=n[e];if(!X(t)){r.push(t);continue}r.length!==0&&(X(r[r.length-1])||r.push(t))}return r.length>0&&X(r[r.length-1])&&r.pop(),r}function gn(e,t,n,r){let i=Array.from({length:e}).fill(0);for(let a of t)if(!X(a))for(let t=0;t<a.length;t++){let o=a[t];if(!o.spanStart||o.spanSize!==1||o.segment===`.`||t>=e||r?.has(o.segment))continue;let s=L(n[o.segment]||``);s>i[t]&&(i[t]=s)}return i}function _n(e,t,n,r,i,a){let o=e.length,s=gn(o,t,n,a),c=Array.from({length:o}).fill(0);for(let t=0;t<o;t++)e[t]===`auto`&&(c[t]=s[t]);for(let t=0;t<o;t++){let n=e[t];if(n===`auto`||n.endsWith(`fr`))continue;let r=parseInt(n,10);!isNaN(r)&&r>0&&(c[t]=r)}for(let t=0;t<o;t++)c[t]<1&&!e[t].endsWith(`fr`)&&(c[t]=1);let l=Math.max(0,o-1)*i,u=c.reduce((e,t)=>e+t,0),d=Math.max(0,r-u-l),f=0;for(let t of e)f+=Z(t);if(f>0){let t=d/f,n=[],r=0;for(let i=0;i<o;i++){let a=Z(e[i]);if(a>0){let e=Math.floor(t*a);c[i]=e,r+=e,n.push(i)}}let i=d-r;for(let e=0;i>0&&e<n.length;e++)c[n[e]]+=1,i--}return c}function vn(e,t,n,r,i,a){let o=e.length,s=gn(o,t,n,a),c=Array.from({length:o});for(let t=0;t<o;t++){let n=e[t];if(n!==`auto`&&!n.endsWith(`fr`)){let e=parseInt(n,10);c[t]=!isNaN(e)&&e>0?e:s[t]}else c[t]=s[t]}for(let i of t)if(!X(i))for(let t=0;t<i.length;t++){let a=i[t];if(!a.spanStart||a.spanSize<=1||a.segment===`.`)continue;let o=L(n[a.segment]||``),s=fn(c,t,a.spanSize,r);if(o>s){let n=o-s,r=[];for(let n=0;n<a.spanSize;n++)Z(e[t+n])>0&&r.push(t+n);if(r.length>0)dn(n,r,c);else{let e=[];for(let n=0;n<a.spanSize;n++)e.push(t+n);dn(n,e,c)}}}for(let e=0;e<o;e++)c[e]<1&&(c[e]=1);let l=0;for(let e=0;e<o;e++)l+=c[e];let u=Math.max(0,o-1)*r,d=2+Math.max(0,1-i)*2,f=o*i*2;return{panelWidth:l+u+d+f,colWidths:c}}function yn(e,t,n){switch(n){case`right`:return yt(e,t);case`center`:return bt(e,t);default:return z(e,t)}}function bn(e,t,n,r,i,a=0,o){let s=[],c=L(i),l=a;for(let i=0;i<e.length;i++){let a=e[i];if(!a.spanStart)continue;let u=fn(t,i,a.spanSize,c),d=i+a.spanSize-1,f=n[i]===`right`?o?.[i]??0:0,p=n[d]===`left`?o?.[d]??0:0,m=l-f,h=l-p,g=0;for(let e=i;e<d;e++){let t=n[e]===`left`?o?.[e]??0:0,r=n[e+1]===`right`?o?.[e+1]??0:0;g+=l-t+(l-r)}let _=u+g;if(a.segment===`.`)s.push(` `.repeat(_+m+h));else{let e=yn(B(r[a.segment]||``,_),_,n[i]||`left`),t=m>0?` `.repeat(m):``,o=h>0?` `.repeat(h):``;s.push(t+e+o)}}return s.join(i)}function xn(e,t,n){let r=n||e.horizontal;return e.teeLeft+r.repeat(t)+e.teeRight}function Sn(e,t,n,r,i){let a=e.minWidth??32,o=e.maxWidth??1/0,s=e.separator?.column??`  `,c=e.separator?.divider,l=L(s),u=e.fitContent??!1,d=e.padding?.horizontal??0,f=e.widthReserve??45,p=Math.min(o,Math.max(a,r-f)),m=pn(e.breakpoints,p),h;h=u?o===1/0?r:Math.min(r,o):p;let g=hn(mn(m.areas),t);if(g.length===0)return{lines:[],panelWidth:h};let _,v=new Set(un);if(e.segments)for(let t of Object.keys(e.segments))v.add(t);if(u){let e=vn(m.columns,g,t,l,d,v);h=Math.min(o,Math.max(a,e.panelWidth)),_=e.colWidths;let n=h-e.panelWidth;if(n>0){let e=0;for(let t of m.columns)e+=Z(t);if(e>0){let t=[],r=0;for(let i=0;i<_.length;i++){let a=Z(m.columns[i]);if(a>0){let o=Math.floor(n*a/e);_[i]+=o,r+=o,t.push(i)}}let i=n-r;for(let e=0;i>0&&e<t.length;e++)_[t[e]]+=1,i--}}}else{let e=h-2-Math.max(0,1-d)*2-m.columns.length*d*2;_=_n(m.columns,g,t,e,l,v)}let y=h-2,b=Math.max(1,d)-d,x=b>0?` `.repeat(b):``,S=y-b*2,C=m.align||m.columns.map(()=>`left`),w=Array(m.columns.length).fill(0);if(d>0){let e=Array(m.columns.length).fill(0);for(let n of g)if(!X(n))for(let r=0;r<n.length;r++){let i=n[r];if(!i.spanStart||i.spanSize!==1||i.segment===`.`||v.has(i.segment))continue;let a=L(t[i.segment]||``);a>e[r]&&(e[r]=a)}let n=0;for(let t=0;t<m.columns.length;t++){if(Z(m.columns[t])>0||e[t]<=0)continue;let r=_[t]-e[t];r<=0||(w[t]=Math.min(d,r),n+=w[t])}if(n>0){let e=0;for(let t of m.columns)e+=Z(t);if(e>0){let t=[],r=0;for(let i=0;i<_.length;i++){let a=Z(m.columns[i]);if(a>0){let o=Math.floor(n*a/e);_[i]+=o,r+=o,t.push(i)}}let i=n-r;for(let e=0;i>0&&e<t.length;e++)_[t[e]]+=1,i--}}}function ee(e,t){let n=0;for(let r=e;r<e+t-1;r++){let e=C[r]===`left`?w[r]??0:0,t=C[r+1]===`right`?w[r+1]??0:0;n+=d-e+(d-t)}return n}if(i){let e=new Set;for(let n of g)if(!X(n))for(let r=0;r<n.length;r++){let a=n[r];if(!a.spanStart||a.segment===`.`||a.segment===`---`||e.has(a.segment))continue;e.add(a.segment);let o=fn(_,r,a.spanSize,l),s=ee(r,a.spanSize),c=i(a.segment,o+s);c!==void 0&&(t[a.segment]=c)}}let te=hn(g,t);if(te.length===0)return{lines:[],panelWidth:h};let T=[];for(let e of te)if(X(e))T.push(xn(n,y,c));else{let r=z(B(bn(e,_,C,t,s,d,w),S),S);T.push(n.vertical+x+r+x+n.vertical)}return{lines:T,panelWidth:h}}const Cn=`\x1B[?2026h`,wn=`\x1B[?2026l`,Tn=`\x1B[0m`;function En(e){return e>=80?`wide`:e>=55?`medium`:`narrow`}function Dn(e){return e&&e>0?Math.max(32,e):80}async function On(e,t,n,r,i,a){let o=(i.display.charset||`unicode`)===`text`?lt:ot,s=e.colors;if(i.display.tui){let r=i.display.tui,c=r.terminalWidth??a?.rawTerminalWidth??120,l;l=typeof r.box==`string`?I[r.box]??t:r.box?{...t,...r.box}:t;let u=Math.max(r.minWidth??32,c-(r.widthReserve??45))-2,d=u-2,f=nn(e,{lines:[],data:e,box:l,contentWidth:d,innerWidth:u,sym:o,config:i,reset:n,colors:s}),p=f.data,m=f.templates,h=s.partFg,g=Sn(r,p,l,c,(t,r)=>{if(t===`context`)return Ot(e,r,o,n,s)??``;if(t===`context.bar`)return Tt(e,r,o,n,s,h);if(t===`block.bar`)return Et(e,r,o,n,s,i,h);if(t===`weekly.bar`)return Dt(e,r,o,n,s,h);let a=m[t];if(a)return tn(a.items,a.gap,a.justify,r)}),_=g.panelWidth-2,v=r.footer?.left?W(r.footer.left,e,p):void 0,y=r.footer?.right?W(r.footer.right,e,p):void 0,b=[];return b.push(Ct(e,l,_,r.title,p)),b.push(...g.lines),b.push(xt(l,_,v,y)),Cn+b.map(e=>Tn+e).join(`
