summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-03-28 20:28:42 +0200
committerhut <hut@lavabit.com>2010-03-28 20:28:42 +0200
commit34c131ef561ffb22586e2094fc0c478a44f24ac6 (patch)
tree700083e2eaaea96ef8d2087075336ed861ee18e9 /ranger
parentffcd934fc4e68d6ddddd9a76a6467ee7db3a76bf (diff)
downloadranger-34c131ef561ffb22586e2094fc0c478a44f24ac6.tar.gz
new option: colorscheme_overlay
For those who want small colorscheme changes without creating
an extra file.
Diffstat (limited to 'ranger')
-rw-r--r--ranger/api/options.py1
-rw-r--r--ranger/defaults/options.py19
-rw-r--r--ranger/gui/colorscheme.py12
-rw-r--r--ranger/shared/settings.py5
4 files changed, 37 insertions, 0 deletions
diff --git a/ranger/api/options.py b/ranger/api/options.py
index 7ead8c90..4748823d 100644
--- a/ranger/api/options.py
+++ b/ranger/api/options.py
@@ -16,6 +16,7 @@
 import re
 from re import compile as regexp
 from ranger import colorschemes as allschemes
+from ranger.gui import color
 
 class AttrToString(object):
 	"""
diff --git a/ranger/defaults/options.py b/ranger/defaults/options.py
index ace68592..ce010195 100644
--- a/ranger/defaults/options.py
+++ b/ranger/defaults/options.py
@@ -85,3 +85,22 @@ sort_reverse = False
 sort_case_insensitive = False
 sort_directories_first = True
 
+
+# Apply an overlay function to the colorscheme.  It will be called with
+# 4 arguments: the context and the 3 values (fg, bg, attr) returned by
+# the original use() function of your colorscheme.  The return value
+# must be a 3-tuple of (fg, bg, attr).
+# Note: Here, the colors/attributes aren't directly imported into
+# the namespace but have to be accessed with color.xyz.
+def colorscheme_overlay(context, fg, bg, attr):
+	if context.directory and attr & color.bold and \
+			not any((context.marked, context.selected)):
+		attr ^= color.bold  # I don't like bold directories!
+
+	if context.main_column and context.selected:
+		fg, bg = color.red, color.default  # To highlight the main column!
+
+	return fg, bg, attr
+
+# The above function was just an example, let's set it back to None
+colorscheme_overlay = None
diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py
index 199a5523..b76131ae 100644
--- a/ranger/gui/colorscheme.py
+++ b/ranger/gui/colorscheme.py
@@ -45,6 +45,10 @@ from curses import color_pair
 from ranger.gui.color import get_color
 from ranger.gui.context import Context
 
+# ColorScheme is not SettingsAware but it will gain access
+# to the settings during the initialization.  We can't import
+# SettingsAware here because of circular imports.
+
 class ColorScheme(object):
 	"""
 	This is the class that colorschemes must inherit from.
@@ -73,6 +77,14 @@ class ColorScheme(object):
 
 			# add custom error messages for broken colorschemes
 			color = self.use(context)
+			if self.settings.colorscheme_overlay:
+				result = self.settings.colorscheme_overlay(context, *color)
+				assert isinstance(result, (tuple, list)), \
+						"Your colorscheme overlay doesn't return a tuple!"
+				assert all(isinstance(val, int) for val in result), \
+						"Your colorscheme overlay doesn't return a tuple"\
+						" containing 3 integers!"
+				color = result
 			self.cache[keys] = color
 			return color
 
diff --git a/ranger/shared/settings.py b/ranger/shared/settings.py
index e53f31b0..63e9d4e4 100644
--- a/ranger/shared/settings.py
+++ b/ranger/shared/settings.py
@@ -40,6 +40,7 @@ ALLOWED_SETTINGS = {
 	'preview_directories': bool,
 	'flushinput': bool,
 	'colorscheme': str,
+	'colorscheme_overlay': (type(None), type(lambda:0)),
 	'hidden_filter': lambda x: isinstance(x, str) or hasattr(x, 'match'),
 }
 
@@ -136,6 +137,10 @@ class SettingsAware(object):
 					raise Exception("The module contains no " \
 							"valid colorscheme!")
 
+		# Making the colorscheme SettingsAware doesn't work because
+		# of circular imports, so we do it like this:
+		settings.colorscheme.settings = settings  
+
 		try:
 			import apps
 		except ImportError: