about summary refs log tree commit diff stats
path: root/code
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-07-03 17:19:52 +0200
committerhut <hut@lavabit.com>2009-07-03 17:19:52 +0200
commitf8634dd6d2477d1871764982fe8d55f2003ab938 (patch)
tree5d278f4fd3538a2d990cd78450d0e883d0fbce1d /code
parent27ebfe639466906a9bdaeb3a8ade280e07921122 (diff)
downloadranger-f8634dd6d2477d1871764982fe8d55f2003ab938.tar.gz
option to show ascii only and replace non-ascii with *
Diffstat (limited to 'code')
-rw-r--r--code/directory.rb2
-rw-r--r--code/draw.rb8
-rw-r--r--code/entry.rb4
-rw-r--r--code/extensions/basic.rb8
4 files changed, 17 insertions, 5 deletions
diff --git a/code/directory.rb b/code/directory.rb
index c738b995..646a15df 100644
--- a/code/directory.rb
+++ b/code/directory.rb
@@ -142,7 +142,7 @@ class Directory
 			@width = 0
 			@files[pos, lines-2].each_with_index do |fn, ix|
 				ix += pos
-				sz = fn.basename.size + fn.infostring.size + 2
+				sz = fn.displayname.size + fn.infostring.size + 2
 				@width = sz + 3 if @width < sz
 			end
 #			@width = @files[pos,lines-2].map{|x| File.basename(x).size}.max
diff --git a/code/draw.rb b/code/draw.rb
index aaca6253..84e0e9b4 100644
--- a/code/draw.rb
+++ b/code/draw.rb
@@ -102,7 +102,7 @@ module Fm
 				:file
 			end
 
-			fn = f.basename
+			fn = f.displayname
 			fn = "* #{fn}" if f.marked?
 
 
@@ -229,8 +229,8 @@ module Fm
 			end
 
 			s1 = "#{Socket.gethostname}:"
-			s2 = "#{@path.last.path}#{"/" unless @path.size == 1}"
-			s3 = "#{cf ? cf.basename : ''}"
+			s2 = "#{@path.last.path.ascii_only_if(Option.ascii_only)}#{"/" unless @path.size == 1}"
+			s3 = "#{cf ? cf.displayname : ''}"
 
 			if s0
 				puti 0, (s1 + s2 + s3).ljust(cols-s0.size)
@@ -291,7 +291,7 @@ module Fm
 				puti btm, "#@buffer    #{@pwd.file_size.bytes(false)}, #{@pwd.free_space.bytes(false)} free, #{@pwd.size}, #{@pwd.pos+1}    ".rjust(cols)
 				more = ''
 				if cf.symlink?
-					more = "#{cf.readlink}"
+					more = "#{cf.readlink.ascii_only_if(Option.ascii_only)}"
 				end
 
 				attr_set(Color.date)
diff --git a/code/entry.rb b/code/entry.rb
index 9f0cb7b9..af1faa83 100644
--- a/code/entry.rb
+++ b/code/entry.rb
@@ -70,6 +70,10 @@ class Directory::Entry
 	alias movie? video?
 	alias sound? audio?
 
+	def displayname()
+		@displayname ||= @basename.ascii_only_if(Option.ascii_only)
+	end
+
 	def handler()
 		## get_handler has to be defined in another file
 		@handler ||= catch(:use) do
diff --git a/code/extensions/basic.rb b/code/extensions/basic.rb
index dd2f0fd0..728af9c3 100644
--- a/code/extensions/basic.rb
+++ b/code/extensions/basic.rb
@@ -33,6 +33,14 @@ class String
 		end
 	end
 
+	def ascii_only()
+		gsub(/[^!-~\s]/, '*')
+	end
+
+	def ascii_only_if(bool)
+		bool ? ascii_only : dup
+	end
+
 	def from_first(str)
 		self.include?(str) ? self [ self.index(str) + str.size .. -1 ] : nil
 	end