cmdr
Check-in [11fff41159]
Not logged in
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fixed problems with the generation of categorized help when encountering sections with sub-sections, but no commands
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 11fff41159a2d93cdc51b2fa8fcbf5a30125b329
User & Date: aku 2014-02-06 05:05:52
Context
2014-02-06
05:35
Added utility package cmdr::help::tcl, dumping the help as Tcl data structure. Like cmdr::help::json, with less overhead to read into other Tcl code. check-in: 865912b8d9 user: aku tags: trunk
05:05
Fixed problems with the generation of categorized help when encountering sections with sub-sections, but no commands check-in: 11fff41159 user: aku tags: trunk
05:04
officer - Modified method extend to return the new command instance, for dynamic re-configuration post-creation. check-in: 7fc0be3870 user: aku tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to help.tcl.

349
350
351
352
353
354
355



356
357
358
359

360
361
362
363
364
365
366
367
368
369
370

371
372
373
374
375
376
377

378
379


380

381
382
383
384
385
386
387
...
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472






473


474
475
476
477
478
479
480
    # Indent the commands and sub-categories a bit more...
    append indent "    "
    set    sep    "    "

    # Get the commands in the category, preliminary formatting
    # (labels, descriptions).




    foreach def [lsort -dict -unique [dict get $cmds $path]] {
	lassign $def syntax desc
	lappend names $syntax
	lappend descs $desc

    }
    set labels [cmdr util padr $names]

    # With the padding all labels are the same length. We can
    # precompute the blank and the width to format the descriptions
    # into.

    regsub -all {[^\t]}  "$indent[lindex $labels 0]$sep" { } blank
    set w [expr {$width - [string length $blank]}]

    # Print the commands, final formatting.

    foreach label $labels desc $descs {
	set desc [textutil::adjust::adjust $desc \
		      -length $w \
		      -strictlength 1]
	set desc [textutil::adjust::indent $desc $blank 1]

	lappend lines $indent$label$sep$desc

    }



    lappend lines {}

    if {![dict exists $subc $path]} return

    # Print the sub-categories, if any.
    foreach c [lsort -dict -unique [dict get $subc $path]] {
	ShowCategory $width lines [linsert $path end $c] $indent
    }
    return
................................................................................
	    append name " " [Arguments $arguments $parameters]
	}
	set    desc [lindex [split $desc .] 0]
	set    cmd  [::list $name $desc]

	foreach category $sections {
	    lappend cmds($category) $cmd
	    set parent [lreverse [lassign [lreverse $category] leaf]]
	    lappend subc($parent) $leaf
	}
    }

    #parray subc
    #parray cmds

    ::list [array get subc] [array get cmds]
}

proc ::cmdr::help::format::SectionOrder {root subc} {









    # IIa. Natural order first.
    set categories [lsort -dict -unique [dict get $subc {}]]

    # IIb. Look for and apply user overrides.
    if {[$root exists *category-order*]} {
	# Record natural order
	set n 0






>
>
>
|
|
|
|
>











>







>


>
>
|
>







 







|
<









|
>
>
>
>
>
>
|
>
>







349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
...
463
464
465
466
467
468
469
470

471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
    # Indent the commands and sub-categories a bit more...
    append indent "    "
    set    sep    "    "

    # Get the commands in the category, preliminary formatting
    # (labels, descriptions).

    set names {}
    set descs {}
    if {[dict exists $cmds $path]} {
	foreach def [lsort -dict -unique [dict get $cmds $path]] {
	    lassign $def syntax desc
	    lappend names $syntax
	    lappend descs $desc
	}
    }
    set labels [cmdr util padr $names]

    # With the padding all labels are the same length. We can
    # precompute the blank and the width to format the descriptions
    # into.

    regsub -all {[^\t]}  "$indent[lindex $labels 0]$sep" { } blank
    set w [expr {$width - [string length $blank]}]

    # Print the commands, final formatting.
    set commands 0
    foreach label $labels desc $descs {
	set desc [textutil::adjust::adjust $desc \
		      -length $w \
		      -strictlength 1]
	set desc [textutil::adjust::indent $desc $blank 1]

	lappend lines $indent$label$sep$desc
	set commands 1
    }

    if {$commands} {
	# Separate sub-categories and commands with an empty line.
	lappend lines {}
    }
    if {![dict exists $subc $path]} return

    # Print the sub-categories, if any.
    foreach c [lsort -dict -unique [dict get $subc $path]] {
	ShowCategory $width lines [linsert $path end $c] $indent
    }
    return
................................................................................
	    append name " " [Arguments $arguments $parameters]
	}
	set    desc [lindex [split $desc .] 0]
	set    cmd  [::list $name $desc]

	foreach category $sections {
	    lappend cmds($category) $cmd
	    LinkParent $category

	}
    }

    #parray subc
    #parray cmds

    ::list [array get subc] [array get cmds]
}

proc ::cmdr::help::format::LinkParent {category} {
    if {![llength $category]} return
    upvar 1 subc subc
    set parent [lreverse [lassign [lreverse $category] leaf]]
    lappend subc($parent) $leaf
    LinkParent $parent
    return
}

proc ::cmdr::help::format::SectionOrder {root subc} {
    # IIa. Natural order first.
    set categories [lsort -dict -unique [dict get $subc {}]]

    # IIb. Look for and apply user overrides.
    if {[$root exists *category-order*]} {
	# Record natural order
	set n 0