summary refs log blame commit diff stats
path: root/code/fm.py
blob: c2fe30a4f63286f7cb6bc4d3fb0f49092685d6b7 (plain) (tree)
1
2
3
4
5
6
          
                           

           
                                                 
                                      













                                                                 
                                           
                                                                       




                                    
                                                                                                                        



                                                         
                                             

                                    
                                                                    



                                                         
                                      
                             

                             

                                          

                            
                           


                                
import sys
import ui, debug, directory

class FM():
	def __init__(self, options, environment):
		self.options = options
		self.env = environment

	def setup(self, path, ui):
		self.ui = ui
		self.enter_dir(path)

	def enter_dir(self, path):
		self.env.path = path
		try:
			self.pwd = self.env.directories[path]
		except KeyError:
			self.env.pwd = directory.Directory(path)
			self.env.directories[path] = self.env.pwd

		self.env.pwd.load_content()
		if len(self.env.pwd) > 0: self.env.cf = self.env.pwd[0]

	def run(self):
		try:
			while 1:
				try:
					self.ui.feed(self.env.directories, self.env.pwd, self.env.cf, self.env.termsize)
					self.ui.draw()
				except KeyboardInterrupt:
					self.interrupt()
				except:
					raise

				try:
					key = self.ui.get_next_key()
					self.press(key)
				except KeyboardInterrupt:
					self.interrupt()
		except:
			self.ui.exit()
			raise

	def press(self, key):
		if (key == ord('q')):
			raise SystemExit()

	def interrupt(self):
		import time
		self.buffer = ""
		time.sleep(0.2)