add some test coverate, split the defaults into sections and move the borg element to a new base object, converting it to use the new borg __init__ syntax.
This commit is contained in:
parent
90c8b7e8c5
commit
4a96bf99d4
|
@ -17,84 +17,36 @@
|
|||
|
||||
"""Terminator by Chris Jones <cmsj@tenshu.net>
|
||||
|
||||
Classes relating to configuratoin"""
|
||||
Classes relating to configuration
|
||||
|
||||
>>> config = Config()
|
||||
>>> config['focus']
|
||||
'click'
|
||||
>>> config['focus'] = 'sloppy'
|
||||
>>>
|
||||
|
||||
"""
|
||||
|
||||
import platform
|
||||
from borg import Borg
|
||||
|
||||
DEFAULTS = {
|
||||
'gt_dir' : '/apps/gnome-terminal',
|
||||
'profile_dir' : '/apps/gnome-terminal/profiles',
|
||||
'titlebars' : True,
|
||||
'zoomedtitlebar' : True,
|
||||
'allow_bold' : True,
|
||||
'audible_bell' : False,
|
||||
'visible_bell' : True,
|
||||
'urgent_bell' : False,
|
||||
'background_color' : '#000000',
|
||||
'background_darkness' : 0.5,
|
||||
'background_type' : 'solid',
|
||||
'background_image' : '',
|
||||
'backspace_binding' : 'ascii-del',
|
||||
'delete_binding' : 'delete-sequence',
|
||||
'cursor_blink' : True,
|
||||
'cursor_shape' : 'block',
|
||||
'cursor_color' : '',
|
||||
'emulation' : 'xterm',
|
||||
'geometry_hinting' : True,
|
||||
'font' : 'Mono 10',
|
||||
'foreground_color' : '#AAAAAA',
|
||||
'scrollbar_position' : "right",
|
||||
'scroll_background' : True,
|
||||
'scroll_on_keystroke' : True,
|
||||
'scroll_on_output' : True,
|
||||
'scrollback_lines' : 500,
|
||||
'global': {
|
||||
'focus' : 'click',
|
||||
'exit_action' : 'close',
|
||||
'palette' : '#000000000000:#CDCD00000000:#0000CDCD0000:\
|
||||
#CDCDCDCD0000:#30BF30BFA38E:#A53C212FA53C:\
|
||||
#0000CDCDCDCD:#FAFAEBEBD7D7:#404040404040:\
|
||||
#FFFF00000000:#0000FFFF0000:#FFFFFFFF0000:\
|
||||
#00000000FFFF:#FFFF0000FFFF:#0000FFFFFFFF:\
|
||||
#FFFFFFFFFFFF',
|
||||
'word_chars' : '-A-Za-z0-9,./?%&#:_',
|
||||
'mouse_autohide' : True,
|
||||
'update_records' : True,
|
||||
'login_shell' : False,
|
||||
'use_custom_command' : False,
|
||||
'custom_command' : '',
|
||||
'use_system_font' : True,
|
||||
'use_theme_colors' : False,
|
||||
'http_proxy' : '',
|
||||
'ignore_hosts' : ['localhost','127.0.0.0/8','*.local'],
|
||||
'encoding' : 'UTF-8',
|
||||
'active_encodings' : ['UTF-8', 'ISO-8859-1'],
|
||||
'enable_real_transparency' : True,
|
||||
'handle_size' : -1,
|
||||
'geometry_hinting' : True,
|
||||
'fullscreen' : False,
|
||||
'borderless' : False,
|
||||
'maximise' : False,
|
||||
'hidden' : False,
|
||||
'handle_size' : -1,
|
||||
'focus_on_close' : 'auto',
|
||||
'f11_modifier' : False,
|
||||
'force_no_bell' : False,
|
||||
'cycle_term_tab' : True,
|
||||
'copy_on_selection' : False,
|
||||
'close_button_on_tab' : True,
|
||||
'tab_position' : 'top',
|
||||
'enable_real_transparency' : True,
|
||||
'title_tx_txt_color' : '#FFFFFF',
|
||||
'title_tx_bg_color' : '#C80003',
|
||||
'title_rx_txt_color' : '#FFFFFF',
|
||||
'title_rx_bg_color' : '#0076C9',
|
||||
'title_ia_txt_color' : '#000000',
|
||||
'title_ia_bg_color' : '#C0BEBF',
|
||||
'try_posix_regexp' : platform.system() != 'Linux',
|
||||
'close_button_on_tab' : True,
|
||||
'hide_tabbar' : False,
|
||||
'scroll_tabbar' : False,
|
||||
'alternate_screen_scroll': True,
|
||||
'split_to_group' : False,
|
||||
'autoclean_groups' : True,
|
||||
'keybindings' : {
|
||||
'try_posix_regexp' : platform.system() != 'Linux',
|
||||
},
|
||||
'keybindings': {
|
||||
'zoom_in' : '<Ctrl>plus',
|
||||
'zoom_out' : '<Ctrl>minus',
|
||||
'zoom_normal' : '<Ctrl>0',
|
||||
|
@ -143,28 +95,132 @@ DEFAULTS = {
|
|||
'group_tab' : '<Super>t',
|
||||
'ungroup_tab' : '<Super><Shift>T',
|
||||
'new_window' : '<Ctrl><Shift>I',
|
||||
}
|
||||
},
|
||||
'profiles': {
|
||||
'default': {
|
||||
'titlebars' : True,
|
||||
'zoomedtitlebar' : True,
|
||||
'allow_bold' : True,
|
||||
'audible_bell' : False,
|
||||
'visible_bell' : True,
|
||||
'urgent_bell' : False,
|
||||
'background_color' : '#000000',
|
||||
'background_darkness' : 0.5,
|
||||
'background_type' : 'solid',
|
||||
'background_image' : '',
|
||||
'backspace_binding' : 'ascii-del',
|
||||
'delete_binding' : 'delete-sequence',
|
||||
'cursor_blink' : True,
|
||||
'cursor_shape' : 'block',
|
||||
'cursor_color' : '',
|
||||
'emulation' : 'xterm',
|
||||
'font' : 'Mono 10',
|
||||
'foreground_color' : '#AAAAAA',
|
||||
'scrollbar_position' : "right",
|
||||
'scroll_background' : True,
|
||||
'scroll_on_keystroke' : True,
|
||||
'scroll_on_output' : True,
|
||||
'scrollback_lines' : 500,
|
||||
'exit_action' : 'close',
|
||||
'palette' :'#000000000000:#CDCD00000000:#0000CDCD0000:\
|
||||
#CDCDCDCD0000:#30BF30BFA38E:#A53C212FA53C:\
|
||||
#0000CDCDCDCD:#FAFAEBEBD7D7:#404040404040:\
|
||||
#FFFF00000000:#0000FFFF0000:#FFFFFFFF0000:\
|
||||
#00000000FFFF:#FFFF0000FFFF:#0000FFFFFFFF:\
|
||||
#FFFFFFFFFFFF',
|
||||
'word_chars' : '-A-Za-z0-9,./?%&#:_',
|
||||
'mouse_autohide' : True,
|
||||
'update_records' : True,
|
||||
'login_shell' : False,
|
||||
'use_custom_command' : False,
|
||||
'custom_command' : '',
|
||||
'use_system_font' : True,
|
||||
'use_theme_colors' : False,
|
||||
'encoding' : 'UTF-8',
|
||||
'active_encodings' : ['UTF-8', 'ISO-8859-1'],
|
||||
'focus_on_close' : 'auto',
|
||||
'force_no_bell' : False,
|
||||
'cycle_term_tab' : True,
|
||||
'copy_on_selection' : False,
|
||||
'title_tx_txt_color' : '#FFFFFF',
|
||||
'title_tx_bg_color' : '#C80003',
|
||||
'title_rx_txt_color' : '#FFFFFF',
|
||||
'title_rx_bg_color' : '#0076C9',
|
||||
'title_ia_txt_color' : '#000000',
|
||||
'title_ia_bg_color' : '#C0BEBF',
|
||||
'alternate_screen_scroll': True,
|
||||
'split_to_group' : False,
|
||||
'autoclean_groups' : True,
|
||||
'http_proxy' : '',
|
||||
'ignore_hosts' : ['localhost','127.0.0.0/8','*.local'],
|
||||
},
|
||||
},
|
||||
'layout': {
|
||||
},
|
||||
'plugins': {
|
||||
},
|
||||
}
|
||||
|
||||
class Config(Borg, dict):
|
||||
"""Class to provide access to our user configuration"""
|
||||
class Config(object):
|
||||
"""Class to provide a slightly richer config API above ConfigBase"""
|
||||
base = None
|
||||
profile = None
|
||||
|
||||
defaults = None
|
||||
def __init__(self, profile='default'):
|
||||
self.base = ConfigBase()
|
||||
self.profile = profile
|
||||
|
||||
def __getitem__(self, key):
|
||||
"""Look up a configuration item"""
|
||||
return(self.base.get_item(key, self.profile))
|
||||
|
||||
class ConfigBase(Borg, dict):
|
||||
"""Class to provide access to our user configuration"""
|
||||
global_config = None
|
||||
profiles = None
|
||||
keybindings = None
|
||||
plugins = None
|
||||
|
||||
def __init__(self):
|
||||
"""Class initialiser"""
|
||||
|
||||
Borg.__init__(self)
|
||||
Borg.__init__(self, self.__class__.__name__)
|
||||
dict.__init__(self)
|
||||
|
||||
self.prepare_attributes()
|
||||
self.load_config()
|
||||
|
||||
def prepare_attributes(self):
|
||||
"""Set up our borg environment"""
|
||||
if self.defaults is None:
|
||||
self.defaults = DEFAULTS
|
||||
if self.global_config is None:
|
||||
self.global_config = DEFAULTS['global']
|
||||
if self.profiles is None:
|
||||
self.profiles = {}
|
||||
self.profiles['default'] = DEFAULTS['profiles']['default']
|
||||
if self.keybindings is None:
|
||||
self.keybindings = DEFAULTS['keybindings']
|
||||
if self.plugins is None:
|
||||
self.plugins = {}
|
||||
|
||||
def __getitem__(self, key):
|
||||
def load_config(self):
|
||||
"""Load configuration data from our various sources"""
|
||||
# FIXME: Load our config from wherever and merge it into the defaults
|
||||
pass
|
||||
|
||||
def get_item(self, key, profile='default', plugin=None):
|
||||
"""Look up a configuration item"""
|
||||
return(self.defaults[key])
|
||||
if self.global_config.has_key(key):
|
||||
return(self.global_config[key])
|
||||
elif self.profiles['default'].has_key(key):
|
||||
return(self.profiles[profile][key])
|
||||
elif key == 'keybindings':
|
||||
return(self.keybindings)
|
||||
elif plugin is not None and self.plugins[plugin].has_key(key):
|
||||
return(self.plugins[plugin][key])
|
||||
else:
|
||||
raise KeyError('ConfigBase::get_item: unknown key %s' % key)
|
||||
|
||||
if __name__ == '__main__':
|
||||
import doctest
|
||||
(failed, attempted) = doctest.testmod()
|
||||
print "%d/%d tests failed" % (failed, attempted)
|
||||
|
|
Loading…
Reference in New Issue