@@ -11,18 +11,23 @@ pub struct Paging<'a> {
11
11
pub current_page : usize ,
12
12
pub capacity : usize ,
13
13
pub active : bool ,
14
-
14
+ pub max_capacity : Option < usize > ,
15
15
term : & ' a Term ,
16
16
current_term_size : ( u16 , u16 ) ,
17
17
items_len : usize ,
18
18
activity_transition : bool ,
19
19
}
20
20
21
21
impl < ' a > Paging < ' a > {
22
- pub fn new ( term : & ' a Term , items_len : usize ) -> Paging < ' a > {
22
+ pub fn new ( term : & ' a Term , items_len : usize , max_capacity : Option < usize > ) -> Paging < ' a > {
23
23
let term_size = term. size ( ) ;
24
24
// Subtract -2 because we need space to render the prompt, if paging is active
25
- let capacity = term_size. 0 as usize - 2 ;
25
+ let capacity = max_capacity
26
+ . unwrap_or ( std:: usize:: MAX )
27
+ . min ( term_size. 0 as usize )
28
+ // Safeguard in case term_size or max_length is 2 or less. Guarantees no unwanted wrapping behavior.
29
+ . max ( 3 )
30
+ - 2 ;
26
31
let pages = ( items_len as f64 / capacity as f64 ) . ceil ( ) as usize ;
27
32
28
33
Paging {
@@ -33,6 +38,7 @@ impl<'a> Paging<'a> {
33
38
term,
34
39
current_term_size : term_size,
35
40
items_len,
41
+ max_capacity,
36
42
// Set transition initially to true to trigger prompt rendering for inactive paging on start
37
43
activity_transition : true ,
38
44
}
@@ -44,7 +50,12 @@ impl<'a> Paging<'a> {
44
50
45
51
if self . current_term_size != new_term_size {
46
52
self . current_term_size = new_term_size;
47
- self . capacity = self . current_term_size . 0 as usize - 2 ;
53
+ self . capacity = self
54
+ . max_capacity
55
+ . unwrap_or ( std:: usize:: MAX )
56
+ . min ( self . current_term_size . 0 as usize )
57
+ . max ( 3 )
58
+ - 2 ;
48
59
self . pages = ( self . items_len as f64 / self . capacity as f64 ) . ceil ( ) as usize ;
49
60
}
50
61
0 commit comments