[core/theme] slight improvements for clarity
This commit is contained in:
parent
99a6a11e3a
commit
1cab99175b
2 changed files with 13 additions and 13 deletions
|
@ -52,26 +52,27 @@ class Theme(object):
|
|||
if isinstance(name, dict): return name # support plain data
|
||||
for path in PATHS:
|
||||
theme_file = os.path.join(path, subdir, '{}.json'.format(name))
|
||||
if os.path.isfile(theme_file):
|
||||
with io.open(theme_file, encoding='utf-8') as data:
|
||||
return json.load(data)
|
||||
result = self.__load_json(theme_file)
|
||||
if result != {}: return result
|
||||
raise RuntimeError('unable to find theme {}'.format(name))
|
||||
|
||||
def __load(self, filename, sections):
|
||||
result = {}
|
||||
with io.open(os.path.expanduser(filename)) as data:
|
||||
colors = json.load(data)
|
||||
for field in sections:
|
||||
for key in colors.get(field, []):
|
||||
result[key] = colors[field][key]
|
||||
return result
|
||||
def __load_json(self, filename):
|
||||
filename = os.path.expanduser(filename)
|
||||
if not os.path.isfile(filename): return {}
|
||||
with io.open(filename) as data:
|
||||
return json.load(data)
|
||||
|
||||
def load_keywords(self, name):
|
||||
try:
|
||||
if isinstance(name, dict):
|
||||
return name
|
||||
if name.lower() == 'wal':
|
||||
return self.__load('~/.cache/wal/colors.json', ['special', 'colors'])
|
||||
wal = self.__load_json('~/.cache/wal/colors.json')
|
||||
result = {}
|
||||
for field in ['special', 'colors']:
|
||||
for key in wal.get(field, {}):
|
||||
result[key] = wal[field][key]
|
||||
return result
|
||||
except Exception as e:
|
||||
log.error('failed to load colors: {}', e)
|
||||
|
||||
|
|
|
@ -28,6 +28,5 @@
|
|||
- github pages
|
||||
|
||||
## TODO
|
||||
- theme: `load` vs. `__load` vs. `load_keywords`
|
||||
- themes: use colors to improve theme readability
|
||||
- brightness: read from CLI tools
|
||||
|
|
Loading…
Reference in a new issue