38 lines
2.6 KiB
Plaintext
38 lines
2.6 KiB
Plaintext
{s n} {
|
|
set debug [list];
|
|
set c [csplit $s]
|
|
if {$n > [expr [llength [lindex $c 0]]-1]} {set n [expr [llength [lindex $c 0]]-1]}
|
|
set b 0
|
|
set u 0
|
|
set cf -1
|
|
set cb -1
|
|
set r ""
|
|
foreach f [lindex $c 1] {
|
|
lappend debug "working on $f";
|
|
append r [lindex [lindex $c 0] $f];
|
|
lappend debug "actually appended the character to be formatted: $r";
|
|
if {[lindex $f 0] > $n} {
|
|
lappend debug "reached end of string"
|
|
if {$b eq 1} {append r "\002"; lappend debug "ending bold";}
|
|
if {$u eq 1} {append r "\037"; lappend debug "ending underline"}
|
|
if {$cf > -1} {append r [format "%s" $cf]; lappend debug "adding foreground colour at end of string"}
|
|
if {$cb > -1} {append r [format ",%s" $cb]; lappend debug "adding background colour at end of string"}
|
|
lappend debug "final result: $r";
|
|
return [join $debug "\n"]
|
|
}
|
|
if {[lindex $f 1] eq "\002"} {set b [expr $b ^ 1]; lappend debug "found bold character"}
|
|
if {[lindex $f 1] eq "\037"} {set u [expr $u ^ 1]; lappend debug "found underline"}
|
|
if {[lindex $f 1] eq "\003"} {set cf -1;set cb -1; lappend debug "found color, setting cf to -1, cb to -1"}
|
|
if {[lindex $f 1] eq "\017"} {set cf -1;set cb -1;set b 0;set u 0; lappend debug "found format reset, setting cb and cf to -1 for some reason"}
|
|
if {[lindex $f 1] eq "\026"} {set t $cb;set cb $cf;set cf $t; lappend debug "found reverse kulerz character, reversing them weirdly"}
|
|
if {[set m [regexp -inline {([\d]+)$} [lindex $f 1]]] ne ""} {set cf [lindex $m 1]; lappend debug "found a really interesting number, setting cf to $cf"}
|
|
if {[set m [regexp -inline {([\d]+),([\d]+)} [lindex $f 1]]] ne ""} {set cf [lindex $m 1];set cb [lindex $m 2]; lappend debug "found even more numbers, setting cf to $cf and cb to $cb"}
|
|
}
|
|
if {$b eq 1} {append r "\002"; lappend debug "starting bold"}
|
|
if {$u eq 1} {append r "\037"; lappend debug "starting underline"}
|
|
if {$cf > -1} {append r [format "%s" $cf]; lappend debug "starting color"}
|
|
if {$cb > -1} {append r [format ",%s" $cb]; lappend debug "adding background color"}
|
|
lappend debug "final result: $r"
|
|
return [join $debug "\n"]
|
|
}
|