cmdr
Check-in [e15928b830]
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:cmdr::help - Extended the backend to invoke a pager if the help is too high for the terminal. Lots of things (not terminal, no support in linenoise, no pager) will disable this. Bumped version to 1.3.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e15928b8301b1afb848fa63e6c241805b900fd71
User & Date: andreask 2014-06-03 00:16:28
Context
2014-06-03
00:19
Fix stupid typo in definition of the Pager support command. check-in: d4b3af213d user: andreask tags: trunk
00:16
cmdr::help - Extended the backend to invoke a pager if the help is too high for the terminal. Lots of things (not terminal, no support in linenoise, no pager) will disable this. Bumped version to 1.3. check-in: e15928b830 user: andreask tags: trunk
2014-05-28
23:33
cmdr::actor, cmdr::officer - Fix bug introduced with revision [7ab77ead21]. The option handling added to "actor::set" in that revision means that the command "my set *command* ..." storing the actual command line (i.e. user information) can break, trying to interpret application specific option information as something for the internal command. Fixed by adding "--" to "actor::set"s option handling, and using it for the breakable command to force interpretation of the user data as such. check-in: cd7539eb28 user: andreask tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to help.tcl.

    25     25   package require Tcl 8.5
    26     26   package require debug
    27     27   package require debug::caller
    28     28   package require lambda
    29     29   package require linenoise
    30     30   package require textutil::adjust
    31     31   package require cmdr::util
           32  +package require cmdr::tty
    32     33   
    33     34   # # ## ### ##### ######## ############# #####################
    34     35   
    35     36   debug define cmdr/help
    36     37   debug level  cmdr/help
    37     38   debug prefix cmdr/help {[debug caller] | }
    38     39   
................................................................................
    43     44       namespace export help
    44     45       namespace ensemble create
    45     46   }
    46     47   
    47     48   namespace eval ::cmdr::help {
    48     49       namespace export query format auto
    49     50       namespace ensemble create
           51  +
           52  +    namespace import ::cmdr::tty
    50     53   }
    51     54   
    52     55   # # ## ### ##### ######## ############# #####################
    53     56   
    54     57   proc ::cmdr::help::query {actor words} {
    55     58       debug.cmdr/help {}
    56     59       # Resolve chain of words (command name path) to the actor
................................................................................
   150    153   		set format full
   151    154   	    }
   152    155   	} else {
   153    156   	    set format by-category
   154    157   	}
   155    158       }
   156    159   
   157         -    puts [format $format \
   158         -	      [$actor root] \
   159         -	      $width \
   160         -	      [cmdr util dictsort \
   161         -		   [query $actor $words]]]
          160  +    set text [format $format \
          161  +		  [$actor root] \
          162  +		  $width \
          163  +		  [cmdr util dictsort \
          164  +		       [query $actor $words]]]
          165  +
          166  +    # Determine how to show the help, in a pager, or not ?
          167  +
          168  +    if {![tty stdout]} {
          169  +	# Not a terminal, no pager possible.
          170  +	# This is also the case handling windows.
          171  +	puts $text
          172  +    } else {
          173  +	# Terminal
          174  +	if {[catch {
          175  +	    set height [linenoise lines]
          176  +	}]} {
          177  +	    # Unable to get the terminal height.
          178  +	    # Don't do paging.
          179  +	    puts $text
          180  +	} else {
          181  +	    # Compare the help's height to the terminal.
          182  +	    set lines [llength [split $text \n]]
          183  +	    if {$lines <= $height} {
          184  +		# The help fits fully into the terminal, no pager
          185  +		# needed.
          186  +		puts $text
          187  +	    } else {
          188  +		# The help is too high, and does not fit into the
          189  +		# current terminal.
          190  +		set pager [Pager]
          191  +		if {![llength $pager]} {
          192  +		    # We found no pager, and give up on trying to use
          193  +		    # one.
          194  +		    puts $text
          195  +		} else {
          196  +		    # We needed and have a pager, run it with the help.
          197  +		    # as input.
          198  +		    set    pipe [open "|$pager" w]
          199  +		    puts  $pipe $text
          200  +		    # This waits until the pager exits.
          201  +		    close $pipe
          202  +		}
          203  +	    }
          204  +	}
          205  +    }
   162    206       return
   163    207   }
          208  +
          209  +proc ::cmdr::help::format::Pager {} {
          210  +    global env
          211  +    if {[info exists env(PAGER)]} {
          212  +	lappend pager $env(PAGER)
          213  +    }
          214  +    lappend pager less
          215  +    lappend pager more
          216  +
          217  +    foreach p $pager {
          218  +	set cmd [auto_execok $p]
          219  +	if {[llength $cmd]} break
          220  +    }
          221  +    return $cmd
          222  +}
   164    223   
   165    224   # # ## ### ##### ######## ############# #####################
   166    225   
   167    226   namespace eval ::cmdr::help::format {
   168    227       namespace export full list short by-category
   169    228       namespace ensemble create
   170    229   }
................................................................................
   522    581   
   523    582       return $categories
   524    583   }
   525    584   
   526    585   
   527    586   # # ## ### ##### ######## ############# #####################
   528    587   ## Ready
   529         -package provide cmdr::help 1.2
          588  +package provide cmdr::help 1.3