Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;;;;;;;;;;;;;;;;;;;; mIRC UI lib for custom windows ;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; ;;;
- ;;; By FIQ (v1.0) ;;;
- ;;; ;;;
- ;;; ;;;
- ;;; Features : ;;;
- ;;; : ;;;
- ;;; : (X=done, /=worked on, -=not started yet, this will be done ;;;
- ;;; : BEFORE version 1.0 ;;;
- ;;; ;;;
- ;;; X : Automatic height/width calculation for "screen resolution" ;;;
- ;;; : ;;;
- ;;; - : Recalculation if you change font or font size ;;;
- ;;; : ;;;
- ;;; / : Dodge of mIRC's own "pagekey scroll" ;;;
- ;;; : ;;;
- ;;; X : Autoscrolling of text ;;;
- ;;; : ;;;
- ;;; X : Setup fixed lines ;;;
- ;;; : ;;;
- ;;; - : Make lines support INPUT for a range of ways, for example ;;;
- ;;; : text input, no/yes questions, prompt for action (using SPACE ;;;
- ;;; : per default). ;;;
- ;;; : ;;;
- ;;; - : Make custom CTRL bindings ;;;
- ;;; : ;;;
- ;;; X : Buildt-in "less" to show off what could be done ;;;
- ;;; : with this thing (the "less" command in Linux terminals) ;;;
- ;;; ;;;
- ;;; ;;;
- ;;; Changelog : ;;;
- ;;; : ;;;
- ;;; * : Due to the first version not released yet, there's no ;;;
- ;;; : changelog at this moment. ;;;
- ;;; ;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;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.
- ;(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.
- on *:START:unset %ui.* | unset %less_id_*
- ;Hack for making PgUp/PgDn's own effect "disappear". Anyone with a better solution is welcome to contact me.
- ;
- ;How this work:
- ;Page up will send you up one page (how suprising) and making the UI placed wrong.
- ;The UI will have two windows, seperated by a dummy line (to hide this effect as good as possible).
- ;When the pageup is processing, the dummy line along with the down window will be removed almost immediatly.
- ;Then, a new dummy line will be created, and a new window on it.
- ;This hack has two problems:
- ; * A horrible flash will appear that is impossible to get rid of
- ; * If the user is flooding PgUp, this may fail.
- alias ui.rline {
- !rline $1-
- !rline $1 $calc($2 +1+ $ui.nscroll($1)) $3-
- }
- alias ui.pagefix {
- var %i = 1
- while (%i <= $ui.nscroll($1)) {
- var %buffer $+ %i $line($1,%i)
- inc %i
- }
- dline $1 $calc($ui.nscroll($1) + 1) $+ - $+ $line($1,0)
- iline $1 1
- var %i = 1
- while (%i <= $ui.nscroll($1)) {
- iline $1 $calc(%i + 1) %buffer [ $+ [ %i ] ]
- inc %i
- }
- }
- alias ui.wname return $iif($left($1,1) == @,$1,@ $+ $1)
- alias ui.getIdInfo return $gettok(%ui.id. [ $+ [ $1 ] ],$2,58)
- alias ui.isBottom return $iif((!%ui.id. [ $+ [ $1 ] $+ [ .bufferCount ] ]) || ($ui.getWindowById($1).lastTextLine == %ui.id. [ $+ [ $1 ] $+ [ .bufferCount ] ]),$true,$false)
- alias ui.getWindowById {
- if (!$ui.getIdInfo($1,1)) { return $false }
- if (!$prop) { return $ui.getIdInfo($1,1) }
- if ($prop == lastTextLine) { return %ui.id. [ $+ [ $1 ] $+ [ .lastTextLine ] ] }
- if ($prop == firstTextLine) { return %ui.id. [ $+ [ $1 ] $+ [ .firstTextLine ] ] }
- }
- alias ui.nscroll {
- if ($prop == w) { var %calc = $calc($window($1).dw / $width(b,$window($1).font,$window($1).fontsize)) }
- else { var %calc = $calc($window($1).dh / $height(b,$window($1).font,$window($1).fontsize)) }
- if (. isin %calc) { var %calc = $calc($ceil(%calc) - 1) }
- return %calc
- }
- alias ui.help {
- if ($exists($scriptdirui_help.txt)) { less UI-help $scriptdirui_help.txt }
- else { echo -ag Help file not found }
- }
- alias ui.createWindow {
- while ($left($1,2) == --) {
- var %switch = $right($gettok($1,1,61),-2)
- if (= isin $1) {
- if (" isin $1) && (" isin $2-) {
- var %oldTokenize $1-
- tokenize 34 $gettok($1,2,61) $2-
- var %switchvalue = $1
- tokenize 32 %oldTokenize
- var %i = 2
- while (" !isin $ [ $+ [ %i ] ]) {
- inc %i
- }
- tokenize 32 $ [ $+ [ %i ] $+ [ - ] ]
- }
- else { var %switchvalue = $gettok($1,2,61) }
- }
- tokenize 32 $2-
- if (%switch == header) { var %windowHeader = %switchvalue }
- elseif (%switch == errorvar) { var %errorVariable = %switchvalue }
- }
- window -m $ui.wname($1)
- ui.fixNoScroll $1
- if (%windowHeader) { ui.setHeader $1 %windowHeader }
- return true
- }
- alias ui.fixNoScroll {
- var %i = 1
- while (%i <= $ui.nscroll($ui.wname($1))) {
- aline $ui.wname($1)
- inc %i
- }
- ;Make this happen again to get PgUp to work as we want.
- aline $ui.wname($1)
- var %i = 1
- while (%i <= $ui.nscroll($ui.wname($1))) {
- aline $ui.wname($1)
- inc %i
- }
- }
- alias ui.setHeader {
- var %len = $calc( $ui.nscroll($ui.wname($1)).w / 2 - $len($2-) / 2 )
- if (. isin %len) { var %len = %len + 0.5 | var %len2 = %len - 0.5 }
- else { var %len2 = %len }
- ui.rline $ui.wname($1) 1 $+ $str($chr(160),%len) $+ $2- $+ $str($chr(160),%len2)
- }
- alias ui.addTextArea {
- while ($left($1,2) == --) {
- var %switch = $right($gettok($1,1,61),-2)
- if (= isin $1) {
- if (" isin $1) && (" isin $2-) {
- var %oldTokenize $1-
- tokenize 34 $gettok($1,2,61) $2-
- var %switchvalue = $1
- tokenize 32 %oldTokenize
- var %i = 2
- while (" !isin $ [ $+ [ %i ] ]) {
- inc %i
- }
- tokenize 32 $ [ $+ [ %i ] $+ [ - ] ]
- }
- else { var %switchvalue = $gettok($1,2,61) }
- }
- tokenize 32 $2-
- if (%switch == scroll) { var %windowScrollType = $iif(%switchvalue,%switchvalue,none) }
- elseif (%switch == errorvar) { var %errorVariable = %switchvalue }
- }
- var %win = $ui.wname($1), %id = $2, %begin = $3, %end = $4
- set %ui.id. $+ %id %win $+ :TEXT: $+ %begin $+ : $+ %end $+ : $+ $iif(%windowScrollType,%windowScrollType,none)
- }
- alias ui.addText {
- if ($ui.getIdInfo($1,2) != TEXT) { echo -s * /ui.addText - ID must be a textarea | return $false }
- if (!$ui.getWindowById($1).lastTextLine) {
- ui.rline $ui.getWindowById($1) $ui.getIdInfo($1,3) $2-
- echo -s running: set $+(%,ui.id.,$1,.lastTextLine) $ui.getIdInfo($1,3) + 1
- set %ui.id. $+ $1 $+ .lastTextLine $ui.getIdInfo($1,3)
- set %ui.id. $+ $1 $+ .firstTextLine $ui.getIdInfo($1,3)
- set %ui.id. $+ $1 $+ .buffer. $+ $ui.getIdInfo($1,3)) $2-
- }
- 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 }
- else {
- if ($ui.getIdInfo($1,5) == manual) {
- if (!%ui.id. [ $+ [ $1 ] $+ [ .bufferCount ] ]) { set %ui.id. $+ $1 $+ .bufferCount $ui.getWindowById($1).lastTextLine }
- else { inc %ui.id. $+ $1 $+ .bufferCount }
- set %ui.id. $+ $1 $+ .buffer. $+ %ui.id. [ $+ [ $1 ] $+ [ .bufferCount ] ] $2-
- }
- else {
- var %i = $ui.getIdInfo($1,3)
- while (%i < $ui.getIdInfo($1,4)) {
- ui.rline $ui.getWindowById($1) %i $line($ui.getWindowById($1),$calc(%i + 1))
- set %ui.id. $+ $1 $+ .buffer. $+ %i $line($ui.getWindowById($1),$calc(%i + 1))
- inc %i
- }
- ui.rline $ui.getWindowById($1) %i $2-
- set %ui.id. $+ $1 $+ .buffer. $+ %i $line($ui.getWindowById($1),$calc(%i + 1))
- }
- }
- }
- alias ui.addKeyTriggers {
- while ($left($1,2) == --) {
- var %switch = $right($gettok($1,1,61),-2)
- if (= isin $1) {
- if (" isin $1) && (" isin $2-) {
- var %oldTokenize $1-
- tokenize 34 $gettok($1,2,61) $2-
- var %switchvalue = $1
- tokenize 32 %oldTokenize
- var %i = 2
- while (" !isin $ [ $+ [ %i ] ]) {
- inc %i
- }
- tokenize 32 $ [ $+ [ %i ] $+ [ - ] ]
- }
- else { var %switchvalue = $gettok($1,2,61) }
- }
- tokenize 32 $2-
- if (%switch == type) { var %type = %switchvalue }
- if (%switch == alias) { var %alias_ $+ $1 %switchvalue }
- }
- set %ui.id. $+ $1 $+ .keytrigger %type
- set %ui.id. $+ $1 $+ .keytrigger.alias %alias_ [ $+ [ $1 ] ]
- set %ui.window. $+ $ui.getWindowById($1) $+ .assignedIds $1
- }
- on *:KEYDOWN:@:*:{
- var %id = %ui.window. [ $+ [ $active ] $+ [ .assignedIds ] ]
- if ($keyval == 33) {
- var %i = 1
- while (%i <= $line(@a,0)) {
- var %buffer $+ %i $line(@a,%i)
- inc %i
- }
- dline @a 1- $+ %i
- var %buffer $+ %i $line(@a,1)
- var %windowcount = %i
- var %i = 1
- while (%i <= %windowcount) {
- echo -s while2 %buffer [ $+ [ %i ] ] aaaaaaa %i
- .timer -h 1 $calc(20+%i) aline @a %buffer [ $+ [ %i ] ]
- inc %i
- }
- }
- if (%id) {
- if ($keyval == 38) {
- ui.scroll %id up
- }
- elseif ($keyval == 40) {
- ui.scroll %id down
- }
- elseif ($keyval == 32) {
- ui.scroll %id pagedown
- }
- elseif ($keychar == q) {
- window -c $active
- unset %ui.*
- unset %less*
- }
- }
- if (%ui.id. [ $+ [ %id ] $+ [ .keytrigger.alias ] ]) { %ui.id. [ $+ [ %id ] $+ [ .keytrigger.alias ] ] %id $keyval }
- }
- alias ui.scroll {
- if ($ui.getWindowById($1).lastTextLine < $ui.getIdInfo($1,4)) { return }
- if ($2 == up) {
- if ($ui.getWindowById($1).firstTextLine == 1) { return }
- var %firstline = $ui.getWindowById($1).firstTextLine - 1
- }
- if ($2 == down) {
- if ($ui.getWindowById($1).lastTextLine == %ui.id. [ $+ [ $1 ] $+ [ .bufferCount ] ]) { return }
- var %firstline = $ui.getWindowById($1).firstTextLine + 1
- }
- if ($2 == pagedown) {
- if ($ui.getWindowById($1).lastTextLine == %ui.id. [ $+ [ $1 ] $+ [ .bufferCount ] ]) { return }
- var %firstline = $ui.getWindowById($1).firstTextLine + $ui.getIdInfo($1,4)
- if (%firstline > $calc(%ui.id. [ $+ [ $1 ] $+ [ .bufferCount ] ] - $ui.getIdInfo($1,4))) { var %firstline = $calc(%ui.id. [ $+ [ $1 ] $+ [ .bufferCount ] ] - $ui.getIdInfo($1,4)) }
- }
- var %i = $ui.getIdInfo($1,3)
- while (%i <= $ui.getIdInfo($1,4)) {
- ui.rline $ui.getWindowById($1) %i %ui.id. [ $+ [ $1 ] $+ [ .buffer. ] $+ [ %firstline ] ]
- inc %i
- inc %firstline
- }
- if ($2 == up) {
- dec %ui.id. [ $+ [ $1 ] $+ [ .firstTextLine ] ]
- dec %ui.id. [ $+ [ $1 ] $+ [ .lastTextLine ] ]
- }
- if ($2 == down) {
- inc %ui.id. [ $+ [ $1 ] $+ [ .firstTextLine ] ]
- inc %ui.id. [ $+ [ $1 ] $+ [ .lastTextLine ] ]
- }
- if ($2 == pageup) {
- dec %ui.id. [ $+ [ $1 ] $+ [ .firstTextLine ] ] $ui.getIdInfo($1,4)
- dec %ui.id. [ $+ [ $1 ] $+ [ .lastTextLine ] ] $ui.getIdInfo($1,4)
- }
- if ($2 == pagedown) {
- set %ui.id. [ $+ [ $1 ] $+ [ .firstTextLine ] ] $ui.getIdInfo($1,4)
- inc %ui.id. [ $+ [ $1 ] $+ [ .lastTextLine ] ] $ui.getIdInfo($1,4)
- }
- }
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; ;;;
- ;;; LESS script by FIQ ;;;
- ;;; Version : 1.0 ;;;
- ;;; ;;;
- ;;; Synopsis : ;;;
- ;;; : ;;;
- ;;; * : LESS [--bottom="Info in bottom"] [--bottomend="Info in bottom] <WINDOW> <FILE> ;;;
- ;;; ;;;
- ;;; --bottom keywords : ;;;
- ;;; : ;;;
- ;;; <TOPLINE> : Top line number ;;;
- ;;; <BOTTOMLINE> : Bottom line number ;;;
- ;;; <FILE> : File opened ;;;
- ;;; ;;;
- ;;; Example : ;;;
- ;;; : ;;;
- ;;; * : LESS @file C:\file.txt ;;;
- ;;; * : LESS --bottom="Manual page a line <TOPLINE>" @man C:\a.man ;;;
- ;;; ;;;
- ;;; PLEASE DON'T LOAD TOO BIG FILES (more than 1000 lines), AS IT MAY CRASH MIRC! ;;;
- ;;; SOLUTION WILL BE CREATED, BUT NOT AS FOR NOW ;;;
- ;;; ;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- alias less {
- while ($left($1,2) == --) {
- var %switch = $right($gettok($1,1,61),-2)
- if (= isin $1) {
- if (" isin $1) && (" isin $2-) {
- var %oldTokenize $1-
- tokenize 34 $gettok($1,2,61) $2-
- var %switchvalue = $1
- tokenize 32 %oldTokenize
- var %i = 2
- while (" !isin $ [ $+ [ %i ] ]) {
- inc %i
- }
- tokenize 32 $ [ $+ [ %i ] $+ [ - ] ]
- }
- else { var %switchvalue = $gettok($1,2,61) }
- }
- tokenize 32 $2-
- if (%switch == bottom) { var %windowBottom = %switchvalue }
- elseif (%switch == bottomend) { var %windowBottomEnd = %switchvalue }
- elseif (%switch == errorvar) { var %errorVariable = %switchvalue }
- }
- if (!$isfile($qt($2-))) { echo -s * /less - $qt($2-) - file doesn't exists. | return }
- if ($left($1,1) != @) { echo -s * /less - $1 must start with a @ | return }
- var %file = $qt($2-)
- echo -s fil: %file
- ui.createWindow $1
- set %less_id_ $+ $1 123
- var %id %less_id_ [ $+ [ $1 ] ]
- set %less_id_ $+ $1 $+ _file %file
- set %less_id_ $+ $1 $+ _bottom $iif(%windowBottom,%windowBottom,:)
- set %less_id_ $+ $1 $+ _bottomend $iif(%windowBottomEnd,%windowBottomEnd,(END) )
- ui.addTextArea --scroll=manual $1 %id 1 $calc($ui.nscroll($ui.wname($1)) - 1)
- var %i = 1
- echo -s running: while %i <= $read(%file,0) - %file - $read($noqt(%file),0)
- while (%i <= $lines(%file)) {
- echo -s running: ui.addText %id $read(%file,%i)
- ui.addText %id $read(%file,%i)
- inc %i
- }
- var %id2 = $rand(1,1000) $+ $ticks
- set %less_id2_ $+ $1 %id2
- ui.addTextArea $1 %id2 $ui.nscroll($ui.wname($1)) $ui.nscroll($ui.wname($1))
- echo -s running: ui.addText %id2 $iif(%windowBottom,%windowBottom,:)
- ui.addText %id2 $iif(%windowBottom,%windowBottom,:)
- ui.addKeyTriggers --type=scroll --alias=less_update %id
- }
- alias less_update {
- 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 ] ]
- ui.addText %id2 $iif($ui.isBottom(%id),$less_replacekeywords(%id,%bottomend),$less_replacekeywords(%id,%bottom))
- }
- 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