proc GetValue {var {default ""}} { upvar $var curvar; return [expr {[info exists curvar]?$curvar:$default}] }

			proc StripColors {text} {
			regsub -all -- {\003[0-9]{0,2}(?:,[0-9]{1,2})?|\017|\037|\002|\026|\007} $text {} text
				return $text
			}
			
			proc GetColors {text} {
				foreach tag [regexp -all -inline {\003[0-9]{0,2}(?:,[0-9]{1,2})?|\017|\037|\002|\026|\007} $text] {
					switch [set type [string index $tag 0]] {
						"" {
							set split [split [string range $tag 1 e] ","]
							if {[set tmp [lindex $split 0]] != ""} {
								set color 1
								set color1 $tmp
								if {[set tmp [lindex $split 1]] != ""} { set color2 $tmp }
							} else { Define 0 "color color1 color2" }
						}
						"" - "" - "" { Tokens 1 extra $type }
						"" { Define 0 "extra color" }
					}
				}
				return "[expr {[GetValue color 0]?"$color1[expr {[info exists color2]?",$color2":""}]":""}][join [GetValue extra] ""]"
			}
			
			#cambiare nome di questa funzione
			proc TextJustify {text {size 80} {split 0} {rientro 0}} {
				foreach line $text {
					set split [split $line " "]
					set howmany [llength $split]
					set cur 0
					set curcolors ""
					set dorientro 0
					set curline ""
					set linelen 0
					foreach word $split {
						set wordlen [string length [StripColors $word]]
						if {$curline != ""} { incr wordlen }
						for {set i 0} {$i < 3} {incr i} {
							if {$i == 1} {
								lappend curline $word
								incr linelen $wordlen
								incr cur
							} elseif {($i == 0 && ($wordlen + $linelen) > $size || ($linelen == "" && $wordlen > $size)) || ($i == 2 && ($cur == $howmany))} {
								lappend return [set tmp "$curcolors[expr {$dorientro?"[string repeat " " $rientro]":""}][join $curline " "]"]
								set curcolors [GetColors $tmp]
								set curline ""
								set linelen $rientro
								set dorientro 1
							}
						}
					}
				}
				return [GetValue return]
			}
