|
Joined: Jun 2003
Posts: 114
Vogon poet
|
OP
Vogon poet
Joined: Jun 2003
Posts: 114 |
I have made an output alias for a socket bot that hard-wraps the text so that it is never more than a specified length. However, I want to do a soft wrap (wherein it never cuts into the middle of a word unless the word itself is > max length) but I can't quite figure out how to go about it. Could anyone gimme a suggestion? Heres the hard wrap:
alias kuran.output {
var %kuran.length = 80
var %kuran.output = $2-
while ($len(%kuran.output) > 0) {
sockwrite -n $1 $left(%kuran.output, %kuran.length)
%kuran.output = $right(%kuran.output, $calc(0 - %kuran.length))
}
}
------------- I am the self-appointed God of needlessly complex mIRCscript.
|
|
|
|
Joined: May 2004
Posts: 24
Ameglian cow
|
Ameglian cow
Joined: May 2004
Posts: 24 |
time ago i made a script that maybe can help you :tongue:
alias spezza { if ($1-) { var %wrap = $wrap($1-,Tahoma,8,195,0), %x = 1 while (%x <= %wrap) { write %dd.w $wrap($1-,Tahoma,8,195,%x) inc %x } } }
|
|
|
|
Joined: Jun 2003
Posts: 114
Vogon poet
|
OP
Vogon poet
Joined: Jun 2003
Posts: 114 |
alias kuran.output {
var %length = 80
var %output = $2-
var %buffer
var %looprot
while ($len(%output) > 0) {
%buffer = $null
while ($gettok(%output, 1, 32) > %length) {
sockwrite -n $1 $left(%output, %length)
%output = $right(%output, $calc(0 - %length))
inc %looprot
if (%looprot > 50) { halt }
}
while ($len(%buffer) < %length && $len(%output) > 0) {
%buffer = $instok(%buffer, $gettok(%output, 1, 32), $numtok(%buffer, 32), 32)
%output = $deltok(%output, 1, 32)
inc %looprot
if (%looprot > 50) { halt }
}
if ($len(%buffer) > %length) {
%output = $instok(%output, $gettok(%buffer, $numtok(%buffer, 32), 32), 0, 32)
%buffer = $deltok(%buffer, $numtok(%buffer, 32), 32)
}
inc %looprot
if (%looprot > 50) { halt }
}
}
This was my sloppy attempt at doing it (note the %looprot to make absolutely sure theres no infinite loops) However, it doesn't work. Oddly enough, it still hard wraps.
------------- I am the self-appointed God of needlessly complex mIRCscript.
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
Try this: alias kuran.output {
!.echo -q $regex($2-,/(.{1,80})(?: |$)|(\S{80})/g)
var %i = 1
while $regml(%i) != $null {
sockwrite -n $1 $ifmatch
inc %i
}
}
Last edited by qwerty; 07/06/04 01:06 AM.
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,962 |
You might also want the s modifier on there in case the input has newlines itself. Also '\s|$' might be more useful in place of ' |$'.
Last edited by starbucks_mafia; 07/06/04 01:44 AM.
Spelling mistakes, grammatical errors, and stupid comments are intentional.
|
|
|
|
Joined: Jun 2003
Posts: 114
Vogon poet
|
OP
Vogon poet
Joined: Jun 2003
Posts: 114 |
God I hate regexes, I can never understand em. But thanks, it works perfect.
------------- I am the self-appointed God of needlessly complex mIRCscript.
|
|
|
|
Joined: Jun 2003
Posts: 114
Vogon poet
|
OP
Vogon poet
Joined: Jun 2003
Posts: 114 |
One last question... Is there any way to make it indent all after the second part of a line? So when it wraps around, the part it wraps is indented with $chr(160) ?
------------- I am the self-appointed God of needlessly complex mIRCscript.
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
Yep, /gs would cover the extreme cases that the text contains newlines. "\s" might also be preferable to " " if the text is going to be echoed in a custom window (in other types of windows tab doesn't look like whitespace).
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: Dec 2002
Posts: 1,922
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,922 |
Perfect  *saves in his regex snippets file*
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
The part that wraps is every $regml(%i) apart from the first. So, you can check in the loop whether %i is bigger than 1 and stick a $chr(160) in front of $regml(%i) if it is: alias kuran.output {
!.echo -q $regex($2-,/(.{1,80})(?:\s|$)|(\S{80})/gs)
var %i = 0, %a = $regml(0), %b = $chr(160)
while %i < %a {
inc %i
sockwrite -n $1 $iif(%i > 1,%b) $+ $regml(%i)
}
}
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
|