summary refs log blame commit diff stats
path: root/HACKING.md
blob: 0b14e38d9c70cceda8afd4e7a3a87dc63611f688 (plain) (tree)
1
2
3
4
5
6
7
8
9
10

                                



            
                                                     


                                            
                                                   




       
                                                                   
 
              
 





                                 
                           


                                                            

 



                                               


                              

             



                                     

 
              


              

              








                                                                                 
 
 

                   
 





                                                                             

                            
 
 

                                            
 

                                                                             
 
 

                                                 
 




                                                                                  
 
                                                                  
Guidelines for Code Modification
================================

Coding Style
------------

* Use syntax compatible to both python 2.6+ and 3.1+.
* Use docstrings with pydoc in mind
* Follow the style guide for python code:
    http://www.python.org/dev/peps/pep-0008/
* Test the code with "doctest" where it makes sense


Patches
-------

Send patches, created with "git format-patch", to the email address

    hut@hut.pm

or open a pull request on GitHub.


Version Numbering
-----------------

Three numbers, A.B.C, where
* A changes on a rewrite
* B changes when major configuration incompatibilities occur
* C changes with each release


Starting Points
---------------

Good places to read about ranger internals are:

* ranger/core/actions.py
* ranger/container/fsobject.py

About the UI:

* ranger/gui/widgets/browsercolumn.py
* ranger/gui/widgets/browserview.py
* ranger/gui/ui.py


Common Changes
==============

Adding options
--------------

* Add a default value in rc.conf, along with a comment that describes the option.
* Add the option to the ALLOWED_SETTINGS dictionary in the file
  ranger/container/settings.py.  Make sure to sort in the new entry
  alphabetically.
* Add an entry in the man page by editing doc/ranger.pod, then rebuild the man
  page by running "make man" in the ranger root directory

The setting is now accessible with self.settings.my_option, assuming self is a
subclass of ranger.core.shared.SettingsAware.


Adding colorschemes
-------------------

* Copy ranger/colorschemes/default.py to ranger/colorschemes/myscheme.py
  and modify it according to your needs.  Alternatively, create a subclass of
  ranger.colorschemes.default.Default and override the "use" method, as it is
  done in the "Jungle" colorscheme.

* Add this line to your ~/.config/ranger/rc.conf:

    set colorscheme myscheme


Change which programs start which file types
--------------------------------------------

Edit the configuration file ~/.config/ranger/rifle.conf.  The default one can
be obtained by running "ranger --copy-config rifle".


Change which file extensions have which mime type
-------------------------------------------------

Modify ranger/data/mime.types.  You may also add your own entries to ~/.mime.types


Change which files are previewed in the auto preview
----------------------------------------------------

In ranger/container/file.py, change the constant PREVIEW_BLACKLIST
{ color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#include <string.h>
#include <unistd.h>

#include <ncurses.h>

#include "log.h"
#include "windows.h"
#include "jabber.h"

static void main_event_loop(void);

void start_profanity(void)
{
    char cmd[50];
    while (TRUE) {
        inp_get_command_str(cmd);

        if (strcmp(cmd, "/quit") == 0) {
            break;
        } else if (strncmp(cmd, "/help", 5) == 0) {
            cons_help();
            inp_clear();
        } else if (strncmp(cmd, "/connect ", 9) == 0) {
            char *user;
            user = strndup(cmd+9, strlen(cmd)-9);

            inp_bar_print_message("Enter password:");
            char passwd[20];
            inp_get_password(passwd);

            inp_bar_print_message(user);
            jabber_connect(user, passwd);
            main_event_loop();
            break;
        } else {
            cons_bad_command(cmd);
            inp_clear();
        }
    }
}

static void main_event_loop(void)
{
    inp_non_block();

    while(TRUE) {
        int ch = ERR;
        char command[100];
        int size = 0;

        // while not enter, process all events, and try to get another char
        while(ch != '\n') {
            usleep(1);
        
            // handle incoming messages
            jabber_process_events();

            // determine if they changed windows
            if (ch == KEY_F(1)) {
                switch_to(0);
            } else if (ch == KEY_F(2)) {
                switch_to(1);
            } else if (ch == KEY_F(3)) {
                switch_to(2);
            } else if (ch == KEY_F(4)) {
                switch_to(3);
            } else if (ch == KEY_F(5)) {
                switch_to(4);
            } else if (ch == KEY_F(6)) {
                switch_to(5);
            } else if (ch == KEY_F(7)) {
                switch_to(6);
            } else if (ch == KEY_F(8)) {
                switch_to(7);
            } else if (ch == KEY_F(9)) {
                switch_to(8);
            } else if (ch == KEY_F(10)) {
                switch_to(9);
            }

            // get another character from the command box
            inp_poll_char(&ch, command, &size);
        }

        // null terminate the input    
        command[size++] = '\0';

        // deal with input

        // /quit command -> exit
        if (strcmp(command, "/quit") == 0) {
            break;

        // /help -> print help to console
        } else if (strncmp(command, "/help", 5) == 0) {
            cons_help();
            inp_clear();

        // /close -> close the current chat window, if in chat
        } else if (strncmp(command, "/close", 6) == 0) {
            if (in_chat()) {
                close_win();
            } else {
                cons_bad_command(command);
            }
            inp_clear();

        // send message to recipient, if in chat
        } else {
            if (in_chat()) {
                char recipient[100] = "";
                get_recipient(recipient);
                jabber_send(command, recipient);
                show_outgoing_msg("me", command);
            } else {
                cons_bad_command(command);
            }
            inp_clear();
        }
    }

    jabber_disconnect();
}