summary refs log blame commit diff stats
path: root/doc/colorschemes.txt
blob: e1fee2da0172cc6cc7a65fd821ec754cc1cf3029 (plain) (tree)
1
2
3
4
5
6
7
8


            


                                                  

            











                                                                       

                                 












                                                                        

                










                                                                           
                                                             









                                                                       

                     

                                                   
                              
                             
 


                                                                    
 


                                                  

 

                   






                                                                  
                                                                  






                                                                            
Colorschemes
============

This text explains colorschemes and how they work.


Context Tags
------------

Context Tags provide information about the context.  If the tag
"in_titlebar" is set, you probably want to know about the color
of a part of the titlebar now.

There are a number of context tags, specified in /ranger/gui/context.py
in the constant CONTEXT_KEYS.

A Context object, defined in the same file, contains attributes with
the names of all tags, whose values are either True or False.


Implementation in the GUI Classes
---------------------------------

The class CursesShortcuts in the file /ranger/gui/curses_shortcuts.py
defines the methods color(*tags), color_at(y, x, wid, *tags) and
color_reset().  This class is a superclass of Displayable, so these
methods are available almost everywhere.

Something like color("in_titlebar", "directory") will be called to
get the color of directories in the titlebar.  This creates a
ranger.gui.context.Context object, sets its attributes "in_titlebar" and
"directory" to True, leaves the others as False, and passes it to the
colorscheme's use(context) method.


The Color Scheme
----------------

A colorscheme should be a subclass of ranger.gui.ColorScheme and
define the method use(context).  By looking at the context, this use-method
has to determine a 3-tuple of integers: (foreground, background, attribute)
and return it.

foreground and background are integers representing colors,
attribute is another integer with each bit representing one attribute.
These integers are interpreted by the used terminal emulator.

Abbreviations for colors and attributes are defined in ranger.gui.color.
Two attributes can be combined via bitwise OR: bold | reverse

Once the color for a set of tags is determined, it will be cached by
default.  If you want more dynamic colorschemes (such as a different
color for very large files), you will need to dig into the source code,
perhaps add an own tag and modify the draw-method of the widget to use
that tag.

Run tc_colorscheme to check if your colorschemes are valid.


Specify a Colorscheme
---------------------

Colorschemes are searched for in these directories:
~/.config/ranger/colorschemes/
/path/to/ranger/colorschemes/

To specify which colorscheme to use, change the option "colorscheme"
in your rc.conf:
set colorscheme default

This means, use the colorscheme contained in
either ~/.config/ranger/colorschemes/default.py or
/path/to/ranger/colorschemes/default.py.


Adapt a colorscheme
-------------------

You may want to adapt a colorscheme to your needs without having
a complete copy of it, but rather the changes only.  Say, you
want the exact same colors as in the default colorscheme, but
the directories to be green rather than blue, because you find the
blue hard to read.

This is done in the jungle colorscheme ranger/colorschemes/jungle,
check it out for implementation details.  In short, I made a subclass
of the default scheme, set the initial colors to the result of the
default use() method and modified the colors how I wanted.

This has the obvious advantage that you need to write less, which
results in less maintainance work and a greater chance that your colorscheme
will work with future versions of ranger.
isanti/profani-tty/commit/src/profanity.c?id=fcfdc175b6c94d1fd57e5a26b31f411a07ba3198'>fcfdc175 ^
020e516a ^
279737ba ^
10ca3e8c ^
dbfb1551 ^
10ca3e8c ^
41fe8c22 ^
3656c782 ^
41fe8c22 ^
bc3c4e09 ^
ac7ec7f2 ^
5be47cc5 ^
b43252a6 ^
e7bfaa64 ^
54e225aa ^
a70aa025 ^
fcfdc175 ^
e8314106 ^
e7bfaa64 ^
2cdbfc7e ^
4c42ce97 ^
a70aa025 ^
cfef64c7 ^

a70aa025 ^




2cdbfc7e ^
9b177a9e ^
2cdbfc7e ^
1155ceab ^
41fe8c22 ^
2cdbfc7e ^
0649aad8 ^
94b0d2c6 ^
2cdbfc7e ^
697db019 ^
de65f505 ^
1e60d17d ^
dbfb1551 ^
dbfb1551 ^
c16871d1 ^

fcfdc175 ^




3656c782 ^
dd11334b ^
b9ab5d9f ^
cfef64c7 ^
3656c782 ^
cfef64c7 ^
b9ab5d9f ^
3656c782 ^

cfef64c7 ^
3656c782 ^

b9ab5d9f ^
b9ab5d9f ^


10ca3e8c ^
b9ab5d9f ^
d28930ea ^
e81dc3b5 ^

e21bc7af ^

30180ac8 ^
1b0ce852 ^




ef942bd2 ^
c90c83f7 ^
10ca3e8c ^
b9ab5d9f ^
e8314106 ^
9b177a9e ^


ee8ff948 ^
9b177a9e ^
ee8ff948 ^
dba48f18 ^
9b177a9e ^
dba48f18 ^
b9ab5d9f ^
8c5866ff ^
6826a66f ^
7344d3b8 ^
4c243722 ^
7344d3b8 ^
e131afdb ^
88f423af ^
b9ab5d9f ^

17757c86 ^
d96e68ea ^
904a5a81 ^
9b177a9e ^
bd1c1394 ^

9b177a9e ^
2490c3ed ^

2602cbf7 ^


d6589157 ^
41fe8c22 ^
697db019 ^
de65f505 ^
1e60d17d ^
d6e4b748 ^
d3cc5bd7 ^
b9ab5d9f ^




3983ee1d ^

0d0ed9b7 ^




055a5f71 ^
3bb1f124 ^
055a5f71 ^


697db019 ^
12727744 ^
1e60d17d ^
88f423af ^
41fe8c22 ^
0338d136 ^
22589e87 ^
9b177a9e ^
c98ce429 ^

9b177a9e ^
551f7df1 ^

199162b1 ^


6bad38c2 ^
e8b2b719 ^
89967905 ^
d96e68ea ^
e8314106 ^
6bad38c2 ^
41fe8c22 ^
1926ceea ^

c851a48a ^
b9ab5d9f ^
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
  
              
                                 
  
                                                            
                                                        
  












                                                                       
                                                                      
  











                                                                                
   
                   
 
                       
                       

      
               
                    
      
 
                   
                   

                   
 

                 
                      

                   
                         
                            


                               
                            
                           
                             




                                
                         



                              
                         
                             
 
                  
                    
      
 
                    

                    
 



                        
                                                      
                            
                                                         
 
                            
                                   
 
    
                                                                
 
                                  
                       
                                   
 
                
 
                                         
 
                            
 
                      
                                
                             
                                 
 
                              
                   

                                                   




                        
 
                  
                   
      
                            
                        
                                 
                            
                    
               
                      
      
     
 

    




                      
           
                                           
 
                                         
                  
                                             
            

                                                                            
                                                              

                                                    
     


           
                                         
 
                          

                             

                             
                                          




                                               
                               
                                                                  
                            
                             
                                      


                                                                                                                 
     
                                                                       
      
            
                                                                
     
                    
                         
                    
                                               
                      
                             
              
                   

                                          
               
                    
                   
                  

               
                    

                 


                 
                      
                   
               
                
      
                          
                




               

                                                       




                                 
 
                                                               


                                          
               
                    
      
                       
                          
                
                 
                  

                   
                    

                  


                  
                     
                  
                     
                     
                       
                
                       

                 
                  
 
/*
 * profanity.c
 * vim: expandtab:ts=4:sts=4:sw=4
 *
 * Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
 * Copyright (C) 2019 Michael Vetter <jubalh@iodoru.org>
 *
 * This file is part of Profanity.
 *
 * Profanity 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.
 *
 * Profanity 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 Profanity.  If not, see <https://www.gnu.org/licenses/>.
 *
 * In addition, as a special exception, the copyright holders give permission to
 * link the code of portions of this program with the OpenSSL library under
 * certain conditions as described in each individual source file, and
 * distribute linked combinations including the two.
 *
 * You must obey the GNU General Public License in all respects for all of the
 * code used other than OpenSSL. If you modify file(s) with this exception, you
 * may extend this exception to your version of the file(s), but you are not
 * obligated to do so. If you do not wish to do so, delete this exception
 * statement from your version. If you delete this exception statement from all
 * source files in the program, then also delete it here.
 *
 */
#include "config.h"

#ifdef HAVE_GIT_VERSION
#include "gitversion.h"
#endif

#ifdef HAVE_GTK
#include "ui/tray.h"
#endif

#include <locale.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>

#include <glib.h>

#include "profanity.h"
#include "common.h"
#include "log.h"
#include "config/files.h"
#include "config/tlscerts.h"
#include "config/accounts.h"
#include "config/preferences.h"
#include "config/theme.h"
#include "config/tlscerts.h"
#include "config/scripts.h"
#include "command/cmd_defs.h"
#include "plugins/plugins.h"
#include "event/client_events.h"
#include "ui/ui.h"
#include "ui/window_list.h"
#include "xmpp/resource.h"
#include "xmpp/session.h"
#include "xmpp/xmpp.h"
#include "xmpp/muc.h"
#include "xmpp/chat_session.h"
#include "xmpp/chat_state.h"
#include "xmpp/contact.h"
#include "xmpp/roster_list.h"

#ifdef HAVE_LIBOTR
#include "otr/otr.h"
#endif

#ifdef HAVE_LIBGPGME
#include "pgp/gpg.h"
#endif

#ifdef HAVE_OMEMO
#include "omemo/omemo.h"
#endif

static void _init(char *log_level, char *config_file);
static void _shutdown(void);
static void _connect_default(const char * const account);

static gboolean cont = TRUE;
static gboolean force_quit = FALSE;

void
prof_run(char *log_level, char *account_name, char *config_file)
{
    _init(log_level, config_file);
    plugins_on_start();
    _connect_default(account_name);

    ui_update();

    log_info("Starting main event loop");

    session_init_activity();

    char *line = NULL;
    while(cont && !force_quit) {
        log_stderr_handler();
        session_check_autoaway();

        line = inp_readline();
        if (line) {
            ProfWin *window = wins_get_current();
            cont = cmd_process_input(window, line);
            free(line);
            line = NULL;
        } else {
            cont = TRUE;
        }

#ifdef HAVE_LIBOTR
        otr_poll();
#endif
        plugins_run_timed();
        notify_remind();
        session_process_events();
        iq_autoping_check();
        ui_update();
#ifdef HAVE_GTK
        tray_update();
#endif
    }
}

void
prof_set_quit(void)
{
    force_quit = TRUE;
}

static void
_connect_default(const char *const account)
{
    ProfWin *window = wins_get_current();
    if (account) {
        cmd_execute_connect(window, account);
    } else {
        char *pref_connect_account = prefs_get_string(PREF_CONNECT_ACCOUNT);
        if (pref_connect_account) {
            cmd_execute_connect(window, pref_connect_account);
            prefs_free_string(pref_connect_account);
        }
    }
}

static void
_init(char *log_level, char *config_file)
{
    setlocale(LC_ALL, "");
    // ignore SIGPIPE
    signal(SIGPIPE, SIG_IGN);
    signal(SIGINT, SIG_IGN);
    signal(SIGTSTP, SIG_IGN);
    signal(SIGWINCH, ui_sigwinch_handler);
    if (pthread_mutex_init(&lock, NULL) != 0) {
        log_error("Mutex init failed");
        exit(1);
    }
    pthread_mutex_lock(&lock);
    files_create_directories();
    log_level_t prof_log_level = log_level_from_string(log_level);
    prefs_load(config_file);
    log_init(prof_log_level);
    log_stderr_init(PROF_LEVEL_ERROR);
    if (strcmp(PACKAGE_STATUS, "development") == 0) {
#ifdef HAVE_GIT_VERSION
            log_info("Starting Profanity (%sdev.%s.%s)...", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
#else
            log_info("Starting Profanity (%sdev)...", PACKAGE_VERSION);
#endif
    } else {
        log_info("Starting Profanity (%s)...", PACKAGE_VERSION);
    }
    chat_log_init();
    groupchat_log_init();
    accounts_load();
    char *theme = prefs_get_string(PREF_THEME);
    theme_init(theme);
    prefs_free_string(theme);
    ui_init();
    session_init();
    cmd_init();
    log_info("Initialising contact list");
    muc_init();
    tlscerts_init();
    scripts_init();
#ifdef HAVE_LIBOTR
    otr_init();
#endif
#ifdef HAVE_LIBGPGME
    p_gpg_init();
#endif
#ifdef HAVE_OMEMO
    omemo_init();
#endif
    atexit(_shutdown);
    plugins_init();
#ifdef HAVE_GTK
    tray_init();
#endif
    inp_nonblocking(TRUE);
    ui_resize();
}

static void
_shutdown(void)
{
    if (prefs_get_boolean(PREF_WINTITLE_SHOW)) {
        if (prefs_get_boolean(PREF_WINTITLE_GOODBYE)) {
            ui_goodbye_title();
        } else {
            ui_clear_win_title();
        }
    }

    jabber_conn_status_t conn_status = connection_get_status();
    if (conn_status == JABBER_CONNECTED) {
        cl_ev_disconnect();
    }
#ifdef HAVE_GTK
    tray_shutdown();
#endif
    session_shutdown();
    plugins_on_shutdown();
    muc_close();
    caps_close();
#ifdef HAVE_LIBOTR
    otr_shutdown();
#endif
#ifdef HAVE_LIBGPGME
    p_gpg_close();
#endif
#ifdef HAVE_OMEMO
    omemo_close();
#endif
    chat_log_close();
    theme_close();
    accounts_close();
    tlscerts_close();
    log_stderr_close();
    log_close();
    plugins_shutdown();
    cmd_uninit();
    ui_close();
    prefs_close();
}