summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2012-08-05 05:30:55 +0200
committerhut <hut@lavabit.com>2012-08-05 14:36:32 +0200
commit417c594f51afb558f256e9b00ea321aee1c5a4ab (patch)
treee278bacfc5872106c4e9a56b825e4e98cd6e7a76
parentc73d6ad8c6aac054dcb2a511640001df4541e64d (diff)
downloadranger-417c594f51afb558f256e9b00ea321aee1c5a4ab.tar.gz
move fm.env.{keymaps,keybuffer} to fm.ui.{keymaps,keybuffer}
-rw-r--r--ranger/config/commands.py6
-rw-r--r--ranger/core/actions.py4
-rw-r--r--ranger/core/environment.py3
-rw-r--r--ranger/core/fm.py10
-rw-r--r--ranger/core/main.py2
-rw-r--r--ranger/gui/ui.py18
-rw-r--r--ranger/gui/widgets/browserview.py2
-rw-r--r--ranger/gui/widgets/console.py2
-rw-r--r--ranger/gui/widgets/pager.py2
-rw-r--r--ranger/gui/widgets/taskview.py2
-rw-r--r--ranger/gui/widgets/titlebar.py4
11 files changed, 29 insertions, 26 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py
index f58d3fbe..88b50860 100644
--- a/ranger/config/commands.py
+++ b/ranger/config/commands.py
@@ -881,7 +881,7 @@ class copymap(Command):
 			return self.notify("Not enough arguments", bad=True)
 
 		for arg in self.args[2:]:
-			self.fm.env.keymaps.copy(self.context, self.arg(1), arg)
+			self.fm.ui.keymaps.copy(self.context, self.arg(1), arg)
 
 
 class copypmap(copymap):
@@ -917,7 +917,7 @@ class unmap(Command):
 
 	def execute(self):
 		for arg in self.args[1:]:
-			self.fm.env.keymaps.unbind(self.context, arg)
+			self.fm.ui.keymaps.unbind(self.context, arg)
 
 
 class cunmap(unmap):
@@ -958,7 +958,7 @@ class map_(Command):
 	resolve_macros = False
 
 	def execute(self):
-		self.fm.env.keymaps.bind(self.context, self.arg(1), self.rest(2))
+		self.fm.ui.keymaps.bind(self.context, self.arg(1), self.rest(2))
 
 
 class cmap(map_):
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index 40aca662..ad797bec 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -897,8 +897,8 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 
 		for context in contexts:
 			write("Keybindings in `%s'\n" % context)
-			if context in self.env.keymaps:
-				recurse([], self.env.keymaps[context])
+			if context in self.fm.ui.keymaps:
+				recurse([], self.fm.ui.keymaps[context])
 			else:
 				write("  None\n")
 			write("\n")
diff --git a/ranger/core/environment.py b/ranger/core/environment.py
index eae230b3..ece1c4c8 100644
--- a/ranger/core/environment.py
+++ b/ranger/core/environment.py
@@ -7,7 +7,6 @@ import socket
 from os.path import abspath, normpath, join, expanduser, isdir
 
 from ranger.fsobject import Directory
-from ranger.ext.keybinding_parser import KeyBuffer, KeyMaps
 from ranger.container.history import History
 from ranger.ext.signals import SignalDispatcher
 from ranger.core.shared import SettingsAware, FileManagerAware
@@ -29,8 +28,6 @@ class Environment(SettingsAware, FileManagerAware, SignalDispatcher):
 		self.path = abspath(expanduser(path))
 		self._cf = None
 		self.pathway = ()
-		self.keybuffer = KeyBuffer()
-		self.keymaps = KeyMaps(self.keybuffer)
 		self.history = History(self.settings.max_history_size, unique=False)
 
 		try:
diff --git a/ranger/core/fm.py b/ranger/core/fm.py
index 141ffc7b..06c95061 100644
--- a/ranger/core/fm.py
+++ b/ranger/core/fm.py
@@ -40,7 +40,10 @@ class FM(Actions, SignalDispatcher):
 		"""Initialize FM."""
 		Actions.__init__(self)
 		SignalDispatcher.__init__(self)
-		self.ui = ui
+		if ui is None:
+			self.ui = UI()
+		else:
+			self.ui = ui
 		self.directories = dict()
 		self.log = deque(maxlen=20)
 		self.bookmarks = bookmarks
@@ -85,9 +88,8 @@ class FM(Actions, SignalDispatcher):
 		if not ranger.arg.clean and self.tags is None:
 			self.tags = Tags(self.confpath('tagged'))
 
-		if self.ui is None:
-			self.ui = UI()
-			self.ui.initialize()
+		self.ui.setup_curses()
+		self.ui.initialize()
 
 		self.rifle.hook_before_executing = lambda a, b, flags: \
 			self.ui.suspend() if 'f' not in flags else None
diff --git a/ranger/core/main.py b/ranger/core/main.py
index 55d52f59..616bf361 100644
--- a/ranger/core/main.py
+++ b/ranger/core/main.py
@@ -97,7 +97,7 @@ def main():
 		if arg.list_unused_keys:
 			from ranger.ext.keybinding_parser import (special_keys,
 					reversed_special_keys)
-			maps = fm.env.keymaps['browser']
+			maps = fm.ui.keymaps['browser']
 			for key in sorted(special_keys.values(), key=lambda x: str(x)):
 				if key not in maps:
 					print("<%s>" % reversed_special_keys[key])
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index a0aa800f..2b6612b1 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -8,7 +8,7 @@ import _curses
 
 from .displayable import DisplayableContainer
 from .mouse_event import MouseEvent
-from ranger.ext.keybinding_parser import ALT_KEY
+from ranger.ext.keybinding_parser import KeyBuffer, KeyMaps, ALT_KEY
 
 TERMINALS_WITH_TITLE = ("xterm", "xterm-256color", "rxvt",
 		"rxvt-256color", "rxvt-unicode", "rxvt-unicode-256color",
@@ -41,24 +41,28 @@ class UI(DisplayableContainer):
 	is_set_up = False
 	load_mode = False
 	is_on = False
+	termsize = (24, 80)
+
 	def __init__(self, env=None, fm=None):
 		self._draw_title = os.environ["TERM"] in TERMINALS_WITH_TITLE
-		os.environ['ESCDELAY'] = '25'   # don't know a cleaner way
+		self.keybuffer = KeyBuffer()
+		self.keymaps = KeyMaps(self.keybuffer)
+		self.keymaps.use_keymap('browser')
 
 		if env is not None:
 			self.env = env
 		if fm is not None:
 			self.fm = fm
 
+	def setup_curses(self):
+		os.environ['ESCDELAY'] = '25'   # don't know a cleaner way
 		try:
 			self.win = curses.initscr()
 		except _curses.error as e:
 			if e.args[0] == "setupterm: could not find terminal":
 				os.environ['TERM'] = 'linux'
 				self.win = curses.initscr()
-		self.env.keymaps.use_keymap('browser')
 		self.termsize = self.win.getmaxyx()
-
 		DisplayableContainer.__init__(self, None)
 
 	def initialize(self):
@@ -136,14 +140,14 @@ class UI(DisplayableContainer):
 			self.hint()
 
 		if key < 0:
-			self.env.keybuffer.clear()
+			self.keybuffer.clear()
 
 		elif not DisplayableContainer.press(self, key):
-			self.env.keymaps.use_keymap('browser')
+			self.keymaps.use_keymap('browser')
 			self.press(key)
 
 	def press(self, key):
-		keybuffer = self.env.keybuffer
+		keybuffer = self.keybuffer
 		self.status.clear_message()
 
 		keybuffer.add(key)
diff --git a/ranger/gui/widgets/browserview.py b/ranger/gui/widgets/browserview.py
index 89d099ea..36e468a0 100644
--- a/ranger/gui/widgets/browserview.py
+++ b/ranger/gui/widgets/browserview.py
@@ -204,7 +204,7 @@ class BrowserView(Widget, DisplayableContainer):
 	def _draw_hints(self):
 		self.need_clear = True
 		hints = []
-		for k, v in self.fm.env.keybuffer.pointer.items():
+		for k, v in self.fm.ui.keybuffer.pointer.items():
 			k = key_to_string(k)
 			if isinstance(v, dict):
 				text = '...'
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py
index 733e2b8b..ba6dca86 100644
--- a/ranger/gui/widgets/console.py
+++ b/ranger/gui/widgets/console.py
@@ -137,7 +137,7 @@ class Console(Widget):
 		self.line = ''
 
 	def press(self, key):
-		self.env.keymaps.use_keymap('console')
+		self.fm.ui.keymaps.use_keymap('console')
 		if not self.fm.ui.press(key):
 			self.type_key(key)
 
diff --git a/ranger/gui/widgets/pager.py b/ranger/gui/widgets/pager.py
index 566c5ff1..cf156715 100644
--- a/ranger/gui/widgets/pager.py
+++ b/ranger/gui/widgets/pager.py
@@ -97,7 +97,7 @@ class Pager(Widget):
 					offset=-self.hei + 1)
 
 	def press(self, key):
-		self.env.keymaps.use_keymap('pager')
+		self.fm.ui.keymaps.use_keymap('pager')
 		self.fm.ui.press(key)
 
 	def set_source(self, source, strip=False):
diff --git a/ranger/gui/widgets/taskview.py b/ranger/gui/widgets/taskview.py
index 59e99679..6bb65701 100644
--- a/ranger/gui/widgets/taskview.py
+++ b/ranger/gui/widgets/taskview.py
@@ -80,7 +80,7 @@ class TaskView(Widget, Accumulator):
 		self.fm.loader.move(_from=i, to=to)
 
 	def press(self, key):
-		self.env.keymaps.use_keymap('taskview')
+		self.fm.ui.keymaps.use_keymap('taskview')
 		self.fm.ui.press(key)
 
 	def get_list(self):
diff --git a/ranger/gui/widgets/titlebar.py b/ranger/gui/widgets/titlebar.py
index f4f4cb77..4ec917b1 100644
--- a/ranger/gui/widgets/titlebar.py
+++ b/ranger/gui/widgets/titlebar.py
@@ -31,7 +31,7 @@ class TitleBar(Widget):
 	def draw(self):
 		if self.need_redraw or \
 				self.env.cf != self.old_cf or\
-				str(self.env.keybuffer) != str(self.old_keybuffer) or\
+				str(self.fm.ui.keybuffer) != str(self.old_keybuffer) or\
 				self.wid != self.old_wid:
 			self.need_redraw = False
 			self.old_wid = self.wid
@@ -121,7 +121,7 @@ class TitleBar(Widget):
 
 	def _get_right_part(self, bar):
 		# TODO: fix that pressed keys are cut off when chaining CTRL keys
-		kb = str(self.env.keybuffer)
+		kb = str(self.fm.ui.keybuffer)
 		self.old_keybuffer = kb
 		bar.addright(kb, 'keybuffer', fixed=True)
 		bar.addright('  ', 'space', fixed=True)