提交 36e788f2 编写于 作者: N Nicolargo

Allow theme to be set in configuration file #862

上级 53de48d0
......@@ -11,7 +11,8 @@ Enhancements and new features:
* Improve IP plugin to display public IP address (issue #646)
* CPU additionnal stats monitoring: Context switch, Interrupts... (issue #810)
* [Folders] Differentiate permission issue and non-existence of a directory (issue #828)
* [Web UI] add cpu name in quicklook plugin (issue #825)
* [Web UI] Add cpu name in quicklook plugin (issue #825)
* Allow theme to be set in configuration file (issue #862)
Bugs corrected:
......
##############################################################################
# User interface
##############################################################################
[outputs]
# Theme name for the Curses interface: black or white
curse_theme=black
##############################################################################
# plugins
##############################################################################
......
......@@ -155,7 +155,7 @@ class GlancesClient(object):
self.stats.load_limits(self.config)
# Init screen
self.screen = GlancesCursesClient(args=self.args)
self.screen = GlancesCursesClient(config=self.config, args=self.args)
# Return result
return ret
......
......@@ -51,8 +51,9 @@ class _GlancesCurses(object):
Note: It is a private class, use GlancesCursesClient or GlancesCursesBrowser.
"""
def __init__(self, args=None):
# Init args
def __init__(self, config=None, args=None):
# Init
self.config = config
self.args = args
# Init windows positions
......@@ -69,6 +70,11 @@ class _GlancesCurses(object):
logger.critical("Cannot init the curses library.\n")
sys.exit(1)
# Load the 'outputs' section of the configuration file
# - Init the theme (default is black)
self.theme = {'name': 'black'}
self.load_config(self.config)
# Init cursor
self._init_cursor()
......@@ -95,6 +101,18 @@ class _GlancesCurses(object):
# History tag
self._init_history()
def load_config(self, config):
'''Load the outputs section of the configuration file'''
# Load the theme
if config.has_section('outputs'):
logger.debug('Read the outputs section in the configuration file')
self.theme['name'] = config.get_value('outputs', 'curse_theme', default='black')
logger.debug('Theme for the curse interface: {0}'.format(self.theme['name']))
def is_theme(self, name):
'''Return True if the theme *name* should be used'''
return getattr(self.args, 'theme_' + name) or self.theme['name'] == name
def _init_history(self):
'''Init the history option'''
......@@ -141,7 +159,7 @@ class _GlancesCurses(object):
if curses.has_colors():
# The screen is compatible with a colored design
if self.args.theme_white:
if self.is_theme('white'):
# White theme: black ==> white
curses.init_pair(1, curses.COLOR_BLACK, -1)
else:
......@@ -165,14 +183,14 @@ class _GlancesCurses(object):
try:
curses.init_pair(9, curses.COLOR_MAGENTA, -1)
except Exception:
if self.args.theme_white:
if self.is_theme('white'):
curses.init_pair(9, curses.COLOR_BLACK, -1)
else:
curses.init_pair(9, curses.COLOR_WHITE, -1)
try:
curses.init_pair(10, curses.COLOR_CYAN, -1)
except Exception:
if self.args.theme_white:
if self.is_theme('white'):
curses.init_pair(10, curses.COLOR_BLACK, -1)
else:
curses.init_pair(10, curses.COLOR_WHITE, -1)
......
......@@ -75,7 +75,7 @@ class GlancesStandalone(object):
glances_processes.max_processes = 50
# Init screen
self.screen = GlancesCursesStandalone(args=args)
self.screen = GlancesCursesStandalone(config=config, args=args)
@property
def quiet(self):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册