summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-06-22 14:25:03 +0200
committerhut <hut@lavabit.com>2010-06-22 14:25:03 +0200
commitdc7ee19fc15eee33c948d0ccd6c06df9682c0bf3 (patch)
tree1bcedc80738cdcf5f7c30287468cc40ba9304229
parentbf14a7e72e7c03673949388365744f26e227ec83 (diff)
downloadranger-dc7ee19fc15eee33c948d0ccd6c06df9682c0bf3.tar.gz
fsobject.file: dynamic width of caca previews, cleanups
-rw-r--r--ranger/core/actions.py2
-rwxr-xr-xranger/data/scope.sh16
-rw-r--r--ranger/fsobject/file.py8
-rw-r--r--ranger/gui/widgets/browsercolumn.py2
4 files changed, 18 insertions, 10 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index 743d82c5..44061aca 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -471,7 +471,7 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 			return
 
 		pager = self.ui.open_embedded_pager()
-		pager.set_source(self.env.cf.get_preview_source())
+		pager.set_source(self.env.cf.get_preview_source(pager))
 
 	# --------------------------
 	# -- Tabs
diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh
index ef5f8ff4..80fd2ea7 100755
--- a/ranger/data/scope.sh
+++ b/ranger/data/scope.sh
@@ -3,12 +3,22 @@
 # This script is called whenever you preview a file.
 # Its output is used as the preview.  ANSI color codes are supported.
 
-# Meaning of exit codes:
+# NOTE: This is considered to be a configuration file.  If you upgrade
+# ranger, it will be left untouched. (You must update it yourself)
+
+# Meanings of arguments:
+# name | meaning
+# -----+--------------------------------------------------------
+# $1   | Full filename of the selected file
+# $2   | Width of the preview pane (number of fitting characters)
+# $3   | Height of the preview pane (number of fitting characters)
+
+# Meanings of exit codes:
 # code | meaning    | action of ranger
 # -----+------------+-------------------------------------------
 # 0    | success    | display stdout as preview
 # 1    | no preview | display no preview at all
-
+# 2    | plain text | display the plain content of the file
 
 mimetype=$(file --mime-type -Lb "$1")
 extension=$(echo "$1" | grep '\.' | grep -o '[^.]\+$')
@@ -32,7 +42,7 @@ case "$mimetype" in
 		exit 0;;
 	# Ascii-previews of images:
 	image/*)
-		img2txt "$1" || exit 1
+		img2txt -W "$2" "$1" || exit 1
 		exit 0;;
 esac
 
diff --git a/ranger/fsobject/file.py b/ranger/fsobject/file.py
index 216b4754..4acad100 100644
--- a/ranger/fsobject/file.py
+++ b/ranger/fsobject/file.py
@@ -14,7 +14,6 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import re
-import zipfile
 from ranger.fsobject import FileSystemObject
 from subprocess import Popen, PIPE
 from ranger.core.runner import devnull
@@ -35,8 +34,6 @@ PREVIEW_BLACKLIST = re.compile(r"""
 				| vob | wav | mpc | flac | divx? | xcf | pdf
 			# binary files:
 				| torrent | class | so | img | py[co] | dmg
-			# containers:
-				| iso | rar | 7z | tar | gz | bz2 | tgz
 		)
 		# ignore filetype-independent suffixes:
 			(\.part|\.bak|~)?
@@ -93,10 +90,11 @@ class File(FileSystemObject):
 			return False
 		return True
 
-	def get_preview_source(self):
+	def get_preview_source(self, widget):
 		if self.fm.settings.preview_script:
 			try:
-				p = Popen([self.fm.settings.preview_script, self.path],
+				p = Popen([self.fm.settings.preview_script, self.path,
+						str(widget.wid), str(widget.hei)],
 						stdout=PIPE, stderr=devnull)
 				if p.poll():  # nonzero exit code
 					return None
diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py
index d617e64e..5585bccc 100644
--- a/ranger/gui/widgets/browsercolumn.py
+++ b/ranger/gui/widgets/browsercolumn.py
@@ -155,7 +155,7 @@ class BrowserColumn(Pager):
 			return
 
 		try:
-			f = self.target.get_preview_source()
+			f = self.target.get_preview_source(self)
 		except:
 			Pager.close(self)
 		else:
3a55 ^
fe179145 ^
5822dff7 ^
9506fb8e ^
fae694a0 ^
9506fb8e ^
a4570538 ^
fe179145 ^

fae694a0 ^
fe179145 ^
fae694a0 ^


4c05e43d ^

fae694a0 ^

fe179145 ^

fae694a0 ^




9506fb8e ^
fae694a0 ^
fae694a0 ^
1159f9ec ^



fe179145 ^
5822dff7 ^
9506fb8e ^
a4570538 ^

fae694a0 ^
fe179145 ^

fae694a0 ^
c6953a55 ^

fe179145 ^
fae694a0 ^
9506fb8e ^

f6f26231 ^
4c05e43d ^
f6f26231 ^







9506fb8e ^
fae694a0 ^

f6f26231 ^










4c05e43d ^

fae694a0 ^

fe179145 ^
5822dff7 ^

fe179145 ^
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