cmdr
Check-in [a52e457615]
Not logged in
Bounty program for improvements to Tcl and certain Tcl packages.

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

Overview
Comment:cmdr::help - Added option to forcibly disable the pager.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a52e457615e40d6ee67831cc4d89321072b68648
User & Date: andreask 2014-06-03 00:24:33
Context
2014-06-03
20:40
cmdr::help, cmdr::pager - Moved the paging support into a separate package, for use outside of the help code. Functiomnality tweak: Linenoise not supporting querying the height does not disable paging, just goes with a default height. check-in: ff5bdec2ca user: andreask tags: trunk
00:24
cmdr::help - Added option to forcibly disable the pager. check-in: a52e457615 user: andreask tags: trunk
00:19
Fix stupid typo in definition of the Pager support command. check-in: d4b3af213d user: andreask tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to help.tcl.

91
92
93
94
95
96
97

98

99
100
101
102
103
104
105
106
107
108



109
110
111
112
113
114
115
...
131
132
133
134
135
136
137

138
139
140
141
142
143
144
...
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
		Activate @[email protected] form of the help.
	    } {
		presence
		when-set [lambda {p x} { $p config @format set @[email protected] }]
	    }}]
    }


    # Standard option for line width to format against.

    lappend options {
	option width {
	    The line width to format the help for.
	    Defaults to the terminal width, or 80 when
	    no terminal is available.
	} {
	    alias w
	    validate integer ;# better: integer > 0, or even > 10
	    generate [lambda {p} { linenoise columns }]
	}



    }
    lappend map @[email protected] [linsert [join $formats {, }] end-1 and]
    lappend map @[email protected] [join $options \n]

    $actor extend help [string map $map {
	section *AutoGenerated*
	description {
................................................................................
    return
}

proc ::cmdr::help::auto-help {actor config} {
    debug.cmdr/help {}

    set width  [$config @width]

    set words  [$config @cmdname]
    set format [$config @format]

    if {$format eq {}} {
	# The chosen default format depends on the presence of
	# additional arguments, i.e. if a specific command is asked
	# for, or not, and the general context (root, leaf, inner
................................................................................
		  [$actor root] \
		  $width \
		  [cmdr util dictsort \
		       [query $actor $words]]]

    # Determine how to show the help, in a pager, or not ?

    if {![tty stdout]} {
	# Not a terminal, no pager possible.
	# This is also the case handling windows.
	puts $text
    } else {
	# Terminal
	if {[catch {
	    set height [linenoise lines]






>
|
>










>
>
>







 







>







 







|







91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
...
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
...
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
		Activate @[email protected] form of the help.
	    } {
		presence
		when-set [lambda {p x} { $p config @format set @[email protected] }]
	    }}]
    }

    # Standard options
    # - line width to format against.
    # - disable paging
    lappend options {
	option width {
	    The line width to format the help for.
	    Defaults to the terminal width, or 80 when
	    no terminal is available.
	} {
	    alias w
	    validate integer ;# better: integer > 0, or even > 10
	    generate [lambda {p} { linenoise columns }]
	}
	option no-pager {
	    Disable use of paging.
	} { presence }
    }
    lappend map @[email protected] [linsert [join $formats {, }] end-1 and]
    lappend map @[email protected] [join $options \n]

    $actor extend help [string map $map {
	section *AutoGenerated*
	description {
................................................................................
    return
}

proc ::cmdr::help::auto-help {actor config} {
    debug.cmdr/help {}

    set width  [$config @width]
    set nopage [$config @no-pager]
    set words  [$config @cmdname]
    set format [$config @format]

    if {$format eq {}} {
	# The chosen default format depends on the presence of
	# additional arguments, i.e. if a specific command is asked
	# for, or not, and the general context (root, leaf, inner
................................................................................
		  [$actor root] \
		  $width \
		  [cmdr util dictsort \
		       [query $actor $words]]]

    # Determine how to show the help, in a pager, or not ?

    if {$nopage || ![tty stdout]} {
	# Not a terminal, no pager possible.
	# This is also the case handling windows.
	puts $text
    } else {
	# Terminal
	if {[catch {
	    set height [linenoise lines]