diff options
author | hut <hut@lavabit.com> | 2009-11-29 20:35:23 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2009-11-29 20:35:23 +0100 |
commit | 5805deca6306eb888ebdad64c14119995521c6b8 (patch) | |
tree | 8041ac52247c99857e0d21dc4c4332cb97556f0e /ranger | |
parent | f027adc08ce0d15717c7694956f23ff637553543 (diff) | |
download | ranger-5805deca6306eb888ebdad64c14119995521c6b8.tar.gz |
random improvements
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/conf/colorschemes/snow.py | 32 | ||||
-rw-r--r-- | ranger/conf/keys.py | 1 | ||||
-rw-r--r-- | ranger/fm.py | 12 | ||||
-rw-r--r-- | ranger/fsobject.py | 21 | ||||
-rw-r--r-- | ranger/gui/colorscheme.py | 2 | ||||
-rw-r--r-- | ranger/gui/wdisplay.py | 14 | ||||
-rw-r--r-- | ranger/gui/wtitlebar.py | 25 |
7 files changed, 87 insertions, 20 deletions
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() + |