Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 17.03 KB | None | 0 0
  1. ;;;;;;;;;;;;;;;;;;;;; mIRC UI lib for custom windows ;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;;                                                                          ;;;
  3. ;;; By FIQ (v1.0)                                                            ;;;
  4. ;;;                                                                          ;;;
  5. ;;;                                                                          ;;;
  6. ;;; Features :                                                               ;;;
  7. ;;;          :                                                               ;;;
  8. ;;;          : (X=done, /=worked on, -=not started yet, this will be done    ;;;
  9. ;;;          : BEFORE version 1.0                                            ;;;
  10. ;;;                                                                          ;;;
  11. ;;;       X  : Automatic height/width calculation for "screen resolution"    ;;;
  12. ;;;          :                                                               ;;;
  13. ;;;       -  : Recalculation if you change font or font size                 ;;;
  14. ;;;          :                                                               ;;;
  15. ;;;       /  : Dodge of mIRC's own "pagekey scroll"                          ;;;
  16. ;;;          :                                                               ;;;
  17. ;;;       X  : Autoscrolling of text                                         ;;;
  18. ;;;          :                                                               ;;;
  19. ;;;       X  : Setup fixed lines                                             ;;;
  20. ;;;          :                                                               ;;;
  21. ;;;       -  : Make lines support INPUT for a range of ways, for example     ;;;
  22. ;;;          : text input, no/yes questions, prompt for action (using SPACE  ;;;
  23. ;;;          : per default).                                                 ;;;
  24. ;;;          :                                                               ;;;
  25. ;;;       -  : Make custom CTRL bindings                                     ;;;
  26. ;;;          :                                                               ;;;
  27. ;;;       X  : Buildt-in "less" to show off what could be done               ;;;
  28. ;;;          : with this thing (the "less" command in Linux terminals)       ;;;
  29. ;;;                                                                          ;;;
  30. ;;;                                                                          ;;;
  31. ;;; Changelog :                                                              ;;;
  32. ;;;           :                                                              ;;;
  33. ;;;         * : Due to the first version not released yet, there's no        ;;;
  34. ;;;           : changelog at this moment.                                    ;;;
  35. ;;;                                                                          ;;;
  36. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  37.  
  38. ;We want to unset everything the module has used in the previous session. Due to people sometimes closes mIRC in an unclean way, we do this on START instead of on EXIT.
  39. ;(Note: As less is in the same file as the UI module, we also have "unset %less_id_*" here, even if it's not part of the lib itself.
  40. on *:START:unset %ui.* | unset %less_id_*
  41.  
  42.  
  43. ;Hack for making PgUp/PgDn's own effect "disappear". Anyone with a better solution is welcome to contact me.
  44. ;
  45. ;How this work:
  46. ;Page up will send you up one page (how suprising) and making the UI placed wrong.
  47. ;The UI will have two windows, seperated by a dummy line (to hide this effect as good as possible).
  48. ;When the pageup is processing, the dummy line along with the down window will be removed almost immediatly.
  49. ;Then, a new dummy line will be created, and a new window on it.
  50. ;This hack has two problems:
  51. ; * A horrible flash will appear that is impossible to get rid of
  52. ; * If the user is flooding PgUp, this may fail.
  53. alias ui.rline {
  54.   !rline $1-
  55.   !rline $1 $calc($2 +1+ $ui.nscroll($1)) $3-
  56. }
  57. alias ui.pagefix {
  58.   var %i = 1
  59.   while (%i <= $ui.nscroll($1)) {
  60.     var %buffer $+ %i $line($1,%i)
  61.     inc %i
  62.   }
  63.   dline $1 $calc($ui.nscroll($1) + 1) $+ - $+ $line($1,0)
  64.   iline $1 1 
  65.   var %i = 1
  66.   while (%i <= $ui.nscroll($1)) {
  67.     iline $1 $calc(%i + 1) %buffer [ $+ [ %i ] ]
  68.     inc %i
  69.   }
  70. }
  71.  
  72.  
  73. alias ui.wname return $iif($left($1,1) == @,$1,@ $+ $1)
  74. alias ui.getIdInfo return $gettok(%ui.id. [ $+ [ $1 ] ],$2,58)
  75. alias ui.isBottom return $iif((!%ui.id. [ $+ [ $1 ] $+ [ .bufferCount ] ]) || ($ui.getWindowById($1).lastTextLine == %ui.id. [ $+ [ $1 ] $+ [ .bufferCount ] ]),$true,$false)
  76. alias ui.getWindowById {
  77.   if (!$ui.getIdInfo($1,1)) { return $false }
  78.   if (!$prop) { return $ui.getIdInfo($1,1) }
  79.   if ($prop == lastTextLine) { return %ui.id. [ $+ [ $1 ] $+ [ .lastTextLine ] ] }
  80.   if ($prop == firstTextLine) { return %ui.id. [ $+ [ $1 ] $+ [ .firstTextLine ] ] }
  81. }
  82. alias ui.nscroll {
  83.   if ($prop == w) { var %calc = $calc($window($1).dw / $width(b,$window($1).font,$window($1).fontsize)) }
  84.   else { var %calc =  $calc($window($1).dh / $height(b,$window($1).font,$window($1).fontsize)) }
  85.   if (. isin %calc) { var %calc = $calc($ceil(%calc) - 1) }
  86.   return %calc
  87. }
  88. alias ui.help {
  89.   if ($exists($scriptdirui_help.txt)) { less UI-help $scriptdirui_help.txt }
  90.   else { echo -ag Help file not found }
  91. }
  92. alias ui.createWindow {
  93.   while ($left($1,2) == --) {
  94.     var %switch = $right($gettok($1,1,61),-2)
  95.     if (= isin $1) {
  96.       if (" isin $1) && (" isin $2-) {
  97.         var %oldTokenize $1-
  98.         tokenize 34 $gettok($1,2,61) $2-
  99.         var %switchvalue = $1
  100.         tokenize 32 %oldTokenize
  101.         var %i = 2
  102.         while (" !isin $ [ $+ [ %i ] ]) {
  103.           inc %i
  104.         }
  105.         tokenize 32 $ [ $+ [ %i ] $+ [ - ] ]
  106.       }
  107.       else { var %switchvalue = $gettok($1,2,61) }
  108.     }
  109.     tokenize 32 $2-
  110.     if (%switch == header) { var %windowHeader = %switchvalue }
  111.     elseif (%switch == errorvar) { var %errorVariable = %switchvalue }
  112.   }
  113.   window -m $ui.wname($1)
  114.   ui.fixNoScroll $1
  115.   if (%windowHeader) { ui.setHeader $1 %windowHeader }
  116.   return true
  117. }
  118. alias ui.fixNoScroll {
  119.   var %i = 1
  120.   while (%i <= $ui.nscroll($ui.wname($1))) {
  121.     aline $ui.wname($1) 
  122.     inc %i
  123.   }
  124.   ;Make this happen again to get PgUp to work as we want.
  125.   aline $ui.wname($1) 
  126.   var %i = 1
  127.   while (%i <= $ui.nscroll($ui.wname($1))) {
  128.     aline $ui.wname($1) 
  129.     inc %i
  130.   }
  131. }
  132. alias ui.setHeader {
  133.   var %len = $calc( $ui.nscroll($ui.wname($1)).w / 2 - $len($2-) / 2 )
  134.   if (. isin %len) { var %len = %len + 0.5 | var %len2 = %len - 0.5 }
  135.   else { var %len2 = %len }
  136.   ui.rline $ui.wname($1) 1  $+ $str($chr(160),%len) $+ $2- $+ $str($chr(160),%len2)
  137. }
  138. alias ui.addTextArea {
  139.   while ($left($1,2) == --) {
  140.     var %switch = $right($gettok($1,1,61),-2)
  141.     if (= isin $1) {
  142.       if (" isin $1) && (" isin $2-) {
  143.         var %oldTokenize $1-
  144.         tokenize 34 $gettok($1,2,61) $2-
  145.         var %switchvalue = $1
  146.         tokenize 32 %oldTokenize
  147.         var %i = 2
  148.         while (" !isin $ [ $+ [ %i ] ]) {
  149.           inc %i
  150.         }
  151.         tokenize 32 $ [ $+ [ %i ] $+ [ - ] ]
  152.       }
  153.       else { var %switchvalue = $gettok($1,2,61) }
  154.     }
  155.     tokenize 32 $2-
  156.     if (%switch == scroll) { var %windowScrollType = $iif(%switchvalue,%switchvalue,none) }
  157.     elseif (%switch == errorvar) { var %errorVariable = %switchvalue }
  158.   }
  159.   var %win = $ui.wname($1), %id = $2, %begin = $3, %end = $4
  160.   set %ui.id. $+ %id %win $+ :TEXT: $+ %begin $+ : $+ %end $+ : $+ $iif(%windowScrollType,%windowScrollType,none)
  161. }
  162. alias ui.addText {
  163.   if ($ui.getIdInfo($1,2) != TEXT) { echo -s * /ui.addText - ID must be a textarea | return $false }
  164.   if (!$ui.getWindowById($1).lastTextLine) {
  165.     ui.rline $ui.getWindowById($1) $ui.getIdInfo($1,3) $2-
  166.     echo -s running: set $+(%,ui.id.,$1,.lastTextLine) $ui.getIdInfo($1,3) + 1
  167.     set %ui.id. $+ $1 $+ .lastTextLine $ui.getIdInfo($1,3)
  168.     set %ui.id. $+ $1 $+ .firstTextLine $ui.getIdInfo($1,3)
  169.     set %ui.id. $+ $1 $+ .buffer. $+ $ui.getIdInfo($1,3)) $2-
  170.   }
  171.   elseif ($ui.getWindowById($1).lastTextLine < $ui.getIdInfo($1,4)) { ui.rline $ui.getWindowById($1) $calc($ui.getWindowById($1).lastTextLine + 1) $2- | set %ui.id. $+ $1 $+ .buffer. $+ %ui.id. [ $+ [ $1 ] $+ [ .lastTextLine ] ] $2- | inc %ui.id. $+ $1 $+ .lastTextLine | return }
  172.   else {
  173.     if ($ui.getIdInfo($1,5) == manual) {
  174.       if (!%ui.id. [ $+ [ $1 ] $+ [ .bufferCount ] ]) { set %ui.id. $+ $1 $+ .bufferCount $ui.getWindowById($1).lastTextLine }
  175.       else { inc %ui.id. $+ $1 $+ .bufferCount }
  176.       set %ui.id. $+ $1 $+ .buffer. $+ %ui.id. [ $+ [ $1 ] $+ [ .bufferCount ] ] $2-
  177.     }
  178.     else {
  179.       var %i = $ui.getIdInfo($1,3)
  180.       while (%i < $ui.getIdInfo($1,4)) {
  181.         ui.rline $ui.getWindowById($1) %i $line($ui.getWindowById($1),$calc(%i + 1))
  182.         set %ui.id. $+ $1 $+ .buffer. $+ %i $line($ui.getWindowById($1),$calc(%i + 1))
  183.         inc %i
  184.       }
  185.       ui.rline $ui.getWindowById($1) %i $2-
  186.       set %ui.id. $+ $1 $+ .buffer. $+ %i $line($ui.getWindowById($1),$calc(%i + 1))
  187.     }
  188.   }  
  189. }
  190. alias ui.addKeyTriggers {
  191.   while ($left($1,2) == --) {
  192.     var %switch = $right($gettok($1,1,61),-2)
  193.     if (= isin $1) {
  194.       if (" isin $1) && (" isin $2-) {
  195.         var %oldTokenize $1-
  196.         tokenize 34 $gettok($1,2,61) $2-
  197.         var %switchvalue = $1
  198.         tokenize 32 %oldTokenize
  199.         var %i = 2
  200.         while (" !isin $ [ $+ [ %i ] ]) {
  201.           inc %i
  202.         }
  203.         tokenize 32 $ [ $+ [ %i ] $+ [ - ] ]
  204.       }
  205.       else { var %switchvalue = $gettok($1,2,61) }
  206.     }
  207.     tokenize 32 $2-
  208.     if (%switch == type) { var %type = %switchvalue }
  209.     if (%switch == alias) { var %alias_ $+ $1 %switchvalue }
  210.   }
  211.   set %ui.id. $+ $1 $+ .keytrigger %type
  212.   set %ui.id. $+ $1 $+ .keytrigger.alias %alias_ [ $+ [ $1 ] ]
  213.   set %ui.window. $+ $ui.getWindowById($1) $+ .assignedIds $1
  214. }
  215. on *:KEYDOWN:@:*:{
  216.   var %id = %ui.window. [ $+ [ $active ] $+ [ .assignedIds ] ]
  217.   if ($keyval == 33) {
  218.     var %i = 1
  219.     while (%i <= $line(@a,0)) {
  220.       var %buffer $+ %i $line(@a,%i)
  221.       inc %i
  222.     }
  223.     dline @a 1- $+ %i
  224.     var %buffer $+ %i $line(@a,1)
  225.     var %windowcount = %i
  226.     var %i = 1
  227.     while (%i <= %windowcount) {
  228.       echo -s while2 %buffer [ $+ [ %i ] ] aaaaaaa %i
  229.       .timer -h 1 $calc(20+%i) aline @a %buffer [ $+ [ %i ] ]
  230.       inc %i
  231.     }
  232.   }
  233.   if (%id) {
  234.     if ($keyval == 38) {
  235.       ui.scroll %id up
  236.     }
  237.     elseif ($keyval == 40) {
  238.       ui.scroll %id down
  239.     }
  240.     elseif ($keyval == 32) {
  241.       ui.scroll %id pagedown
  242.     }
  243.     elseif ($keychar == q) {
  244.       window -c $active
  245.       unset %ui.*
  246.       unset %less*
  247.     }
  248.   }
  249.   if (%ui.id. [ $+ [ %id ] $+ [ .keytrigger.alias ] ]) { %ui.id. [ $+ [ %id ] $+ [ .keytrigger.alias ] ] %id $keyval }
  250. }
  251. alias ui.scroll {
  252.   if ($ui.getWindowById($1).lastTextLine < $ui.getIdInfo($1,4)) { return }
  253.   if ($2 == up) {
  254.     if ($ui.getWindowById($1).firstTextLine == 1) { return }
  255.     var %firstline = $ui.getWindowById($1).firstTextLine - 1
  256.   }
  257.   if ($2 == down) {
  258.     if ($ui.getWindowById($1).lastTextLine == %ui.id. [ $+ [ $1 ] $+ [ .bufferCount ] ]) { return }
  259.     var %firstline = $ui.getWindowById($1).firstTextLine + 1
  260.   }
  261.   if ($2 == pagedown) {
  262.     if ($ui.getWindowById($1).lastTextLine == %ui.id. [ $+ [ $1 ] $+ [ .bufferCount ] ]) { return }
  263.     var %firstline = $ui.getWindowById($1).firstTextLine + $ui.getIdInfo($1,4)
  264.     if (%firstline > $calc(%ui.id. [ $+ [ $1 ] $+ [ .bufferCount ] ] - $ui.getIdInfo($1,4))) { var %firstline = $calc(%ui.id. [ $+ [ $1 ] $+ [ .bufferCount ] ] - $ui.getIdInfo($1,4)) }
  265.   }
  266.   var %i = $ui.getIdInfo($1,3)
  267.   while (%i <= $ui.getIdInfo($1,4)) {
  268.     ui.rline $ui.getWindowById($1) %i %ui.id. [ $+ [ $1 ] $+ [ .buffer. ] $+ [ %firstline ] ]
  269.     inc %i
  270.     inc %firstline
  271.   }
  272.   if ($2 == up) {
  273.     dec %ui.id. [ $+ [ $1 ] $+ [ .firstTextLine ] ]
  274.     dec %ui.id. [ $+ [ $1 ] $+ [ .lastTextLine ] ]
  275.   }
  276.   if ($2 == down) {
  277.     inc %ui.id. [ $+ [ $1 ] $+ [ .firstTextLine ] ]
  278.     inc %ui.id. [ $+ [ $1 ] $+ [ .lastTextLine ] ]
  279.   }
  280.   if ($2 == pageup) {
  281.     dec %ui.id. [ $+ [ $1 ] $+ [ .firstTextLine ] ] $ui.getIdInfo($1,4)
  282.     dec %ui.id. [ $+ [ $1 ] $+ [ .lastTextLine ] ] $ui.getIdInfo($1,4)
  283.   }
  284.   if ($2 == pagedown) {
  285.     set %ui.id. [ $+ [ $1 ] $+ [ .firstTextLine ] ] $ui.getIdInfo($1,4)
  286.     inc %ui.id. [ $+ [ $1 ] $+ [ .lastTextLine ] ] $ui.getIdInfo($1,4)
  287.   }
  288. }
  289. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  290. ;;;                                                                                            ;;;
  291. ;;; LESS script by FIQ                                                                         ;;;
  292. ;;; Version : 1.0                                                                              ;;;
  293. ;;;                                                                                            ;;;
  294. ;;; Synopsis :                                                                                 ;;;
  295. ;;;          :                                                                                 ;;;
  296. ;;;        * : LESS [--bottom="Info in bottom"] [--bottomend="Info in bottom] <WINDOW> <FILE>  ;;;
  297. ;;;                                                                                            ;;;
  298. ;;; --bottom keywords :                                                                        ;;;
  299. ;;;                   :                                                                        ;;;
  300. ;;;         <TOPLINE> : Top line number                                                        ;;;
  301. ;;;      <BOTTOMLINE> : Bottom line number                                                     ;;;
  302. ;;;            <FILE> : File opened                                                            ;;;
  303. ;;;                                                                                            ;;;
  304. ;;; Example :                                                                                  ;;;
  305. ;;;         :                                                                                  ;;;
  306. ;;;       * : LESS @file C:\file.txt                                                           ;;;
  307. ;;;       * : LESS --bottom="Manual page a line <TOPLINE>" @man C:\a.man                       ;;;
  308. ;;;                                                                                            ;;;
  309. ;;; PLEASE DON'T LOAD TOO BIG FILES (more than 1000 lines), AS IT MAY CRASH MIRC!              ;;;
  310. ;;; SOLUTION WILL BE CREATED, BUT NOT AS FOR NOW                                               ;;;
  311. ;;;                                                                                            ;;;
  312. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  313.  
  314.  
  315. alias less {
  316.   while ($left($1,2) == --) {
  317.     var %switch = $right($gettok($1,1,61),-2)
  318.     if (= isin $1) {
  319.       if (" isin $1) && (" isin $2-) {
  320.         var %oldTokenize $1-
  321.         tokenize 34 $gettok($1,2,61) $2-
  322.         var %switchvalue = $1
  323.         tokenize 32 %oldTokenize
  324.         var %i = 2
  325.         while (" !isin $ [ $+ [ %i ] ]) {
  326.           inc %i
  327.         }
  328.         tokenize 32 $ [ $+ [ %i ] $+ [ - ] ]
  329.       }
  330.       else { var %switchvalue = $gettok($1,2,61) }
  331.     }
  332.     tokenize 32 $2-
  333.     if (%switch == bottom) { var %windowBottom = %switchvalue }
  334.     elseif (%switch == bottomend) { var %windowBottomEnd = %switchvalue }
  335.     elseif (%switch == errorvar) { var %errorVariable = %switchvalue }
  336.   }
  337.   if (!$isfile($qt($2-))) { echo -s * /less - $qt($2-) - file doesn't exists. | return }
  338.   if ($left($1,1) != @) { echo -s * /less - $1 must start with a @ | return }
  339.   var %file = $qt($2-)
  340.   echo -s fil: %file
  341.   ui.createWindow $1
  342.   set %less_id_ $+ $1 123
  343.   var %id %less_id_ [ $+ [ $1 ] ]
  344.   set %less_id_ $+ $1 $+ _file %file
  345.   set %less_id_ $+ $1 $+ _bottom $iif(%windowBottom,%windowBottom,:)
  346.   set %less_id_ $+ $1 $+ _bottomend $iif(%windowBottomEnd,%windowBottomEnd,(END) )
  347.   ui.addTextArea --scroll=manual $1 %id 1 $calc($ui.nscroll($ui.wname($1)) - 1)
  348.   var %i = 1
  349.   echo -s running: while %i <= $read(%file,0) - %file - $read($noqt(%file),0)
  350.   while (%i <= $lines(%file)) {
  351.     echo -s running: ui.addText %id $read(%file,%i)
  352.     ui.addText %id $read(%file,%i)
  353.     inc %i
  354.   }
  355.   var %id2 = $rand(1,1000) $+ $ticks
  356.   set %less_id2_ $+ $1 %id2
  357.   ui.addTextArea $1 %id2 $ui.nscroll($ui.wname($1)) $ui.nscroll($ui.wname($1))
  358.   echo -s running: ui.addText %id2 $iif(%windowBottom,%windowBottom,:)
  359.   ui.addText %id2 $iif(%windowBottom,%windowBottom,:)
  360.   ui.addKeyTriggers --type=scroll --alias=less_update %id
  361. }
  362. alias less_update {
  363.   var %id2 = %less_id2_ [ $+ [ $ui.getWindowById($1) ] ], %id = %less_id_ [ $+ [ $ui.getWindowById($1) ] ], %bottom = %less_id_ [ $+ [ $ui.getWindowById($1) ] $+ [ _bottom ] ], %bottomend = %less_id_ [ $+ [ $ui.getWindowById($1) ] $+ [ _bottomend ] ]
  364.   ui.addText %id2 $iif($ui.isBottom(%id),$less_replacekeywords(%id,%bottomend),$less_replacekeywords(%id,%bottom))
  365. }
  366. alias less_replacekeywords return $replace($2,<topline>,$ui.getWindowById($1).firstTextLine,<bottomline>,$ui.getWindowById($1).lastTextLine,<file>,%less_id_ [ $+ [ $1 ] $+ [ _file ] ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement