[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
|
if isinstance(name, dict): return name # support plain data
|
||||||
for path in PATHS:
|
for path in PATHS:
|
||||||
theme_file = os.path.join(path, subdir, '{}.json'.format(name))
|
theme_file = os.path.join(path, subdir, '{}.json'.format(name))
|
||||||
if os.path.isfile(theme_file):
|
result = self.__load_json(theme_file)
|
||||||
with io.open(theme_file, encoding='utf-8') as data:
|
if result != {}: return result
|
||||||
return json.load(data)
|
|
||||||
raise RuntimeError('unable to find theme {}'.format(name))
|
raise RuntimeError('unable to find theme {}'.format(name))
|
||||||
|
|
||||||
def __load(self, filename, sections):
|
def __load_json(self, filename):
|
||||||
result = {}
|
filename = os.path.expanduser(filename)
|
||||||
with io.open(os.path.expanduser(filename)) as data:
|
if not os.path.isfile(filename): return {}
|
||||||
colors = json.load(data)
|
with io.open(filename) as data:
|
||||||
for field in sections:
|
return json.load(data)
|
||||||
for key in colors.get(field, []):
|
|
||||||
result[key] = colors[field][key]
|
|
||||||
return result
|
|
||||||
|
|
||||||
def load_keywords(self, name):
|
def load_keywords(self, name):
|
||||||
try:
|
try:
|
||||||
if isinstance(name, dict):
|
if isinstance(name, dict):
|
||||||
return name
|
return name
|
||||||
if name.lower() == 'wal':
|
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:
|
except Exception as e:
|
||||||
log.error('failed to load colors: {}', e)
|
log.error('failed to load colors: {}', e)
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,5 @@
|
||||||
- github pages
|
- github pages
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
- theme: `load` vs. `__load` vs. `load_keywords`
|
|
||||||
- themes: use colors to improve theme readability
|
- themes: use colors to improve theme readability
|
||||||
- brightness: read from CLI tools
|
- brightness: read from CLI tools
|
||||||
|
|
Loading…
Reference in a new issue