diff options
author | Christian Zangl <laktak@cdak.net> | 2019-12-03 16:05:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-03 16:05:26 +0100 |
commit | 14499c13222e6c5440bafc64b658c39d85f14dfd (patch) | |
tree | 6a8839689cd092dd90d76602b439b01dc877967f /ranger | |
parent | cda581b3bbc47dab9873359233c7b94a268111a1 (diff) | |
parent | 4ff19f6c059fc0d477273304988dc6b7c0ee6320 (diff) | |
download | ranger-14499c13222e6c5440bafc64b658c39d85f14dfd.tar.gz |
Merge branch 'master' into paste_conflict
Diffstat (limited to 'ranger')
-rwxr-xr-x | ranger/config/commands.py | 5 | ||||
-rw-r--r-- | ranger/config/rifle.conf | 14 | ||||
-rw-r--r-- | ranger/container/fsobject.py | 6 | ||||
-rw-r--r-- | ranger/core/actions.py | 6 | ||||
-rw-r--r-- | ranger/core/fm.py | 25 | ||||
-rw-r--r-- | ranger/core/runner.py | 4 | ||||
-rw-r--r-- | ranger/data/mime.types | 4 | ||||
-rw-r--r-- | ranger/ext/img_display.py | 35 | ||||
-rwxr-xr-x | ranger/ext/rifle.py | 7 |
9 files changed, 70 insertions, 36 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py index 0eae4e19..06d5abb7 100755 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -1924,11 +1924,14 @@ class yank(Command): ['xsel'], ['xsel', '-b'], ], + 'wl-copy': [ + ['wl-copy'], + ], 'pbcopy': [ ['pbcopy'], ], } - ordered_managers = ['pbcopy', 'xclip', 'xsel'] + ordered_managers = ['pbcopy', 'wl-copy', 'xclip', 'xsel'] executables = get_executables() for manager in ordered_managers: if manager in executables: diff --git a/ranger/config/rifle.conf b/ranger/config/rifle.conf index f04d1031..86f53fd1 100644 --- a/ranger/config/rifle.conf +++ b/ranger/config/rifle.conf @@ -26,7 +26,7 @@ # directory | $1 is a directory # number <n> | change the number of this command to n # terminal | stdin, stderr and stdout are connected to a terminal -# X | $DISPLAY is not empty (i.e. Xorg runs) +# X | A graphical environment is available (darwin, Xorg, or Wayland) # # There are also pseudo-conditions which have a "side effect": # flag <flags> | Change how the program is run. See below. @@ -66,13 +66,13 @@ ext x?html?, has uzbl-tabbed, X, flag f = uzbl-tabbed -- "$@" ext x?html?, has uzbl-browser, X, flag f = uzbl-browser -- "$@" ext x?html?, has uzbl-core, X, flag f = uzbl-core -- "$@" ext x?html?, has midori, X, flag f = midori -- "$@" -ext x?html?, has chromium-browser, X, flag f = chromium-browser -- "$@" -ext x?html?, has chromium, X, flag f = chromium -- "$@" -ext x?html?, has google-chrome, X, flag f = google-chrome -- "$@" ext x?html?, has opera, X, flag f = opera -- "$@" ext x?html?, has firefox, X, flag f = firefox -- "$@" ext x?html?, has seamonkey, X, flag f = seamonkey -- "$@" ext x?html?, has iceweasel, X, flag f = iceweasel -- "$@" +ext x?html?, has chromium-browser, X, flag f = chromium-browser -- "$@" +ext x?html?, has chromium, X, flag f = chromium -- "$@" +ext x?html?, has google-chrome, X, flag f = google-chrome -- "$@" ext x?html?, has epiphany, X, flag f = epiphany -- "$@" ext x?html?, has konqueror, X, flag f = konqueror -- "$@" ext x?html?, has elinks, terminal = elinks "$@" @@ -259,6 +259,12 @@ label wallpaper, number 12, mime ^image, has feh, X = feh --bg-tile "$1" label wallpaper, number 13, mime ^image, has feh, X = feh --bg-center "$1" label wallpaper, number 14, mime ^image, has feh, X = feh --bg-fill "$1" +#------------------------------------------- +# Generic file openers +#------------------------------------------- +label open, has xdg-open = xdg-open -- "$@" +label open, has open = open -- "$@" + # Define the editor for non-text files + pager as last action !mime ^text, !ext xml|json|csv|tex|py|pl|rb|js|sh|php = ask label editor, !mime ^text, !ext xml|json|csv|tex|py|pl|rb|js|sh|php = ${VISUAL:-$EDITOR} -- "$@" diff --git a/ranger/container/fsobject.py b/ranger/container/fsobject.py index 4fb47354..7de889bf 100644 --- a/ranger/container/fsobject.py +++ b/ranger/container/fsobject.py @@ -342,10 +342,10 @@ class FileSystemObject( # pylint: disable=too-many-instance-attributes,too-many if self.permissions is not None: return self.permissions - if self.is_directory: - perms = ['d'] - elif self.is_link: + if self.is_link: perms = ['l'] + elif self.is_directory: + perms = ['d'] else: perms = ['-'] diff --git a/ranger/core/actions.py b/ranger/core/actions.py index ed99f1c6..38345597 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -1598,13 +1598,15 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m Paste the selected items into the current directory or to dest if provided. """ - if dest is None or isdir(dest): + if dest is None: + dest = self.thistab.path + if isdir(dest): loadable = CopyLoader(self.copy_buffer, self.do_cut, overwrite, dest, make_safe_path) self.loader.add(loadable, append=append) self.do_cut = False else: - self.notify('Failed to paste. The given path is invalid.', bad=True) + self.notify('Failed to paste. The destination is invalid.', bad=True) def delete(self, files=None): # XXX: warn when deleting mount points/unseen marked files? diff --git a/ranger/core/fm.py b/ranger/core/fm.py index 43001e8b..7d23c9b6 100644 --- a/ranger/core/fm.py +++ b/ranger/core/fm.py @@ -22,11 +22,7 @@ from ranger.container.tags import Tags, TagsDummy from ranger.gui.ui import UI from ranger.container.bookmarks import Bookmarks from ranger.core.runner import Runner -from ranger.ext.img_display import (W3MImageDisplayer, ITerm2ImageDisplayer, - TerminologyImageDisplayer, - URXVTImageDisplayer, URXVTImageFSDisplayer, - KittyImageDisplayer, UeberzugImageDisplayer, - ImageDisplayer) +from ranger.ext.img_display import get_image_displayer from ranger.core.metadata import MetadataManager from ranger.ext.rifle import Rifle from ranger.container.directory import Directory @@ -104,7 +100,7 @@ class FM(Actions, # pylint: disable=too-many-instance-attributes def set_image_displayer(): if self.image_displayer: self.image_displayer.quit() - self.image_displayer = self._get_image_displayer() + self.image_displayer = get_image_displayer(self.settings.preview_images_method) set_image_displayer() self.settings.signal_bind('setopt.preview_images_method', set_image_displayer, priority=settings.SIGNAL_PRIORITY_AFTER_SYNC) @@ -227,23 +223,6 @@ class FM(Actions, # pylint: disable=too-many-instance-attributes for line in entry.splitlines(): yield line - def _get_image_displayer(self): # pylint: disable=too-many-return-statements - if self.settings.preview_images_method == "w3m": - return W3MImageDisplayer() - elif self.settings.preview_images_method == "iterm2": - return ITerm2ImageDisplayer() - elif self.settings.preview_images_method == "terminology": - return TerminologyImageDisplayer() - elif self.settings.preview_images_method == "urxvt": - return URXVTImageDisplayer() - elif self.settings.preview_images_method == "urxvt-full": - return URXVTImageFSDisplayer() - elif self.settings.preview_images_method == "kitty": - return KittyImageDisplayer() - elif self.settings.preview_images_method == "ueberzug": - return UeberzugImageDisplayer() - return ImageDisplayer() - def _get_thisfile(self): return self.thistab.thisfile diff --git a/ranger/core/runner.py b/ranger/core/runner.py index f38b026a..d465f070 100644 --- a/ranger/core/runner.py +++ b/ranger/core/runner.py @@ -214,7 +214,9 @@ class Runner(object): # pylint: disable=too-few-public-methods toggle_ui = True context.wait = True if 't' in context.flags: - if 'DISPLAY' not in os.environ: + if not ('WAYLAND_DISPLAY' in os.environ + or sys.platform == 'darwin' + or 'DISPLAY' in os.environ): return self._log("Can not run with 't' flag, no display found!") term = get_term() if isinstance(action, str): diff --git a/ranger/data/mime.types b/ranger/data/mime.types index 900cb7d9..abee11f6 100644 --- a/ranger/data/mime.types +++ b/ranger/data/mime.types @@ -12,11 +12,13 @@ audio/flac flac audio/musepack mpc mpp mp+ -audio/ogg oga ogg spx +audio/ogg oga ogg spx opus audio/wavpack wv wvc audio/webm weba audio/x-ape ape +image/webp webp + video/mkv mkv video/webm webm video/flash flv diff --git a/ranger/ext/img_display.py b/ranger/ext/img_display.py index 2cce5c7a..7e911848 100644 --- a/ranger/ext/img_display.py +++ b/ranger/ext/img_display.py @@ -23,6 +23,7 @@ import warnings import json import threading from subprocess import Popen, PIPE +from collections import defaultdict import termios from contextlib import contextmanager @@ -72,6 +73,33 @@ class ImgDisplayUnsupportedException(Exception): pass +def fallback_image_displayer(): + """Simply makes some noise when chosen. Temporary fallback behavior.""" + + raise ImgDisplayUnsupportedException + + +IMAGE_DISPLAYER_REGISTRY = defaultdict(fallback_image_displayer) + + +def register_image_displayer(nickname=None): + """Register an ImageDisplayer by nickname if available.""" + + def decorator(image_displayer_class): + if nickname: + registry_key = nickname + else: + registry_key = image_displayer_class.__name__ + IMAGE_DISPLAYER_REGISTRY[registry_key] = image_displayer_class + return image_displayer_class + return decorator + + +def get_image_displayer(registry_key): + image_displayer_class = IMAGE_DISPLAYER_REGISTRY[registry_key] + return image_displayer_class() + + class ImageDisplayer(object): """Image display provider functions for drawing images in the terminal""" @@ -90,6 +118,7 @@ class ImageDisplayer(object): pass +@register_image_displayer("w3m") class W3MImageDisplayer(ImageDisplayer, FileManagerAware): """Implementation of ImageDisplayer using w3mimgdisplay, an utilitary program from w3m (a text-based web browser). w3mimgdisplay can display @@ -243,6 +272,7 @@ class W3MImageDisplayer(ImageDisplayer, FileManagerAware): # ranger-independent libraries. +@register_image_displayer("iterm2") class ITerm2ImageDisplayer(ImageDisplayer, FileManagerAware): """Implementation of ImageDisplayer using iTerm2 image display support (http://iterm2.com/images.html). @@ -351,6 +381,7 @@ class ITerm2ImageDisplayer(ImageDisplayer, FileManagerAware): return width, height +@register_image_displayer("terminology") class TerminologyImageDisplayer(ImageDisplayer, FileManagerAware): """Implementation of ImageDisplayer using terminology image display support (https://github.com/billiob/terminology). @@ -390,6 +421,7 @@ class TerminologyImageDisplayer(ImageDisplayer, FileManagerAware): self.clear(0, 0, 0, 0) +@register_image_displayer("urxvt") class URXVTImageDisplayer(ImageDisplayer, FileManagerAware): """Implementation of ImageDisplayer working by setting the urxvt background image "under" the preview pane. @@ -474,6 +506,7 @@ class URXVTImageDisplayer(ImageDisplayer, FileManagerAware): self.clear(0, 0, 0, 0) # dummy assignments +@register_image_displayer("urxvt-full") class URXVTImageFSDisplayer(URXVTImageDisplayer): """URXVTImageDisplayer that utilizes the whole terminal.""" @@ -486,6 +519,7 @@ class URXVTImageFSDisplayer(URXVTImageDisplayer): return self._get_centered_offsets() +@register_image_displayer("kitty") class KittyImageDisplayer(ImageDisplayer, FileManagerAware): """Implementation of ImageDisplayer for kitty (https://github.com/kovidgoyal/kitty/) terminal. It uses the built APC to send commands and data to kitty, @@ -681,6 +715,7 @@ class KittyImageDisplayer(ImageDisplayer, FileManagerAware): # continue +@register_image_displayer("ueberzug") class UeberzugImageDisplayer(ImageDisplayer): """Implementation of ImageDisplayer using ueberzug. Ueberzug can display images in a Xorg session. diff --git a/ranger/ext/rifle.py b/ranger/ext/rifle.py index a55e14c7..a73a188b 100755 --- a/ranger/ext/rifle.py +++ b/ranger/ext/rifle.py @@ -237,7 +237,9 @@ class Rifle(object): # pylint: disable=too-many-instance-attributes self._app_flags = argument return True elif function == 'X': - return sys.platform == 'darwin' or 'DISPLAY' in os.environ + return ('WAYLAND_DISPLAY' in os.environ + or sys.platform == 'darwin' + or 'DISPLAY' in os.environ) elif function == 'env': return bool(os.environ.get(argument)) elif function == 'else': @@ -293,6 +295,9 @@ class Rifle(object): # pylint: disable=too-many-instance-attributes self._app_flags = '' self._app_label = None if skip_ask and cmd == ASK_COMMAND: + # TODO(vifon): Fix properly, see + # https://github.com/ranger/ranger/pull/1341#issuecomment-537264495 + count += 1 continue for test in tests: if not self._eval_condition(test, files, None): |