mIRC Home    About    Download    Register    News    Help

Print Thread
Dialogs and colors & Retaining multiple spaces. #224862 20/08/10 08:29 AM
Joined: Aug 2010
Posts: 134
T
Thels Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
Hello.

I'm writing my own little mIRC enhancement script, and I ran into a few questions. For the purpose of these questions, assume that there are no external files available, as I like to hand out the script to other users and prefer to keep it light (ie, only a single .mrc file). If what I ask is not possible with core mIRC 7.1, then I rather forgo it.

I just switched to using a custom dialog to set my options. I never messed with custom dialogs before, as I never bothered with a semiprofessional way to configure options, so I'm pretty new about it.

First, I'm following the advice from the mIRC help file to use "option dbu", which should make it appear the same on every windows computer. Is that really advisable, if all I'm planning to do are simple options like tabs, check options, an entry field here and there and a couple of drop down combos?

Second, is there any way to show colors inside a custom dialog. I was hoping to do something like the Event/Message/Highlight option on the Display tab of mIRC options, but it doesn't really seem possible.

Third, mIRC eats spaces. When using the following script (which I know is pretty redundant this way, but this is just an example), all the double spaces someone enters are gone. Is there a way to retain the spaces, at least long enough for me to replace them by other characters, and replace them back to spaces once I'm ready to output the line again?

on ^*:text:*:#: {
echo -bfi2lmqt $chan $+(<, $nick, >) $1-
haltdef
}


Learning something new every day.
Re: Dialogs and colors & Retaining multiple spaces. [Re: Thels] #224864 20/08/10 09:38 AM
Joined: Feb 2006
Posts: 546
J
jaytea Offline
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
regarding the spaces issue, there does exist a method to echo the exact line as messaged by the user (with excess spaces intact) by using /loadbuf, an example of which is given here: http://pastebin.com/hczBVrFs

the preferred method involves using a DLL such as Saturn's spaces.dll available along with a full double article on the nature of handling spaces in mIRC at: http://www.xise.nl/mirc/wiki/doku.php?id=spaces





"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Re: Dialogs and colors & Retaining multiple spaces. [Re: Thels] #224867 20/08/10 10:11 AM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
dbu works fine no matter what dialog you're making. If you want colors in your dialog, using DCX is a good way to go, but will require that you include their DLL file with your script. There's a lot you can do with DCX to make your dialog(s) look unique.


Invision Support
#Invision on irc.irchighway.net
Re: Dialogs and colors & Retaining multiple spaces. [Re: Riamus2] #224868 20/08/10 10:53 AM
Joined: Aug 2010
Posts: 134
T
Thels Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
Originally Posted By: Riamus2
dbu works fine no matter what dialog you're making. If you want colors in your dialog, using DCX is a good way to go, but will require that you include their DLL file with your script. There's a lot you can do with DCX to make your dialog(s) look unique.


Yes, I realize that using external DLLs can greatly enhance the looks of the custom dialogs. However, since I'm aiming at handing this script out to other users, including a DLL file just for the options screen when it is not at all required for the script itself does not seem user friendly to me. Thanks for your help, though.

Last edited by Thels; 20/08/10 10:59 AM.

Learning something new every day.
Re: Dialogs and colors & Retaining multiple spaces. [Re: jaytea] #224869 20/08/10 10:58 AM
Joined: Aug 2010
Posts: 134
T
Thels Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
Originally Posted By: jaytea
regarding the spaces issue, there does exist a method to echo the exact line as messaged by the user (with excess spaces intact) by using /loadbuf, an example of which is given here: http://pastebin.com/hczBVrFs

the preferred method involves using a DLL such as Saturn's spaces.dll available along with a full double article on the nature of handling spaces in mIRC at: http://www.xise.nl/mirc/wiki/doku.php?id=spaces


Ok, I'm looking into this. I guess I should have mentioned before, but the problem goes two ways. When other users enter lines with leading or multiple spaces, it needs to be displayed on the current user's screen. But when the current user enters lines with leading or multiple spaces, it both needs to be displayed on the current user's screen, and sent to other users. Would a similar script support that?

Also, does anyone have experience with $chr(160)? It always used to look like a space, and still does to me. I'm using it in some of my bots as an easy trick to use leading or multiple spaces, and I haven't heard anyone complaining about it so far.

Thanks for your input. smile

EDIT: After staring at it for a while trying to decipher it, I decided to copy-paste it to my remote, and see what it does (making sure I have no other on text entries in any of my remotes). It doesn't exactly seem to work as intended.

When someone enters:
<Nick> test test

It comes out as:
<Nick>
test test

That's when literally copy-pasting the code. I'll try to see what I'm doing wrong.

Last edited by Thels; 20/08/10 11:12 AM.

Learning something new every day.
Re: Dialogs and colors & Retaining multiple spaces. [Re: Thels] #224870 20/08/10 11:30 AM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
$chr(160) works fine for everyone who uses mIRC 7.1. If your script will be used on previous versions of mIRC *or* if you are sending that to other users (in channels, queries, etc), then not everyone will see it as a space. That will depend on the font and encoding being used.

If you are displaying this to others or your script may be used on older versions of mIRC, spaces.dll is a good way to go (at least, I've heard it is as I haven't ever used it), or you can "fake" it by using control codes between spaces. Basically, you replace each space with something like Ctrl-B + Ctrl-B + $chr(32) (without the +'s, of course). You could also just use a single Ctrl-O as long as you don't care about losing colors/etc later in the line. Just keep in mind that doing it that way will result in more characters on the line and could mean long lines won't display the same way.

Note that /play can be used to display multiple spaces to other users if you have multiple spaces stored in a text file or clipboard. That's really only useful if you are manually putting the spaces in the file or you Copy a line of text to the clipboard.

As a note, in almost all cases, you really don't have to display multiple spaces. Most users understand that multiple spaces are stripped in mIRC and it doesn't hurt for those who don't know that to learn it. About the only reason to display multiple spaces that I can think of is to align text. If you're displaying ASCII art, that makes sense. If you're trying to display tables or something, then why? Locally, you can display them using TABs in a custom window with a listbox or you can use DCX to have TABs displayed in a dialog. And there isn't much reason to display some kind of table to users in IRC (it's a chat client). Of course, I don't know what you're trying to accomplish and maybe there is a good reason to need multiple spaces... but in most cases, it's not necessary and can easily be avoided.


Invision Support
#Invision on irc.irchighway.net
Re: Dialogs and colors & Retaining multiple spaces. [Re: Riamus2] #224873 20/08/10 11:48 AM
Joined: Aug 2010
Posts: 134
T
Thels Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
When abusing $chr(160), the following little script gets the deal done already. I didn't know about $regml(1), so this thread bumped me in the right direction, all right smile

Code:
on &$^*:text:/(.*)/:#:{
  echo -bfi2lmqt $chan $+(<, $left($remove($nick($chan, $nick).pnick, $nick), 1) , $nick, >) $replace($+($chr(32), $regml(1)), $+($chr(32), $chr(32)), $+($chr(32), $chr(160)))
  haltdef
}


Basically, what the script does is, whenever you receive a line of text, my script picks it up, does some things to it like color the text between "" characters, color and underline links, etc... It also combines messages from other users that were split over multiple lines back into a single line. For that, since only the end user will see it, I think I'm going to stick to $chr(160) until I hear someone having problems with that.

It does more or less the same things for messages by the current user sent to other users. Displaying it for the current user of course can use $chr(160) again. As for displaying text to others, I'm not sure, yet. If the /play command requires the clipboard or creating/deleting a file every time you enter a message, then I'm not going that way. Perhaps I'll just allow the end user to choose between using $chr(160), using double bold tags or letting leading/multiple spaces disappear.

As for my bot(s), I'll have to look into spaces.dll, I guess. I'm currently using $chr(160) to properly align ascii characters, and I've been doing so for a while. I never heard anyone having problems with the alignment so far, but it might be wise to keep my options open.

Keeping leading and multiple spaces is not really a requirement. It's just that I've already been using this script for a while, and am just improving it over time. So far it just ignores leading/adjacent spaces, but if there is an easy way to keep them intact, I'd be happy to.

EDIT: Changed the code slightly to keep a leading space intact.

Last edited by Thels; 20/08/10 12:07 PM.

Learning something new every day.
Re: Dialogs and colors & Retaining multiple spaces. [Re: Thels] #225221 28/08/10 05:33 PM
Joined: Aug 2010
Posts: 134
T
Thels Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
$regml(1) did wonders. Now I'm wondering, is there a similar feature for input? $editbox($active) seems to be empty by the time the user presses enter frown


Learning something new every day.
Re: Dialogs and colors & Retaining multiple spaces. [Re: Thels] #225251 29/08/10 11:14 AM
Joined: Aug 2010
Posts: 134
T
Thels Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
Seems I can get somewhere with the following code. Still requires a lot of work, though.

Code:
on *:input:*: {
  if !$ctrlenter {
    haltdef
    editbox -n /
    .timergetinput 1 0 getinput
  }
}

alias getinput {
  echo -a Editbox: $replace($editbox($active), $chr(32), $chr(160))
  editbox -a
}


Does anyone know why the above code would generate an error when using ".timer" instead of ".timergetinput"? I get "THELS#CHANNEL Unknown command" or "THELS Unknown command" when trying it in the status window, Thels being my IRC nickname of course.


Learning something new every day.
Re: Dialogs and colors & Retaining multiple spaces. [Re: Thels] #225254 29/08/10 12:15 PM
Joined: Aug 2010
Posts: 134
T
Thels Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
Hmm, I was running into some problems.

I changed to using the Status Window's editbox, and using the /! command. The advantages were that it wouldn't mess up the history position, still allowing users to go up and down using the arrow keys. Secondly, it would work for both the editboxes, instead of only the primary one.

However, the disadvantage is that /! only calls the very last line, and keeps calling that same last line.

I tried using the active window again, and using / once more, and now I can pick up multiple consecutive lines (in reverse order, but that's no biggie).

It comes with two disadvantages, though. First, it messes up the current history position. Second, it assumes the first editbox is used. I can easily load the information from the second editbox, but how do I know which one to load from?

Code for using the status window: (Does not support multiple lines, but does work with both editboxes and does not screw up the history position.)

Code:
on *:input:*: {
  if !$ctrlenter {
    if $left($1, 1) != / && $left($1, 1) != $readini($mircini,text,commandchar) {
      haltdef
      if !%lines {
        set %linestatus $editbox(Status Window)
        editbox -ns /!
        .timergetinput 1 0 getinput
      }
      inc %lines 1
      set %linewindow [ $+ [ %lines ] ] $active
    }
  }
}

alias getinput {
  echo -a Line %lines Window %linewindow [ $+ [ %lines ] ] Editbox: $replace($editbox(Status Window), $chr(32), $chr(160))
  dec %lines 1
  if !%lines {
    editbox -s %linestatus
  }
  else {
    editbox -ns /!
    .timergetinput 1 0 getinput
  }
}


Code for using the active window: (Supports multiple lines, but messes up the history position, and does not work with the second editbox.)

Code:
on *:input:*: {
  if !$ctrlenter {
    if $left($1, 1) != / && $left($1, 1) != $readini($mircini,text,commandchar) {
      haltdef
      if !%lines {
        editbox -na /
        .timergetinput 1 0 getinput $1-
      }
      inc %lines 1
      set %linewindow [ $+ [ %lines ] ] $active
    }
  }
}

alias getinput {
  echo -a Line %lines Window %linewindow [ $+ [ %lines ] ] Editbox: $replace($editbox($active), $chr(32), $chr(160))
  dec %lines 1
  if !%lines {
    editbox -a
  }
  else {
    editbox -na /
    .timergetinput 1 0 getinput $1-
  }
}


EDIT: Copy-pasted the wrong code.

Last edited by Thels; 29/08/10 12:18 PM.

Learning something new every day.
Re: Dialogs and colors & Retaining multiple spaces. [Re: Thels] #225284 29/08/10 10:54 PM
Joined: Aug 2010
Posts: 134
T
Thels Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
I managed to sort it out.

This code retrieves the lines from the editbox history, keeping the spaces. It works with both editboxes, and it works when multiple lines are being pasted at once.

It should theoretically always find it's result, but in the cases where it doesn't, it still has the space tokenized input.

Code:
on *:input:#: {
  if !$ctrlenter {

    ;If there is already a input queue for this window, simply add one additional line.
    if $hget(input, lines) {
      haltdef
      hinc input lines 1
      hadd input $+(line, $hget(input, lines)) $1-
    }

    ;If the primary editbox is empty, recall the last line for the primary editbox.
    elseif $editbox($active) == $null {
      haltdef
      hinc input lines 1
      hadd input $+(line, $hget(input, lines)) $1-
      editbox -afn /
      .timergrabinput 1 0 grabinput 1
    }

    ;If the primary editbox is not empty, but the secondary editbox is, recall the last line for the secondary editbox.
    elseif $editbox($active, 1) == $null {
      haltdef
      hinc input lines 1
      hadd input $+(line, $hget(input, lines)) $1-
      editbox -afno /
      .timergrabinput 1 0 grabinput
    }

    ;Catch the error in case the secondary editbox is unavailable.
    :error
    reseterror
  }
}

;Grab the input entries.
alias -l grabinput {

  ;Compare the value with a tokenized version of the editbox, to see if they match.
  if $1 {
    tokenize 32 $editbox($active)
    if $hget(input, $+(line, $hget(input, lines))) == $1- {
      hadd input $+(line, $hget(input, lines)) $hardspace($editbox($active))
      hdec input lines 1

      ;If there are more lines in queue, request the next editbox line.
      if $hget(input, lines) {
        editbox -afn /
        .timergrabinput 1 0 grabinput 1
        return
      }

      ;Clear the editbox.
      editbox -a
    }
    else {
      editbox -a

      ;If the primary editbox does not match, but the secondary editbox is empty, recall the last line for the secondary editbox.
      if $editbox($active, 1) == $null {
        editbox -afno /
        .timergrabinput 1 0 grabinput
        return
      }
    }
  }
  else {
    tokenize 32 $editbox($active, 1)
    if $hget(input, $+(line, $hget(input, lines))) == $1- {
      hadd input $+(line, $hget(input, lines)) $hardspace($editbox($active, 1))
      hdec input lines 1

      ;If there are more lines in queue, request the next editbox line.
      if $hget(input, lines) {
        editbox -afno /
        .timergrabinput 1 0 grabinput
        return
      }
    }

    ;If the result does not match, and the first editbox is empty, return the focus to the first editbox.
    elseif $editbox($active) == $null {
      editbox -af
    }

    ;Clear the editbox.
    editbox -ao
  }

  ;Catch the error in case the secondary editbox is unavailable.
  :error
  reseterror
  hdel input lines
  evalinput
}

;Evaluate the input entries.
alias -l evalinput {
  var %count 1
  while $hget(input, $+(line, %count)) != $null {
    tokenize 32 $hget(input, $+(line, %count))

    ;If the first parameter does not start with /, say the line in the channel.
    if $left($remove($1, $chr(160)), 1) != / && $left($remove($1, $chr(160)), 1) != $readini($mircini,text,commandchar) {
      say $1-
    }

    ;If the first parameter equals /me, emote the remaining line in the channel.
    elseif $right($remove($1, $chr(160)), -1) == me {
      me $2-
    }

    ;Remove the $chr(160) signs and execute the line.
    else {
      $remove($1-, $chr(160))
      ;Include an errorcatcher, to allow further lines to execute.
      :error
    }
    hdel input $+(line, %count)
    var %count $calc(%count + 1)
  }
}

alias -l hardspace return $replace($+($chr(32), $1-), $+($chr(32), $chr(32)), $+($chr(32), $chr(160)), $+($chr(160), $chr(32)), $+($chr(160), $chr(160)))


Note: While it can pick up adjacent spaces, it of course cannot actually send these out, so the code replaces the spaces by non breaking spaces. All leading spaces, and all spaces but the first in a group of spaces are being converted, keeping the parameters 1:1 with what they would be in a tokenized version, so the end result is something like:

Code:
   word1   word2   word3   
___word1 __word2 __word3 __

Last edited by Thels; 29/08/10 10:58 PM.

Learning something new every day.
Re: Dialogs and colors & Retaining multiple spaces. [Re: Thels] #225286 30/08/10 01:01 AM
Joined: Apr 2010
Posts: 943
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 943
/savebuf
/bread
are your friends...


I am SReject
My Stuff
Re: Dialogs and colors & Retaining multiple spaces. [Re: FroggieDaFrog] #225298 30/08/10 08:47 AM
Joined: Aug 2010
Posts: 134
T
Thels Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
Originally Posted By: FroggieDaFrog
/savebuf
/bread
are your friends...


I fail to see how they are relevant here.

The script I posted retrieves the non space tokenized version of the input, before it's actually executed. IE, I can do stuff with it like adding colors and whatnot and then execute it.

If I understand /savebuf correctly, you read the last line from the window, which thus is already sent out to other users, and therefor pointless.


Learning something new every day.
Re: Dialogs and colors & Retaining multiple spaces. [Re: Thels] #225301 30/08/10 09:05 AM
Joined: Apr 2010
Posts: 943
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 943
I didn't completely read you post before i posted. But I think I have something for you that might be of interest. Instead of replacing multiple spaces with another character, I have a little trick that will preserve them completely from the edit box.

Code:
;/KeepSpaces <window>
;$keepspaces(<window>)
alias KeepSpaces {
  ;this subs out every character for it's nummeric value, then stores it into a &binvar
  bset &tmp $regsubex($editbox($$1-),/(.)/g,$asc(\t) $+ $chr(32))
  ;dostuff with &tmp. Possibly add it to a hashtable(/hadd -b) to recall later[$hget(table,item,&var)]?
}


Ofcourse, I've left, up to you, how to get the editbox text.

Edited: Fixed typos, added some comments to code


Last edited by FroggieDaFrog; 30/08/10 09:08 AM.

I am SReject
My Stuff
Re: Dialogs and colors & Retaining multiple spaces. [Re: FroggieDaFrog] #225302 30/08/10 09:28 AM
Joined: Aug 2010
Posts: 134
T
Thels Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
Ah, ok. Then I misunderstood your post. My apologies.

Myeah, I could keep them around as spaces, of course. If I understood Saturn's tutorial (http://www.xise.nl/mirc/wiki/doku.php?id=spaces), I could even save the spaces to a variable. I've thought about rewriting the above script to meet towards that.

Of course this all is pointless when all you want to do with the text is send it out again, since there's no way to do that without getting rid of spaces. (I've heard of /play, but haven't looked into that, yet. Heard it required a constant writing to and loading from files, which is not too great, though perhaps I could do it for lines with leading/adjacent spaces only.)

Anyhow, my aim here was at preserving spaces on input without the need of a .dll file. Whatever needs to be done with them afterward was not the issue here. Thanks for your input, though.


Learning something new every day.
Re: Dialogs and colors & Retaining multiple spaces. [Re: FroggieDaFrog] #225303 30/08/10 09:41 AM
Joined: Feb 2006
Posts: 546
J
jaytea Offline
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
you could then write &tmp to a file and use /play and /loadbuf to, respectively, message the target and add the line to a window's buffer (since both commands preserve spaces).

to reproduce mIRC's behaviour entirely is undoubtedly complicated and ultimately impractical when compared to solutions offered by, for example, Saturn's spaces.dll. however, it is interesting to know that there exist methods such as Thels's (which, by the way, is brilliant) to overcome these problems with pure mIRC script :P


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Re: Dialogs and colors & Retaining multiple spaces. [Re: jaytea] #225313 30/08/10 12:59 PM
Joined: Aug 2010
Posts: 134
T
Thels Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
Originally Posted By: jaytea
however, it is interesting to know that there exist methods such as Thels's (which, by the way, is brilliant) to overcome these problems with pure mIRC script :P


Thanks for the compliment. smile

By the way, I modified the code to add some safety nets in case the script would bug out for one reason or another (in the earlier example, IF something would go wrong, all further input without ctrlenter would be eaten by the script :P).

I also used regular variables instead of a hash table. Since the number of variables is equal to 3 + number of lines posted, it shouldn't be a problem. This also shows better that the $chr(160) trick is not required for grabbing the input, but merely for the /say and /me commands at the very end of the code.

I might come up with a /play and /loadbuf alternative, to allow adjacent spaces to go from input to output without the need for spaces, but that would mostly be for academical reasons.

Code:
on *:input:*: {
  if !$ctrlenter {

    ;If there is already an input queue, simply add one additional line.
    ;(Checking the timer is merely a safety net. It should always be running while %inputlines is set).
    if %inputlines && $timer(grabinput) {
      haltdef
      inc %inputlines 1
      inc %inputlinem 1
      set %inputline [ $+ [ %inputlines ] ] $1-
      return
    }

    ;(Removing the variables is merely a safety net. They should always be removed at the end of an input run).
    unset %inputline*

    ;If there is no input queue, and the line is a command, stop processing unless it's /say, /me, /msg or /describe.
    set %inputlinec $readini($mircini, text, commandchar)
    if $left($1, 1) == / || $left($1, 1) == %inputlinec {
      if $right($1, -1) != say && $right($1, -1) != me && $right($1, -1) != msg && $right($1, -1) != describe {
        if $right($1, -1) != .say && $right($1, -1) != .me && $right($1, -1) != .msg && $right($1, -1) != .describe {
          return
        }
      }
    }

    ;If the primary editbox is empty, recall the last line for the primary editbox.
    if $editbox($active) == $null {
      haltdef
      set %inputlines 1
      set %inputlinem 1
      set %inputline1 $1-
      editbox -afn /
      .timergrabinput 1 0 grabinput 1
    }

    ;If the primary editbox is not empty, but the secondary editbox is, recall the last line for the secondary editbox.
    elseif $editbox($active, 1) == $null {
      haltdef
      set %inputlines 1
      set %inputlinem 1
      set %inputline1 $1-
      editbox -afno /
      .timergrabinput 1 0 grabinput
    }

    ;Catch the error in case the secondary editbox is unavailable.
    :error
    reseterror
  }
}

;Grab the input entries.
alias -l grabinput {

  ;Compare the value with a tokenized version of the editbox, to see if they match.
  if $1 {
    tokenize 32 $editbox($active)
    if %inputline [ $+ [ %inputlines ] ] == $1- {
      set %inputline [ $+ [ %inputlines ] ] $editbox($active)
      dec %inputlines 1

      ;If there are more lines in queue, request the next editbox line.
      if %inputlines {
        editbox -afn /
        .timergrabinput 1 0 grabinput 1
        return
      }

      ;Clear the editbox.
      editbox -a
    }
    else {
      editbox -a

      ;If the primary editbox does not match, but the secondary editbox is empty, recall the last line for the secondary editbox.
      if $editbox($active, 1) == $null {
        editbox -afno /
        .timergrabinput 1 0 grabinput
        return
      }
    }
  }
  else {
    tokenize 32 $editbox($active, 1)
    if %inputline [ $+ [ %inputlines ] ] == $1- {
      set %inputline [ $+ [ %inputlines ] ] $editbox($active, 1)
      dec %inputlines 1

      ;If there are more lines in queue, request the next editbox line.
      if %inputlines {
        editbox -afno /
        .timergrabinput 1 0 grabinput
        return
      }
    }

    ;If the result does not match, and the first editbox is empty, return the focus to the first editbox.
    elseif $editbox($active) == $null {
      editbox -af
    }

    ;Clear the editbox.
    editbox -ao
  }

  ;Catch the error in case the secondary editbox is unavailable.
  :error
  reseterror

  ;Send all input entries for evaluation.
  set %inputlines 0
  while %inputlines < %inputlinem {
    inc %inputlines 1
    noop $evalinput(%inputline [ $+ [ %inputlines ] ] )
  }
  unset %inputline*
}

;Evaluate the input entry.
alias -l evalinput {
  var %line $1
  tokenize 32 %line

  ;If the first parameter does not start with /, send the line to the channel.
  if $left($1, 1) != / && $left($1, 1) != %inputlinec {
    say $hardspace(%line)
    return
  }

  ;Remove the first parameter from the line.
  var %line $right(%line, $calc(0 - $pos(%line, $1, 1) - $len($1)))

  ;If the first parameter equals /say or /me, send the remaining line to the channel.
  if $right($1, -1) == say ||  $right($1, -1) == .say || $right($1, -1) == me || $right($1, -1) == .me {
    $right($1, -1) $hardspace(%line)
    return
  }

  ;Remove the second parameter from the line.
  var %line $right(%line, $calc(0 - $pos(%line, $2, 1) - $len($2)))

  ;If the first parameter equals /msg or /describe, send the remaining line to $2.
  if $right($1, -1) == msg || $right($1, -1) == .msg || $right($1, -1) == describe || $right($1, -1) == .describe {
    $right($1, -1) $2 $hardspace(%line)
    return
  }

  ;Execute the space tokenized version as a regular alias. Include an :error to allow further lines to execute.
  $1-
  :error
}

;Replace non breaking spaces by normal spaces. (Only required at the very end to output the line again.)
alias -l hardspace return $replace($+($chr(32), $1-), $+($chr(32), $chr(32)), $+($chr(32), $chr(160)), $+($chr(160), $chr(32)), $+($chr(160), $chr(160)))


Now, if I could only come up with a way to set the entrybox history position back to the very end. smile


Learning something new every day.
Re: Dialogs and colors & Retaining multiple spaces. [Re: FroggieDaFrog] #225322 30/08/10 03:58 PM
Joined: Aug 2010
Posts: 134
T
Thels Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
I realize I don't understand very much about $regsubex yet.

Earlier, in this little piece of code, I didn't understand the ":/(.*)/:" part either, other than that it would put the text in $regml(1), and I just worked with that.

Code:
on &$^*:text:/(.*)/:#:{
  echo -bfi2lmqt $chan $+(<, $left($remove($nick($chan, $nick).pnick, $nick), 1) , $nick, >) $replace($+($chr(32), $regml(1)), $+($chr(32), $chr(32)), $+($chr(32), $chr(160)))
  haltdef
}


Then coming to this piece of code. I haven't worked with binvars, but bset seems obvious enough. Can't simply use bset -t, since it would eat the spaces, but then comes the part after.

Code:
;/KeepSpaces <window>
;$keepspaces(<window>)
alias KeepSpaces {
  ;this subs out every character for it's nummeric value, then stores it into a &binvar
  bset &tmp $regsubex($editbox($$1-),/(.)/g,$asc(\t) $+ $chr(32))
  ;dostuff with &tmp. Possibly add it to a hashtable(/hadd -b) to recall later[$hget(table,item,&var)]?
}


$regsubex($editbox($$1-),/(.)/g,$asc(\t) $+ $chr(32))

The first part, $editbox($$1-), is where the text is supposed to go, I can understand that. The second and third parts are quite lost on me. I know $asc of course, but I have no clue why it's doing that on \t.

EDIT: http://www.regular-expressions.info/ seems to have the information I need. I'm starting to see the light.

Last edited by Thels; 30/08/10 04:17 PM.

Learning something new every day.