From 30b2579508d921c6b5b2d9d6540126737b10d8b7 Mon Sep 17 00:00:00 2001 From: hut Date: Tue, 15 Dec 2009 12:28:00 +0100 Subject: cleanups, display link destinations --- ranger/colorschemes/jungle.py | 8 ++++---- ranger/fsobject/fsobject.py | 29 ++++++++++++++++++++++------- ranger/gui/colorscheme.py | 4 ++-- ranger/gui/widgets/filelist.py | 26 ++++++++++++++++---------- ranger/gui/widgets/statusbar.py | 34 +++++++++++++++++++++++++++------- 5 files changed, 71 insertions(+), 30 deletions(-) diff --git a/ranger/colorschemes/jungle.py b/ranger/colorschemes/jungle.py index d2b9efd2..c70d95c7 100644 --- a/ranger/colorschemes/jungle.py +++ b/ranger/colorschemes/jungle.py @@ -31,7 +31,7 @@ class Default(ColorScheme): fg = yellow # banananas if context.link: - fg = cyan + fg = context.good and cyan or magenta if context.maindisplay and context.selected: attr |= bold @@ -53,10 +53,10 @@ class Default(ColorScheme): attr = normal elif context.in_statusbar: - if context.permissions: - if context.allowed: + if context.permissions or context.link: + if context.good: fg = cyan - elif context.denied: + elif context.bad: fg = magenta return fg, bg, attr diff --git a/ranger/fsobject/fsobject.py b/ranger/fsobject/fsobject.py index 728ff46d..30ed7839 100644 --- a/ranger/fsobject/fsobject.py +++ b/ranger/fsobject/fsobject.py @@ -17,7 +17,7 @@ class FileSystemObject(MimeTypeAware, FileManagerAware): loaded = False runnable = False islink = False - brokenlink = False + readlink = None stat = None infostring = None permissions = None @@ -90,13 +90,22 @@ class FileSystemObject(MimeTypeAware, FileManagerAware): """reads useful information about the filesystem-object from the filesystem and caches it for later use""" import os + import stat from ranger.ext.human_readable import human_readable self.loaded = True + try: + self.stat = os.lstat(self.path) + except OSError: + self.stat = None + self.islink = False + self.accessible = False + else: + self.islink = stat.S_ISLNK(self.stat.st_mode) + self.accessible = True + if os.access(self.path, os.F_OK): - self.stat = os.stat(self.path) - self.islink = os.path.islink(self.path) self.exists = True self.accessible = True @@ -119,18 +128,24 @@ and caches it for later use""" self.infostring = None else: - self.stat = None - self.islink = False - self.infostring = None + if self.islink: + self.infostring = '->' + else: + self.infostring = None self.type = T_NONEXISTANT self.exists = False self.runnable = False - self.accessible = False + + if self.islink: + self.readlink = os.readlink(self.path) def get_permission_string(self): if self.permissions is not None: return self.permissions + if self.accessible is False: + return '----------' + import stat perms = '-' mode = self.stat.st_mode diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py index 537f4458..f7a2a2d7 100644 --- a/ranger/gui/colorscheme.py +++ b/ranger/gui/colorscheme.py @@ -3,8 +3,8 @@ CONTEXT_KEYS = [ 'reset', 'error', 'directory', 'file', 'hostname', 'executable', 'media', 'link', 'video', 'audio', 'image', 'media', 'document', 'container', - 'broken', 'selected', 'empty', 'maindisplay', - 'allowed', 'denied', + 'selected', 'empty', 'maindisplay', + 'good', 'bad', 'space', 'permissions', 'owner', 'group', 'mtime', 'nlink', 'scroll', 'all', 'bot', 'top', 'percentage', 'keybuffer'] diff --git a/ranger/gui/widgets/filelist.py b/ranger/gui/widgets/filelist.py index 4f9a7149..7a5e38da 100644 --- a/ranger/gui/widgets/filelist.py +++ b/ranger/gui/widgets/filelist.py @@ -51,7 +51,7 @@ class FileList(Widget): return False if isinstance(self.target, File): - if not self.settings.preview_files: + if not self._preview_this_file(self.target): return False return True @@ -72,22 +72,27 @@ class FileList(Widget): self.draw_directory() # else: # self.win.addnstr(self.y, self.x, "unknown type.", self.wid) + + def _preview_this_file(self, target): + return target.document and not self.settings.preview_files def draw_file(self): """Draw a preview of the file, if the settings allow it""" if not self.target.accessible: self.win.addnstr(self.y, self.x, "not accessible", self.wid) return + + if not self._preview_this_file(self.target): + return - if self.settings.preview_files: - try: - if self.target.size < 1024 * 20: - f = open(self.target.path, 'r') - for line in range(self.hei): - read = f.readline().expandtabs() - self.win.addnstr(self.y + line, self.x, read, self.wid) - except: - pass + try: + if self.target.size < 1024 * 20: + f = open(self.target.path, 'r') + for line in range(self.hei): + read = f.readline().expandtabs() + self.win.addnstr(self.y + line, self.x, read, self.wid) + except: + pass def draw_directory(self): """Draw the contents of a directory""" @@ -141,6 +146,7 @@ class FileList(Widget): if drawed.islink: this_color.append('link') + this_color.append(drawed.exists and 'good' or 'bad') string = drawed.basename if self.main_display: diff --git a/ranger/gui/widgets/statusbar.py b/ranger/gui/widgets/statusbar.py index 6153101c..41da7b06 100644 --- a/ranger/gui/widgets/statusbar.py +++ b/ranger/gui/widgets/statusbar.py @@ -21,6 +21,11 @@ class StatusBar(Widget): self.filelist = filelist def draw(self): + """Draw the statusbar""" + + # each item in the returned array looks like: + # [ list_with_color_tags, string ] + # [ ['permissions', 'allowed'], '-rwxr-xr-x' ] left = self._get_left_part() right = self._get_right_part() self._print_result(self._combine_parts(left, right)) @@ -28,16 +33,23 @@ class StatusBar(Widget): def _get_left_part(self): part = [] - target = self.env.at_level(0).pointed_file + if self.filelist is not None: + target = self.filelist.target.pointed_file + else: + target = self.env.at_level(0).pointed_file + if target is None: return part + if target.accessible is False: + return part + perms = target.get_permission_string() color = ['permissions'] if getuid() == target.stat.st_uid: - color.append('allowed') + color.append('good') else: - color.append('denied') + color.append('bad') part.append([color, perms]) part.append([['space'], " "]) @@ -47,8 +59,13 @@ class StatusBar(Widget): part.append([['space'], " "]) part.append([['group'], self._get_group(target)]) part.append([['space'], " "]) - part.append([['mtime'], strftime(self.timeformat, \ - localtime(target.stat.st_mtime))]) + if target.islink: + color = ['link'] + color.append(target.exists and 'good' or 'bad') + part.append([color, '-> ' + target.readlink]) + else: + part.append([['mtime'], strftime(self.timeformat, \ + localtime(target.stat.st_mtime))]) return part def _get_owner(self, target): @@ -77,7 +94,10 @@ class StatusBar(Widget): def _get_right_part(self): part = [] - target = self.env.at_level(0) + if self.filelist is not None: + target = self.filelist.target + else: + target = self.env.at_level(0) if self.filelist is not None: pos = target.scroll_begin @@ -90,7 +110,7 @@ class StatusBar(Widget): part.append([['scroll', 'bot'], 'Bot']) else: part.append([['scroll', 'percentage'], \ - '{0:0>.0f}%'.format(100.0*pos/max_pos)]) + '{0:0>.0f}%'.format(100.0 * pos / max_pos)]) else: part.append([['scroll', 'all'], 'All']) return part -- cgit 1.4.1-2-gfad0