Class: TTY::Pager::BasicPager

Inherits:
Abstract
  • Object
show all
Defined in:
lib/tty/pager/basic.rb

Overview

A basic pager is used to work on systems where system pager is not supported.

Defined Under Namespace

Classes: PageCursor

Constant Summary collapse

PAGE_BREAK =
"\n--- Page -%<page>s- Press enter/return to continue " \
"(or q to quit) ---"
DEFAULT_PROMPT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Default prompt for paging

Returns:

  • (Proc)
->(page) { format(PAGE_BREAK, page: page) }

Constants inherited from Abstract

Abstract::UndefinedMethodError

Instance Method Summary collapse

Methods inherited from Abstract

#enabled?, page, #page, #try_write

Constructor Details

#initialize(height: TTY::Screen.height, width: TTY::Screen.width, prompt: DEFAULT_PROMPT, **options) ⇒ BasicPager

Create a basic pager

Parameters:

  • :height (Integer)

    the terminal height

  • :width (Integer)

    the terminal width

  • :prompt (Proc)

    a proc object that accepts page number



36
37
38
39
40
41
42
43
44
45
# File 'lib/tty/pager/basic.rb', line 36

def initialize(height: TTY::Screen.height, width: TTY::Screen.width,
               prompt: DEFAULT_PROMPT, **options)
  super(**options)
  @width   = width
  @prompt  = prompt
  prompt_height = Strings.wrap(prompt.call(100).to_s, width).lines.count
  @page_cursor = PageCursor.new(height - prompt_height)

  reset
end

Instance Method Details

#closeObject

Stop the pager, wait for it to clean up



76
77
78
79
# File 'lib/tty/pager/basic.rb', line 76

def close
  reset
  true
end

#puts(text) ⇒ Object

Print a line of text to the pager, prompting on page end.

Raises:



69
70
71
# File 'lib/tty/pager/basic.rb', line 69

def puts(text)
  send_text(:puts, text)
end

#write(*args) ⇒ TTY::Pager::BasicPager Also known as: <<

Write text to the pager, prompting on page end.

Returns:

Raises:



55
56
57
58
59
60
# File 'lib/tty/pager/basic.rb', line 55

def write(*args)
  args.each do |text|
    send_text(:write, text)
  end
  self
end