-- Perl 5.8.8 documentation --
Fink::CLI

NAME

Fink::CLI - functions for user interaction

SYNOPSIS

DESCRIPTION

These functions handle a variety of output formatting and user interaction/response tasks.

Functions

No functions are exported by default. You can get whichever ones you need with things like:

    use Fink::Services '&prompt_boolean';
    use Fink::Services qw(&print_breaking &prompt);
  • print_breaking
        print_breaking $string;
        print_breaking $string, $linebreak;
        print_breaking $string, $linebreak, $prefix1;
        print_breaking $string, $linebreak, $prefix1, $prefix2;

    Wraps $string, breaking at word-breaks, and prints it on STDOUT. The screen width is determined by get_term_width, or if that fails, the package global variable $linelength. Breaking is performed only at space chars. If $linebreak is true, a linefeed will be appended to the last line printed, otherwise one will not be appended. Optionally, prefixes can be defined to prepend to each line printed: $prefix1 is prepended to the first line, $prefix2 is prepended to all other lines. If only $prefix1 is defined, that will be prepended to all lines.

    If $string is a multiline string (i.e., it contains embedded newlines other than an optional one at the end of the whole string), the prefix rules are applied to each contained line separately. That means $prefix1 affects the first line printed for each line in $string and $prefix2 affects all other lines printed for each line in $string.

  • print_breaking_stderr

    This is a wrapper around print_breaking that causes output to go to STDERR. See print_breaking for a complete description of parameters and usage.

  • prompt
        my $answer = prompt $prompt;
        my $answer = prompt $prompt, $default;

    Ask the user a question and return the answer. The user is prompted via STDOUT/STDIN using $prompt (which is word-wrapped). If the user returns a null string or Fink is configured to automatically accept defaults (i.e., bin/fink was invoked with the -y or --yes option), the default answer $default is returned (or a null string if no $default is not defined).

  • prompt_boolean
        my $answer = prompt_boolean $prompt;
        my $answer = prompt_boolean $prompt, $default_true;
        my $answer = prompt_boolean $prompt, $default_true, $timeout;

    Ask the user a yes/no question and return the logical value of the answer. The user is prompted via STDOUT/STDIN using $prompt (which is word-wrapped). If $default_true is true or undef, the default answer is true, otherwise it is false. If the user returns a null string or Fink is configured to automatically accept defaults (i.e., bin/fink was invoked with the -y or --yes option), the default answer is returned. The optional $timeout argument establishes a wait period (in seconds) for the prompt, after which the default answer will be used.

  • prompt_selection_new
        my $answer = prompt_selection_new $prompt, \@default, @choices;

    Ask the user a multiple-choice question and return the answer. The user is prompted via STDOUT/STDIN using $prompt (which is word-wrapped) and a list of choices. The choices are numbered (beginning with 1) and the user selects by number. The list @choices is an ordered pairwise list (label1,value1,label2,value2,...). If the user returns a null string or Fink is configured to automatically accept defaults (i.e., bin/fink was invoked with the -y or --yes option), the default answer is used according to the following:

      @default = undef;                # choice 1
      @default = [];                   # choice 1
      @default = ["number", $number];  # choice $number
      @default = ["label", $label];    # first choice with label $label
      @default = ["value", $label];    # first choice with value $value
  • prompt_selection
        my $answer = prompt_selection $prompt, %options;

    Ask the user a multiple-choice question and return the answer. The user is prompted via STDOUT/STDIN using $prompt (which is word-wrapped) and a list of choices. The choices are numbered (beginning with 1) and the user selects by number.

    The %options are given as option => value pairs. The following options are known: choices (required) The option 'choices' must be a reference to an ordered pairwise array [ label1 => value1, label2 => value2, ... ]. The labels will be displayed to the user; the values are the return values if that option is chosen. default (optional) If the option 'default' is given, then it determines which choice will be returned if no input is detected. This can occur if the user enters a null string, or if Fink is configured to automatically accept defaults (i.e., bin/fink was invoked with the -y or --yes option). The following formats are recognized for the 'default' option: @default = []; # choice 1 @default = ["number", $number]; # choice $number @default = ["label", $label]; # first choice with label $label @default = ["value", $label]; # first choice with value $value Default value: choice 1 timeout (optional) The 'timeout' option establishes a wait period (in seconds) for the prompt, after which the default answer will be used. If a timeout is given, any existing alarm() is destroyed. Default value: no timeout

  • get_input
        my $answer = get_input $prompt;
        my $answer = get_input $prompt, $timeout;

    Prints the string $prompt, then gets a single line of input from STDIN. If $timeout is zero or not given, will block forever waiting for input. If $timeout is given and is positive, will only wait that many seconds for input before giving up. Returns the entered string (including the trailing newline), or a null string if the timeout expires or immediately (without waiting for input) if fink is run with the -y option. If not -y, this function destroys any pre-existing alarm().

  • get_term_width
      my $width = get_term_width;

    This function returns the width of the terminal window, or zero if STDOUT is not a terminal. Uses Term::ReadKey if it is available, greps the TERMCAP env var if ReadKey is not installed, tries tput if neither are available, and if nothing works just returns 80.