Class: TTY::Pager::BasicPager
- 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
->(page) { format(PAGE_BREAK, page: page) }
Constants inherited from Abstract
Abstract::UndefinedMethodError
Instance Method Summary collapse
-
#close ⇒ Object
Stop the pager, wait for it to clean up.
-
#initialize(height: TTY::Screen.height, width: TTY::Screen.width, prompt: DEFAULT_PROMPT, **options) ⇒ BasicPager
constructor
Create a basic pager.
-
#puts(text) ⇒ Object
Print a line of text to the pager, prompting on page end.
-
#write(*args) ⇒ TTY::Pager::BasicPager
(also: #<<)
Write text to the pager, prompting on page end.
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
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, **) super(**) @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
#close ⇒ Object
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.
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.
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 |