Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load COL_SCHEMEs from files #163

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions hangups/ui/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sys
import urwid
import readlike
import shlex

import hangups
from hangups.ui.notify import Notifier
Expand Down Expand Up @@ -829,13 +830,40 @@ def main():
default_log_path = os.path.join(dirs.user_log_dir, 'hangups.log')
default_token_path = os.path.join(dirs.user_cache_dir, 'refresh_token.txt')
default_config_path = os.path.join(dirs.user_config_dir, 'hangups.conf')
default_colors_path = os.path.join(dirs.user_config_dir, 'colors')

# Create a default empty config file if does not exist.
dir_maker(default_config_path)
if not os.path.isfile(default_config_path):
with open(default_config_path, 'a') as cfg:
cfg.write("")

# Create empty colors directory if there is none
dir_maker(default_colors_path)

# Read .col files
attributes = {'active_tab', 'inactive_tab', 'msg_date', 'msg_sender', 'msg_text', 'status_line', 'tab_background'}
for root, dirs, files in os.walk(default_colors_path):
for filename in files:
splitName = os.path.splitext(filename)
if splitName[1] == 'col':
obj = []
usedAttrs = []

name = splitName[0]

with open(os.path.join(root, filename), "rt") as f:
for line in f.read().split('\n'):
split = shlex.split(line, comments=True)
if len(split) == 3 and split[0] in attributes:
usedAttrs.append(split[0])
obj.append(tuple(split))

for attr in (attributes - set(usedAttrs)):
obj.append(tuple([attr, '', '']))

COL_SCHEMES[name] = set(obj)

parser = configargparse.ArgumentParser(
prog='hangups', default_config_files=[default_config_path],
formatter_class=configargparse.ArgumentDefaultsHelpFormatter,
Expand Down