Load config files and modules in core

This commit is contained in:
Kim Silkebækken 2012-12-10 13:19:45 +01:00
parent 157fff0834
commit 3e949adb39
5 changed files with 59 additions and 16 deletions

View File

@ -1,5 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
class Colorscheme(object):
def __init__(self, colorscheme):
pass
cterm_to_hex = { cterm_to_hex = {
16: 0x000000, 17: 0x00005f, 18: 0x000087, 19: 0x0000af, 20: 0x0000d7, 21: 0x0000ff, 16: 0x000000, 17: 0x00005f, 18: 0x000087, 19: 0x0000af, 20: 0x0000d7, 21: 0x0000ff,
22: 0x005f00, 23: 0x005f5f, 24: 0x005f87, 25: 0x005faf, 26: 0x005fd7, 27: 0x005fff, 22: 0x005f00, 23: 0x005f5f, 24: 0x005f87, 25: 0x005faf, 26: 0x005fd7, 27: 0x005fff,

View File

@ -1,17 +1,50 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import importlib
import json
import os
import sys
from colorscheme import Colorscheme
from theme import Theme
class Powerline(object): class Powerline(object):
def __init__(self, segments): def __init__(self, ext):
'''Create a new Powerline. try:
config_home = os.environ['XDG_CONFIG_HOME']
except KeyError:
config_home = os.path.expanduser('~/.config')
Segments that aren't filler segments and whose contents aren't None are config_path = os.path.join(config_home, 'powerline')
dropped from the segment array. plugin_path = os.path.realpath(os.path.dirname(__file__))
''' self.search_paths = [config_path, plugin_path]
self.renderer = None # FIXME This should be assigned here based on the current configuration
self.segments = [segment for segment in segments if segment['contents'] is not None or segment['filler']]
def render(self, renderer, width=None): sys.path[:0] = self.search_paths
self.renderer = renderer(self.segments)
return self.renderer.render(width) # Load main config file, limited to the current extension
self.config = self._load_json_config('config')[ext]
# Load and initialize colorscheme
colorscheme_config = self._load_json_config(os.path.join('colorschemes', self.config['colorscheme']))
self.colorscheme = Colorscheme(colorscheme_config)
# Load and initialize extension theme
theme_config = self._load_json_config(os.path.join('themes', ext, self.config['theme']))
self.theme = Theme(ext, theme_config)
# Load and initialize extension renderer
renderer_module_name = 'powerline.ext.{0}.renderer'.format(ext)
renderer_class_name = '{0}Renderer'.format(ext.capitalize())
renderer_class = getattr(importlib.import_module(renderer_module_name), renderer_class_name)
self.renderer = renderer_class(self.colorscheme, self.theme)
def _load_json_config(self, config_file):
config_file += '.json'
for path in self.search_paths:
config_file_path = os.path.join(path, config_file)
if os.path.isfile(config_file_path):
with open(config_file_path, 'rb') as config_file_fp:
return json.load(config_file_fp)
raise IOError('Config file not found in search path: {0}'.format(config_file))

View File

@ -6,8 +6,8 @@ from powerline.renderer import Renderer
class VimRenderer(Renderer): class VimRenderer(Renderer):
'''Powerline vim segment renderer. '''Powerline vim segment renderer.
''' '''
def __init__(self, segments): def __init__(self, colorscheme, theme):
super(VimRenderer, self).__init__(segments) super(VimRenderer, self).__init__(colorscheme, theme)
self.hl_groups = {} self.hl_groups = {}
def hl(self, fg=None, bg=None, attr=None): def hl(self, fg=None, bg=None, attr=None):

View File

@ -19,11 +19,11 @@ class Renderer(object):
}, },
} }
def __init__(self, segments):
self.segments = segments
self._hl = {}
def render(self, width=None): def __init__(self, colorscheme, theme):
pass
def render(self, mode, width=None):
'''Render all the segments with the specified renderer. '''Render all the segments with the specified renderer.
This method loops through the segment array and compares the This method loops through the segment array and compares the

View File

@ -1 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
class Theme(object):
def __init__(self, ext, theme):
pass