This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

makecell / spacing output

Help for those learning Tcl or writing their own scripts.
Post Reply
b
blinky
Voice
Posts: 10
Joined: Wed Apr 26, 2006 7:03 pm

makecell / spacing output

Post by blinky »

im very new to tcl and i was wondering what this i see in a script i have.

putquick "PRIVMSG $chan : \002[makecell "Found $total_results in [string trim $query_time]" 25 left][makecell "\".db help\" for info http://edited.com" 61 right] "

it seems like its some sort of way to space it out. this isnt the only place i see 'makecell' in this script. i couldnt find any documentation on that in the tcl wiki. any ideas what it is?

i also do want to space things by # of characters.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

There is no predefined function by that name. The function must be in the script itself or in a script which is needed to run that script.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
b
blinky
Voice
Posts: 10
Joined: Wed Apr 26, 2006 7:03 pm

Post by blinky »

haha i feel so stupid. i found it.

Code: Select all

proc makecell {text width align} {
  set text [noentities $text]
  set length [string length [noirc $text]]
  if {$length >= $width} {
    set padding $width
    set text [string range $text 0 [incr padding -2]]
    set length [incr padding 1]
  }

  if {$align == "left"} {
    set temp $text
    for {set i 0} {$i < $width - $length} {incr i} {
      append temp " "
    }
  } else {
    set temp ""
    for {set i 0} {$i < $width - $length} {incr i} {
      append temp " "
    }
    append temp $text
  }

  return $temp
}
it still doesnt space is right. i think multiple empty spaces are cut down to 1. is there a way to add definate spaces?
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

spaces are truncated by some clients (mostly mIRC), you can prevent this by using a control charcter every even character like " \002 \002 " will display 3 spaces, even with mIRC space truncating. remember to keep an even number of these characters, to not write bold after the spaces :D. This will of course not work if the IRC server blocks/removes control characters :D.

Alternately you can try using tabs (\t), but you never know how many whitespaces the client will actually write. usually 1, 3 or 5 (X-Chat writes only 1).
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Post Reply