summary refs log tree commit diff stats
path: root/setup.py
blob: 042fb70fda0ae10a6d931db082643d787b0985c6 (plain) (blame)
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
#!/usr/bin/env python
# Copyright (C) 2009, 2010, 2011  Roman Zimbelmann <romanz@lavabit.com>
# This software is distributed under the terms of the GNU GPL version 3.

import distutils.core
import ranger

if __name__ == '__main__':
	distutils.core.setup(
		name='ranger',
		description='Vim-like file manager',
		long_description=ranger.__doc__,
		version=ranger.__version__,
		author=ranger.__author__,
		author_email=ranger.__email__,
		license=ranger.__license__,
		url='http://savannah.nongnu.org/projects/ranger',
		scripts=['ranger/data/ranger'],
		data_files=[('share/man/man1', ['doc/ranger.1'])],
		package_data={'ranger': ['data/*', 'defaults/rc.conf']},
		packages=('ranger',
		          'ranger.api',
		          'ranger.colorschemes',
		          'ranger.container',
		          'ranger.core',
		          'ranger.defaults',
		          'ranger.ext',
		          'ranger.fsobject',
		          'ranger.gui',
		          'ranger.gui.widgets'))
'#n102'>102 103 104
105















                                                                       
                                          
































                                                                     



                                            






                                        
                                   






                                                        



                                                                       











                                                                                         

                                                                            
                                                          















                                                                                            
                                                                    
# 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/>.

from ranger.ext.keybinding_parser import (parse_keybinding,
	ANYKEY, PASSIVE_ACTION, QUANT_KEY)

digits = set(range(ord('0'), ord('9')+1))

class KeyMaps(dict):
	def __init__(self, keybuffer=None):
		dict.__init__(self)
		self.keybuffer = keybuffer
		self.used_keymap = None

	def bind(self, context, keys, leaf):
		try:
			pointer = self[context]
		except:
			self[context] = pointer = dict()
		keys = list(parse_keybinding(keys))
		if not keys:
			return
		last_key = keys[-1]
		for key in keys[:-1]:
			try:
				pointer = pointer[key]
			except:
				pointer[key] = pointer = dict()
		pointer[last_key] = leaf

	def use_keymap(self, keymap_name):
		self.keybuffer.keymap = self.get(keymap_name, dict())
		if self.used_keymap != keymap_name:
			self.used_keymap = keymap_name
			self.keybuffer.clear()


class KeyBuffer(object):
	any_key             = ANYKEY
	passive_key         = PASSIVE_ACTION
	quantifier_key      = QUANT_KEY
	exclude_from_anykey = [27]

	def __init__(self, keymap=None):
		self.keymap = keymap
		self.clear()

	def clear(self):
		self.keys = []
		self.wildcards = []
		self.pointer = self.keymap
		self.result = None
		self.quantifier = None
		self.finished_parsing_quantifier = False
		self.finished_parsing = False
		self.parse_error = False

		if self.keymap and self.quantifier_key in self.keymap:
			if self.keymap[self.quantifier_key] == 'false':
				self.finished_parsing_quantifier = True

	def add(self, key):
		self.keys.append(key)
		if not self.finished_parsing_quantifier and key in digits:
			if self.quantifier is None:
				self.quantifier = 0
			self.quantifier = self.quantifier * 10 + key - 48 # (48 = ord(0))
		else:
			self.finished_parsing_quantifier = True

			moved = True
			if key in self.pointer:
				self.pointer = self.pointer[key]
			elif self.any_key in self.pointer and \
					key not in self.exclude_from_anykey:
				self.wildcards.append(key)
				self.pointer = self.pointer[self.any_key]
			else:
				moved = False

			if moved:
				if isinstance(self.pointer, dict):
					if self.passive_key in self.pointer:
						self.result = self.pointer[self.passive_key]
				else:
					self.result = self.pointer
					self.finished_parsing = True
			else:
				self.finished_parsing = True
				self.parse_error = True

	def __str__(self):
		return "".join("{0:c}".format(c) for c in self.keys)