summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-02-28 18:30:28 +0100
committerhut <hut@lavabit.com>2010-02-28 19:21:33 +0100
commit0619b0954cdd3a05dcd93498046a8b9c4daad8e0 (patch)
treea80bb1b519eb6fd9aa7e3bc970c42880c6168066
parent3d625436fc5284c38fcfe054396d98dcb7495a0d (diff)
downloadranger-0619b0954cdd3a05dcd93498046a8b9c4daad8e0.tar.gz
colorschemes: 1. fixed jungle, 2. use "Default" scheme by default
-rw-r--r--ranger/colorschemes/jungle.py75
-rw-r--r--ranger/shared/settings.py28
2 files changed, 26 insertions, 77 deletions
diff --git a/ranger/colorschemes/jungle.py b/ranger/colorschemes/jungle.py
index 8d408fa0..e6c3307f 100644
--- a/ranger/colorschemes/jungle.py
+++ b/ranger/colorschemes/jungle.py
@@ -16,75 +16,16 @@
 from ranger.gui.colorscheme import ColorScheme
 from ranger.gui.color import *
 
-class Default(ColorScheme):
-	def use(self, context):
-		fg, bg, attr = default_colors
-
-		if context.reset:
-			pass
-
-		elif context.in_browser:
-			if context.selected:
-				attr = reverse
-			else:
-				attr = normal
-
-			if context.empty or context.error:
-				bg = red
-
-			if context.media:
-				fg = magenta # fruits
-
-			if context.container:
-				fg = red # flowers
-
-			if context.directory:
-				fg = green # trees =)
-
-			elif context.executable and not \
-					any((context.media, context.container)):
-				fg = yellow # banananas
-
-			if context.link:
-				fg = context.good and cyan or magenta
+from ranger.colorschemes.default import Default as SubClass
 
-			if context.main_column and context.selected:
-				attr |= bold
-
-		elif context.in_titlebar:
-			attr |= bold
-
-			if context.hostname:
-				fg = green
-
-			elif context.directory:
-				fg = blue
-
-			elif context.link:
-				fg = cyan
-
-			elif context.keybuffer:
-				fg = yellow
-				attr = normal
-
-		elif context.in_statusbar:
-			if context.permissions or context.link:
-				if context.good:
-					fg = cyan
-				elif context.bad:
-					fg = magenta
-
-		if context.text:
-			if context.highlight:
-				attr |= reverse
-				fg = yellow
+class Default(SubClass):
+	def use(self, context):
+		fg, bg, attr = SubClass.use(self, context)
 
-		if context.in_taskview:
-			if context.title:
-				fg = yellow
-				attr |= reverse
+		if context.directory and not context.marked:
+			fg = green
 
-			if context.selected:
-				attr |= reverse
+		if context.in_titlebar and context.hostname:
+			fg = red if context.bad else blue
 
 		return fg, bg, attr
diff --git a/ranger/shared/settings.py b/ranger/shared/settings.py
index 36728b48..c01e5796 100644
--- a/ranger/shared/settings.py
+++ b/ranger/shared/settings.py
@@ -13,7 +13,9 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+import types
 from ranger.ext.openstruct import OpenStruct
+from ranger.gui.colorscheme import ColorScheme
 
 ALLOWED_SETTINGS = {
 	'show_hidden': bool,
@@ -29,7 +31,7 @@ ALLOWED_SETTINGS = {
 	'scroll_offset': int,
 	'preview_files': bool,
 	'flushinput': bool,
-	'colorscheme': object,
+	'colorscheme': (ColorScheme, types.ModuleType),
 	'hidden_filter': lambda x: isinstance(x, str) or hasattr(x, 'match'),
 }
 
@@ -70,20 +72,26 @@ class SettingsAware(object):
 		# If a module is specified as the colorscheme, replace it with one
 		# valid colorscheme inside that module.
 
+		all_content = options.colorscheme.__dict__.items()
+
 		if isclass(options.colorscheme) and \
 				issubclass(options.colorscheme, ColorScheme):
 			options.colorscheme = options.colorscheme()
 
 		elif ismodule(options.colorscheme):
-			for var_name in dir(options.colorscheme):
-				var = getattr(options.colorscheme, var_name)
-				if var != ColorScheme and isclass(var) \
-						and issubclass(var, ColorScheme):
-					options.colorscheme = var()
-					break
+			if hasattr(options.colorscheme, 'Default') \
+			and isclass(options.colorscheme.Default) \
+			and issubclass(options.colorscheme.Default, ColorScheme):
+				options.colorscheme = options.colorscheme.Default()
 			else:
-				raise Exception("The module contains no valid colorscheme!")
-
+				for name, var in options.colorscheme.__dict__.items():
+					if var != ColorScheme and isclass(var) \
+					and issubclass(var, ColorScheme):
+						options.colorscheme = var()
+						break
+				else:
+					raise Exception("The module contains no " \
+							"valid colorscheme!")
 		else:
 			raise Exception("Cannot locate colorscheme!")
 
@@ -104,5 +112,5 @@ def check_option_types(opt):
 		else:
 			assert isinstance(optvalue, typ), \
 				"The option `" + name + "' has an incorrect type!"\
-				" Expected " + str(typ) + "!"
+				" Got " + str(type(optvalue)) + ", expected " + str(typ) + "!"
 	return True