Improve commit show

remotes/origin/master
Сергей Маринкевич 4 years ago
parent 727130cf90
commit 54a31c4a7a

@ -16,7 +16,7 @@ class Commit(object):
self.hash = match.group("hash") self.hash = match.group("hash")
self.title = match.group("title") self.title = match.group("title")
process = subprocess.Popen(["git", "log", "--oneline"], stdout=subprocess.PIPE, stderr=open('/dev/null', 'w')) process = subprocess.Popen(["git", "--no-pager", "log", "--decorate=short", "--oneline"], stdout=subprocess.PIPE, stderr=open('/dev/null', 'w'))
commits = [] commits = []
for part in process.communicate(): for part in process.communicate():
if part == None: if part == None:
@ -46,7 +46,9 @@ max_y, max_x = maxcoords[0], maxcoords[1]
def show_commit(commit): def show_commit(commit):
os.system(f"git show {commit.hash}") stdscr.erase()
stdscr.refresh()
os.system(f"LESS='RSX' git show {commit.hash}")
pad = curses.newpad(len(commits), max_x) pad = curses.newpad(len(commits), max_x)
@ -54,12 +56,13 @@ pad = curses.newpad(len(commits), max_x)
def print_commit(commit, pos_y, selected): def print_commit(commit, pos_y, selected):
pad.addstr(pos_y, 0, " " * (max_x - 1)) pad.addstr(pos_y, 0, " " * (max_x - 1))
cut_to = max_x - 3 - len(commit.hash)
if selected: if selected:
pad.addstr(pos_y, 0, f"{commit.hash}", curses.color_pair(1)) pad.addstr(pos_y, 0, f"{commit.hash}", curses.color_pair(1))
pad.addstr(pos_y, len(commit.hash) + 2, f"{commit.title}", curses.color_pair(1)) pad.addstr(pos_y, len(commit.hash) + 2, f"{commit.title[:cut_to]}", curses.color_pair(1))
else: else:
pad.addstr(pos_y, 0, f"{commit.hash}", curses.color_pair(2)) pad.addstr(pos_y, 0, f"{commit.hash}", curses.color_pair(2))
pad.addstr(pos_y, len(commit.hash) + 2, f"{commit.title}") pad.addstr(pos_y, len(commit.hash) + 2, f"{commit.title[:cut_to]}")
print_commit(commits[0], 0, True) print_commit(commits[0], 0, True)

Loading…
Cancel
Save