about summary refs log tree commit diff stats
path: root/src/stanza.h
diff options
context:
space:
mode:
authorDolan O'Toole <dolan.otoole@corelogic.co.uk>2012-12-05 18:20:48 +0000
committerJames Booth <boothj5@gmail.com>2012-12-05 19:15:16 +0000
commitb89ca4fc3ecfce7a99a5b3d4216eebeec657f586 (patch)
treedabbd7a16903a9ff7dc03043cd8bec7a07995b7d /src/stanza.h
parentc0ac3673afb8de9b017d6a20433cbca9e20995b5 (diff)
downloadprofani-tty-b89ca4fc3ecfce7a99a5b3d4216eebeec657f586.tar.gz
Merged Dolans fix for not clearing typing message
Diffstat (limited to 'src/stanza.h')
0 files changed, 0 insertions, 0 deletions
/a> 107 108 109 110 111 112 113 114 115 116 117 118
# Copyright (c) 2009, 2010 hut <hut@lavabit.com>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

from time import time
from collections import deque

from ranger.actions import Actions
from ranger.container import Bookmarks
from ranger.ext.relpath import relpath_conf
from ranger import __version__
from ranger.fsobject import Loader

CTRL_C = 3
TICKS_BEFORE_COLLECTING_GARBAGE = 100

class FM(Actions):
	input_blocked = False
	input_blocked_until = 0
	stderr_to_out = False
	def __init__(self, ui=None, bookmarks=None, tags=None):
		"""Initialize FM."""
		Actions.__init__(self)
		self.ui = ui
		self.log = deque(maxlen=20)
		self.bookmarks = bookmarks
		self.tags = tags
		self.loader = Loader()
		self.apps = self.settings.apps.CustomApplications()

		from ranger.shared import FileManagerAware
		FileManagerAware.fm = self

	def initialize(self):
		"""If ui/bookmarks are None, they will be initialized here."""
		from ranger.fsobject.directory import Directory

		if self.bookmarks is None:
			self.bookmarks = Bookmarks(
					bookmarkfile=relpath_conf('bookmarks'),
					bookmarktype=Directory,
					autosave=self.settings.autosave_bookmarks)
			self.bookmarks.load()

		else:
			self.bookmarks = bookmarks

		from ranger.container.tags import Tags
		if self.tags is None:
			self.tags = Tags('~/.ranger/tagged')

		if self.ui is None:
			from ranger.gui.defaultui import DefaultUI
			self.ui = DefaultUI()
			self.ui.initialize()

	def block_input(self, sec=0):
		self.input_blocked = sec != 0
		self.input_blocked_until = time() + sec

	def loop(self):
		"""
		The main loop consists of:
		1. reloading bookmarks if outdated
		2. letting the loader work
		3. drawing and finalizing ui
		4. reading and handling user input
		5. after X loops: collecting unused directory objects
		"""

		self.env.enter_dir(self.env.path)

		gc_tick = 0

		try:
			while True:
				try:
					self.bookmarks.update_if_outdated()
					self.loader.work()
					if hasattr(self.ui, 'throbber'):
						if self.loader.has_work():
							self.ui.throbber(self.loader.status)
						else:
							self.ui.throbber(remove=True)

					self.ui.redraw()

					self.ui.set_load_mode(self.loader.has_work())

					key = self.ui.get_next_key()

					if key > 0:
						if self.input_blocked and \
								time() > self.input_blocked_until:
							self.input_blocked = False
						if not self.input_blocked:
							self.ui.handle_key(key)

					gc_tick += 1
					if gc_tick > TICKS_BEFORE_COLLECTING_GARBAGE:
						gc_tick = 0
						self.env.garbage_collect()

				finally:
					pass
		finally:
			self.bookmarks.remember(self.env.pwd)
			self.bookmarks.save()