summary refs log tree commit diff stats
path: root/note/ask.html
blob: ee0c3a6489c2dc6161d9872b96c67cefd37b60a4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
	<head>
		<title>Don't ask to ask, just ask1</title>
		<link rel="stylesheet" href="/style.css" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
	</head>
	<body>
		<h1>Don't ask to ask, just ask!</h1>
		<p>Please don't send random emails and IRC messages saying "Are you there?  I have a thing to ask you about...".  Just ask the question.  If I'm online I might answer right away, if I'm not I'll answer you when I have time.  An "Are you there?" or "Can I ask a question?" question is just a waste of time and effort.</p>
		<div id="footer">
			<hr />
			<p><a href="/">Runxi Yu's Website</a></p>
			<p>Unless otherwise specified with the "<span class="copyright">copyright</span>" HTML/CSS class, works hosted on this subdomain (<code>www.andrewyu.org</code>) served with the HTTP(S) protocol is available under <a href="https://www.andrewyu.org/note/pubdom.html">Runxi Yu's Public Domain Dedication</a>.</p>
		</div>
	</body>
</html>
21:20:09 +0100 removed options.py, improved plugins. *UPDATE YOUR COMMANDS.PY*' href='/akspecs/ranger/commit/ranger/gui/colorscheme.py?id=972da7babcecbe47bd56a3d2d19157b4aba61e99'>972da7ba ^
b68d28c1 ^
d1a1173d ^






b68d28c1 ^
d1a1173d ^





51ec08da ^
d1a1173d ^
76791a70 ^
d1a1173d ^



b68d28c1 ^
d1a1173d ^





9252d69e ^

b68d28c1 ^
d1a1173d ^



51d9c72e ^
ab41c776 ^
b3d031a9 ^
d1a1173d ^



5348e120 ^

d1a1173d ^




f6de1679 ^
d1a1173d ^

d69f1ed3 ^
d1a1173d ^
b3d031a9 ^
d1a1173d ^
b3d031a9 ^
1687e0f4 ^
d1a1173d ^






aa434db9 ^
8f6434f9 ^

d1a1173d ^













84a22ae0 ^
1687e0f4 ^
d1a1173d ^
5348e120 ^
f6de1679 ^
51ec08da ^

5348e120 ^
f6de1679 ^
c78ee48d ^
d1a1173d ^






1687e0f4 ^
bc79568d ^
ab41c776 ^
f7199d8e ^
bc79568d ^

f7199d8e ^
bc79568d ^


f7199d8e ^


bc79568d ^


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

                                                                 
 
                                                    








                                                                          
                              







                                                                      

                                                                          

   
                                                                  
 
              
                              
                             
                   

             
                                      
                                      
                                                    

                                                      
 
 



                                  
                          
                                                             






                                                              
                                                         





                                                            
                                                                                 
                                                                 
                                                                                           



                              
                                                              





                                                   

                           
                                                                     



                                                     
 
 
                                                                            



                                                                         

                                             




                                
                                     

                            
                                                                                          
 
                       
            
                                               
                         






                                                                          
                                                         

                                          













                                                                        
                                        
                                                                              
         
                     
                                                              

                                                                                               
                     
                                                               
                                                                                






                                                         
                                                                                   
 
 
                             

                                                              
                                                                           


                                                                             


                                          


                                                        
# This file is part of ranger, the console file manager.
# License: GNU GPL version 3, see the file "AUTHORS" for details.

"""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 in your settings (e.g. ~/.config/ranger/rc.conf):
set colorscheme yourschemename
"""

from __future__ import (absolute_import, division, print_function)

import os.path
from abc import abstractmethod
from curses import color_pair
from io import open

import ranger
from ranger.gui.color import get_color
from ranger.gui.context import Context
from ranger.core.main import allow_access_to_confdir
from ranger.ext.cached_function import cached_function
from ranger.ext.iter_tools import flatten


class ColorSchemeError(Exception):
    pass


class ColorScheme(object):
    """This is the class that colorschemes must inherit from.

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

    @cached_function
    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.
        """
        context = Context(keys)
        color = self.use(context)
        if len(color) != 3 or not all(isinstance(value, int) for value in color):
            raise ValueError("Bad Value from colorscheme.  Need "
                             "a tuple of (foreground_color, background_color, attribute).")
        return color

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

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

    @abstractmethod
    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):  # pylint: disable=too-many-branches
    # 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

    if not signal.value:
        signal.value = 'default'

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

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

    def is_scheme(cls):
        try:
            return issubclass(cls, ColorScheme)
        except TypeError:
            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):
                with open(initpy, "a", encoding="utf-8"):
                    # Just create the file
                    pass

    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 ColorSchemeError("Cannot locate colorscheme `%s'" % scheme_name)
    else:
        if usecustom:
            allow_access_to_confdir(ranger.args.confdir, True)
        scheme_module = getattr(
            __import__(scheme_supermodule, globals(), locals(), [scheme_name], 0), scheme_name)
        if usecustom:
            allow_access_to_confdir(ranger.args.confdir, False)
        if hasattr(scheme_module, 'Scheme') and is_scheme(scheme_module.Scheme):
            signal.value = scheme_module.Scheme()
        else:
            for var in scheme_module.__dict__.values():
                if var != ColorScheme and is_scheme(var):
                    signal.value = var()
                    break
            else:
                raise ColorSchemeError("The module contains no valid colorscheme!")


def get_all_colorschemes(fm):
    colorschemes = set()
    # Load colorscheme names from main ranger/colorschemes dir
    for item in os.listdir(os.path.join(ranger.RANGERDIR, 'colorschemes')):
        if not item.startswith('__'):
            colorschemes.add(item.rsplit('.', 1)[0])
    # Load colorscheme names from ~/.config/ranger/colorschemes if dir exists
    confpath = fm.confpath('colorschemes')
    if os.path.isdir(confpath):
        for item in os.listdir(confpath):
            if not item.startswith('__'):
                colorschemes.add(item.rsplit('.', 1)[0])
    return list(sorted(colorschemes))