summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xdoc/tools/print_colors.py16
-rw-r--r--ranger/api/commands.py33
-rwxr-xr-xranger/data/scope.sh4
-rw-r--r--ranger/gui/color.py14
-rw-r--r--ranger/gui/ui.py5
5 files changed, 57 insertions, 15 deletions
diff --git a/doc/tools/print_colors.py b/doc/tools/print_colors.py
index ce040b33..b3eba749 100755
--- a/doc/tools/print_colors.py
+++ b/doc/tools/print_colors.py
@@ -10,10 +10,18 @@ from curses import *
 @wrapper
 def main(win):
     def print_all_colors(attr):
-        for c in range(0, curses.COLORS):
-            init_pair(c, c, -1)
-            win.addstr(str(c) + ' ', color_pair(c) | attr)
-    use_default_colors()
+        for c in range(-1, curses.COLORS):
+            try:
+                init_pair(c, c, 0)
+            except:
+                pass
+            else:
+                win.addstr(str(c) + ' ', color_pair(c) | attr)
+    start_color()
+    try:
+        use_default_colors()
+    except:
+        pass
     win.addstr("available colors: %d\n\n" % curses.COLORS)
     print_all_colors(0)
     win.addstr("\n\n")
diff --git a/ranger/api/commands.py b/ranger/api/commands.py
index 305bab75..98b0a23a 100644
--- a/ranger/api/commands.py
+++ b/ranger/api/commands.py
@@ -273,22 +273,41 @@ class Command(FileManagerAware):
         rel_dirname = dirname(rel_dest)
 
         try:
+            directory = self.fm.get_directory(abs_dest)
+
             # are we at the end of a directory?
             if rel_dest.endswith('/') or rel_dest == '':
-                _, dirnames, filenames = next(os.walk(abs_dest))
-                names = dirnames + filenames
+                if directory.content_loaded:
+                    # Take the order from the directory object
+                    names = [f.basename for f in directory.files]
+                    if self.fm.thisfile.basename in names:
+                        i = names.index(self.fm.thisfile.basename)
+                        names = names[i:] + names[:i]
+                else:
+                    # Fall back to old method with "os.walk"
+                    _, dirnames, filenames = next(os.walk(abs_dest))
+                    names = dirnames + filenames
+                    names.sort()
 
             # are we in the middle of the filename?
             else:
-                _, dirnames, filenames = next(os.walk(abs_dirname))
-                names = [name for name in (dirnames + filenames) \
-                        if name.startswith(rel_basename)]
+                if directory.content_loaded:
+                    # Take the order from the directory object
+                    names = [f.basename for f in directory.files \
+                            if f.basename.startswith(rel_basename)]
+                    if self.fm.thisfile.basename in names:
+                        i = names.index(self.fm.thisfile.basename)
+                        names = names[i:] + names[:i]
+                else:
+                    # Fall back to old method with "os.walk"
+                    _, dirnames, filenames = next(os.walk(abs_dirname))
+                    names = [name for name in (dirnames + filenames) \
+                            if name.startswith(rel_basename)]
+                    names.sort()
         except (OSError, StopIteration):
             # os.walk found nothing
             pass
         else:
-            names.sort()
-
             # no results, return None
             if len(names) == 0:
                 return
diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh
index 76481f94..9f7aaf1c 100755
--- a/ranger/data/scope.sh
+++ b/ranger/data/scope.sh
@@ -26,7 +26,7 @@ maxln=200    # Stop after $maxln lines.  Can be used like ls | head -n $maxln
 
 # Find out something about the file:
 mimetype=$(file --mime-type -Lb "$path")
-extension=$(echo "${path##*.}" | tr "[:upper:]" "[:lower:]")
+extension=$(/bin/echo -E "${path##*.}" | tr "[:upper:]" "[:lower:]")
 
 # Functions:
 # runs a command and saves its output into $output.  Useful if you need
@@ -34,7 +34,7 @@ extension=$(echo "${path##*.}" | tr "[:upper:]" "[:lower:]")
 try() { output=$(eval '"$@"'); }
 
 # writes the output of the previously used "try" command
-dump() { echo "$output"; }
+dump() { /bin/echo -E "$output"; }
 
 # a common post-processing function used after most commands
 trim() { head -n "$maxln"; }
diff --git a/ranger/gui/color.py b/ranger/gui/color.py
index 991943b6..d64b5b40 100644
--- a/ranger/gui/color.py
+++ b/ranger/gui/color.py
@@ -15,6 +15,8 @@ bool(attr & reverse) # => False
 
 import curses
 
+DEFAULT_FOREGROUND = curses.COLOR_WHITE
+DEFAULT_BACKGROUND = curses.COLOR_BLACK
 COLOR_PAIRS = {10: 0}
 
 def get_color(fg, bg):
@@ -23,7 +25,17 @@ def get_color(fg, bg):
     key = (fg, bg)
     if key not in COLOR_PAIRS:
         size = len(COLOR_PAIRS)
-        curses.init_pair(size, fg, bg)
+        try:
+            curses.init_pair(size, fg, bg)
+        except:
+            # If curses.use_default_colors() failed during the initialization
+            # of curses, then using -1 as fg or bg will fail as well, which
+            # we need to handle with fallback-defaults:
+            if fg == -1:  # -1 is the "default" color
+                fg = DEFAULT_FOREGROUND
+            if bg == -1:  # -1 is the "default" color
+                bg = DEFAULT_BACKGROUND
+            curses.init_pair(size, fg, bg)
         COLOR_PAIRS[key] = size
 
     return COLOR_PAIRS[key]
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index 3aeeb4fe..1f95ac59 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -71,7 +71,10 @@ class UI(DisplayableContainer):
         except:
             pass
         curses.start_color()
-        curses.use_default_colors()
+        try:
+            curses.use_default_colors()
+        except:
+            pass
 
         self.settings.signal_bind('setopt.mouse_enabled', _setup_mouse)
         _setup_mouse(dict(value=self.settings.mouse_enabled))