def print_stash(): gui.print_header("Stash", BG_YELLOW) # get stash information from git repo = connection.repo refs = repo.head.repo.refs stash = refs["refs/stash"] stash_log = stash.log() stash_log.reverse() # create entry to be formated as table stash_list = [] stash_counter = 0 for s in stash_log: entry = [] entry.append("stash@{" + str(stash_counter) + "}:") entry.append(util.get_relative_date(s.time[0])) entry.append(s.message) stash_list.append(entry) stash_counter += 1 # print stash information as table # calculate max widths needed col_num = len(stash_list[0]) max_col_widths = [0] * col_num for entry in stash_list: for i in range(col_num): max_col_widths[i] = max(max_col_widths[i], len(entry[i]) + spacing) # cap message length so there is no line break w = util.get_window_size() msg_length = w.x - max_col_widths[0] - max_col_widths[1] # use max length max_col_widths[2] = msg_length for entry in stash_list: entry[2] = entry[2][:msg_length] # print table for entry in stash_list: text = "" text += YELLOW + entry[0].ljust(max_col_widths[0]) + RESET text += CYAN + entry[1].ljust(max_col_widths[1]) + RESET text += entry[2].ljust(max_col_widths[2]) print(text)
def list_tasks_of_diff(): t = connection.repo.head.commit.tree x = connection.repo.git.diff(t, '--color=always').split('\n') y = connection.repo.git.diff(t, '--color=always', '--staged').split('\n') z = y # list only for staged z = x # list staged and unstaged final_lines = [] for line in z: if line.startswith(GREEN): line = line.lstrip(GREEN)[1:] final_lines.append(line) elif line.startswith(RED): line = line.lstrip(RED)[1:] final_lines.append(line) counter_dict = {} for task in s.tasks: counter_dict[task.value] = 0 not_empty = False for task in s.tasks: for line in final_lines: if task.value in line: counter_dict[task.value] += 1 not_empty = True if not_empty: # Highlight line line = ' ' * utils.get_window_size().x print(f"{BG_RED}{line}{RESET}") print() # Print actual Tasks print_tasks(counter_dict) # Highlight line print(f"{BG_RED}{line}{RESET}") print()
def list_tasks(cli_tasks): # TODO should avoid adding unused Tasks in the first place instead of adding them and then clearing the list if args.ignore_conf: settings.clear_tasks() if cli_tasks != None: from gitviper.task import Task for cli_task in cli_tasks: settings.add_task( Task(cli_task, None, None, None, None, None, None)) # initialize dict for k in settings.tasks: occurences_dict[k] = [] # get files as list files = utils.get_files() # fill dictionary for task in settings.tasks: for f in files: fill_dictionary(task, f) # create list of dict entries and ignore empty task-entries occurences_dict_list = [] for key in occurences_dict: if len(occurences_dict[key]) == 0: # TODO use some sort of Debug print to be able to show when using --debug # print("No tasks for: " + key.representation) continue else: occurences_dict_list.append((key, occurences_dict[key])) # sort list by priority def getKey(item): return item[0].priority occurences_dict_sorted_by_priority = sorted(occurences_dict_list, reverse=True, key=getKey) # print table for kv in occurences_dict_sorted_by_priority: task = kv[0] # Task occurence_list = kv[1] # Occurence [] task_list_line_entries = [] for o in occurence_list: for line in split_stream(o, task): task_list_line_entries.append(line) # find max column widths substitutes = [0] * 4 # substitutes for invisible characters substitutes[1] = len( BOLD + RESET ) # for highlighting tasks # FIXME adjust to new format, individual color per Task? if settings.show_paths_for_task_list == args.toggle_paths: substitutes[2] = len( BOLD + BLUE + RESET) # for highlighting filename if also showing path else: substitutes[2] = 0 max_widths = [0] * 3 for task_list_line_entry in task_list_line_entries: max_widths[0] = max(max_widths[0], len(task_list_line_entry.linecontent)) max_widths[1] = max(max_widths[1], len(task_list_line_entry.path)) max_widths[2] = max(max_widths[2], len(task_list_line_entry.linenumber)) if settings.show_paths_for_task_list == args.toggle_paths: max_widths[1] -= substitutes[2] line_beginning_spacing = " " #max_widths[0] = len(line_beginning_spacing) # clamp to window width s = len(spacing) availablespace = int(utils.get_window_size().x) - len( line_beginning_spacing ) - s - max_widths[1] - s - max_widths[2] - s - len( window_padding ) + substitutes[ 1] + s + 6 # the last ' + s + 2' is for setting [0] to 'line_beginning_spacing' and add whitespace to the right side max_widths[0] = availablespace print(" " + task.color + BOLD + task.representation + " [" + str(len(task_list_line_entries)) + "]" + RESET) print() for task_list_line_entry in task_list_line_entries: if len(task_list_line_entry.linecontent) > max_widths[0]: task_list_line_entry.linecontent = task_list_line_entry.linecontent[:max_widths[ 0] - 3] + "..." taskword = line_beginning_spacing line = task_list_line_entry.linecontent[:max_widths[0]].ljust( max_widths[0]) + spacing filename = task_list_line_entry.path.ljust( max_widths[1] + substitutes[2]) + spacing linenumber = task_list_line_entry.linenumber.rjust(max_widths[2]) # TODO use python3.6 f-strings text = "%s%s%s%s" % (taskword, line, filename, linenumber) print(text) print()
def log(max_commit_count, max_days_old, separate_commits): branch = connection.repo.active_branch num_commits = len(list(connection.repo.iter_commits(branch))) # when max_days_old is specified, max_commit_count will be ignored # but to increase performance it is still limited to 500 if max_days_old > 0: max_commit_count = 500 commits = list(connection.repo.iter_commits(branch, max_count = max_commit_count)) info_text = "" # add ahead / behind info if there is a remote branch if gitstuff.remote_exists(branch): info_text = CYAN + "[ " info_text += branch.name info_text += " → " info_text += branch.tracking_branch().name ahead = gitstuff.get_ahead(branch) behind = gitstuff.get_behind(branch) if ahead > 0 or behind > 0: info_text += BOLD if ahead > 0: info_text += " push(" + str(ahead) + ")" if behind > 0: info_text += " pull(" + str(behind) + ")" info_text += RESET # BOLD_OFF info_text += CYAN info_text += " ]" + RESET else: info_text += CYAN + "[ " + branch.name + " ] " + RESET info_text += YELLOW + " <local branch> " + RESET gui.print_header("Commits (" + str(num_commits) + ")", BG_CYAN, info_text) # generate commit arrays commit_arrays = [] for commit in commits: commit_arrays.append(commit_to_string(commit)) # check if all commits are from the same author multi_author = s.always_show_authors if not s.always_show_authors: if len(commit_arrays) > 0: initial_author = commit_arrays[0].author for commit in commit_arrays: if commit.author != initial_author: multi_author = True break # limit all commits to commits newer than max_days_old counter = 0 for commit in commit_arrays: if max_days_old > 0: if utilities.is_date_older_than_days(commit.date, max_days_old): break counter += 1 if counter == 0: print(" < No commits for the last " + str(max_days_old) + " days >") return commit_arrays = commit_arrays[ 0 : counter ] # calculate table max_col_widths = [0, 0, 0] for commit in commit_arrays: max_col_widths[0] = max(max_col_widths[0], len(commit.relative_date + spacing)) max_col_widths[1] = max(max_col_widths[1], len(commit.author + spacing)) max_col_widths[2] = max(max_col_widths[2], len(commit.message + spacing)) # don't show author if all commits are from same author if not multi_author: max_col_widths[1] = 0 # cap message length so there is no line break w = utilities.get_window_size() msg_length = int(w.x) - max_col_widths[0] - max_col_widths[1] # store max needed length for commit before adjusting length for messages max_commit_length = max_col_widths[0] + max_col_widths[1] + max_col_widths[2] - len(spacing) max_commit_length = min(max_commit_length, int(w.x)) max_col_widths[2] = msg_length last_displayed_date = commit_arrays[0].relative_date for commit in commit_arrays: # detect new day if separate_commits and utilities.age_in_days(commit.date) > 0: if last_displayed_date != commit.relative_date: last_displayed_date = commit.relative_date print(CYAN + "-" * max_commit_length + RESET) # actually print commit entries text = CYAN + commit.relative_date.ljust(max_col_widths[0]) + RESET if multi_author: text += GREEN + commit.author.ljust(max_col_widths[1]) + RESET # highlight first word of each message msg = commit.message # [:max_col_widths[2]] if len(msg) > max_col_widths[2]: msg = msg[:max_col_widths[2]-3] + "..." msg = msg.split(" ") msg[0] = BOLD + msg[0] + RESET text += " ".join(msg) print(text)