diff options
-rw-r--r-- | ranger/fsobject/fsobject.py | 9 | ||||
-rw-r--r-- | ranger/gui/ui.py | 6 |
2 files changed, 8 insertions, 7 deletions
diff --git a/ranger/fsobject/fsobject.py b/ranger/fsobject/fsobject.py index 1d1f202d..943c8aa4 100644 --- a/ranger/fsobject/fsobject.py +++ b/ranger/fsobject/fsobject.py @@ -30,10 +30,13 @@ if hasattr(str, 'maketrans'): maketrans = str.maketrans else: from string import maketrans -unsafe_chars = '\n' + ''.join(map(chr, range(32))) + ''.join(map(chr, range(128, 256))) -safe_string_table = maketrans(unsafe_chars, '?' * len(unsafe_chars)) +_unsafe_chars = '\n' + ''.join(map(chr, range(32))) + ''.join(map(chr, range(128, 256))) +_safe_string_table = maketrans(_unsafe_chars, '?' * len(_unsafe_chars)) _extract_number_re = re.compile(r'([^0-9]?)(\d*)') +def safe_path(path): + return path.translate(_safe_string_table) + class FileSystemObject(FileManagerAware): (basename, basename_lower, @@ -114,7 +117,7 @@ class FileSystemObject(FileManagerAware): @lazy_property def safe_basename(self): - return self.basename.translate(safe_string_table) + return self.basename.translate(_safe_string_table) for attr in ('video', 'audio', 'image', 'media', 'document', 'container'): diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py index 91d0d774..064d4a16 100644 --- a/ranger/gui/ui.py +++ b/ranger/gui/ui.py @@ -21,6 +21,7 @@ import _curses from .displayable import DisplayableContainer from .mouse_event import MouseEvent from ranger.ext.keybinding_parser import ALT_KEY +from ranger.fsobject.fsobject import safe_path TERMINALS_WITH_TITLE = ("xterm", "xterm-256color", "rxvt", "rxvt-256color", "rxvt-unicode", "aterm", "Eterm", @@ -293,10 +294,7 @@ class UI(DisplayableContainer): split = cwd.rsplit(os.sep, self.settings.shorten_title) if os.sep in split[0]: cwd = os.sep.join(split[1:]) - try: - sys.stdout.write("\033]2;ranger:" + cwd + "\007") - except UnicodeEncodeError: - sys.stdout.write("\033]2;ranger:" + ascii_only(cwd) + "\007") + sys.stdout.write("\033]2;ranger:" + safe_path(cwd) + "\007") self.win.refresh() def finalize(self): |