Module: Toys::StandardMixins::Pager

Includes:
Mixin
Defined in:
lib/toys/standard_mixins/pager.rb

Overview

A mixin that provides a pager.

This mixin provides an instance of Utils::Pager, which invokes an external pager for output.

You can also pass additional keyword arguments to the include directive to configure the pager object. These will be passed on to Utils::Pager#initialize.

Examples:


include :pager

def run
  pager do |io|
    io.puts "A long string\n"
  end
end

Constant Summary collapse

KEY =

Context key for the Pager object.

Returns:

  • (Object)
::Object.new.freeze

Instance Method Summary collapse

Methods included from Mixin

create

Instance Method Details

#pager(&block) ⇒ Toys::Utils::Pager, Integer

Access the Pager.

If no block is given, returns the pager object.

If a block is given, the pager is executed with the given block, and the exit code of the pager process is returned.

Returns:



45
46
47
48
49
# File 'lib/toys/standard_mixins/pager.rb', line 45

def pager(&block)
  pager = self[KEY]
  return pager unless block
  self[KEY].start(&block)
end