about summary refs log tree commit diff stats
path: root/ex11.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-06-03 14:55:33 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-06-03 14:55:33 -0700
commit6b34a1c9bf03d46282a747efb2faf1cf1addb14e (patch)
tree34c8079feb20ab7a86fdfe334c288b7f606c8034 /ex11.mu
parentb9ad848cff8977fdb9d29915675e7a448b5292cc (diff)
downloadmu-6b34a1c9bf03d46282a747efb2faf1cf1addb14e.tar.gz
.
Diffstat (limited to 'ex11.mu')
0 files changed, 0 insertions, 0 deletions
010-01-06 00:36:51 +0100 committer hut <hut@lavabit.com> 2010-01-06 00:36:51 +0100 colorscheme: clean up' href='/akspecs/ranger/commit/ranger/gui/colorscheme.py?id=9ec914e306514c7a6f0cf3d401e97712dc197501'>9ec914e3 ^
a2853ab6 ^
9ec914e3 ^









2e74a4d0 ^
9ec914e3 ^

51d9c72e ^
6d985a2c ^
51d9c72e ^

6d985a2c ^
7740d525 ^
a4570538 ^

9dc6fe07 ^
34c131ef ^



51d9c72e ^
9ec914e3 ^

465bff73 ^
9ec914e3 ^



65cb1a32 ^
f027adc0 ^

9dc6fe07 ^
f027adc0 ^
9ec914e3 ^





6d985a2c ^
f027adc0 ^

9dc6fe07 ^
f027adc0 ^
7740d525 ^
9dc6fe07 ^
aea67778 ^
f027adc0 ^
34c131ef ^







f027adc0 ^

9dc6fe07 ^
f027adc0 ^
9ec914e3 ^

ea87d005 ^
9ec914e3 ^

f027adc0 ^
9ec914e3 ^
9dc6fe07 ^
9dc6fe07 ^
54c8375a ^
165bde56 ^

9ec914e3 ^
54c8375a ^
51d9c72e ^

2e74a4d0 ^
51d9c72e ^











eaaeed3d ^



51d9c72e ^
a2853ab6 ^
51d9c72e ^
a4570538 ^

51d9c72e ^



a4570538 ^
51d9c72e ^
a4570538 ^
51d9c72e ^
df031abc ^
51d9c72e ^



2e74a4d0 ^




51d9c72e ^
df031abc ^
51d9c72e ^

df031abc ^
51d9c72e ^









1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
                                                                 
 



                                                                      
 






                                                                       
 










                                                                          
                              









                                                                      
                    

   
         
                             

             
                                      
                                      

                                                      
 



                                                             
                                 

                                                              
 



                                                                  
 

                               
 
                             





                                                                    
                                      

                                               
 
                                
                                               
 
                                                                           
                                                 







                                                                                                  

                                                
 
                                  

                                                                   
 

                                                 
                                              
                                                           
 
                               
                                                                             

                                                             
                   
                                  

                                       
                                                                             











                                                                        



                                                         
 
                                                                              
                     

                                                                                  



                                                         
                                                                                
                                                   
                                                                    
                                                          
                                 



                                                                    




                                                                                
             
                                                                               

                                                                                    
                                                                                









                                                                                            
# Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""
Colorschemes define colors for specific contexts.

Generally, this works by passing a set of keywords (strings) to
the colorscheme.get() method to receive the tuple (fg, bg, attr).
fg, bg are the foreground and background colors and attr is the attribute.
The values are specified in ranger.gui.color.

A colorscheme must...

1. be inside either of these directories:
~/.config/ranger/colorschemes/
path/to/ranger/colorschemes/

2. be a subclass of ranger.gui.colorscheme.ColorScheme

3. implement a use(self, context) method which returns (fg, bg, attr).
context is a struct which contains all entries of CONTEXT_KEYS,
associated with either True or False.

define which colorscheme to use by having this to your options.py:
from ranger import colorschemes
colorscheme = "name"
"""

import os
from curses import color_pair

import ranger
from ranger.gui.color import get_color
from ranger.gui.context import Context
from ranger.core.helper import allow_access_to_confdir
from ranger.core.shared import SettingsAware

# 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(SettingsAware):
	"""
	This is the class that colorschemes must inherit from.

	it defines get() 
	it defines the get() method, which returns the color tuple
	which fits to the given keys.
	"""

	def __init__(self):
		self.cache = {}

	def get(self, *keys):
		"""
		Returns the (fg, bg, attr) for the given keys.

		Using this function rather than use() will cache all
		colors for faster access.
		"""
		keys = frozenset(keys)
		try:
			return self.cache[keys]

		except KeyError:
			context = Context(keys)

			# 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

	def get_attr(self, *keys):
		"""
		Returns the curses attribute for the specified keys

		Ready to use for curses.setattr()
		"""
		fg, bg, attr = self.get(*keys)
		return attr | color_pair(get_color(fg, bg))

	def use(self, context):
		"""Use the colorscheme to determine the (fg, bg, attr) tuple.

		Override this method in your own colorscheme.
		"""
		return (-1, -1, 0)

def _colorscheme_name_to_class(signal):
	# Find the colorscheme.  First look in ~/.config/ranger/colorschemes,
	# then at RANGERDIR/colorschemes.  If the file contains a class
	# named Scheme, it is used.  Otherwise, an arbitrary other class
	# is picked.
	if isinstance(signal.value, ColorScheme): return

	scheme_name = signal.value
	usecustom = not ranger.arg.clean

	def exists(colorscheme):
		return os.path.exists(colorscheme + '.py')

	def is_scheme(x):
		try:
			return issubclass(x, ColorScheme)
		except:
			return False

	# create ~/.config/ranger/colorschemes/__init__.py if it doesn't exist
	if usecustom:
		if os.path.exists(signal.fm.confpath('colorschemes')):
			initpy = signal.fm.confpath('colorschemes', '__init__.py')
			if not os.path.exists(initpy):
				open(initpy, 'a').close()

	if usecustom and \
			exists(signal.fm.confpath('colorschemes', scheme_name)):
		scheme_supermodule = 'colorschemes'
	elif exists(signal.fm.relpath('colorschemes', scheme_name)):
		scheme_supermodule = 'ranger.colorschemes'
		usecustom = False
	else:
		scheme_supermodule = None  # found no matching file.

	if scheme_supermodule is None:
		if signal.previous and isinstance(signal.previous, ColorScheme):
			signal.value = signal.previous
		else:
			signal.value = ColorScheme()
		raise Exception("Cannot locate colorscheme `%s'" % scheme_name)
	else:
		if usecustom: allow_access_to_confdir(ranger.arg.confdir, True)
		scheme_module = getattr(__import__(scheme_supermodule,
				globals(), locals(), [scheme_name], 0), scheme_name)
		if usecustom: allow_access_to_confdir(ranger.arg.confdir, False)
		if hasattr(scheme_module, 'Scheme') \
				and is_scheme(scheme_module.Scheme):
			signal.value = scheme_module.Scheme()
		else:
			for name, var in scheme_module.__dict__.items():
				if var != ColorScheme and is_scheme(var):
					signal.value = var()
					break
			else:
				raise Exception("The module contains no valid colorscheme!")