Revision 439826ec kamaki/cli/utils.py
b/kamaki/cli/utils.py | ||
---|---|---|
191 | 191 |
print('%s%s' % (prefix, item)) |
192 | 192 |
|
193 | 193 |
|
194 |
def page_hold(index, limit, maxlen): |
|
195 |
"""Check if there are results to show, and hold the page when needed |
|
196 |
:param index: (int) > 0 |
|
197 |
:param limit: (int) 0 < limit <= max, page hold if limit mod index == 0 |
|
198 |
:param maxlen: (int) Don't hold if index reaches maxlen |
|
199 |
|
|
200 |
:returns: True if there are more to show, False if all results are shown |
|
201 |
""" |
|
202 |
if index >= limit and index % limit == 0: |
|
203 |
if index >= maxlen: |
|
204 |
return False |
|
205 |
else: |
|
206 |
print('(%s listed - %s more - "enter" to continue)' % ( |
|
207 |
index, |
|
208 |
maxlen - index)) |
|
209 |
c = ' ' |
|
210 |
while c != '\n': |
|
211 |
c = stdin.read(1) |
|
212 |
return True |
|
213 |
|
|
214 |
|
|
194 | 215 |
def print_items(items, |
195 | 216 |
title=('id', 'name'), |
196 | 217 |
with_enumeration=False, |
... | ... | |
232 | 253 |
print_list(item, ident=1) |
233 | 254 |
else: |
234 | 255 |
print(' %s' % item) |
235 |
if num_of_pages and len(items) > (i + 1) and 0 == (i + 1) % page_size: |
|
236 |
num_of_pages -= 1 |
|
237 |
print('(%s listed - %s more - "enter" to continue)' % ( |
|
238 |
i + 1, |
|
239 |
len(items) - (i + 1))) |
|
240 |
c = ' ' |
|
241 |
while c != '\n': |
|
242 |
c = stdin.read(1) |
|
256 |
page_hold(i + 1, page_size, len(items)) |
|
243 | 257 |
|
244 | 258 |
|
245 | 259 |
def format_size(size): |
Also available in: Unified diff