about summary refs log tree commit diff stats
path: root/main.c
diff options
context:
space:
mode:
authorAnselm R. Garbe <arg@suckless.org>2007-05-29 11:47:55 +0200
committerAnselm R. Garbe <arg@suckless.org>2007-05-29 11:47:55 +0200
commite1deda9e040c052af62aecc2fb4ee770fb2496a2 (patch)
tree177398c12063bb524e065d74836c6f75fd0bf075 /main.c
parent199a6016114875656102d11e79a80939bfaff3b3 (diff)
downloaddwm-e1deda9e040c052af62aecc2fb4ee770fb2496a2.tar.gz
added anydot to Copyright holders, because he contributed a lot recently
Diffstat (limited to 'main.c')
-rw-r--r--main.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/main.c b/main.c
index 23fd7bd..884d5a3 100644
--- a/main.c
+++ b/main.c
@@ -1,5 +1,6 @@
 /* © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
  * © 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
+ * © 2007 Premysl Hruby <dfenze at gmail dot com>
  * See LICENSE file for license details. */
 #include "dwm.h"
 #include <errno.h>
: 5px; padding-right: 5px; } td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { 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 */
import curses
from curses.ascii import *
from ranger import RANGERDIR
from ranger.gui.widgets.console import Console
from ranger.container.bookmarks import ALLOWED_KEYS as ALLOWED_BOOKMARK_KEYS

def do(method, *args, **kw):
	return lambda fm: getattr(fm, method)(*args, **kw)

# syntax for binding keys: bind(*keys, fnc)
# fnc is a function which is called with the FM instance,
# keys are one or more key-combinations which are either:
# * a string
# * an integer which represents an ascii code
# * a tuple of integers
#
# in initialize_console_commands, fnc is a function which is
# called with the console widget instance instead.

def initialize_commands(command_list):
	"""Initialize the commands for the main user interface"""

	def bind(*args):
		command_list.bind(args[-1], *args[:-1])

	bind('h', curses.KEY_BACKSPACE, DEL, do('move_left'))
	bind('l', do('move_right'))
	bind(curses.KEY_ENTER, ctrl('j'), do('move_right', mode=1))
	bind('H', do('history_go', -1))
	bind('L', do('history_go',  1))
	bind('j', do('move_pointer', relative = 1))
	bind('J', do('move_pointer_by_pages', 0.5))
	bind('k', do('move_pointer', relative = -1))
	bind('K', do('move_pointer_by_pages', -0.5))
	bind('gg', do('move_pointer', absolute = 0))
	bind('G', do('move_pointer', absolute = -1))
	bind('E', do('edit_file'))

	bind('yy', 'cp', do('copy'))
	bind('cut', do('cut'))
	bind('p', do('paste'))

	bind('th', do('toggle_boolean_option', 'show_hidden'))
	bind('tp', do('toggle_boolean_option', 'preview_files'))
	bind('td', do('toggle_boolean_option', 'directories_first'))

	bind('cd', do('open_console', ':', 'cd '))
	bind('f', do('open_console', '>', 'find '))

	# key combinations which change the current directory
	def cd(path):
		return lambda fm: fm.enter_dir(path)

	bind('gh', do('cd', '~'))
	bind('ge', do('cd', '/etc'))
	bind('gu', do('cd', '/usr'))
	bind('gr', do('cd', '/'))
	bind('gm', do('cd', '/media'))
	bind('gn', do('cd', '/mnt'))
	bind('gt', do('cd', '~/.trash'))
	bind('gs', do('cd', '/srv'))
	bind('gR', do('cd', RANGERDIR))

	bind('n', do('search_forward'))
	bind('N', do('search_backward'))

	# bookmarks
	for key in ALLOWED_BOOKMARK_KEYS:
		bind("`" + key, "'" + key, do('enter_bookmark', key))
		bind("m" + key, do('set_bookmark', key))
		bind("um" + key, do('unset_bookmark', key))

	# system functions
	bind(ctrl('D'), 'q', 'ZZ', do('exit'))
	bind(ctrl('R'), do('reset'))
	bind(ctrl('L'), do('redraw'))
	bind(ctrl('C'), do('interrupt'))
	bind(curses.KEY_RESIZE, do('resize'))
	bind(curses.KEY_MOUSE, do('handle_mouse'))
	bind(':', do('open_console', ':'))
	bind('>', do('open_console', '>'))
	bind('/', do('open_console', '/'))
	bind('?', do('open_console', '?'))
	bind('!', do('open_console', '!'))
	bind('r', do('open_console', '@'))

	def test(fm):
		from ranger import log
		log(fm.bookmarks.dct)
	bind('x', test)

	command_list.rebuild_paths()


def initialize_console_commands(command_list):
	"""Initialize the commands for the console widget only"""

	def bind(*args):
		command_list.bind(args[-1], *args[:-1])

	def do_fm(method, *args, **kw):
		return lambda con: getattr(con.fm, method)(*args, **kw)

	# movement
	bind(curses.KEY_UP, do('history_move', -1))
	bind(curses.KEY_DOWN, do('history_move', 1))
	bind(ctrl('b'), curses.KEY_LEFT, do('move', relative = -1))
	bind(ctrl('f'), curses.KEY_RIGHT, do('move', relative = 1))
	bind(ctrl('a'), curses.KEY_HOME, do('move', absolute = 0))
	bind(ctrl('e'), curses.KEY_END, do('move', absolute = -1))
	bind(ctrl('d'), curses.KEY_DC, do('delete', 0))
	bind(ctrl('h'), curses.KEY_BACKSPACE, DEL, do('delete', -1))
	bind(ctrl('w'), do('delete_word'))
	bind(ctrl('k'), do('delete_rest', 1))
	bind(ctrl('u'), do('delete_rest', -1))
	bind(ctrl('y'), do('paste'))

	# system functions
	bind(ctrl('c'), ESC, do('close'))
	bind(ctrl('j'), curses.KEY_ENTER, do('execute'))
	bind(ctrl('l'), do_fm('redraw'))
	bind(TAB, do('tab'))
	bind(curses.KEY_BTAB, do('tab', -1))
	bind(curses.KEY_RESIZE, do_fm('resize'))

	# type keys
	def type_key(key):
		return lambda con: con.type_key(key)

	for i in range(ord(' '), ord('~')+1):
		bind(i, type_key(i))

	command_list.rebuild_paths()