import{r as e,t}from"./chunk-74CEPOFO-V0JXh91S.mjs";import{t as n}from"./chunk-HWKDQ44K-BJxdK4fT.mjs";var r={name:`column`,summary:`columnate lists`,usage:`column [OPTION]... [FILE]...`,description:`Format input into multiple columns. By default, fills rows first. Use -t to create a table based on whitespace-delimited input.`,options:[`-t           Create a table (determine columns from input)`,`-s SEP       Input field delimiter (default: whitespace)`,`-o SEP       Output field delimiter (default: two spaces)`,`-c WIDTH     Output width for fill mode (default: 80)`,`-n           Don't merge multiple adjacent delimiters`],examples:[`ls | column              # Fill columns with ls output`,`cat data | column -t     # Format as table`,`column -t -s ',' file    # Format CSV as table`,`column -c 40 file        # Fill 40-char wide columns`]},i={table:{short:`t`,long:`table`,type:`boolean`},separator:{short:`s`,type:`string`},outputSep:{short:`o`,type:`string`},width:{short:`c`,type:`number`,default:80},noMerge:{short:`n`,type:`boolean`}};function a(e,t,n){return t?n?e.split(t):e.split(t).filter(e=>e.length>0):n?e.split(/[ \t]/):e.split(/[ \t]+/).filter(e=>e.length>0)}function o(e){let t=[];for(let n of e)for(let e=0;e<n.length;e++){let r=n[e].length;(t[e]===void 0||r>t[e])&&(t[e]=r)}return t}function s(e,t){if(e.length===0)return``;let n=o(e),r=[];for(let i of e){let e=[];for(let t=0;t<i.length;t++)t===i.length-1?e.push(i[t]):e.push(i[t].padEnd(n[t]));r.push(e.join(t))}return r.join(`
`)}function c(e,t,n){if(e.length===0)return``;let r=Math.max(...e.map(e=>e.length)),i=n.length,a=r+i,o=Math.max(1,Math.floor((t+i)/a)),s=Math.ceil(e.length/o),c=[];for(let t=0;t<s;t++){let i=[];for(let n=0;n<o;n++){let a=n*s+t;a<e.length&&(n===o-1||(n+1)*s+t>=e.length?i.push(e[a]):i.push(e[a].padEnd(r)))}c.push(i.join(n))}return c.join(`
`)}var l={name:`column`,execute:async(o,l)=>{if(t(o))return e(r);let u=n(`column`,o,i);if(!u.ok)return u.error;let{table:d,separator:f,outputSep:p,width:m,noMerge:h}=u.result.flags,g=u.result.positional,_=p??`  `,v;if(g.length===0)v=l.stdin??``;else{let e=[];for(let t of g)if(t===`-`)e.push(l.stdin??``);else{let n=l.fs.resolvePath(l.cwd,t),r=await l.fs.readFile(n);if(r===null)return{exitCode:1,stdout:``,stderr:`column: ${t}: No such file or directory
`};e.push(r)}v=e.join(``)}if(v===``||v.trim()===``)return{exitCode:0,stdout:``,stderr:``};let y=v.split(`
`);v.endsWith(`
`)&&y[y.length-1]===``&&y.pop();let b=y.filter(e=>e.trim().length>0),x;if(d)x=s(b.map(e=>a(e,f,h)),_);else{let e=[];for(let t of b){let n=a(t,f,h);e.push(...n)}x=c(e,m,_)}return x.length>0&&(x+=`
`),{exitCode:0,stdout:x,stderr:``}}},u={name:`column`,flags:[{flag:`-t`,type:`boolean`},{flag:`-s`,type:`value`,valueHint:`delimiter`},{flag:`-o`,type:`value`,valueHint:`string`},{flag:`-c`,type:`value`,valueHint:`number`},{flag:`-n`,type:`boolean`}],stdinType:`text`,needsFiles:!0};export{u as n,l as t};
//# sourceMappingURL=chunk-LWEGUNWT-DhbhFY11.mjs.map