MUX Wrap()

Since MUX wrap() is typically useless by itself and MUX _still_ doesn't handle %r's as delimiters very well I've decided to release this snippet of useful code.

Author: Ian@BrazilMUX
Category: Functions
Commands: @create, @describe, @lock.

Instructions

Copy and paste the below code into a compatible MUSH or MUX.

MUSHCode for MUX Wrap()

@create Useful MUX wrapping function
@lock Useful MUX wrapping function==me
&FN_JWRAP Useful MUX wrapping function=localize(setq(5,l)[setq(9,%1)][setq(p,%2)][setq(q,%3)][map(map_jwrap,u(fn_swapr,edit(%0,%t,%b %b %b %b)),~,%r)])
&FN_SWAPR Useful MUX wrapping function=edit(edit(edit(edit(edit(%0,`,`0),%r,`1),~,%r),`1,~),`0,`)
&MAP_JWRAP Useful MUX wrapping function=setq(8,switch(-%0,-,space(%q9),-<?>*,setq(5,mid(%0,1,1))[mid(%0,3,4000)],%0))[map(u_jwrap_%q5,u(fn_swapr,wrap(edit(%q8,%r,~),%q9)),~,%r)]
&U_JWRAP_R Useful MUX wrapping function=%qp[rjust(trim(edit(%0,%r,~)),%q9)]%qq
&U_JWRAP_C Useful MUX wrapping function=%qp[center(trim(edit(%0,%r,~)),%q9)]%qq
&U_JWRAP_L Useful MUX wrapping function=%qp[ljust(edit(%0,%r,~),%q9)]%qq
@Desc Useful MUX wrapping function=%tSince MUX wrap%() is typically useless by itself and MUX _still_ doesn't handle %%r's as delimiters very well I've decided to release this snippet of useful code.%r%r%tFN_JWRAP is the wrapping function. The first argument should be the text. The second argument should be the width to wrap to. The optional third and fourth arguments simply concatenate text to the left and right of every line.%r%r%tANSI is handled well only for the prefix and postfix strings due to having to edit() the text to wrap in order to circumvent MUX's inability to handle CRLFs as input delimiters. Yes, there is an evil way I could actaully get around that, but it would be a very poor choice and likely to be broken in future versions of MUX.%r%r%tA particularly useful feature is the ability to set left, centered, and right alignment. At the start of a line (that is, at the very beginning or just after a %%R with no proceeding spaces) use <L>, <C>, or <R> tags to specify the alignment you desire. By default left alignment is used.%r%rNote that the wrapping function does pad all lines with spaces to exactly fit the width specified.
&CREDITS Useful MUX wrapping function=Please give credit where credit is due. This code was generated by Ian@BrazilMUX. Feel free to use it, modify it, and redistributed it. I've tried to make this code reasonably efficient and secure, but I really haven't optimized it carefully. May you find it useful. :)