import{c as y}from"./chunk-AH77CRWX.js";import{a as C}from"./chunk-HWKDQ44K.js";import{a as F,b as x}from"./chunk-74CEPOFO.js";var H={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 v(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 T(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 W(t,e){if(t.length===0)return"";let o=T(t),n=[];for(let l of t){let c=[];for(let s=0;s<l.length;s++)s===l.length-1?c.push(l[s]):c.push(l[s].padEnd(o[s]));n.push(c.join(e))}return n.join(`
`)}function j(t,e,o){if(t.length===0)return"";let n=Math.max(...t.map(a=>a.length)),l=o.length,c=n+l,s=Math.max(1,Math.floor((e+l)/c)),p=Math.ceil(t.length/s),d=[];for(let a=0;a<p;a++){let i=[];for(let r=0;r<s;r++){let m=r*p+a;m<t.length&&(r===s-1||(r+1)*p+a>=t.length?i.push(t[m]):i.push(t[m].padEnd(n)))}d.push(i.join(o))}return d.join(`
`)}var S={name:"column",execute:async(t,e)=>{if(x(t))return F(H);let o=C("column",t,I);if(!o.ok)return o.error;let{table:n,separator:l,outputSep:c,width:s,noMerge:p}=o.result.flags,d=o.result.positional,a=c??"  ",i;if(d.length===0)i=y(e.stdin)??"";else{let u=[];for(let f of d)if(f==="-")u.push(y(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),h;if(n){let u=g.map(f=>v(f,l,p));h=W(u,a)}else{let u=[];for(let f of g){let w=v(f,l,p);u.push(...w)}h=j(u,s,a)}return h.length>0&&(h+=`
`),{exitCode:0,stdout:h,stderr:""}}},L={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{S as a,L as b};
