From 6099d9a30611e406afd5a257acd4b9bcb6954857 Mon Sep 17 00:00:00 2001 From: hut Date: Sat, 27 Mar 2010 04:04:21 +0100 Subject: fixed #74 and closed #67 (was fixed earlier) --- TODO | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'TODO') diff --git a/TODO b/TODO index 17991c40..e6dc7f6c 100644 --- a/TODO +++ b/TODO @@ -70,10 +70,10 @@ Bugs ( ) #60 10/02/05 utf support improvable (X) #62 10/02/15 curs_set can raise an exception (X) #65 10/02/16 "source ranger ranger some/file.txt" shouldn't cd after exit - ( ) #67 10/03/08 terminal title in tty + (X) #67 10/03/08 terminal title in tty (X) #69 10/03/11 tab-completion breaks with Apps subclass ( ) #73 10/03/21 when clicking on the first column, it goes 1x down - ( ) #74 10/03/21 console doesn't scroll + (X) #74 10/03/21 console doesn't scroll Ideas -- cgit 1.4.1-2-gfad0 From 8895b1301b0f32a3627225810441496a3e7cb211 Mon Sep 17 00:00:00 2001 From: hut Date: Sat, 27 Mar 2010 04:06:48 +0100 Subject: closed #40 for now --- TODO | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'TODO') diff --git a/TODO b/TODO index e6dc7f6c..98d459d7 100644 --- a/TODO +++ b/TODO @@ -60,8 +60,8 @@ Bugs (X) #25 10/01/06 directories sometimes dont reload correctly (X) #26 10/01/06 :delete on symlinks of directories fails (X) #31 10/01/06 ^C breaks cd-after-exit by stopping sourced shell script - ( ) #40 10/01/17 freeze with unavailable sshfs - Looks like I need threads for that... + (X) #40 10/01/17 freeze with unavailable sshfs + Not rangers fault (?) (X) #41 10/01/17 capital file extensions are not recognized (X) #46 10/01/19 old username displayed after using su (X) #49 10/01/19 fix unit tests :'( -- cgit 1.4.1-2-gfad0 From f7db061bba50fa5a01e34fa7764e36b2646f8a3a Mon Sep 17 00:00:00 2001 From: hut Date: Sat, 27 Mar 2010 04:36:08 +0100 Subject: closed #73, reason was it didn't move and coords didnt get updated --- TODO | 2 +- ranger/gui/displayable.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'TODO') diff --git a/TODO b/TODO index 98d459d7..020ac20a 100644 --- a/TODO +++ b/TODO @@ -72,7 +72,7 @@ Bugs (X) #65 10/02/16 "source ranger ranger some/file.txt" shouldn't cd after exit (X) #67 10/03/08 terminal title in tty (X) #69 10/03/11 tab-completion breaks with Apps subclass - ( ) #73 10/03/21 when clicking on the first column, it goes 1x down + (X) #73 10/03/21 when clicking on the first column, it goes 1x down (X) #74 10/03/21 console doesn't scroll diff --git a/ranger/gui/displayable.py b/ranger/gui/displayable.py index ceefb3f1..88a78b37 100644 --- a/ranger/gui/displayable.py +++ b/ranger/gui/displayable.py @@ -72,6 +72,7 @@ class Displayable(EnvironmentAware, FileManagerAware, CursesShortcuts): self.hei = 0 self.paryx = (0, 0) self.parent = None + self.fresh = True self._old_visible = self.visible @@ -154,7 +155,7 @@ class Displayable(EnvironmentAware, FileManagerAware, CursesShortcuts): def resize(self, y, x, hei=None, wid=None): """Resize the widget""" - do_move = False + do_move = self.fresh try: maxy, maxx = self.env.termsize except TypeError: @@ -212,6 +213,7 @@ class Displayable(EnvironmentAware, FileManagerAware, CursesShortcuts): except: pass + self.fresh = False self.paryx = self.win.getparyx() self.y, self.x = self.paryx if self.parent: -- cgit 1.4.1-2-gfad0 From dab4db4449321c4765410a52a35c150087de766f Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 28 Mar 2010 00:28:12 +0100 Subject: todo: updated --- TODO | 2 ++ 1 file changed, 2 insertions(+) (limited to 'TODO') diff --git a/TODO b/TODO index 020ac20a..b1089225 100644 --- a/TODO +++ b/TODO @@ -87,4 +87,6 @@ Ideas ( ) #53 10/01/23 merge fm and environment ( ) #68 10/03/10 threads, to seperate ui and loading ( ) #72 10/03/21 ranger daemon which does the slow io tasks + ( ) #75 10/03/28 navigate in history + ( ) #76 10/03/28 save history between sessions -- cgit 1.4.1-2-gfad0 From d3c262a924eebdab926b9569ecdb225b3be1e4a9 Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 28 Mar 2010 01:33:35 +0100 Subject: closed issue #71 --- TODO | 2 +- ranger/fsobject/file.py | 25 +++++++++++++++++++++++++ ranger/gui/widgets/browsercolumn.py | 25 ++++++++++++++++++++++--- 3 files changed, 48 insertions(+), 4 deletions(-) (limited to 'TODO') diff --git a/TODO b/TODO index b1089225..7da64db5 100644 --- a/TODO +++ b/TODO @@ -48,7 +48,7 @@ General ( ) #64 10/02/25 scroll in previews (X) #66 10/02/28 explain how colorschemes work ( ) #70 10/03/14 mouse handler for titlebar - ( ) #71 10/03/21 previews: black/whitelist + read file + (X) #71 10/03/21 previews: black/whitelist + read file Bugs diff --git a/ranger/fsobject/file.py b/ranger/fsobject/file.py index 86621095..15bfc18b 100644 --- a/ranger/fsobject/file.py +++ b/ranger/fsobject/file.py @@ -13,6 +13,31 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +control_characters = set(chr(n) for n in set(range(0, 9)) | set(range(14,32))) + from .fsobject import FileSystemObject as SuperClass class File(SuperClass): is_file = True + + @property + def first4bytes(self): + try: + return self._first4bytes + except: + try: + f = open(self.path, 'r') + self._first4bytes = f.read(4) + f.close() + return self._first4bytes + except: + pass + + def is_binary(self): + if not self.first4bytes: + return + if self.first4bytes == "\x7F\x45\x4C\x46": + return True + if control_characters & set(self.first4bytes): + return True + return False + diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py index 238a4803..06a89627 100644 --- a/ranger/gui/widgets/browsercolumn.py +++ b/ranger/gui/widgets/browsercolumn.py @@ -41,6 +41,15 @@ PREVIEW_BLACKLIST = re.compile(r""" $ """, re.VERBOSE | re.IGNORECASE) +PREVIEW_WHITELIST = re.compile(r""" + \.( + txt | py | c + ) + # ignore filetype-independent suffixes: + (\.part|\.bak|~)? + $ +""", re.VERBOSE | re.IGNORECASE) + class BrowserColumn(Pager): main_column = False display_infostring = False @@ -149,10 +158,20 @@ class BrowserColumn(Pager): self.last_redraw_time = time() def _preview_this_file(self, target): + if not self.settings.preview_files: + return False + if not self.target or not self.target.is_file: + return False maxsize = self.settings.max_filesize_for_preview - return self.settings.preview_files \ - and not PREVIEW_BLACKLIST.search(target.basename) \ - and (maxsize is None or maxsize >= target.size) + if maxsize is not None and target.size > maxsize: + return False + if PREVIEW_WHITELIST.search(target.basename): + return True + if PREVIEW_BLACKLIST.search(target.basename): + return False + if target.is_binary(): + return False + return True def _draw_file(self): """Draw a preview of the file, if the settings allow it""" -- cgit 1.4.1-2-gfad0 From 636f69d346e31ee59702c814574c1379aa9cb8e6 Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 28 Mar 2010 01:59:17 +0100 Subject: closed issue #70: mouse click handler for the titlebar --- TODO | 2 +- ranger/gui/widgets/titlebar.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'TODO') diff --git a/TODO b/TODO index 7da64db5..464f8ffb 100644 --- a/TODO +++ b/TODO @@ -47,7 +47,7 @@ General (X) #63 10/02/15 limit filesize in previews ( ) #64 10/02/25 scroll in previews (X) #66 10/02/28 explain how colorschemes work - ( ) #70 10/03/14 mouse handler for titlebar + (X) #70 10/03/14 mouse handler for titlebar (X) #71 10/03/21 previews: black/whitelist + read file diff --git a/ranger/gui/widgets/titlebar.py b/ranger/gui/widgets/titlebar.py index e1be8e97..18d363dc 100644 --- a/ranger/gui/widgets/titlebar.py +++ b/ranger/gui/widgets/titlebar.py @@ -43,6 +43,26 @@ class TitleBar(Widget): self.color('in_titlebar', 'throbber') self.win.addnstr(self.y, self.wid - 2, self.throbber, 1) + def click(self, event): + """Handle a MouseEvent""" + if not event.pressed(1) or not self.result: + return False + + pos = 0 + for i, part in enumerate(self.result): + pos += len(part.string) + if event.x < pos: + if i < 2: + self.fm.enter_dir("~") + elif i == 2: + self.fm.enter_dir("/") + else: + try: + self.fm.env.enter_dir(self.env.pathway[(i-3)/2]) + except: + pass + return False + def _calc_bar(self): bar = Bar('in_titlebar') self._get_left_part(bar) -- cgit 1.4.1-2-gfad0 From 34c131ef561ffb22586e2094fc0c478a44f24ac6 Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 28 Mar 2010 20:28:42 +0200 Subject: new option: colorscheme_overlay For those who want small colorscheme changes without creating an extra file. --- TODO | 1 + ranger/api/options.py | 1 + ranger/defaults/options.py | 19 +++++++++++++++++++ ranger/gui/colorscheme.py | 12 ++++++++++++ ranger/shared/settings.py | 5 +++++ 5 files changed, 38 insertions(+) (limited to 'TODO') diff --git a/TODO b/TODO index 464f8ffb..2f8578cc 100644 --- a/TODO +++ b/TODO @@ -89,4 +89,5 @@ Ideas ( ) #72 10/03/21 ranger daemon which does the slow io tasks ( ) #75 10/03/28 navigate in history ( ) #76 10/03/28 save history between sessions + (X) #77 10/03/28 colorscheme overlay in options.py diff --git a/ranger/api/options.py b/ranger/api/options.py index 7ead8c90..4748823d 100644 --- a/ranger/api/options.py +++ b/ranger/api/options.py @@ -16,6 +16,7 @@ import re from re import compile as regexp from ranger import colorschemes as allschemes +from ranger.gui import color class AttrToString(object): """ diff --git a/ranger/defaults/options.py b/ranger/defaults/options.py index ace68592..ce010195 100644 --- a/ranger/defaults/options.py +++ b/ranger/defaults/options.py @@ -85,3 +85,22 @@ sort_reverse = False sort_case_insensitive = False sort_directories_first = True + +# Apply an overlay function to the colorscheme. It will be called with +# 4 arguments: the context and the 3 values (fg, bg, attr) returned by +# the original use() function of your colorscheme. The return value +# must be a 3-tuple of (fg, bg, attr). +# Note: Here, the colors/attributes aren't directly imported into +# the namespace but have to be accessed with color.xyz. +def colorscheme_overlay(context, fg, bg, attr): + if context.directory and attr & color.bold and \ + not any((context.marked, context.selected)): + attr ^= color.bold # I don't like bold directories! + + if context.main_column and context.selected: + fg, bg = color.red, color.default # To highlight the main column! + + return fg, bg, attr + +# The above function was just an example, let's set it back to None +colorscheme_overlay = None diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py index 199a5523..b76131ae 100644 --- a/ranger/gui/colorscheme.py +++ b/ranger/gui/colorscheme.py @@ -45,6 +45,10 @@ from curses import color_pair from ranger.gui.color import get_color from ranger.gui.context import Context +# ColorScheme is not SettingsAware but it will gain access +# to the settings during the initialization. We can't import +# SettingsAware here because of circular imports. + class ColorScheme(object): """ This is the class that colorschemes must inherit from. @@ -73,6 +77,14 @@ class ColorScheme(object): # add custom error messages for broken colorschemes color = self.use(context) + if self.settings.colorscheme_overlay: + result = self.settings.colorscheme_overlay(context, *color) + assert isinstance(result, (tuple, list)), \ + "Your colorscheme overlay doesn't return a tuple!" + assert all(isinstance(val, int) for val in result), \ + "Your colorscheme overlay doesn't return a tuple"\ + " containing 3 integers!" + color = result self.cache[keys] = color return color diff --git a/ranger/shared/settings.py b/ranger/shared/settings.py index e53f31b0..63e9d4e4 100644 --- a/ranger/shared/settings.py +++ b/ranger/shared/settings.py @@ -40,6 +40,7 @@ ALLOWED_SETTINGS = { 'preview_directories': bool, 'flushinput': bool, 'colorscheme': str, + 'colorscheme_overlay': (type(None), type(lambda:0)), 'hidden_filter': lambda x: isinstance(x, str) or hasattr(x, 'match'), } @@ -136,6 +137,10 @@ class SettingsAware(object): raise Exception("The module contains no " \ "valid colorscheme!") + # Making the colorscheme SettingsAware doesn't work because + # of circular imports, so we do it like this: + settings.colorscheme.settings = settings + try: import apps except ImportError: -- cgit 1.4.1-2-gfad0 From cc4210ff98da5708fd32c71650bbf9a54ec84d1c Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 29 Mar 2010 02:18:03 +0200 Subject: closed issue #76 (was implemented in f5e9c01e) --- TODO | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'TODO') diff --git a/TODO b/TODO index 2f8578cc..bb125775 100644 --- a/TODO +++ b/TODO @@ -88,6 +88,6 @@ Ideas ( ) #68 10/03/10 threads, to seperate ui and loading ( ) #72 10/03/21 ranger daemon which does the slow io tasks ( ) #75 10/03/28 navigate in history - ( ) #76 10/03/28 save history between sessions + (X) #76 10/03/28 save history between sessions (X) #77 10/03/28 colorscheme overlay in options.py -- cgit 1.4.1-2-gfad0 From 6908d0cc5d706c85f1eeb5f2d12490766bd98a91 Mon Sep 17 00:00:00 2001 From: hut Date: Wed, 31 Mar 2010 05:13:10 +0200 Subject: TODO: closed #45, it was implemented already --- TODO | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'TODO') diff --git a/TODO b/TODO index bb125775..62e559bd 100644 --- a/TODO +++ b/TODO @@ -83,7 +83,7 @@ Ideas (X) #27 10/01/06 hide bookmarks in list which contain hidden dir (X) #28 10/01/06 use regexp instead of string for searching ( ) #33 10/01/08 accelerate mousewheel speed - ( ) #45 10/01/18 hooks for events like setting changes + (X) #45 10/01/18 hooks for events like setting changes ( ) #53 10/01/23 merge fm and environment ( ) #68 10/03/10 threads, to seperate ui and loading ( ) #72 10/03/21 ranger daemon which does the slow io tasks -- cgit 1.4.1-2-gfad0 From 5a8b6059fa54ca98f558e283696d86429222f053 Mon Sep 17 00:00:00 2001 From: hut Date: Wed, 31 Mar 2010 06:48:42 +0200 Subject: TODO: added #78 --- TODO | 1 + 1 file changed, 1 insertion(+) (limited to 'TODO') diff --git a/TODO b/TODO index 62e559bd..a0c7f03a 100644 --- a/TODO +++ b/TODO @@ -74,6 +74,7 @@ Bugs (X) #69 10/03/11 tab-completion breaks with Apps subclass (X) #73 10/03/21 when clicking on the first column, it goes 1x down (X) #74 10/03/21 console doesn't scroll + ( ) #78 10/03/31 broken preview when deleting all files in a directory Ideas -- cgit 1.4.1-2-gfad0