factor help script command into parts

Creates a helper function, cmd_help, which displays the help string
for a single command.  Presently, it is called from the loop in help.

The routine has been extended to allow indentation of command groups,
so an improved help command can improve the display of information.
This commit is contained in:
Zachary T Welch 2009-11-19 06:44:58 -08:00
parent 9e9633c6b9
commit 82449e2d60
1 changed files with 34 additions and 28 deletions

View File

@ -25,20 +25,13 @@ proc exit {} {
ocd_throw exit
}
#Print help text for a command. Word wrap
#help text that is too wide inside column.
proc help {args} {
global ocd_helptext
set cmd $args
foreach a [lsort $ocd_helptext] {
if {[string length $cmd] == 0 || \
[string first $cmd $a] != -1 || \
[string first $cmd [lindex $a 1]] != -1} \
{
set w 50
set cmdname [lindex $a 0]
set h [lindex $a 1]
proc cmd_help {cmdname h indent} {
set indent [expr $indent * 2]
set fmt_str [format "%%%ds%%-%ds %%s" $indent [expr 25 - $indent]]
set w [expr 50 - $indent]
set n 0
while 1 {
if {$n > [string length $h]} {break}
@ -58,11 +51,24 @@ proc help {args} {
}
}
puts [format "%-25s %s" $cmdname \
[string range $h $n [expr $next_a-1]] ]
puts [format $fmt_str "" $cmdname \
[string range $h $n [expr $next_a - 1]] ]
set cmdname ""
set n [expr $next_a]
}
}
#Print help text for a command. Word wrap
#help text that is too wide inside column.
proc help {args} {
global ocd_helptext
set cmd $args
foreach a [lsort $ocd_helptext] {
if {[string length $cmd] == 0 || \
[string first $cmd $a] != -1 || \
[string first $cmd [lindex $a 1]] != -1} \
{
cmd_help [lindex $a 0] [lindex $a 1] 0
}
}
}