package require punk
package require patternpunk

pipealias block_padleft .= {list $input [string repeat " " $indent]} |/0,padding/1> linelist |> .= {lmap v $data {val "$padding$v"}} |> list_as_lines <input/0,indent/1|

pipealias block_padright .= {list $input [string repeat " " $colsize]} |/0,padding/1> linelist |> .= {lmap v $data {overtype::right $padding $v}} |> list_as_lines <input/0,colsize/1|

puts stdout "block_padleft pipeline"
puts stdout "[alias block_padleft]"
puts stderr "block_padleft \[>punk . logo] 50"
puts stdout "[block_padleft [>punk . logo] 50]"


package require overtype
set out ""
foreach ln [.= block_padleft [>punk . logo ] 2 |> linelist] bgline [.= block_padleft [>punk . logo] 100 |> linelist] {
    append out [overtype::left $bgline [a+ green bold]$ln[a+]]\n
}
puts stdout "$out"

proc block_width {block} {
    if {![llength $block]} {
        return [string length $block]
    }
    tcl::mathfunc::max {*}[lmap v [linelist $block] {string length $v}]
}
pipealias block_join_width .= {list $lhs [string repeat " " $w1] $rhs [string repeat " " $w2]} {|
            /2,col1/1,col2/3
            >} linelist {|
            data2
            >} .=lhs> linelist {|
            >} .= {lmap v $data w $data2 {val "[overtype::left $col1 $v][overtype::left $col2 $w]"}} {|
            >} list_as_lines <lhs/0,w1/1,rhs/2,w2/3|
            
pipealias block_join .= {list $lhs [string repeat " " [block_width $lhs]] $rhs [string repeat " " [block_width $rhs]]} {|
            /2,col1/1,col2/3
            >} linelist {|
            data2
            >} .=lhs> linelist {|
            >} .= {lmap v $data w $data2 {val "[overtype::left $col1 $v][overtype::left $col2 $w]"}} {|
            >} list_as_lines <lhs/0,rhs/1|            

pipealias block_join_right .= {list $lhs [string repeat " " [block_width $lhs]] $rhs [string repeat " " [block_width $rhs]]} {|
            /2,col1/1,col2/3
            >} linelist {|
            data2
            >} .=lhs> linelist {|
            >} .= {lmap v $data w $data2 {val "[overtype::right $col1 $v][overtype::right $col2 $w]"}} {|
            >} list_as_lines <lhs/0,rhs/1|