Class: Rvim::ListView
- Inherits:
-
Object
- Object
- Rvim::ListView
- Defined in:
- lib/rvim/list_view.rb
Instance Attribute Summary collapse
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
Instance Method Summary collapse
- #advance!(rows) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(lines) ⇒ ListView
constructor
A new instance of ListView.
- #more?(rows) ⇒ Boolean
- #page(rows) ⇒ Object
-
#page_size(rows) ⇒ Object
Visible rows for the list.
Constructor Details
#initialize(lines) ⇒ ListView
Returns a new instance of ListView.
7 8 9 10 |
# File 'lib/rvim/list_view.rb', line 7 def initialize(lines) @lines = lines @cursor = 0 end |
Instance Attribute Details
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor.
5 6 7 |
# File 'lib/rvim/list_view.rb', line 5 def cursor @cursor end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
5 6 7 |
# File 'lib/rvim/list_view.rb', line 5 def lines @lines end |
Instance Method Details
#advance!(rows) ⇒ Object
26 27 28 |
# File 'lib/rvim/list_view.rb', line 26 def advance!(rows) @cursor += page_size(rows) end |
#empty? ⇒ Boolean
30 31 32 |
# File 'lib/rvim/list_view.rb', line 30 def empty? @lines.empty? end |
#more?(rows) ⇒ Boolean
22 23 24 |
# File 'lib/rvim/list_view.rb', line 22 def more?(rows) @cursor + page_size(rows) < @lines.size end |
#page(rows) ⇒ Object
18 19 20 |
# File 'lib/rvim/list_view.rb', line 18 def page(rows) @lines[@cursor, page_size(rows)] || [] end |
#page_size(rows) ⇒ Object
Visible rows for the list. Caller passes the total rows allocated; we subtract 1 for the “– More –” prompt at the bottom.
14 15 16 |
# File 'lib/rvim/list_view.rb', line 14 def page_size(rows) [rows - 1, 1].max end |