summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-11-29 20:35:23 +0100
committerhut <hut@lavabit.com>2009-11-29 20:35:23 +0100
commit5805deca6306eb888ebdad64c14119995521c6b8 (patch)
tree8041ac52247c99857e0d21dc4c4332cb97556f0e
parentf027adc08ce0d15717c7694956f23ff637553543 (diff)
downloadranger-5805deca6306eb888ebdad64c14119995521c6b8.tar.gz
random improvements
-rwxr-xr-xranger.py4
-rw-r--r--ranger/conf/colorschemes/snow.py32
-rw-r--r--ranger/conf/keys.py1
-rw-r--r--ranger/fm.py12
-rw-r--r--ranger/fsobject.py21
-rw-r--r--ranger/gui/colorscheme.py2
-rw-r--r--ranger/gui/wdisplay.py14
-rw-r--r--ranger/gui/wtitlebar.py25
-rw-r--r--test/tc_directory.py35
9 files changed, 107 insertions, 39 deletions
diff --git a/ranger.py b/ranger.py
index d4c4a961..8a2d5967 100755
--- a/ranger.py
+++ b/ranger.py
@@ -21,7 +21,7 @@ from ranger.environment import Environment
 from ranger.command import CommandList
 from ranger.conf import keys, options
 from ranger.gui.defaultui import DefaultUI as UI
-from ranger.conf.colorschemes.snow import Snow as ColorScheme
+from ranger.conf.colorschemes.snow import MyColorScheme
 
 import sys, os, locale
 
@@ -46,7 +46,7 @@ try:
 
 	env = Environment(opt)
 	commandlist = CommandList()
-	colorscheme = ColorScheme()
+	colorscheme = MyColorScheme()
 	keys.initialize_commands(commandlist)
 
 	my_ui = UI(env, commandlist, colorscheme)
diff --git a/ranger/conf/colorschemes/snow.py b/ranger/conf/colorschemes/snow.py
index 40909c9d..ee2ecb4a 100644
--- a/ranger/conf/colorschemes/snow.py
+++ b/ranger/conf/colorschemes/snow.py
@@ -1,14 +1,14 @@
 from ranger.gui.colorscheme import ColorScheme
 from ranger.gui.color import *
 
-class Snow(ColorScheme):
+class MyColorScheme(ColorScheme):
 	def use(self, context):
-		if context.reset:
-			return default_colors
+		fg, bg, attr = default_colors
 
-		if context.wdisplay:
-			fg, bg = default, default
+		if context.reset:
+			pass
 
+		elif context.in_display:
 			if context.selected:
 				attr = reverse
 			else:
@@ -19,20 +19,28 @@ class Snow(ColorScheme):
 
 			if context.directory:
 				fg = blue
-
-			if context.executable:
+			elif context.executable:
 				fg = green
 
 			if context.media:
-				fg = pink
+				fg = magenta
 
 			if context.link:
 				fg = cyan
 
 			if context.maindisplay and context.selected:
-				attr = attr | bold
-				fg = yellow
+				attr |= bold
 
-			return fg, bg, attr
+		elif context.in_titlebar:
+			attr |= bold
+
+			if context.hostname:
+				fg = green
+
+			elif context.directory:
+				fg = blue
+
+			elif context.link:
+				fg = cyan
 
-		return default_colors
+		return fg, bg, attr
diff --git a/ranger/conf/keys.py b/ranger/conf/keys.py
index 7c08ae4f..54e2ba0d 100644
--- a/ranger/conf/keys.py
+++ b/ranger/conf/keys.py
@@ -31,6 +31,7 @@ def initialize_commands(cl):
 	cl.bind(move_pages( -0.5 ),     'K')
 	cl.bind(move( absolute = 0 ),   'gg')
 	cl.bind(move( absolute = -1 ),  'G')
+	cl.bind(FM.edit_file,           'E')
 
 	cl.bind(toggle_option('show_hidden'), 'th')
 
diff --git a/ranger/fm.py b/ranger/fm.py
index c30fb92c..b8df319c 100644
--- a/ranger/fm.py
+++ b/ranger/fm.py
@@ -47,6 +47,18 @@ class FM():
 		from subprocess import Popen
 		Popen(('mplayer', '-fs', path), stdout = null, stderr = null)
 
+	def edit_file(self):
+		from subprocess import Popen
+		import os
+		if self.env.cf is None: return
+
+		self.ui.exit()
+
+		p = Popen(('vim', self.env.cf.path))
+		os.waitpid(p.pid, 0)
+
+		self.ui.initialize()
+
 	def move_pointer(self, relative = 0, absolute = None):
 		self.env.cf = self.env.pwd.move_pointer(relative, absolute)
 
diff --git a/ranger/fsobject.py b/ranger/fsobject.py
index e482f5fa..081c22be 100644
--- a/ranger/fsobject.py
+++ b/ranger/fsobject.py
@@ -60,12 +60,13 @@ class FileSystemObject(object):
 			elif os.path.isfile(self.path):
 				self.type = T_FILE
 				self.size = self.stat.st_size
-				self.infostring = ' %d' % self.stat.st_size
+				self.infostring = ' ' + human_readable(self.stat.st_size)
 			else:
 				self.type = T_UNKNOWN
 				self.infostring = None
 
 		else:
+			self.stat = None
 			self.islink = False
 			self.infostring = None
 			self.type = T_NONEXISTANT
@@ -90,3 +91,21 @@ class FileSystemObject(object):
 			self.load()
 			return True
 		return False
+
+ONE_KB = 1024
+UNITS = tuple('BKMGTY')
+MAX_I = len(UNITS) - 1
+
+def human_readable(byte):
+	i = 0
+	flt = float(byte)
+
+	while flt > ONE_KB and i < MAX_I:
+		flt /= ONE_KB
+		i += 1
+	
+	if int(flt) == flt:
+		return '%.0f %s' % (flt, UNITS[i])
+
+	else:
+		return '%.2f %s' % (flt, UNITS[i])
diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py
index ff3f9243..e69e9d7e 100644
--- a/ranger/gui/colorscheme.py
+++ b/ranger/gui/colorscheme.py
@@ -1,4 +1,4 @@
-CONTEXT_KEYS = ['reset', 'wdisplay', 'wstatusbar', 'wtitlebar', 'wconsole', 'directory', 'file', 'maindisplay', 'executable', 'media', 'link', 'broken', 'selected', 'empty']
+CONTEXT_KEYS = ['reset', 'in_display', 'in_statusbar', 'in_titlebar', 'in_console', 'directory', 'file', 'maindisplay', 'executable', 'media', 'link', 'broken', 'selected', 'empty', 'currentfile', 'hostname']
 
 class ColorSchemeContext():
 	pass
diff --git a/ranger/gui/wdisplay.py b/ranger/gui/wdisplay.py
index f021279b..00f73a93 100644
--- a/ranger/gui/wdisplay.py
+++ b/ranger/gui/wdisplay.py
@@ -46,13 +46,14 @@ class WDisplay(SuperClass):
 	def draw_directory(self):
 		from ranger.directory import Directory
 		import curses
+		import stat
 
 		self.target.show_hidden = self.show_hidden
 		self.target.load_content_if_outdated()
 		self.target.directories_first = self.directories_first
 		self.target.sort_if_outdated()
 
-		base_color = ['wdisplay']
+		base_color = ['in_display']
 
 		if self.main_display:
 			base_color.append('maindisplay')
@@ -73,10 +74,12 @@ class WDisplay(SuperClass):
 
 		selected_i = self.target.pointed_index
 		for line in range(self.hei):
-			# last file reached?
 			i = line + self.scroll_begin
-			try: drawed = self.target[i]
-			except IndexError: break
+
+			try:
+				drawed = self.target[i]
+			except IndexError:
+				break
 
 			this_color = base_color[:]
 
@@ -88,6 +91,9 @@ class WDisplay(SuperClass):
 			else:
 				this_color.append('file')
 
+			if drawed.stat is not None and drawed.stat.st_mode & stat.S_IXUSR:
+				this_color.append('executable')
+
 			if drawed.islink:
 				this_color.append('link')
 
diff --git a/ranger/gui/wtitlebar.py b/ranger/gui/wtitlebar.py
index 2ac8ae65..b95311dd 100644
--- a/ranger/gui/wtitlebar.py
+++ b/ranger/gui/wtitlebar.py
@@ -1,12 +1,33 @@
-import curses
+import curses, socket
 from ranger.gui.widget import Widget as SuperClass
 
+
 class WTitleBar(SuperClass):
 	def feed_env(self, env):
 		self.pathway = env.pathway
+		self.cf = env.cf
 
 	def draw(self):
 		self.win.move(self.y, self.x)
+
+		try:
+			self.color('in_titlebar', 'hostname')
+			self.win.addnstr(socket.gethostname(), self.wid)
+		except:
+			pass
+
 		for path in self.pathway:
 			currentx = self.win.getyx()[1]
-			self.win.addnstr(path.basename + ' / ', (self.wid - currentx))
+
+			if path.islink:
+				self.color('in_titlebar', 'link')
+			else:
+				self.color('in_titlebar', 'directory')
+
+			self.win.addnstr(path.basename + '/', max(self.wid - currentx, 0))
+		if self.cf is not None:
+			currentx = self.win.getyx()[1]
+			self.color('in_titlebar', 'file')
+			self.win.addnstr(self.cf.basename, max(self.wid - currentx, 0))
+		self.color_reset()
+
diff --git a/test/tc_directory.py b/test/tc_directory.py
index 275e3129..c2129a29 100644
--- a/test/tc_directory.py
+++ b/test/tc_directory.py
@@ -66,23 +66,24 @@ class Test1(unittest.TestCase):
 		self.assertRaises(fsobject.NotLoadedYet, len, dir)
 		self.assertRaises(fsobject.NotLoadedYet, dir.__getitem__, 0)
 
-	def test_modify_frozen_clone(self):
-		dir = Directory(TESTDIR)
-		clone = dir.frozen_clone()
-
-		# assert that their attributes are equal, except for frozen, which
-		# should be true for the clone.
-		self.assertTrue(clone.frozen)
-		clone.frozen = False
-		self.assertEqual(dir.__dict__, clone.__dict__)
-		clone.frozen = True
-
-		# check for inequality after loading filenames with one object
-		self.assertEqual(dir.filenames, clone.filenames)
-		dir.load_content()
-		self.assertNotEqual(dir.filenames, clone.filenames)
-
-		self.assertRaises(fsobject.FrozenException, clone.load_content)
+	# This test is obsolete!
+#	def test_modify_frozen_clone(self):
+#		dir = Directory(TESTDIR)
+#		clone = dir.frozen_clone()
+#
+#		# assert that their attributes are equal, except for frozen, which
+#		# should be true for the clone.
+#		self.assertTrue(clone.frozen)
+#		clone.frozen = False
+#		self.assertEqual(dir.__dict__, clone.__dict__)
+#		clone.frozen = True
+#
+#		# check for inequality after loading filenames with one object
+#		self.assertEqual(dir.filenames, clone.filenames)
+#		dir.load_content()
+#		self.assertNotEqual(dir.filenames, clone.filenames)
+#
+#		self.assertRaises(fsobject.FrozenException, clone.load_content)
 
 	def test_load_if_outdated(self):
 		import os