def __init__(self, arguments: dict) -> None: try: self.path, self.revision, self.files = parse_args(**arguments) repo = Repo(path=self.path) path = repo.working_dir.replace(os.path.expanduser('~'), '~', 1) self.working_dir = repo.working_dir revision = self.revision[0] if self.revision == 'HEAD': revision = repo._nrepo.head.ref.name title = '%s \uf418 %s' % (path.rstrip('/'), revision) shortcuts.set_title('%s - Git Log Viewer' % title) except NoRevisionMatches: print('No revisions match the given arguments.', file=sys.stderr) sys.exit(1) except NoPathMatches: print("No paths match the given arguments.", file=sys.stderr) sys.exit(1) self.date_max_len = 0 self.name_max_len = 0 self._repo = repo self.line_count = self._repo.count_commits(self.revision[0]) self.commit_list: List[Commit] = [] self.log_entry_list: List[Commit] = [] self.search_state: Optional[SearchState] = None self._search_thread: Optional[Thread] = None super().__init__(line_count=self.line_count, get_line=self.get_line, show_cursor=False) self.fill_up(utils.screen_height())
def search(self, search_state: SearchState, include_current_position=True, count=1): LOG.debug('applying search %r, %r, %r', search_state, include_current_position, count) self.search_state = search_state index = self.cursor_position.y new_position = self.cursor_position.y LOG.debug('Current position %r', index) needle = self.search_state.text STATUS.set_status("Searching for '%s'" % needle) if self.search_state.direction == SearchDirection.FORWARD: if not include_current_position: index += 1 while True: try: commit = self.commit_list[index] except IndexError: if not self.fill_up(utils.screen_height()): break commit = self.commit_list[index] if needle in commit.short_id or needle in commit.subject \ or needle in commit.author_name \ or any(needle in haystack for haystack in commit.branches): new_position = index break index += 1 else: if not include_current_position and index > 0: index -= 1 while index >= 0: commit = self.commit_list[index] if needle in commit.short_id() or needle in commit.subject \ or needle in commit.author_name(): new_position = index break index -= 1 if new_position != self.cursor_position.y: self.cursor_position = Point(x=self.cursor_position.x, y=index) STATUS.clear()
def pageup_key(_: KeyPressEvent): control = LAYOUT.current_control line_number = control.current_line - screen_height() * 2 + 1 if line_number < 0: line_number = 0 control.goto_line(line_number)
def pagedown_key(_: KeyPressEvent): control = LAYOUT.current_control line_number = control.current_line + screen_height() * 2 - 1 control.goto_line(line_number)
def preferred_height(self, width: int, max_available_height: int, wrap_lines: bool, get_line_prefix) -> Optional[int]: return screen_height() / 2