diff options
Diffstat (limited to 'alot')
-rw-r--r-- | alot/defaults/alot.rc | 19 | ||||
-rw-r--r-- | alot/settings.py | 65 |
2 files changed, 60 insertions, 24 deletions
diff --git a/alot/defaults/alot.rc b/alot/defaults/alot.rc index bd53960e..fe55fdbd 100644 --- a/alot/defaults/alot.rc +++ b/alot/defaults/alot.rc @@ -229,15 +229,11 @@ bufferlist_results_odd_bg = default bufferlist_results_odd_fg = default search_thread_authors_bg = default search_thread_authors_fg = #6d6 -search_thread_authors_unread_bg = default search_thread_authors_unread_fg = #6d6,bold -search_thread_authors_flagged_bg = default search_thread_authors_flagged_fg = light red,bold search_thread_authors_focus_bg = #68a search_thread_authors_focus_fg = #8f6 -search_thread_authors_focus_unread_bg = #68a search_thread_authors_focus_unread_fg = #8f6,bold -search_thread_authors_focus_flagged_bg = #68a search_thread_authors_focus_flagged_fg = light red search_thread_bg = default search_thread_content_bg = default @@ -265,15 +261,11 @@ search_thread_mailcount_focus_flagged_bg = #68a search_thread_mailcount_focus_flagged_fg = light red search_thread_subject_bg = default search_thread_subject_fg = g58 -search_thread_subject_unread_bg = default search_thread_subject_unread_fg = g58,bold -search_thread_subject_flagged_bg = default search_thread_subject_flagged_fg = light red search_thread_subject_focus_bg = #68a search_thread_subject_focus_fg = g89 -search_thread_subject_focus_unread_bg = #68a search_thread_subject_focus_unread_fg = g89,bold -search_thread_subject_focus_flagged_bg = #68a search_thread_subject_focus_flagged_fg = light red,bold search_thread_tags_bg = default search_thread_tags_fg = #a86 @@ -346,16 +338,9 @@ thread_summary_odd_bg = dark blue thread_summary_odd_fg = white search_thread_authors_bg = default search_thread_authors_fg = dark green -search_thread_authors_unread_bg = default search_thread_authors_unread_fg = dark green,bold -search_thread_authors_flagged_bg = default -search_thread_authors_flagged_fg = dark green search_thread_authors_focus_bg = dark gray search_thread_authors_focus_fg = dark green,bold -search_thread_authors_focus_unread_bg = dark gray -search_thread_authors_focus_unread_fg = dark green,bold -search_thread_authors_focus_flagged_bg = dark gray -search_thread_authors_focus_flagged_fg = dark green,bold search_thread_bg = default search_thread_content_bg = default search_thread_content_fg = dark gray @@ -374,15 +359,11 @@ search_thread_mailcount_focus_bg = dark gray search_thread_mailcount_focus_fg = light gray search_thread_subject_bg = default search_thread_subject_fg = light gray -search_thread_subject_unread_bg = default search_thread_subject_unread_fg = light gray,bold -search_thread_subject_flagged_bg = default search_thread_subject_flagged_fg = light red search_thread_subject_focus_bg = dark gray search_thread_subject_focus_fg = light gray -search_thread_subject_focus_unread_bg = dark gray search_thread_subject_focus_unread_fg = light gray,bold -search_thread_subject_focus_flagged_bg = dark gray search_thread_subject_focus_flagged_fg = light red,bold search_thread_tags_bg = default search_thread_tags_fg = brown diff --git a/alot/settings.py b/alot/settings.py index 38a88c0e..b9b410ce 100644 --- a/alot/settings.py +++ b/alot/settings.py @@ -1,5 +1,6 @@ import imp import os +import re import ast import mailcap import codecs @@ -93,11 +94,11 @@ class AlotConfigParser(FallbackConfigParser): names = set([s[:-3] for s in names]) p = list() for attr in names: - nf = self.get('16c-theme', attr + '_fg', fallback='default') - nb = self.get('16c-theme', attr + '_bg', fallback='default') - m = self.get('1c-theme', attr, fallback='default') - hf = self.get('256c-theme', attr + '_fg', fallback='default') - hb = self.get('256c-theme', attr + '_bg', fallback='default') + nf = self.__get_themeing_option('16c-theme', attr + '_fg') + nb = self.__get_themeing_option('16c-theme', attr + '_bg') + m = self.__get_themeing_option('1c-theme', attr) + hf = self.__get_themeing_option('256c-theme', attr + '_fg') + hb = self.__get_themeing_option('256c-theme', attr + '_bg') p.append((attr, nf, nb, m, hf, hb)) if attr.startswith('tag_') and attr + '_focus' not in names: nb = self.get('16c-theme', 'tag_focus_bg', @@ -107,6 +108,60 @@ class AlotConfigParser(FallbackConfigParser): p.append((attr + '_focus', nf, nb, m, hf, hb)) return p + def __get_themeing_option(self, section, option, default='default'): + """ + Retrieve the value of the given option from the given section of the config + file. + + If the option does not exist, try its parent options before falling back to + the specified default. The parent of an option is the name of the option + itself minus the last section enclosed in underscores; so the parent of the + option `aaa_bbb_ccc_fg` is of the form `aaa_bbb_fg`. + + :param section: the section of the config file to search for the given + option + :type section: string + :param option: the option to lookup + :type option: string + :param default: the value that is to be returned if neither the requested + option nor a parent exists + :type default: string + :return: the value of the given option, or the specified default + :rtype: string + """ + result = '' + parent_option_re = '(.+)_[^_]+_(fg|bg)' + if self.has_option(section, option): + result = self.get(section, option) + else: + has_parent_option = re.search(parent_option_re, option) + if has_parent_option: + parent_option = '{0}_{1}'.format(has_parent_option.group(1), + has_parent_option.group(2)) + result = self.__get_themeing_option(section, parent_option) + else: + result = default + return result + + def has_themeing(self, themeing): + """ + Return true if the given themeing option exists in the current colour + theme. + + :param themeing: The themeing option to check for + :type theming: string + :return: True if themeing exist, False otherwise + :rtype: bool + """ + mode = self.getint('general', 'colourmode') + if mode == 2: + theme = '1c-theme' + else: + theme = '{colours}c-theme'.format(colours=mode) + has_fg = self.has_option(theme, themeing + '_fg') + has_bg = self.has_option(theme, themeing + '_bg') + return (has_fg or has_bg) + def get_tagattr(self, tag, focus=False): """ look up attribute string to use for a given tagstring |