about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authormark-dawn <albama92@gmail.com>2018-02-18 15:06:20 +0100
committermark-dawn <albama92@gmail.com>2018-05-29 10:06:08 +0200
commit3c428cad7e752c38a282ba1c83190eb41fc4ff3a (patch)
treeac7b6def551079aa0f197bc37df042a95d850511
parentc7528ea081cd621829dd23c4e47d67d8d2da6a9b (diff)
downloadranger-3c428cad7e752c38a282ba1c83190eb41fc4ff3a.tar.gz
Grammar Fixes
Fixed grammar horrors in ranger.pod and ranger.conf
Improved resize handling
-rw-r--r--doc/ranger.pod12
-rw-r--r--ranger/config/rc.conf16
-rw-r--r--ranger/container/settings.py2
-rw-r--r--ranger/core/fm.py2
-rw-r--r--ranger/ext/img_display.py43
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:
id=5f6edeea5197c45feaaafd6c2e83a7491d37cfa0'>^
2b36eee9 ^
8fd7deed ^
4aff81ec ^

2b36eee9 ^

d2f360d8 ^
1209ddac ^
d2f360d8 ^
d2f360d8 ^
a97886ef ^
1209ddac ^



cb2344a2 ^
1209ddac ^


2b36eee9 ^

4aff81ec ^
adceed3d ^
4aff81ec ^

48f993d0 ^
4aff81ec ^









2b36eee9 ^
4aff81ec ^
8fd7deed ^
4aff81ec ^
2b36eee9 ^
4aff81ec ^




2b36eee9 ^
2b36eee9 ^



















fbc21293 ^






2b36eee9 ^





4a943d4e ^























































































2b36eee9 ^
2b36eee9 ^




4a943d4e ^

2b36eee9 ^

4aff81ec ^


4a943d4e ^








a97886ef ^





















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349