import{a as C}from"./chunk-HWKDQ44K.js";import{a as y,b as F}from"./chunk-74CEPOFO.js";import"./chunk-DXB73IDG.js";var W={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"]},j={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 I(t,e,o){return e?o?t.split(e):t.split(e).filter(n=>n.length>0):o?t.split(/[ \t]/):t.split(/[ \t]+/).filter(n=>n.length>0)}function x(t){let e=[];for(let o of t)for(let n=0;n<o.length;n++){let l=o[n].length;(e[n]===void 0||l>e[n])&&(e[n]=l)}return e}function E(t,e){if(t.length===0)return"";let o=x(t),n=[];for(let l of t){let a=[];for(let s=0;s<l.length;s++)s===l.length-1?a.push(l[s]):a.push(l[s].padEnd(o[s]));n.push(a.join(e))}return n.join(`
`)}function M(t,e,o){if(t.length===0)return"";let n=Math.max(...t.map(c=>c.length)),l=o.length,a=n+l,s=Math.max(1,Math.floor((e+l)/a)),h=Math.ceil(t.length/s),p=[];for(let c=0;c<h;c++){let i=[];for(let r=0;r<s;r++){let m=r*h+c;m<t.length&&(r===s-1||(r+1)*h+c>=t.length?i.push(t[m]):i.push(t[m].padEnd(n)))}p.push(i.join(o))}return p.join(`
`)}var T={name:"column",execute:async(t,e)=>{if(F(t))return y(W);let o=C("column",t,j);if(!o.ok)return o.error;let{table:n,separator:l,outputSep:a,width:s,noMerge:h}=o.result.flags,p=o.result.positional,c=a??"  ",i;if(p.length===0)i=e.stdin??"";else{let u=[];for(let f of p)if(f==="-")u.push(e.stdin??"");else{let w=e.fs.resolvePath(e.cwd,f),b=await e.fs.readFile(w);if(b===null)return{exitCode:1,stdout:"",stderr:`column: ${f}: No such file or directory
`};u.push(b)}i=u.join("")}if(i===""||i.trim()==="")return{exitCode:0,stdout:"",stderr:""};let r=i.split(`
`);i.endsWith(`
`)&&r[r.length-1]===""&&r.pop();let g=r.filter(u=>u.trim().length>0),d;if(n){let u=g.map(f=>I(f,l,h));d=E(u,c)}else{let u=[];for(let f of g){let w=I(f,l,h);u.push(...w)}d=M(u,s,c)}return d.length>0&&(d+=`
`),{exitCode:0,stdout:d,stderr:""}}};export{T as column};
