TABLE OF CONTENTS


::pwtk::fprint

SYNOPSIS

proc ::pwtk::fprint {channel args} {

DESCRIPTION

Print a properly indented message to a channel.

USAGE

    ::pwtk::fprint channel ?-nonewline? message

    ::pwtk::fprint channel ?-nonewline? label message

SOURCE

    set arg_ $args
    set opt {}
    if { [lindex $args 0] eq "-nonewline" } {
        set opt -nonewline
        set args [lrange $args 1 end]
    }

    if { [llength $args] == 1} {
        set label " "
    } elseif { [llength $args] == 2} {
        set label "[lindex $args 0]|"
    } else {
        error "expecting [procName] channel ?-nonewline? ?label? message, but got:
[procName] $channel $arg_" 1        
    }
    
    set message [lindex $args end]
    if { $message eq {} } {
        puts {*}$opt $channel ""
    } else {
        foreach line [split $message \n] {
            if { [string trim $line] == "" } {
                puts {*}$opt $channel ""
            } else {
                puts {*}$opt $channel [format "%5s %s" $label $line]
            }       
        }
    }
    flush $channel
}