import{A as e,_ as t,g as n,h as r}from"./subsystem-kTFXkQM5.js";import{spinner as i}from"@clack/prompts";import{createOscProgressController as a,supportsOscProgress as o}from"osc-progress";let s=0;const c={setLabel:()=>{},setPercent:()=>{},tick:()=>{},done:()=>{}};function l(l){if(l.enabled===!1||s>0)return c;let u=l.stream??process.stderr,d=u.isTTY,f=!d&&l.fallback===`log`;if(!d&&!f)return c;let p=typeof l.delayMs==`number`?l.delayMs:0,m=d&&o(process.env,d),h=d&&(l.fallback===void 0||l.fallback===`spinner`),g=d&&l.fallback===`line`,_=!1,v=l.label,y=l.total??null,b=0,x=0,S=l.indeterminate??(l.total===void 0||l.total===null);s+=1,d&&n(u);let C=m?a({env:process.env,isTty:u.isTTY,write:e=>u.write(e)}):null,w=h?i():null,T=g?()=>{if(!_)return;let t=S?``:` ${x}%`;r(),u.write(`${e.accent(v)}${t}`)}:null,E=f?(()=>{let e=``,t=0;return()=>{if(!_)return;let n=S?``:` ${x}%`,r=`${v}${n}`,i=Date.now();r===e&&i-t<250||(e=r,t=i,u.write(`${r}\n`))}})():null,D=null,O=()=>{_&&(C&&(S?C.setIndeterminate(v):C.setPercent(v,x)),w&&w.message(e.accent(v)),T&&T(),E&&E())},k=()=>{_||(_=!0,w&&w.start(e.accent(v)),O())};p===0?k():D=setTimeout(k,p);let A=e=>{v=e,O()},j=e=>{x=Math.max(0,Math.min(100,Math.round(e))),S=!1,O()};return{setLabel:A,setPercent:j,tick:(e=1)=>{y&&(b=Math.min(y,b+e),j(y>0?Math.round(b/y*100):0))},done:()=>{if(D&&=(clearTimeout(D),null),!_){s=Math.max(0,s-1);return}C&&C.clear(),w&&w.stop(),r(),d&&t(u),s=Math.max(0,s-1)}}}async function u(e,t){let n=l(e);try{return await t(n)}finally{n.done()}}async function d(e,t){return await u(e,async e=>await t(({completed:t,total:n,label:r})=>{r&&e.setLabel(r),!(!Number.isFinite(n)||n<=0)&&e.setPercent(t/n*100)},e))}export{u as n,d as r,l as t};
