diff options
author | mark-dawn <albama92@gmail.com> | 2018-02-18 15:06:20 +0100 |
---|---|---|
committer | mark-dawn <albama92@gmail.com> | 2018-05-29 10:06:08 +0200 |
commit | 3c428cad7e752c38a282ba1c83190eb41fc4ff3a (patch) | |
tree | ac7b6def551079aa0f197bc37df042a95d850511 | |
parent | c7528ea081cd621829dd23c4e47d67d8d2da6a9b (diff) | |
download | ranger-3c428cad7e752c38a282ba1c83190eb41fc4ff3a.tar.gz |
Grammar Fixes
Fixed grammar horrors in ranger.pod and ranger.conf Improved resize handling
-rw-r--r-- | doc/ranger.pod | 12 | ||||
-rw-r--r-- | ranger/config/rc.conf | 16 | ||||
-rw-r--r-- | ranger/container/settings.py | 2 | ||||
-rw-r--r-- | ranger/core/fm.py | 2 | ||||
-rw-r--r-- | ranger/ext/img_display.py | 43 |
5 files changed, 39 insertions, 36 deletions
diff --git a/doc/ranger.pod b/doc/ranger.pod index fbe20012..a45ab2e4 100644 --- a/doc/ranger.pod +++ b/doc/ranger.pod @@ -222,7 +222,7 @@ C<iterm2_font_width> and C<iterm2_font_height> to the desired values. =head3 terminology -This only works in terminology. It can render vectors graphics, but works only locally. +This only works in terminology. It can render vector graphics, but works only locally. To enable this feature, set the option C<preview_images_method> to terminology. =head3 urxvt @@ -243,18 +243,14 @@ To enable this feature, set the option C<preview_images_method> to urxvt-full. =head3 kitty -This only works on Kitty. -It requires PIL or pillow at the moment to work. A nasty bug that can -corrupt the terminal window when scrolling quicly many images, that can -be solved by with the C<redraw_window> command. +This only works on Kitty. It requires PIL (or pillow) to work. -To enable this feature, set the option C<preview_images_method> to kitty +To enable this feature, set the option C<preview_images_method> to kitty. =head3 kitty-network The same as kitty, but uses a streaming method to allow previews remotely, -for example in an ssh session. However the system is slighly more computationally taxing -and the quality of the preview is reduced for bandwidth considerations. +for example in an ssh session. However the system is more computationally taxing. =head2 SELECTION diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf index cf27cbb5..7adbc239 100644 --- a/ranger/config/rc.conf +++ b/ranger/config/rc.conf @@ -88,7 +88,7 @@ set preview_images false # # * terminology: # Previews images in full color in the terminology terminal emulator. -# Supports a wide variety of formats, even vector graphics like svg +# Supports a wide variety of formats, even vector graphics like svg. # # * urxvt: # Preview images in full color using urxvt image backgrounds. This @@ -99,17 +99,15 @@ set preview_images false # whole terminal window. # # * kitty: -# Preview images in full color using kitty image protocol -# (https://github.com/kovidgoyal/kitty/blob/master/graphics-protocol.asciidoc), +# Preview images in full color using kitty image protocol. # Requires python PIL or pillow library. -# In experimental stage: tmux support is untested, and a scrolling too fast a folder with many images may glitch ranger; -# Future improvements to kitty will ameliorate this issue, for now call the command 'redraw_window' to get rid of the garbage. +# Tmux support is untested. # # * kitty-network -# Similar to base kitty, bit instead of local storage it uses kitty's protocol special feature to -# stream the whole image over standard input. More error prone, and more intensive since it scales down images, -# producing also worse quality previews. -# However it makes possible to see previews froma ranger instance over the network, +# Similar to base kitty, but instead of local storage it streams the whole image +# over standard input. More error prone, +# and more intensive since it base64 encodes entire images. +# However it makes possible to see previews from ranger over the network, # so it makes sense to enable this on remote machines. # Note that has been untested over an actual network. set preview_images_method w3m diff --git a/ranger/container/settings.py b/ranger/container/settings.py index dcadf8bf..b360cf20 100644 --- a/ranger/container/settings.py +++ b/ranger/container/settings.py @@ -100,7 +100,7 @@ ALLOWED_VALUES = { 'confirm_on_delete': ['multiple', 'always', 'never'], 'line_numbers': ['false', 'absolute', 'relative'], 'one_indexed': [False, True], - 'preview_images_method': ['w3m', 'iterm2', 'urxvt', + 'preview_images_method': ['w3m', 'iterm2', 'terminology', 'urxvt', 'urxvt-full', 'kitty', 'kitty-network'], 'vcs_backend_bzr': ['disabled', 'local', 'enabled'], 'vcs_backend_git': ['enabled', 'disabled', 'local'], diff --git a/ranger/core/fm.py b/ranger/core/fm.py index 226b1461..5f4e141d 100644 --- a/ranger/core/fm.py +++ b/ranger/core/fm.py @@ -239,7 +239,7 @@ class FM(Actions, # pylint: disable=too-many-instance-attributes elif self.settings.preview_images_method == "kitty": return KittyImageDisplayer() elif self.settings.preview_images_method == "kitty-network": - return KittyImageDisplayer(stream=True, resize_height=480) + return KittyImageDisplayer(stream=True) return ImageDisplayer() def _get_thisfile(self): diff --git a/ranger/ext/img_display.py b/ranger/ext/img_display.py index 09d3429c..f444e0f9 100644 --- a/ranger/ext/img_display.py +++ b/ranger/ext/img_display.py @@ -11,6 +11,7 @@ implementations, which are currently w3m, iTerm2 and urxvt. from __future__ import (absolute_import, division, print_function) +import math import base64 import curses import errno @@ -42,9 +43,9 @@ W3MIMGDISPLAY_PATHS = [ @contextmanager -def temporarly_moved_cursor(to_y, to_x): +def temporarily_moved_cursor(to_y, to_x): """Common boilerplate code to move the cursor to a drawing area. Use it as: - with temporarly_moved_cursor(dest_y, dest_x): + with temporarily_moved_cursor(dest_y, dest_x): your_func_here()""" curses.putp(curses.tigetstr("sc")) move_cur(to_y, to_x) @@ -236,7 +237,7 @@ class ITerm2ImageDisplayer(ImageDisplayer, FileManagerAware): """ def draw(self, path, start_x, start_y, width, height): - with temporarly_moved_cursor(start_y, start_x): + with temporarily_moved_cursor(start_y, start_x): sys.stdout.write(self._generate_iterm2_input(path, width, height)) def clear(self, start_x, start_y, width, height): @@ -346,7 +347,7 @@ class TerminologyImageDisplayer(ImageDisplayer, FileManagerAware): self.close_protocol = "\000" def draw(self, path, start_x, start_y, width, height): - with temporarly_moved_cursor(start_y, start_x): + with temporarily_moved_cursor(start_y, start_x): # Write intent sys.stdout.write("%s}ic#%d;%d;%s%s" % ( self.display_protocol, @@ -479,13 +480,12 @@ class KittyImageDisplayer(ImageDisplayer): protocol_start = b'\033_G' protocol_end = b'\033\\' - def __init__(self, stream=False, resize_height=720): + def __init__(self, stream=False): self.image_id = 0 self.temp_paths = [] # parameter deciding if we're going to send the picture data # in the command body, or save it to a temporary file self.stream = stream - self.max_height = resize_height if "screen" in os.environ['TERM']: # TODO: probably need to modify the preamble @@ -527,7 +527,7 @@ class KittyImageDisplayer(ImageDisplayer): # to spawn other processes, so it _should_ be faster import PIL.Image self.backend = PIL.Image - self.filter = PIL.Image.BILINEAR + self.filter = PIL.Image.LANCZOS except ImportError: sys.stderr.write("PIL not Found") # TODO: implement a wrapper class for Imagemagick process to @@ -543,24 +543,23 @@ class KittyImageDisplayer(ImageDisplayer): assert self.backend is not None # sanity check if we actually have a backend image = self.backend.open(path) - aspect = image.width / image.height - # first let's reduce the size of the image - if image.height > self.max_height: - image = image.resize((int(self.max_height * aspect), self.max_height), self.filter) - # since kitty streches the image to fill the view box # we need to resize the box to not get distortion - mismatch_ratio = aspect / (width * 0.5 / height) + mismatch_ratio = (image.width / image.height) / (width * 0.5 / height) if mismatch_ratio > 1.05: new_h = height / mismatch_ratio - start_y += int((height - new_h) / 2) + start_y += int((height - new_h) // 2) height = int(new_h) elif mismatch_ratio < 0.95: new_w = width * mismatch_ratio - start_x += int((width - new_w) / 2) + start_x += int((width - new_w) // 2) width = int(new_w) + # resize image to a smaller size. Ideally this should be + # image = self._resize_max_area(image, (480*960), self.filter) + if self.stream: + image = self._resize_max_area(image, (480 * 960), self.filter) # encode the whole image as base64 # TODO: implement z compression # to possibly increase resolution in sent image @@ -581,13 +580,14 @@ class KittyImageDisplayer(ImageDisplayer): # f: size of a pixel fragment (100 just mean that the file is png encoded, # the only format except raw RGB(A) bitmap that kitty understand) # c, r: size in cells of the viewbox - cmds.update({'t': 't', 'f': 100, 'c': width, 'r': height}) + cmds.update({'t': 't', 'f': 100, + 'c': width, 'r': height}) with NamedTemporaryFile(prefix='rgr_thumb_', suffix='.png', delete=False) as tmpf: image.save(tmpf, format='png', compress_level=0) self.temp_paths.append(tmpf.name) payload = base64.standard_b64encode(tmpf.name.encode(self.fsenc)) - with temporarly_moved_cursor(start_y, start_x): + with temporarily_moved_cursor(start_y, start_x): for cmd_str in self._format_cmd_str(cmds, payload=payload): sys.stdout.buffer.write(cmd_str) # catch kitty answer before the escape codes corrupt the console @@ -627,6 +627,15 @@ class KittyImageDisplayer(ImageDisplayer): else: yield self.protocol_start + central_blk + b';' + self.protocol_end + @staticmethod + def _resize_max_area(image, max_area, img_filter): + aspect = image.width / image.height + area = image.width * image.height + if area > max_area: + image = image.resize((int(math.sqrt(area * aspect)), + int(math.sqrt(area / aspect))), img_filter) + return image + def quit(self): # clear all remaining images, then check if all files went through or are orphaned while self.image_id >= 1: |