@redaktyn/cli 1.6.3 → 1.6.5

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.
package/redaktyn-ui.mjs CHANGED
@@ -1,5 +1,5 @@
1
- const m=process.env,i=process.stderr,T=!!m.REDAKTYN_FORCE_UI,w=T||!!i.isTTY&&m.TERM!=="dumb"&&!m.CI,g=w&&!m.NO_COLOR,h=w&&!!i.isTTY&&!m.CI&&!m.REDAKTYN_NO_ANIMATION&&!T,E=!m.REDAKTYN_ASCII&&m.TERM!=="linux"&&m.TERM!=="dumb",S=/truecolor|24bit/i.test(m.COLORTERM??""),N=/256color/i.test(m.TERM??""),b=(t,r,n)=>a=>g?`\x1B[${S?`38;2;${t}`:N?`38;5;${r}`:n}m${a}\x1B[0m`:String(a),e={clay:b("217;119;87",173,33),green:b("95;168;112",71,32),amber:b("212;164;76",178,33),red:b("208;93;93",167,31),blue:b("112;160;214",74,36),dim:t=>g?`\x1B[2m${t}\x1B[0m`:String(t),bold:t=>g?`\x1B[1m${t}\x1B[0m`:String(t),gray:t=>g?`\x1B[90m${t}\x1B[0m`:String(t)},O={clay:e.clay,green:e.green,amber:e.amber,red:e.red,blue:e.blue,dim:e.dim},s=E?{ok:"\u2714",fail:"\u2716",warn:"\u25B2",dot:"\xB7",arrow:"\u2192",down:"\u25BC",bar:"\u2502",mark:"\u25CE",full:"\u2588",empty:"\u2591",tl:"\u256D",tr:"\u256E",bl:"\u2570",br:"\u256F",h:"\u2500",v:"\u2502",lock:"\u{1F512}"}:{ok:"+",fail:"x",warn:"!",dot:"-",arrow:"->",down:"v",bar:"|",mark:"(o)",full:"#",empty:".",tl:"+",tr:"+",bl:"+",br:"+",h:"-",v:"|",lock:""},R=/\x1b\[[0-9;]*m/g,f=t=>String(t).replace(R,"").length,k=(t,r)=>t+" ".repeat(Math.max(0,r-f(t))),A=()=>Math.max(60,Math.min(i.columns||80,100)),p=(t="")=>i.write(t+`
2
- `);let v=!1;function _(t,r){if(!w||v)return;v=!0;const n=r?e.dim(` v${r}`):"";p(""),p(` ${e.clay(s.mark)} ${e.bold(e.clay("R E D A K T Y N"))}${n}`),p(` ${e.dim("zero-knowledge secret protection")}${t?e.dim(` ${s.dot} ${t}`):""}`),p("")}function B(t,r,{tone:n="clay",width:a}={}){const c=O[n]??e.clay,l=Math.max(f(t)+4,...r.map(f)),o=Math.min(a??l+2,A()-4),$=u=>f(u)<=o-2?k(u,o-2):String(u).replace(R,"").slice(0,o-3)+"\u2026",d=`${s.tl}${s.h} ${t} ${s.h.repeat(Math.max(1,o-f(t)-3))}${s.tr}`,x=r.map(u=>`${c(s.v)} ${$(u)} ${c(s.v)}`);p(" "+c(d)),x.forEach(u=>p(" "+u)),p(" "+c(`${s.bl}${s.h.repeat(o)}${s.br}`))}function H(t,{indent:r=2,labelWidth:n}={}){const a=n??Math.max(...t.map(([c])=>f(c)));return t.map(([c,l])=>`${" ".repeat(r)}${e.gray(k(c,a))} ${l}`)}const I=E?["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"]:["-","\\","|","/"];let y=!1;const M=()=>{y&&(i.write("\x1B[?25h"),y=!1)};process.on("exit",M),process.on("SIGINT",()=>{M(),i.write(`
3
- `),process.exit(130)});const C=t=>{const r=Date.now()-t;return r<1e3?`${r} ms`:`${(r/1e3).toFixed(1)} s`};function K(t){const r=Date.now();if(!w)return i.write(`${t}\u2026
4
- `),{update(){},succeed(){},fail(){},warn(){}};let n=t,a=null,c=0;if(h){i.write("\x1B[?25l"),y=!0;const o=()=>i.write(`\r\x1B[2K ${e.clay(I[c++%I.length])} ${n}`);o(),a=setInterval(o,80)}const l=(o,$,d=!0)=>{a&&clearInterval(a),h&&(i.write("\r\x1B[2K"),M()),p(` ${o} ${$??n}${d?e.dim(` ${C(r)}`):""}`)};return{update(o){n=o,h||p(` ${e.clay(s.dot)} ${o}`)},succeed(o){l(e.green(s.ok),o)},fail(o){l(e.red(s.fail),o,!1)},warn(o){l(e.amber(s.warn),o,!1)}}}async function z(t,r,n){const a=K(t);try{const c=await r(a);return a.succeed(typeof n=="function"?n(c):n),c}catch(c){throw a.fail(`${t}: ${c instanceof Error?c.message:c}`),c}}function G(t,r,n=24){const a=r===0?n:Math.round(t/r*n);return e.clay(s.full.repeat(a))+e.gray(s.empty.repeat(n-a))+e.dim(` ${t}/${r}`)}const D=t=>new Promise(r=>setTimeout(r,t)),F="0123456789abcdef";async function P(t,r,{show:n=16,hold:a=450}={}){const c=r.slice(0,n),l=$=>$.replace(/(.{4})/g,"$1 ").trim();if(!h){p(`${t}${e.amber(l(c))} ${e.dim("\u2026")}`);return}const o=14;for(let $=0;$<=o;$++){const d=Math.floor($/o*n);let x=c.slice(0,d);for(let u=d;u<n;u++)x+=F[Math.floor(Math.random()*16)];i.write(`\r\x1B[2K${t}${$<o?e.gray(l(x)):e.amber(l(x))} ${e.dim("\u2026")}`),await D(a/o)}i.write(`
5
- `)}function U(t){return t<1024?`${t} B`:t<1048576?`${(t/1024).toFixed(1)} KB`:`${(t/1048576).toFixed(1)} MB`}export{h as animated,_ as banner,G as bar,B as box,s as g,U as humanBytes,e as k,P as reveal,w as rich,H as rows,p as say,K as step,z as task,g as useColor,f as visibleLength};
1
+ const m=process.env,l=process.stderr,v=!!m.REDAKTYN_FORCE_UI,g=v||!!l.isTTY&&m.TERM!=="dumb"&&!m.CI,h=g&&!m.NO_COLOR,x=g&&!!l.isTTY&&!m.CI&&!m.REDAKTYN_NO_ANIMATION&&!v,y=!m.REDAKTYN_ASCII&&m.TERM!=="linux"&&m.TERM!=="dumb",O=/truecolor|24bit/i.test(m.COLORTERM??""),A=/256color/i.test(m.TERM??""),w=(t,e,n)=>c=>h?`\x1B[${O?`38;2;${t}`:A?`38;5;${e}`:n}m${c}\x1B[0m`:String(c),r={clay:w("217;119;87",173,33),green:w("95;168;112",71,32),amber:w("212;164;76",178,33),red:w("208;93;93",167,31),blue:w("112;160;214",74,36),dim:t=>h?`\x1B[2m${t}\x1B[0m`:String(t),bold:t=>h?`\x1B[1m${t}\x1B[0m`:String(t),gray:t=>h?`\x1B[90m${t}\x1B[0m`:String(t)},C={clay:r.clay,green:r.green,amber:r.amber,red:r.red,blue:r.blue,dim:r.dim},i=y?{ok:"\u2714",fail:"\u2716",warn:"\u25B2",dot:"\xB7",arrow:"\u2192",down:"\u25BC",bar:"\u2502",mark:"\u25CE",full:"\u2588",empty:"\u2591",tl:"\u256D",tr:"\u256E",bl:"\u2570",br:"\u256F",h:"\u2500",v:"\u2502",lock:"\u{1F512}"}:{ok:"+",fail:"x",warn:"!",dot:"-",arrow:"->",down:"v",bar:"|",mark:"(o)",full:"#",empty:".",tl:"+",tr:"+",bl:"+",br:"+",h:"-",v:"|",lock:""},I=/\x1b\[[0-9;]*m/g,b=t=>String(t).replace(I,"").length,R=(t,e)=>t+" ".repeat(Math.max(0,e-b(t))),K=()=>Math.max(60,Math.min(l.columns||80,100)),d=(t="")=>l.write(t+`
2
+ `);let k=!1;function B(t,e){if(!g||k)return;k=!0;const n=e?r.dim(` v${e}`):"";d(""),d(` ${r.clay(i.mark)} ${r.bold(r.clay("R E D A K T Y N"))}${n}`),d(` ${r.dim("zero-knowledge secret protection")}${t?r.dim(` ${i.dot} ${t}`):""}`),d("")}function H(t,e,{tone:n="clay",width:c}={}){const o=C[n]??r.clay,$=Math.max(b(t)+4,...e.map(b)),s=Math.min(c??$+2,K()-4),p=a=>b(a)<=s-2?R(a,s-2):String(a).replace(I,"").slice(0,s-3)+"\u2026",u=`${i.tl}${i.h} ${t} ${i.h.repeat(Math.max(1,s-b(t)-3))}${i.tr}`,f=e.map(a=>`${o(i.v)} ${p(a)} ${o(i.v)}`);d(" "+o(u)),f.forEach(a=>d(" "+a)),d(" "+o(`${i.bl}${i.h.repeat(s)}${i.br}`))}function z(t,{indent:e=2,labelWidth:n}={}){const c=n??Math.max(...t.map(([o])=>b(o)));return t.map(([o,$])=>`${" ".repeat(e)}${r.gray(R(o,c))} ${$}`)}const S=y?["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"]:["-","\\","|","/"];let M=!1;const T=()=>{M&&(l.write("\x1B[?25h"),M=!1)};process.on("exit",T),process.on("SIGINT",()=>{T(),l.write(`
3
+ `),process.exit(130)});const D=t=>{const e=Date.now()-t;return e<1e3?`${e} ms`:`${(e/1e3).toFixed(1)} s`};function F(t,{rail:e=!1}={}){const n=e?"":" ",c=e?" ":" ",o=Date.now();if(!g)return l.write(`${t}\u2026
4
+ `),{update(){},succeed(){},fail(){},warn(){},pause(){},resume(){}};let $=t,s=null,p=0,u=null;x&&(l.write("\x1B[?25l"),M=!0,u=()=>l.write(`\r\x1B[2K${n}${r.clay(S[p++%S.length])}${c}${$}`),u(),s=setInterval(u,80));const f=(a,E,N=!0)=>{s&&clearInterval(s),x&&(l.write("\r\x1B[2K"),T()),d(`${n}${a}${c}${E??$}${N?r.dim(` ${D(o)}`):""}`)};return{pause(){s&&(clearInterval(s),s=null),x&&(l.write("\r\x1B[2K"),T())},resume(){x&&u&&!s&&(l.write("\x1B[?25l"),M=!0,u(),s=setInterval(u,80))},update(a){$=a,x||d(`${n}${r.clay(i.dot)}${c}${a}`)},succeed(a){f(e?r.green(y?"\u25C7":"o"):r.green(i.ok),a)},fail(a){f(e?r.red(y?"\u25A0":"x"):r.red(i.fail),a,!1)},warn(a){f(r.amber(i.warn),a,!1)}}}async function G(t,e,n){const c=F(t);try{const o=await e(c);return c.succeed(typeof n=="function"?n(o):n),o}catch(o){throw c.fail(`${t}: ${o instanceof Error?o.message:o}`),o}}function P(t,e,n=24){const c=e===0?n:Math.round(t/e*n);return r.clay(i.full.repeat(c))+r.gray(i.empty.repeat(n-c))+r.dim(` ${t}/${e}`)}const Y=t=>new Promise(e=>setTimeout(e,t)),_="0123456789abcdef";async function U(t,e,{show:n=16,hold:c=450}={}){const o=e.slice(0,n),$=p=>p.replace(/(.{4})/g,"$1 ").trim();if(!x){d(`${t}${r.amber($(o))} ${r.dim("\u2026")}`);return}const s=14;for(let p=0;p<=s;p++){const u=Math.floor(p/s*n);let f=o.slice(0,u);for(let a=u;a<n;a++)f+=_[Math.floor(Math.random()*16)];l.write(`\r\x1B[2K${t}${p<s?r.gray($(f)):r.amber($(f))} ${r.dim("\u2026")}`),await Y(c/s)}l.write(`
5
+ `)}function X(t){return t<1024?`${t} B`:t<1048576?`${(t/1024).toFixed(1)} KB`:`${(t/1048576).toFixed(1)} MB`}export{x as animated,B as banner,P as bar,H as box,i as g,X as humanBytes,r as k,U as reveal,g as rich,z as rows,d as say,F as step,G as task,h as useColor,b as visibleLength};