rfd 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/bin/rfd +5 -0
- data/lib/rfd.rb +456 -0
- data/lib/rfd/commands.rb +234 -0
- data/lib/rfd/item.rb +176 -0
- data/lib/rfd/windows.rb +227 -0
- data/rfd.gemspec +24 -0
- data/spec/controller_spec.rb +277 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/support/capture_helper.rb +21 -0
- data/spec/testdir/.file1 +0 -0
- data/spec/testdir/.file2 +0 -0
- data/spec/testdir/.file3 +0 -0
- data/spec/testdir/.link1 +0 -0
- data/spec/testdir/file1 +1 -0
- data/spec/testdir/file2 +0 -0
- data/spec/testdir/file3 +0 -0
- data/spec/testdir/link1 +1 -0
- data/spec/testdir/link2 +0 -0
- metadata +137 -0
data/rfd.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "rfd"
|
7
|
+
spec.version = '0.0.1'
|
8
|
+
spec.authors = ["Akira Matsuda"]
|
9
|
+
spec.email = ["ronnie@dio.jp"]
|
10
|
+
spec.description = 'Ruby on Files and Directories'
|
11
|
+
spec.summary = 'Ruby on Files and Directories'
|
12
|
+
spec.homepage = 'https://github.com/amatsuda/rfd'
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency 'ffi-ncurses'
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
end
|
@@ -0,0 +1,277 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rfd'
|
3
|
+
|
4
|
+
describe Rfd::Controller do
|
5
|
+
include CaptureHelper
|
6
|
+
|
7
|
+
around do |example|
|
8
|
+
@stdout = capture(:stdout) do
|
9
|
+
@rfd = Rfd.start testdir
|
10
|
+
def (@rfd.main).maxy
|
11
|
+
3
|
12
|
+
end
|
13
|
+
|
14
|
+
example.run
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
after :all do
|
19
|
+
Curses.endwin
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:testdir) { File.join __dir__, 'testdir' }
|
23
|
+
let!(:controller) { @rfd }
|
24
|
+
subject { controller }
|
25
|
+
let(:items) { controller.items }
|
26
|
+
|
27
|
+
describe '#spawn_panes' do
|
28
|
+
before { controller.spawn_panes 3 }
|
29
|
+
|
30
|
+
subject { controller.main.instance_variable_get :@panes }
|
31
|
+
it { should have(3).panes }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#current_item' do
|
35
|
+
before do
|
36
|
+
controller.instance_variable_set :@current_row, 3
|
37
|
+
end
|
38
|
+
its(:current_item) { should == items[3] }
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#marked_items' do
|
42
|
+
before do
|
43
|
+
items[2].toggle_mark
|
44
|
+
items[3].toggle_mark
|
45
|
+
end
|
46
|
+
its(:marked_items) { should == [items[2], items[3]] }
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#selected_items' do
|
50
|
+
context 'When no items were marked' do
|
51
|
+
context 'When the cursor is on . or ..' do
|
52
|
+
its(:selected_items) { should be_empty }
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'When the cursor is not on . nor ..' do
|
56
|
+
before do
|
57
|
+
controller.instance_variable_set :@current_row, 5
|
58
|
+
end
|
59
|
+
its(:selected_items) { should == [items[5]] }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
context 'When items were marked' do
|
63
|
+
before do
|
64
|
+
items[2].toggle_mark
|
65
|
+
items[4].toggle_mark
|
66
|
+
end
|
67
|
+
its(:selected_items) { should == [items[2], items[4]] }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '#move_cursor' do
|
72
|
+
context 'When moving to nil' do
|
73
|
+
before do
|
74
|
+
controller.move_cursor nil
|
75
|
+
end
|
76
|
+
its(:current_row) { should == 0 }
|
77
|
+
end
|
78
|
+
context 'When moving to a certain row' do
|
79
|
+
before do
|
80
|
+
controller.move_cursor 2
|
81
|
+
end
|
82
|
+
its(:current_row) { should == 2 }
|
83
|
+
|
84
|
+
context 'When moving to the second pane' do
|
85
|
+
before do
|
86
|
+
controller.move_cursor 5
|
87
|
+
end
|
88
|
+
subject { controller.main.instance_variable_get :@panes }
|
89
|
+
its(:current_index) { should == 1 }
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'When moving to the second page' do
|
93
|
+
before do
|
94
|
+
controller.move_cursor 7
|
95
|
+
end
|
96
|
+
its(:current_page) { should == 1 }
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '#cd' do
|
102
|
+
before do
|
103
|
+
controller.cd 'dir1'
|
104
|
+
end
|
105
|
+
its(:current_dir) { should == File.join(testdir, 'dir1') }
|
106
|
+
|
107
|
+
describe '#popd' do
|
108
|
+
before do
|
109
|
+
controller.popd
|
110
|
+
end
|
111
|
+
its(:current_dir) { should == testdir }
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe '#ls' do
|
116
|
+
before do
|
117
|
+
controller.instance_variable_set :@items, []
|
118
|
+
controller.ls
|
119
|
+
end
|
120
|
+
its(:items) { should_not be_empty }
|
121
|
+
end
|
122
|
+
|
123
|
+
describe '#sort' do
|
124
|
+
let(:item) do
|
125
|
+
Dir.mkdir File.join testdir, '.a'
|
126
|
+
Rfd::Item.new dir: testdir, name: '.a', window_width: 100
|
127
|
+
end
|
128
|
+
before do
|
129
|
+
controller.items << item
|
130
|
+
controller.sort
|
131
|
+
end
|
132
|
+
after do
|
133
|
+
Dir.rmdir File.join testdir, '.a'
|
134
|
+
end
|
135
|
+
subject { item }
|
136
|
+
its(:index) { should == 2 } # . .. then next
|
137
|
+
end
|
138
|
+
|
139
|
+
describe '#chmod' do
|
140
|
+
let(:item) { controller.items.detect {|i| !i.directory?} }
|
141
|
+
before do
|
142
|
+
item.toggle_mark
|
143
|
+
controller.chmod 'a+w'
|
144
|
+
item.instance_variable_set :@lstat, nil # clear cached value
|
145
|
+
item.instance_variable_set :@mode, nil # clear cached value
|
146
|
+
end
|
147
|
+
subject { item }
|
148
|
+
its(:mode) { should == '-rw-rw-rw-' }
|
149
|
+
end
|
150
|
+
|
151
|
+
describe '#find' do
|
152
|
+
before do
|
153
|
+
controller.find 'd'
|
154
|
+
end
|
155
|
+
its('current_item.name') { should start_with('d') }
|
156
|
+
end
|
157
|
+
|
158
|
+
describe '#find_reverse' do
|
159
|
+
before do
|
160
|
+
controller.find_reverse 'f'
|
161
|
+
end
|
162
|
+
its('current_item.name') { should == 'file3' }
|
163
|
+
end
|
164
|
+
|
165
|
+
describe '#grep' do
|
166
|
+
before do
|
167
|
+
controller.grep 'dir'
|
168
|
+
end
|
169
|
+
subject { controller.items[2..-1] }
|
170
|
+
its(:size) { should be > 2 }
|
171
|
+
it "all items' name should include 'dir'" do
|
172
|
+
subject.all? {|i| i.name.should include('dir')}
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
describe '#cp' do
|
177
|
+
before do
|
178
|
+
controller.find 'file1'
|
179
|
+
controller.cp 'file4'
|
180
|
+
end
|
181
|
+
after do
|
182
|
+
File.delete File.join(testdir, 'file4')
|
183
|
+
end
|
184
|
+
it 'should be the same file as the copy source file' do
|
185
|
+
File.read(File.join(testdir, 'file1')).should == File.read(File.join(testdir, 'file4'))
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe '#mv' do
|
190
|
+
before do
|
191
|
+
controller.find 'file3'
|
192
|
+
controller.mv 'dir2'
|
193
|
+
end
|
194
|
+
after do
|
195
|
+
FileUtils.mv File.join(testdir, 'dir2/file3'), File.join(testdir, 'file3')
|
196
|
+
end
|
197
|
+
it 'should move current file to the specified directory' do
|
198
|
+
File.exist?(File.join(testdir, 'dir2/file3')).should == true
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe '#rename' do
|
203
|
+
before do
|
204
|
+
controller.find '.file2'
|
205
|
+
controller.toggle_mark
|
206
|
+
controller.find 'file3'
|
207
|
+
controller.toggle_mark
|
208
|
+
controller.rename 'fi/faaai'
|
209
|
+
end
|
210
|
+
after do
|
211
|
+
FileUtils.mv File.join(testdir, '.faaaile2'), File.join(testdir, '.file2')
|
212
|
+
FileUtils.mv File.join(testdir, 'faaaile3'), File.join(testdir, 'file3')
|
213
|
+
end
|
214
|
+
it 'should rename selected files' do
|
215
|
+
File.exist?(File.join(testdir, '.faaaile2')).should == true
|
216
|
+
File.exist?(File.join(testdir, 'faaaile3')).should == true
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe '#mkdir' do
|
221
|
+
before do
|
222
|
+
controller.mkdir 'aho'
|
223
|
+
end
|
224
|
+
after do
|
225
|
+
Dir.delete File.join(testdir, 'aho')
|
226
|
+
end
|
227
|
+
it 'should create a new directory' do
|
228
|
+
Dir.exist?(File.join(testdir, 'aho')).should == true
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
describe '#touch' do
|
233
|
+
before do
|
234
|
+
controller.touch 'fuga'
|
235
|
+
end
|
236
|
+
after do
|
237
|
+
File.delete File.join(testdir, 'fuga')
|
238
|
+
end
|
239
|
+
it 'should create a new file' do
|
240
|
+
File.exist?(File.join(testdir, 'fuga')).should == true
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
describe '#first_page? and #last_page?' do
|
245
|
+
context 'When on the first page' do
|
246
|
+
it { should be_first_page }
|
247
|
+
it { should_not be_last_page }
|
248
|
+
end
|
249
|
+
context 'When on the first page' do
|
250
|
+
before do
|
251
|
+
controller.k
|
252
|
+
end
|
253
|
+
it { should_not be_first_page }
|
254
|
+
it { should be_last_page }
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
describe '#total_pages' do
|
259
|
+
its(:total_pages) { should == 3 } # 15 / (3 * 2) + 1
|
260
|
+
end
|
261
|
+
|
262
|
+
describe '#switch_page' do
|
263
|
+
before do
|
264
|
+
controller.switch_page 2
|
265
|
+
end
|
266
|
+
its(:current_page) { should == 2 }
|
267
|
+
end
|
268
|
+
|
269
|
+
describe '#toggle_mark' do
|
270
|
+
before do
|
271
|
+
controller.move_cursor 10
|
272
|
+
controller.toggle_mark
|
273
|
+
end
|
274
|
+
subject { items[10] }
|
275
|
+
it { should be_marked }
|
276
|
+
end
|
277
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
# copied from ActiveSupport 4
|
4
|
+
module CaptureHelper
|
5
|
+
def capture(stream)
|
6
|
+
stream = stream.to_s
|
7
|
+
captured_stream = Tempfile.new(stream)
|
8
|
+
stream_io = eval("$#{stream}")
|
9
|
+
origin_stream = stream_io.dup
|
10
|
+
stream_io.reopen(captured_stream)
|
11
|
+
|
12
|
+
yield
|
13
|
+
|
14
|
+
stream_io.rewind
|
15
|
+
return captured_stream.read
|
16
|
+
ensure
|
17
|
+
captured_stream.close
|
18
|
+
captured_stream.unlink
|
19
|
+
stream_io.reopen(origin_stream)
|
20
|
+
end
|
21
|
+
end
|
data/spec/testdir/.file1
ADDED
File without changes
|
data/spec/testdir/.file2
ADDED
File without changes
|
data/spec/testdir/.file3
ADDED
File without changes
|
data/spec/testdir/.link1
ADDED
File without changes
|
data/spec/testdir/file1
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
file1
|
data/spec/testdir/file2
ADDED
File without changes
|
data/spec/testdir/file3
ADDED
File without changes
|
data/spec/testdir/link1
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
file1
|
data/spec/testdir/link2
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rfd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Akira Matsuda
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ffi-ncurses
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Ruby on Files and Directories
|
70
|
+
email:
|
71
|
+
- ronnie@dio.jp
|
72
|
+
executables:
|
73
|
+
- rfd
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- Gemfile
|
79
|
+
- MIT-LICENSE
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/rfd
|
83
|
+
- lib/rfd.rb
|
84
|
+
- lib/rfd/commands.rb
|
85
|
+
- lib/rfd/item.rb
|
86
|
+
- lib/rfd/windows.rb
|
87
|
+
- rfd.gemspec
|
88
|
+
- spec/controller_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
- spec/support/capture_helper.rb
|
91
|
+
- spec/testdir/.file1
|
92
|
+
- spec/testdir/.file2
|
93
|
+
- spec/testdir/.file3
|
94
|
+
- spec/testdir/.link1
|
95
|
+
- spec/testdir/file1
|
96
|
+
- spec/testdir/file2
|
97
|
+
- spec/testdir/file3
|
98
|
+
- spec/testdir/link1
|
99
|
+
- spec/testdir/link2
|
100
|
+
homepage: https://github.com/amatsuda/rfd
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.0.3
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: Ruby on Files and Directories
|
124
|
+
test_files:
|
125
|
+
- spec/controller_spec.rb
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
- spec/support/capture_helper.rb
|
128
|
+
- spec/testdir/.file1
|
129
|
+
- spec/testdir/.file2
|
130
|
+
- spec/testdir/.file3
|
131
|
+
- spec/testdir/.link1
|
132
|
+
- spec/testdir/file1
|
133
|
+
- spec/testdir/file2
|
134
|
+
- spec/testdir/file3
|
135
|
+
- spec/testdir/link1
|
136
|
+
- spec/testdir/link2
|
137
|
+
has_rdoc:
|