summary refs log blame commit diff stats
path: root/Makefile
blob: 392c6a9aa982d8fe3f66a57df74f121cd30cb42a (plain) (tree)
> direction.horizontal(): self.startx = direction.move( direction=direction.right(), override=narg, maximum=self.max_width, current=self.startx, pagesize=self.wid, offset=-self.wid + 1) if direction.vertical(): if self.source_is_stream: self._get_line(self.scroll_begin + self.hei * 2) self.scroll_begin = direction.move( direction=direction.down(), override=narg, maximum=len(self.lines), current=self.scroll_begin, pagesize=self.hei, offset=-self.hei + 1) def press(self, key): self.env.keymaps.use_keymap('pager') self.fm.ui.press(key) def set_source(self, source, strip=False): if self.source and self.source_is_stream: self.source.close() self.max_width = 0 if isinstance(source, str): self.source_is_stream = False self.lines = source.splitlines() if self.lines: self.max_width = max(len(line) for line in self.lines) elif hasattr(source, '__getitem__'): self.source_is_stream = False self.lines = source if self.lines: self.max_width = max(len(line) for line in source) elif hasattr(source, 'readline'): self.source_is_stream = True self.lines = [] else: self.source = None self.source_is_stream = False return False self.markup = 'ansi' if not self.source_is_stream and strip: self.lines = map(lambda x: x.strip(), self.lines) self.source = source return True def click(self, event): n = event.ctrl() and 1 or 3 direction = event.mouse_wheel_direction() if direction: self.move(down=direction * n) return True def _get_line(self, n, attempt_to_read=True): assert isinstance(n, int), n try: return self.lines[n] except (KeyError, IndexError): if attempt_to_read and self.source_is_stream: try: for l in self.source: if len(l) > self.max_width: self.max_width = len(l) self.lines.append(l) if len(self.lines) > n: break except (UnicodeError, IOError): pass return self._get_line(n, attempt_to_read=False) return "" def _generate_lines(self, starty, startx): i = starty if not self.source: raise StopIteration while True: try: line = self._get_line(i).expandtabs(4) if self.markup is 'ansi': line = ansi.char_slice(line, startx, self.wid) + ansi.reset else: line = line[startx:self.wid + startx] yield line.rstrip() except IndexError: raise StopIteration i += 1