"""
Load config from filepath
"""
- try:
- with open(filepath) as f:
- content = ''.join(f.readlines())
+ with open(filepath) as f:
+ content = ''.join(f.readlines())
+ match = comment_re.search(content)
+ while match:
+ content = content[:match.start()] + content[match.end():]
match = comment_re.search(content)
- while match:
- content = content[:match.start()] + content[match.end():]
- match = comment_re.search(content)
- return json.loads(content)
- except IOError:
- return None
+ return json.loads(content)
# Load default colorset
c = {}
default_config = 'rainbowstream/colorset/default.json'
data = load_config(default_config)
-if data:
- for d in data:
- c[d] = data[d]
-db.theme_store('default')
+for d in data:
+ c[d] = data[d]
+c['theme'] = 'default'
# Load user's colorset
rainbow_config = os.environ.get(
'HOME',
os.environ.get(
'USERPROFILE',
'')) + os.sep + '.rainbow_config.json'
-data = load_config(rainbow_config)
-if data:
+try:
+ data = load_config(rainbow_config)
for d in data:
c[d] = data[d]
- db.theme_update('user')
+ c['theme'] = 'custom'
+except:
+ pass
from .db import *
db = RainbowDB()
-cur_theme = None
def check_theme():
"""
"""
exists = db.theme_query()
themes = [t.theme_name for t in exists]
- if cur_theme != themes[0]:
- cur_theme = themes[0]
+ if c['theme'] != themes[0]:
+ c['theme'] = themes[0]
# Determine path
- if cur_theme == 'user':
+ if c['theme'] == 'custom':
config = os.environ.get(
'HOME',
os.environ.get(
'USERPROFILE',
'')) + os.sep + '.rainbow_config.json'
else:
- config = 'rainbowstream/colorset/'+cur_theme+'.json'
+ config = 'rainbowstream/colorset/'+c['theme']+'.json'
# Load new config
data = load_config(config)
if data:
files = os.listdir('rainbowstream/colorset')
themes = [f.split('.')[0] for f in files if f.split('.')[-1] == 'json']
- themes += ['user']
g['themes'] = themes
+ db.theme_store(c['theme'])
def switch():
"""
if not g['stuff']:
# List themes
- line = ' ' * 2 + light_yellow('* ')
for theme in g['themes']:
+ line = ''
# Detect custom config
- if theme == 'user':
+ if theme == 'custom':
line += light_magenta('custom')
exists = db.theme_query()
themes = [t.theme_name for t in exists]
- if themes[0] == 'user':
+ if themes[0] == 'custom':
line += light_magenta(' (applied)')
else:
line += light_magenta(' (not specified)')
else:
line += light_magenta(theme)
+ if c['theme'] == theme :
+ line = ' '*2 + light_yellow('* ') + line
+ else:
+ line = ' '*4 + line
printNicely(line)
else:
# Change theme
for nc in new_config:
c[nc] = new_config[nc]
# Update db
- theme_update(g['stuff'])
+ db.theme_update(g['stuff'])
g['decorated_name'] = color_func(
c['DECORATED_NAME'])(
'[@' + g['original_name'] + ']: ')