Skip to content

Instantly share code, notes, and snippets.

@ryanfb
Created October 4, 2008 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanfb/14698 to your computer and use it in GitHub Desktop.
Save ryanfb/14698 to your computer and use it in GitHub Desktop.
proc uajoin args { set b [lindex $args 0]; set args [lrange $args 1 [llength $args]]; set o ""; set nlines [maxlines $args]; set newline ""; set nl ""; foreach j $args { lappend nl [uaddspaces $nlines $j]; }; for {set i 0} { $i < $nlines } { incr i } { append o $newline; set d ""; foreach k $nl { append o "$d[lindex [split $k "\n"] $i]"; set d $b; }; set newline "\n"; }; return $o; }
proc uaddspaces {x y} { set a " "; set lines [split $y "\n"]; set n [llength $lines]; set d [expr "$x - $n"]; set m [umaxstringlength $lines]; set e [string repeat $a $m]; set nlines [upadlinesto $m $lines]; set y [join $nlines "\n"]; for {set i 0} {$i < $d} {incr i} { set y "$y\n$e"; }; return $y; }
proc umaxstringlength a {set m 0; foreach j $a { set sl [ulength [strip_all $j]]; if {$m < $sl} {set m $sl}}; return $m}
proc upadlinesto {m lines} {set nlines "";set a " "; foreach j $lines { set sl [ulength [strip_all $j]]; if {$sl < $m} { set j "$j[string repeat $a [expr {$m - $sl}]]"; }; lappend nlines $j; }; return $nlines}
proc uaflip what {uajoin "" [. $what\n[uvflip $what]] [. [flip $what]\n[uvflip [flip $what]]]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment