iPXE
Functions
jumpscroll.c File Reference
#include <assert.h>
#include <ipxe/keys.h>
#include <ipxe/jumpscroll.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
unsigned int jump_scroll_key (struct jump_scroller *scroll, int key)
 Jump scrolling. More...
 
unsigned int jump_scroll_move (struct jump_scroller *scroll, unsigned int move)
 Move scroller. More...
 
int jump_scroll (struct jump_scroller *scroll)
 Jump scroll to new page (if applicable) More...
 

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ jump_scroll_key()

unsigned int jump_scroll_key ( struct jump_scroller scroll,
int  key 
)

Jump scrolling.

Handle keypress

Parameters
scrollJump scroller
keyKey pressed by user
Return values
moveScroller movement, or zero

Definition at line 42 of file jumpscroll.c.

42  {
43  unsigned int flags = 0;
44  int16_t delta;
45 
46  /* Sanity checks */
47  assert ( scroll->rows != 0 );
48  assert ( scroll->count != 0 );
49  assert ( scroll->current < scroll->count );
50  assert ( scroll->first < scroll->count );
51  assert ( scroll->first <= scroll->current );
52  assert ( scroll->current < ( scroll->first + scroll->rows ) );
53 
54  /* Handle key, if applicable */
55  switch ( key ) {
56  case KEY_UP:
57  delta = -1;
58  break;
59  case TAB:
61  /* fall through */
62  case KEY_DOWN:
63  delta = +1;
64  break;
65  case KEY_PPAGE:
66  delta = ( scroll->first - scroll->current - 1 );
67  break;
68  case KEY_NPAGE:
69  delta = ( scroll->first - scroll->current + scroll->rows );
70  break;
71  case KEY_HOME:
72  delta = -( scroll->count );
73  break;
74  case KEY_END:
75  delta = +( scroll->count );
76  break;
77  default:
78  delta = 0;
79  break;
80  }
81 
82  return ( SCROLL ( delta ) | flags );
83 }
#define SCROLL(delta)
Construct scroll movement.
Definition: jumpscroll.h:32
#define KEY_NPAGE
Page down.
Definition: keys.h:113
#define KEY_HOME
Home.
Definition: keys.h:109
#define KEY_DOWN
Down arrow.
Definition: keys.h:105
#define KEY_UP
Up arrow.
Definition: keys.h:104
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int first
First visible item.
Definition: jumpscroll.h:23
unsigned int count
Total number of items.
Definition: jumpscroll.h:19
#define TAB
Definition: keys.h:46
uint8_t flags
Flags.
Definition: ena.h:18
#define KEY_PPAGE
Page up.
Definition: keys.h:112
#define KEY_END
End.
Definition: keys.h:108
unsigned int rows
Maximum number of visible rows.
Definition: jumpscroll.h:17
signed short int16_t
Definition: stdint.h:16
#define SCROLL_WRAP
Wrap around scrolling.
Definition: jumpscroll.h:44
unsigned int current
Currently selected item.
Definition: jumpscroll.h:21
union @383 key
Sense key.
Definition: scsi.h:18

References assert(), jump_scroller::count, jump_scroller::current, jump_scroller::first, flags, key, KEY_DOWN, KEY_END, KEY_HOME, KEY_NPAGE, KEY_PPAGE, KEY_UP, jump_scroller::rows, SCROLL, SCROLL_WRAP, and TAB.

Referenced by form_loop(), main_loop(), and menu_loop().

◆ jump_scroll_move()

unsigned int jump_scroll_move ( struct jump_scroller scroll,
unsigned int  move 
)

Move scroller.

Parameters
scrollJump scroller
moveScroller movement
Return values
moveContinuing scroller movement (if applicable)

Definition at line 92 of file jumpscroll.c.

93  {
94  int16_t delta = SCROLL_DELTA ( move );
95  int current = scroll->current;
96  int last = ( scroll->count - 1 );
97 
98  /* Sanity checks */
99  assert ( move != 0 );
100  assert ( scroll->count != 0 );
101 
102  /* Move to the new current item */
103  current += delta;
104 
105  /* Default to continuing movement in the same direction */
106  delta = ( ( delta >= 0 ) ? +1 : -1 );
107 
108  /* Check for start/end of list */
109  if ( ( current >= 0 ) && ( current <= last ) ) {
110  /* We are still within the list. Update the current
111  * item and continue moving in the same direction (if
112  * applicable).
113  */
114  scroll->current = current;
115  } else {
116  /* We have attempted to move outside the list. If we
117  * are wrapping around, then continue in the same
118  * direction (if applicable), otherwise reverse.
119  */
120  if ( ! ( move & SCROLL_WRAP ) )
121  delta = -delta;
122 
123  /* Move to start or end of list as appropriate */
124  if ( delta >= 0 ) {
125  scroll->current = 0;
126  } else {
127  scroll->current = last;
128  }
129  }
130 
131  return ( SCROLL ( delta ) | ( move & SCROLL_FLAGS ) );
132 }
#define SCROLL(delta)
Construct scroll movement.
Definition: jumpscroll.h:32
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define SCROLL_DELTA(scroll)
Extract change in scroller position.
Definition: jumpscroll.h:40
unsigned int count
Total number of items.
Definition: jumpscroll.h:19
#define SCROLL_FLAGS
Scroll movement flags.
Definition: jumpscroll.h:43
static int move(int y, int x)
Definition: curses.h:593
signed short int16_t
Definition: stdint.h:16
#define SCROLL_WRAP
Wrap around scrolling.
Definition: jumpscroll.h:44
unsigned int current
Currently selected item.
Definition: jumpscroll.h:21

References assert(), jump_scroller::count, jump_scroller::current, move(), SCROLL, SCROLL_DELTA, SCROLL_FLAGS, and SCROLL_WRAP.

Referenced by form_loop(), main_loop(), and menu_loop().

◆ jump_scroll()

int jump_scroll ( struct jump_scroller scroll)

Jump scroll to new page (if applicable)

Parameters
scrollJump scroller
Return values
jumpedJumped to a new page

Definition at line 140 of file jumpscroll.c.

140  {
141  unsigned int index;
142 
143  /* Sanity checks */
144  assert ( scroll->rows != 0 );
145  assert ( scroll->count != 0 );
146  assert ( scroll->current < scroll->count );
147  assert ( scroll->first < scroll->count );
148 
149  /* Do nothing if we are already on the correct page */
150  index = ( scroll->current - scroll->first );
151  if ( index < scroll->rows )
152  return 0;
153 
154  /* Move to required page */
155  while ( scroll->first < scroll->current )
156  scroll->first += scroll->rows;
157  while ( scroll->first > scroll->current )
158  scroll->first -= scroll->rows;
159 
160  return 1;
161 }
long index
Definition: bigint.h:61
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int first
First visible item.
Definition: jumpscroll.h:23
unsigned int count
Total number of items.
Definition: jumpscroll.h:19
unsigned int rows
Maximum number of visible rows.
Definition: jumpscroll.h:17
unsigned int current
Currently selected item.
Definition: jumpscroll.h:21

References assert(), jump_scroller::count, jump_scroller::current, jump_scroller::first, index, and jump_scroller::rows.

Referenced by main_loop(), menu_loop(), and show_menu().