summary refs log tree commit diff stats
path: root/code/environment.py
blob: 515fc8c60d82a21eeec9122868aa5f351432f980 (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
31
32
33
34
35
36
37
38
import directory

class Vector():
	def __init__(self, x, y):
		self.x = x
		self.y = y

class Environment():
	# A collection of data which is relevant for more than
	# one class.
	def __init__(self, opt):
		self.opt = opt
		self.path = None
		self.pathway = ()
		self.directories = {}
		self.pwd = None # current directory
		self.cf = None # current file
		self.keybuffer = ''
		self.copy = None
		self.termsize = Vector(80, 24)
	
	def at_level(self, level):
		if level <= 0:
			try:
				return self.pathway[level - 1]
			except IndexError:
				return None
		else:
			return self.cf

	def get_directory(self, path):
		import os
		path = os.path.abspath(path)
		try:
			return self.directories[path]
		except KeyError:
			self.directories[path] = directory.Directory(path)
			return self.directories[path]