From adfea091f816cc2f4007e99b6b2be35a821857da Mon Sep 17 00:00:00 2001 From: hut Date: Wed, 8 Apr 2009 00:00:00 +0200 Subject: the first usable version. I was not using git yet, this was a simple backup --- code/extensions.rb | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 code/extensions.rb (limited to 'code/extensions.rb') diff --git a/code/extensions.rb b/code/extensions.rb new file mode 100644 index 00000000..db238614 --- /dev/null +++ b/code/extensions.rb @@ -0,0 +1,176 @@ +class Directory + def initialize(path) + @path = path + @pos = 0 + @pointed_file = '' + @width = 0 + refresh + end + + attr_reader(:path, :files, :pos, :width, :infos) + + def pos=(x) + @pos = x + @pointed_file = @files[x] + resize + end + + def pointed_file=(x) + if @files.include?(x) + @pointed_file = x + @pos = @files.index(x) + else + self.pos = 0 + end + resize + end + + def size() @files.size end + + def resize() + pos = Fm.get_offset(self, lines) + if @files.empty? + @width = 0 + else + @width = 0 + @files[pos, lines-2].each_with_index do |fn, ix| + ix += pos +# log File.basename(fn) + @infos[ix] + sz = File.basename(fn).size + @infos[ix].size + 2 + @width = sz if @width < sz + end +# @width = @files[pos,lines-2].map{|x| File.basename(x).size}.max + end + end + + def get_file_infos() + @infos = [] + @files.each do |fn| + if File.directory?(fn) + begin + sz = Dir.entries(fn).size - 2 + rescue + sz = "?" + end + @infos << "#{sz}" + else + if File.size?(fn) + @infos << " #{File.size(fn).bytes 2}" + else + @infos << "" + end + end + end + end + + def refresh() + glob = Dir.new(@path).to_a.sort! + if OPTIONS['hidden'] + glob -= ['.', '..', 'lost+found'] + else + glob.reject!{|x| x[0] == ?. or x == 'lost+found'} + end + if glob.empty? + glob = ['.'] + end + glob.map!{|x| File.join(@path, x)} + dirs = glob.select{|x| File.directory?(x)} + @files = dirs + (glob - dirs) + + get_file_infos + resize + + if @pos >= @files.size + @pos = @files.size - 1 + elsif @files.include?(@pointed_file) + @pos = @files.index(@pointed_file) + end + end +end + + +class File + MODES_HASH = { + '0' => '---', + '1' => '--x', + '2' => '-w-', + '3' => '-wx', + '4' => 'r--', + '5' => 'r-x', + '6' => 'rw-', + '7' => 'rwx' + } + def self.modestr(f) + unless exists?(f) + return '----------' + end + + if symlink?(f) + result = 'l' + elsif directory?(f) + result = 'd' + else + result = '-' + end + + s = ("%o" % File.stat(f).mode)[-3..-1] + for m in s.each_char + result << MODES_HASH[m] + end + + result + end +end + +class Numeric + def limit(max, min = 0) + self < min ? min : (self > max ? max : self) + end + + def bytes n_round = 2 + n = 1024 + a = %w(B K M G T Y) + + i = 0 + flt = self.to_f + + while flt > n and i < a.length - 1 + flt /= n + i += 1 + end + +# flt = flt.round(n_round) + r = 10 ** n_round + flt *= r + flt = flt.round.to_f / r + int = flt.to_i + flt = int if int == flt + + return flt.to_s + ' ' + a[i] + end +end + +class Array + def wrap(n) + n.times { push shift } + end +end + +class String + def clear + replace String.new + end + def sh + res = dup + res.gsub!('\\\\', "\000") + res.gsub!(' ', '\\ ') + res.gsub!('(', '\\(') + res.gsub!(')', '\\)') + res.gsub!('*', '\\*') + res.gsub!('\'', '\\\'') + res.gsub!('"', '\\"') + res.gsub!("\000", '\\\\') + return res + end +end + -- cgit 1.4.1-2-gfad0 t of the filename' href='/akspecs/ranger/commit/Makefile?h=v1.9.0b6&id=6ac4be61c3c701fdfca6c2f23d7060c817e82840'>6ac4be61 ^
e9e4b4ff ^


2c5ea01d ^

ea775b1c ^
2c5ea01d ^















e9e4b4ff ^











50a0cb1c ^
e9e4b4ff ^

50a0cb1c ^
e9e4b4ff ^
2c5ea01d ^
e9e4b4ff ^


2c5ea01d ^
e9e4b4ff ^







2c5ea01d ^
e9e4b4ff ^
0c2c782d ^

6ac4be61 ^
ea775b1c ^








6ac4be61 ^
ea775b1c ^

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