Skip to content
This repository has been archived by the owner on Mar 12, 2019. It is now read-only.

Commit

Permalink
make the column drawing variable to the current size of the terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
nvie committed Jul 17, 2009
1 parent bd6d624 commit 8b2d0ff
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 37 deletions.
39 changes: 27 additions & 12 deletions lib/gitit.py
Expand Up @@ -223,7 +223,7 @@ def progress_bar(self, percentage_done, width = 32):
return '[' + colors.colors['black-on-green'] + format_string_done + \
colors.colors['default'] + format_string_togo + '] %d%%' % \
int(percentage_done * 100)

def list(self, show_types = ['open']):
self.require_itdb()
releasedirs = filter(lambda x: x[1] == 'tree', git.tree(it.ITDB_BRANCH + \
Expand All @@ -232,6 +232,10 @@ def list(self, show_types = ['open']):
print 'no tickets yet. use \'it new\' to add new tickets.'
return

# Get the available terminal drawing space
_, width = os.popen('stty size').read().strip().split()
width = int(width)

print_count = 0
for _, _, sha, rel in releasedirs:
reldir = os.path.join(it.TICKET_DIR, rel)
Expand Down Expand Up @@ -263,24 +267,35 @@ def list(self, show_types = ['open']):

# ...and finally, print them
hide_status = show_types == [ 'open' ]
cols = [ 'id ', \
'type ', \
cols = [ { 'id': 'id', 'width': 7, 'visible': True },
{ 'id': 'type', 'width': 7, 'visible': True },
{ 'id': 'title', 'width': 0, 'visible': True },
{ 'id': 'status', 'width': 8, 'visible': not hide_status },
{ 'id': 'date', 'width': 6, 'visible': True },
{ 'id': 'priority', 'width': 8, 'visible': True },
]
if not hide_status:
cols.append('title ')
cols.append('status ')
else:
cols.append('title ')
cols.append('date ')
cols.append('priority')

# Calculate the real value for the zero-width column
# Assumption here is that there is only 1 zero-width column
visible_colwidths = map(lambda c: c['width'], filter(lambda c: c['visible'], cols))
total_width = sum(visible_colwidths) + len(visible_colwidths) - 1
for col in cols:
if col['width'] == 0:
col['width'] = max(0, width - total_width)

colstrings = []
for col in cols:
if not col['visible']:
continue
colstrings.append(misc.pad_to_length(col['id'], col['width']))

print colors.colors['blue-on-white'] + \
' '.join(cols) + \
' '.join(colstrings) + \
colors.colors['default']

for t in tickets_to_print:
print_count += 1
print t.oneline(status=not hide_status, prio=True)
print t.oneline(cols)

print ''
else:
Expand Down
6 changes: 6 additions & 0 deletions lib/misc.py
Expand Up @@ -7,6 +7,12 @@ def chop(s, maxlen = 20, suffix = ''):
else:
return s

def pad_to_length(s, width):
if width <= len(s):
return s
else:
return s + ' ' * (width - len(s))

def mkdirs(newdir):
return os.system('mkdir -p "%s"' % newdir) == 0

Expand Down
54 changes: 29 additions & 25 deletions lib/ticket.py
Expand Up @@ -148,31 +148,35 @@ def __init__(self):
self.assigned_to = '-'
self.release = 'uncategorized'

def oneline(self, status = False, prio = True):
date = '%s/%s' % (self.date.month, self.date.day)
if status:
subject = '%s%-60s%s' % (colors.colors[self.status_colors[self.status]], misc.chop(self.title, 60, '..'), colors.colors['default'])
else:
subject = '%s%-69s%s' % (colors.colors[self.status_colors[self.status]], misc.chop(self.title, 69, '..'), colors.colors['default'])
status_text = '%s%-8s%s' % (colors.colors[self.status_colors[self.status]], misc.chop(self.status, 8), colors.colors['default'])

# Hide the prio field in case of a closed ticket
if self.status == 'open':
priostr = self.prio_names[self.prio-1]
prio_text = '%s%-8s%s' % (colors.colors[self.prio_colors[priostr]], priostr, colors.colors['default'])
else:
prio_text = '%-8s' % '-'

cols = [ '%-7s' % misc.chop(self.id, 7), \
'%-7s' % misc.chop(self.type, 7), \
subject, \
]
if status:
cols.append(status_text)
cols.append('%-6s' % date)
if prio:
cols.append(prio_text)
return ' '.join(cols)
def oneline(self, cols):
colstrings = []
for col in cols:
if not col['visible']:
continue

w = col['width']
id = col['id']
if id == 'id':
colstrings.append(misc.chop(self.id, w))
elif id == 'type':
colstrings.append(misc.pad_to_length(self.type, w))
elif id == 'date':
colstrings.append(misc.pad_to_length('%s/%s' % (self.date.month, self.date.day), w))
elif id == 'title':
colstrings.append('%s%s%s' % (colors.colors[self.status_colors[self.status]], \
misc.pad_to_length(misc.chop(self.title, w, '..'), w), \
colors.colors['default']))
elif id == 'status':
colstrings.append('%s%s%s' % (colors.colors[self.status_colors[self.status]], \
misc.chop(self.status, 8), \
colors.colors['default']))
elif id == 'priority':
priostr = self.prio_names[self.prio-1]
colstrings.append('%s%s%s' % (colors.colors[self.prio_colors[priostr]], \
priostr, \
colors.colors['default']))

return ' '.join(colstrings)

def __str__(self):
headers = [ 'Subject: %s' % self.title,
Expand Down

0 comments on commit 8b2d0ff

Please sign in to comment.