Skip to content

Commit

Permalink
Support bold_for_light_color in khal, minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
black committed Jan 12, 2016
1 parent a6a106a commit a39ffed
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 24 deletions.
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ Dominik Joe Pantůček - joe [at] joe [dot] cz - http://joe.cz/
Thomas Schaper - libreman [at] libremail [dot] nl
Oliver Kiddle - okiddle [at] yahoo [dot] co [dot] uk
Filip Pytloun - filip [at] pytloun [dot] cz - https://fpy.cz
Sebastian Hamann
25 changes: 14 additions & 11 deletions khal/calendar_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_event_color(event, default_color):
return event.color


def str_highlight_day(day, devents, hmethod, default_color, multiple, color):
def str_highlight_day(day, devents, hmethod, default_color, multiple, color, bold_for_light_color):
"""returns a string with day highlighted according to configuration
"""
dstr = str(day.day).rjust(2)
Expand All @@ -75,11 +75,13 @@ def str_highlight_day(day, devents, hmethod, default_color, multiple, color):
if len(dcolors) > 1:
if multiple == '':
if hmethod == "foreground" or hmethod == "fg":
return colored(dstr[:1], fg=dcolors[0]) + \
colored(dstr[1:], fg=dcolors[1])
return colored(dstr[:1], fg=dcolors[0],
bold_for_light_color=bold_for_light_color) + \
colored(dstr[1:], fg=dcolors[1], bold_for_light_color=bold_for_light_color)
else:
return colored(dstr[:1], bg=dcolors[0]) + \
colored(dstr[1:], bg=dcolors[1])
return colored(dstr[:1], bg=dcolors[0],
bold_for_light_color=bold_for_light_color) + \
colored(dstr[1:], bg=dcolors[1], bold_for_light_color=bold_for_light_color)
else:
dcolor = multiple
else:
Expand All @@ -91,15 +93,15 @@ def str_highlight_day(day, devents, hmethod, default_color, multiple, color):
dcolor = color
if dcolor != '':
if hmethod == "foreground" or hmethod == "fg":
return colored(dstr, fg=dcolor)
return colored(dstr, fg=dcolor, bold_for_light_color=bold_for_light_color)
else:
return colored(dstr, bg=dcolor)
return colored(dstr, bg=dcolor, bold_for_light_color=bold_for_light_color)
return dstr


def str_week(week, today, collection=None,
hmethod=None, default_color=None, multiple=None, color=None,
highlight_event_days=False, locale=None):
highlight_event_days=False, locale=None, bold_for_light_color=True):
"""returns a string representing one week,
if for day == today colour is reversed
Expand All @@ -119,7 +121,7 @@ def str_week(week, today, collection=None,
devents = list(collection.get_events_on(day))
if len(devents) > 0:
day = str_highlight_day(day, devents, hmethod, default_color,
multiple, color)
multiple, color, bold_for_light_color)
else:
day = str(day.day).rjust(2)
else:
Expand All @@ -140,7 +142,8 @@ def vertical_month(month=datetime.date.today().month,
multiple='',
color='',
highlight_event_days=False,
locale=None):
locale=None,
bold_for_light_color=True):
"""
returns a list() of str() of weeks for a vertical arranged calendar
Expand Down Expand Up @@ -172,7 +175,7 @@ def vertical_month(month=datetime.date.today().month,
for week in _calendar.monthdatescalendar(year, month):
new_month = len([day for day in week if day.day == 1])
strweek = str_week(week, today, collection, hmethod, default_color,
multiple, color, highlight_event_days, locale)
multiple, color, highlight_event_days, locale, bold_for_light_color)
if new_month:
m_name = style(month_abbr(week[6].month).ljust(4), bold=True)
elif weeknumber == 'left':
Expand Down
16 changes: 13 additions & 3 deletions khal/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ def calendar(ctx, days, events, dates, full=False):
multiple=ctx.obj['conf']['highlight_days']['multiple'],
color=ctx.obj['conf']['highlight_days']['color'],
highlight_event_days=ctx.obj['conf']['default']['highlight_event_days'],
full=full
full=full,
bold_for_light_color=ctx.obj['conf']['view']['bold_for_light_color']
)

@cli.command()
Expand All @@ -273,6 +274,7 @@ def agenda(ctx, days, events, dates, full=False):
days=days or ctx.obj['conf']['default']['days'],
events=events,
full=full,
bold_for_light_color=ctx.obj['conf']['view']['bold_for_light_color']
)

@cli.command()
Expand Down Expand Up @@ -399,7 +401,11 @@ def search(ctx, search_string):
term_width, _ = get_terminal_size()
for event in events:
desc = textwrap.wrap(event.event_description, term_width)
event_column.extend([colored(d, event.color) for d in desc])
event_column.extend(
[colored(d, event.color,
bold_for_light_color=ctx.obj['conf']['view']['bold_for_light_color'])
for d in desc]
)
click.echo(
'\n'.join(event_column).encode(ctx.obj['conf']['locale']['encoding'])
)
Expand Down Expand Up @@ -443,7 +449,11 @@ def at(ctx, datetime=None):
items = event.event_description.splitlines()
for item in items:
lines += textwrap.wrap(item, term_width)
event_column.extend([colored(line, event.color) for line in lines])
event_column.extend(
[colored(line, event.color,
bold_for_light_color=ctx.obj['conf']['view']['bold_for_light_color'])
for line in lines]
)
click.echo(
'\n'.join(event_column).encode(ctx.obj['conf']['locale']['encoding'])
)
Expand Down
22 changes: 15 additions & 7 deletions khal/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def construct_daynames(daylist, longdateformat):
yield (date, date.strftime(longdateformat))


def get_agenda(collection, locale, dates=None, firstweekday=0,
days=None, events=None, width=45, full=False, show_all_days=False):
def get_agenda(collection, locale, dates=None, firstweekday=0, days=None, events=None, width=45,
full=False, show_all_days=False, bold_for_light_color=True):
"""returns a list of events scheduled for all days in daylist
included are header "rows"
Expand Down Expand Up @@ -112,7 +112,10 @@ def get_agenda(collection, locale, dates=None, firstweekday=0,
items = event.relative_to(day, full).splitlines()
for item in items:
lines += textwrap.wrap(item, width)
event_column.extend([colored(line, event.color) for line in lines])
event_column.extend(
[colored(line, event.color, bold_for_light_color=bold_for_light_color)
for line in lines]
)

if event_column == []:
event_column = [style('No events', bold=True)]
Expand All @@ -127,6 +130,7 @@ def calendar(collection, date=None, firstweekday=0, encoding='utf-8', locale=Non
color='',
highlight_event_days=0,
full=False,
bold_for_light_color=True,
**kwargs):
if date is None:
date = [datetime.datetime.today()]
Expand All @@ -136,7 +140,8 @@ def calendar(collection, date=None, firstweekday=0, encoding='utf-8', locale=Non
rwidth = term_width - lwidth - 4
event_column = get_agenda(
collection, locale, dates=date, width=rwidth,
show_all_days=show_all_days, full=full, **kwargs)
show_all_days=show_all_days, full=full, bold_for_light_color=bold_for_light_color,
**kwargs)
calendar_column = calendar_display.vertical_month(
firstweekday=firstweekday, weeknumber=weeknumber,
collection=collection,
Expand All @@ -145,17 +150,20 @@ def calendar(collection, date=None, firstweekday=0, encoding='utf-8', locale=Non
multiple=multiple,
color=color,
highlight_event_days=highlight_event_days,
locale=locale)
locale=locale,
bold_for_light_color=bold_for_light_color)
rows = merge_columns(calendar_column, event_column)
# XXX: Generate this as a unicode in the first place, rather than
# casting it.
echo('\n'.join(rows).encode(encoding))


def agenda(collection, date=None, encoding='utf-8', show_all_days=False, full=False, **kwargs):
def agenda(collection, date=None, encoding='utf-8', show_all_days=False, full=False,
bold_for_light_color=True, **kwargs):
term_width, _ = get_terminal_size()
event_column = get_agenda(collection, dates=date, width=term_width,
show_all_days=show_all_days, full=full, **kwargs)
show_all_days=show_all_days, full=full,
bold_for_light_color=bold_for_light_color, **kwargs)
# XXX: Generate this as a unicode in the first place, rather than
# casting it.
echo('\n'.join(event_column))
Expand Down
3 changes: 1 addition & 2 deletions khal/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ def get_terminal_size():
}


def colored(string, fg=None, bg=None):
bold_for_light_color = True # FIXME: this should be a config option
def colored(string, fg=None, bg=None, bold_for_light_color=True):
result = ''
for colorstring, is_bg in ((fg, False), (bg, True)):
if colorstring:
Expand Down
2 changes: 1 addition & 1 deletion khal/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ def _urwid_palette_entry(name, color, hmethod):
color = 'h' + str(best)
# We unconditionally add the color to the high color slot. It seems to work
# in lower color terminals as well.
if hmethod == 'fg' or hmethod == 'foreground':
if hmethod in ['fg', 'foreground']:
return (name, '', '', '', color, '')
else:
return (name, '', '', '', '', color)
Expand Down

0 comments on commit a39ffed

Please sign in to comment.