Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1fa1416

Browse files
committed
Improve visuals of duration counters
Show timers only if category is shown
1 parent fea9fbc commit 1fa1416

6 files changed

Lines changed: 43 additions & 21 deletions

File tree

GitViper.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,37 +38,46 @@
3838

3939
start_time = time.time()
4040

41+
time_separator = "".join(["-"] * int(window_width))
42+
4143
def show_time():
4244
global start_time
43-
if args.show_time:
44-
print("%s seconds" % round(time.time() - start_time, 3))
45-
start_time = time.time()
46-
print("-------------------------------------------------------")
47-
print()
45+
delta_time = str(round(time.time() - start_time, 3))
46+
print(BOLD + BLUE + (delta_time + " seconds ").rjust(int(window_width)) + RESET)
47+
reset_time()
4848

49+
def reset_time():
50+
global start_time
51+
start_time = time.time()
52+
53+
def finalize_category(category_is_visible):
54+
if category_is_visible:
55+
if args.show_time:
56+
show_time()
57+
print(BOLD + BLUE + time_separator + RESET)
58+
print()
59+
else:
60+
print()
61+
else:
62+
reset_time()
4963

5064
try:
5165
if not args.hide_tasks:
52-
gitviper.list_tasks()
53-
54-
show_time()
66+
finalize_category(gitviper.list_tasks())
5567

5668
# git
5769
gitconnector.connect()
5870

5971
if connection.is_git_repo:
6072
if not args.hide_branches:
61-
gitviper.list_branches()
62-
show_time()
73+
finalize_category(gitviper.list_branches())
6374
if not args.hide_logs:
64-
gitviper.list_logs(args.log_number)
65-
show_time()
75+
finalize_category(gitviper.list_logs(args.log_number))
6676
if not args.hide_stash:
67-
gitviper.list_stash()
68-
show_time()
77+
finalize_category(gitviper.list_stash())
6978
if not args.hide_status:
70-
gitviper.list_status()
71-
show_time()
79+
finalize_category(gitviper.list_status())
80+
7281
except KeyboardInterrupt:
7382
print()
7483
except BrokenPipeError: # occurs sometimes after quitting less when big git-logs are displayed

gitviper/branches.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def list_branches():
2121
else:
2222
_list_all_branches()
2323

24-
print()
24+
return True
25+
return False
2526

2627
def should_show_branches():
2728
remotes = connection.repo.remotes

gitviper/log.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
def list_logs(num):
1515
if show_logs():
1616
log(num)
17-
print()
17+
18+
return True
19+
20+
return False
1821

1922
def show_logs():
2023
try:

gitviper/stash.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
def list_stash():
1111
if stash_exists():
1212
print_stash()
13-
print()
13+
14+
return True
15+
16+
return False
1417

1518
def stash_exists():
1619
return len(connection.repo.git.stash("list")) > 0

gitviper/status.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
def list_status():
1212
if connection.repo.is_dirty() or len(connection.repo.untracked_files) > 0:
1313
_list_status()
14-
print()
14+
15+
return True
16+
17+
return False
1518

1619
def _list_status():
1720
gui.print_header("Status", BG_GREEN)

gitviper/tasks.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ def list_tasks():
4545
print(line1)
4646
if len(line2.strip()) > 0:
4747
print(line2)
48+
4849
if len(line1.strip()) > 0 or len(line2.strip()) > 0:
49-
print()
50+
return True
51+
52+
return False
5053

5154
def count_tasks(filename, counter_dict):
5255
with open(filename, 'r') as myfile:

0 commit comments

Comments
 (0)