From 6b8f18331fdfe27b33007c3dd91befbd1b998798 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Fri, 30 Sep 2016 16:14:43 -0700 Subject: [PATCH] Make size a graph Change-Id: I89ee2092d15e6c6fd75bda2a16b104c668078097 --- gertty/palette.py | 5 +++++ gertty/view/change_list.py | 42 ++++++++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/gertty/palette.py b/gertty/palette.py index d9729c6..4d5e81b 100644 --- a/gertty/palette.py +++ b/gertty/palette.py @@ -93,6 +93,11 @@ DEFAULT_PALETTE={ 'focused-held-change': ['light red,standout', ''], 'marked-change': ['dark cyan', ''], 'focused-marked-change': ['dark cyan,standout', ''], + 'added-graph': ['dark green', ''], + 'removed-graph': ['dark red', ''], + 'added-removed-graph': ['dark green', 'dark red'], + 'focused-added-graph': ['default,standout', 'dark green'], + 'focused-removed-graph': ['default,standout', 'dark red'], } # A delta from the default palette diff --git a/gertty/view/change_list.py b/gertty/view/change_list.py index 1c08479..d502513 100644 --- a/gertty/view/change_list.py +++ b/gertty/view/change_list.py @@ -100,6 +100,10 @@ class ChangeRow(urwid.Button, ChangeListColumns): 'negative-label': 'focused-negative-label', 'min-label': 'focused-min-label', 'max-label': 'focused-max-label', + + + 'added-graph': 'focused-added-graph', + 'removed-graph': 'focused-removed-graph', } def selectable(self): @@ -144,6 +148,35 @@ class ChangeRow(urwid.Button, ChangeListColumns): return True return False + def _makeSize(self, added, removed): + # Removed is a red graph on top, added is a green graph on bottom. + # + # The graph is 4 cells wide. If both the red and green graphs + # are in the cell, we set the bg to red, fg to green, and set + # a box in the bottom half of the cell. + # + # If only one of the graphs is in the cell, we set a box in + # either the top or bottom of the cell, and set the fg color + # appropriately. This is so that the reverse-video which + # operates on the line when focused works as expected. + + lower_box = u'\u2584' + upper_box = u'\u2580' + ret = [] + # The graph is logarithmic -- one cell for each order of + # magnitude. + for threshold in [1, 10, 100, 1000]: + color = [] + if (added > threshold and removed > threshold): + ret.append(('added-removed-graph', lower_box)) + elif (added > threshold): + ret.append(('added-graph', lower_box)) + elif (removed > threshold): + ret.append(('removed-graph', upper_box)) + else: + ret.append(' ') + return ret + def update(self, change, categories): if change.reviewed or change.hidden: style = 'reviewed-change' @@ -177,13 +210,14 @@ class ChangeRow(urwid.Button, ChangeListColumns): self.updated.set_text(updated_time.strftime("%I:%M %p").upper()) else: self.updated.set_text(updated_time.strftime("%Y-%m-%d")) - total_added_removed = 0 + total_added = 0 + total_removed = 0 for rfile in change.revisions[-1].files: if rfile.status is None: continue - total_added_removed += rfile.inserted or 0 - total_added_removed += rfile.deleted or 0 - self.size.set_text(str(total_added_removed)) + total_added += rfile.inserted or 0 + total_removed += rfile.deleted or 0 + self.size.set_text(self._makeSize(total_added, total_removed)) self.category_columns = [] for category in categories: