Run the pager.
(self)
| 167 | self._Write('\n') |
| 168 | |
| 169 | def Run(self): |
| 170 | """Run the pager.""" |
| 171 | # No paging if the contents are small enough. |
| 172 | if len(self._lines) <= self._height: |
| 173 | self._Write(self._contents) |
| 174 | return |
| 175 | |
| 176 | # We will not always reset previous values. |
| 177 | reset_prev_values = True |
| 178 | # Save room for the prompt at the bottom of the page. |
| 179 | self._height -= 1 |
| 180 | |
| 181 | # Loop over all the pages. |
| 182 | pos = 0 |
| 183 | while pos < len(self._lines): |
| 184 | # Write a page of lines. |
| 185 | nxt = pos + self._height |
| 186 | if nxt > len(self._lines): |
| 187 | nxt = len(self._lines) |
| 188 | pos = nxt - self._height |
| 189 | # Checks if the starting position is in between the current printed lines |
| 190 | # so we don't need to reprint all the lines. |
| 191 | if self.prev_pos < pos < self.prev_nxt: |
| 192 | # we start where the previous page ended. |
| 193 | self._Write('\n'.join(self._lines[self.prev_nxt:nxt]) + '\n') |
| 194 | elif pos != self.prev_pos and nxt != self.prev_nxt: |
| 195 | self._Write('\n'.join(self._lines[pos:nxt]) + '\n') |
| 196 | |
| 197 | # Handle the prompt response. |
| 198 | percent = self._prompt.format(percent=100 * nxt // len(self._lines)) |
| 199 | digits = '' |
| 200 | while True: |
| 201 | # We want to reset prev values if we just exited out of the while loop |
| 202 | if reset_prev_values: |
| 203 | self.prev_pos, self.prev_nxt = pos, nxt |
| 204 | reset_prev_values = False |
| 205 | self._Write(percent) |
| 206 | c = self._attr.GetRawKey() |
| 207 | self._Write(self._clear) |
| 208 | |
| 209 | # Parse the command. |
| 210 | if c in (None, # EOF. |
| 211 | 'q', # Quit. |
| 212 | 'Q', # Quit. |
| 213 | '\x03', # ^C (unix & windows terminal interrupt) |
| 214 | '\x1b', # ESC. |
| 215 | ): |
| 216 | # Quit. |
| 217 | return |
| 218 | elif c in ('/', '?'): |
| 219 | c = self._GetSearchCommand(c) |
| 220 | elif c.isdigit(): |
| 221 | # Collect digits for operation count. |
| 222 | digits += c |
| 223 | continue |
| 224 | |
| 225 | # Set the optional command count. |
| 226 | if digits: |
no test coverage detected