rfd 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1dd36a7cd7b7b8a56e25d704089e6c390935e07
4
- data.tar.gz: eb3055ac47eb7a6105fb9a1a0b093323bab1d23a
3
+ metadata.gz: 433838cecd4fd367a1820347e5e6914cf4baf3a9
4
+ data.tar.gz: d92980f79fc3a0bd3a553f10360d061d054dfc0f
5
5
  SHA512:
6
- metadata.gz: 14187a51b3c5d3ea90b7f4fcbd363170c9cd391e0d4ea7f54f75045de1a34e6dd762c56f61964af537b4a4e83d28325198e794c99c4dd942f8a94645d41a0a92
7
- data.tar.gz: d1beb6cd74c3c03c06c02140d2d2680727ab27ac8cb2dfcb93da8659e1f0c23f3c879437701e6f81b8eb90884a298ac23786a166eb4f949c59faa403524fd5e7
6
+ metadata.gz: ac5d0d885e4d5c26c431711072be5bd878a876c2be73999a3e0cc9638f3cfb7d109c5cd091d8032c5fb803f7f3b064c2ed15642e3df813fc0e32fc8055714738
7
+ data.tar.gz: cd1051af5fa5fdc53978193962f2ca25d95163cbc870b6fea55c0cadb3905c47407af90f075e5ac9370891ef648a6c18ff95a31bfcc6fc423a54faa00d93e763
data/README.md CHANGED
@@ -14,7 +14,7 @@ rfd is a terminal based File explorer, inpsired by the legendary freesoft MS-DOS
14
14
 
15
15
  ## Tested environment
16
16
 
17
- Mac OSX Snow Leopard
17
+ Mac OS X Mountain Lion, Mac OS X Lion
18
18
 
19
19
  ## Usage
20
20
 
data/lib/rfd.rb CHANGED
@@ -53,7 +53,7 @@ module Rfd
53
53
  @header_l = HeaderLeftWindow.new
54
54
  @header_r = HeaderRightWindow.new
55
55
  @command_line = CommandLineWindow.new
56
- @direction, @dir_history = nil, []
56
+ @direction, @dir_history, @last_command, @times = nil, [], nil, nil
57
57
  end
58
58
 
59
59
  # The main loop.
@@ -61,6 +61,7 @@ module Rfd
61
61
  mouse_event = Curses::MEVENT.new
62
62
  loop do
63
63
  begin
64
+ number_pressed = false
64
65
  case (c = Curses.getch)
65
66
  when Curses::KEY_RETURN
66
67
  enter
@@ -81,6 +82,9 @@ module Rfd
81
82
  when Curses::KEY_CTRL_A..Curses::KEY_CTRL_Z
82
83
  chr = ((c - 1 + 65) ^ 0b0100000).chr
83
84
  public_send "ctrl_#{chr}" if respond_to?("ctrl_#{chr}")
85
+ when 48..57 # ?0..?9
86
+ public_send c.chr
87
+ number_pressed = true
84
88
  when 0..255
85
89
  if respond_to? c.chr
86
90
  public_send c.chr
@@ -98,6 +102,7 @@ module Rfd
98
102
  else
99
103
  debug "key: #{c}" if ENV['DEBUG']
100
104
  end
105
+ @times = nil unless number_pressed
101
106
  rescue StopIteration
102
107
  raise
103
108
  rescue => e
@@ -115,6 +120,11 @@ module Rfd
115
120
  @current_row = @current_page = 0
116
121
  end
117
122
 
123
+ # Number of times to repeat the next command.
124
+ def times
125
+ (@times || 1).to_i
126
+ end
127
+
118
128
  # The file or directory on which the cursor is on.
119
129
  def current_item
120
130
  items[current_row]
@@ -273,13 +283,13 @@ module Rfd
273
283
 
274
284
  # Focus at the first file or directory of which name starts with the given String.
275
285
  def find(str)
276
- index = items.index {|i| i.name.start_with? str}
286
+ index = items.index {|i| i.index > current_row && i.name.start_with?(str)} || items.index {|i| i.name.start_with? str}
277
287
  move_cursor index if index
278
288
  end
279
289
 
280
290
  # Focus at the last file or directory of which name starts with the given String.
281
291
  def find_reverse(str)
282
- index = items.reverse.index {|i| i.name.start_with? str}
292
+ index = items.reverse.index {|i| i.index < current_row && i.name.start_with?(str)} || items.reverse.index {|i| i.name.start_with? str}
283
293
  move_cursor items.size - index - 1 if index
284
294
  end
285
295
 
@@ -586,10 +596,17 @@ module Rfd
586
596
  header_r.draw_total_items count: items.size, size: items.inject(0) {|sum, i| sum += i.size}
587
597
  end
588
598
 
599
+ # Swktch on / off marking on the current file or directory.
589
600
  def toggle_mark
590
601
  main.toggle_mark current_item
591
602
  end
592
603
 
604
+ # Get a char as a String from user input.
605
+ def get_char
606
+ c = Curses.getch
607
+ c.chr if (0..255) === c
608
+ end
609
+
593
610
  # Accept user input, and directly execute it as a Ruby method call to the controller.
594
611
  #
595
612
  # ==== Parameters
data/lib/rfd/commands.rb CHANGED
@@ -26,7 +26,12 @@ module Rfd
26
26
 
27
27
  # "f"ind the first file or directory of which name starts with the given String.
28
28
  def f
29
- process_command_line preset_command: 'find'
29
+ c = get_char and (@last_command = -> { find c }).call
30
+ end
31
+
32
+ # Move the cursor to the top of the list.
33
+ def g
34
+ move_cursor 0
30
35
  end
31
36
 
32
37
  # Move the cursor to the left pane.
@@ -36,20 +41,12 @@ module Rfd
36
41
 
37
42
  # Move the cursor down.
38
43
  def j
39
- if current_row + 1 >= items.size
40
- move_cursor 0
41
- else
42
- move_cursor current_row + 1
43
- end
44
+ move_cursor (current_row + times) % items.size
44
45
  end
45
46
 
46
47
  # Move the cursor up.
47
48
  def k
48
- if current_row == 0
49
- move_cursor items.size - 1
50
- else
51
- move_cursor current_row - 1
52
- end
49
+ move_cursor (current_row - times) % items.size
53
50
  end
54
51
 
55
52
  # Move the cursor to the right pane.
@@ -62,6 +59,11 @@ module Rfd
62
59
  process_command_line preset_command: 'mv'
63
60
  end
64
61
 
62
+ # Redo the latest f or F.
63
+ def n
64
+ @last_command.call if @last_command
65
+ end
66
+
65
67
  # "o"pen selected files and directories with the OS "open" command.
66
68
  def o
67
69
  if selected_items.any?
@@ -127,7 +129,7 @@ module Rfd
127
129
 
128
130
  # "f"ind the last file or directory of which name starts with the given String.
129
131
  def F
130
- process_command_line preset_command: 'find_reverse'
132
+ c = get_char and (@last_command = -> { find_reverse c }).call
131
133
  end
132
134
 
133
135
  # Move the cursor to the top.
@@ -135,6 +137,11 @@ module Rfd
135
137
  move_cursor current_page * max_items
136
138
  end
137
139
 
140
+ # Move the cursor to the bottom of the list.
141
+ def G
142
+ move_cursor items.size - 1
143
+ end
144
+
138
145
  # Ma"K"e a directory.
139
146
  def K
140
147
  process_command_line preset_command: 'mkdir'
@@ -190,31 +197,26 @@ module Rfd
190
197
 
191
198
  # Forward to the "n"ext page.
192
199
  def ctrl_n
193
- if total_pages > 1
194
- if last_page?
195
- move_cursor 0
196
- else
197
- move_cursor (current_page + 1) * max_items
198
- end
199
- end
200
+ move_cursor (current_page + 1) % total_pages * max_items if total_pages > 1
200
201
  end
201
202
 
202
203
  # Back to the "p"revious page.
203
204
  def ctrl_p
204
- if total_pages > 1
205
- if first_page?
206
- move_cursor (total_pages - 1) * max_items
207
- else
208
- move_cursor (current_page - 1) * max_items
209
- end
205
+ move_cursor (current_page - 1) % total_pages * max_items if total_pages > 1
206
+ end
207
+
208
+ # Split the main "w"indow into given number of columns.
209
+ def ctrl_w
210
+ if @times
211
+ spawn_panes @times.to_i
212
+ ls
210
213
  end
211
214
  end
212
215
 
213
- # Change the number of columns in the main window.
214
- (?1..?9).each do |n|
216
+ # Number of times to repeat the next command.
217
+ (?0..?9).each do |n|
215
218
  define_method(n) do
216
- spawn_panes n.to_i
217
- ls
219
+ (@times ||= '') << n
218
220
  end
219
221
  end
220
222
 
@@ -265,7 +267,7 @@ module Rfd
265
267
  # cd to the upper hierarchy.
266
268
  def del
267
269
  if current_dir != '/'
268
- cd '..'
270
+ cd File.expand_path(File.join(current_dir, ['..'] * times))
269
271
  ls
270
272
  end
271
273
  end
data/rfd.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "rfd"
7
- spec.version = '0.1.0'
7
+ spec.version = '0.2.0'
8
8
  spec.authors = ["Akira Matsuda"]
9
9
  spec.email = ["ronnie@dio.jp"]
10
10
  spec.description = 'Ruby on Files & Directories'
@@ -375,4 +375,21 @@ describe Rfd::Controller do
375
375
  subject { items[10] }
376
376
  it { should be_marked }
377
377
  end
378
+
379
+ describe 'times' do
380
+ subject { controller.times }
381
+ context 'before accepting 0-9' do
382
+ it { should == 1 }
383
+ end
384
+ context 'When 0-9 were typed' do
385
+ before do
386
+ controller.public_send '3'
387
+ controller.public_send '7'
388
+ end
389
+ after do
390
+ controller.instance_variable_set :@times, nil
391
+ end
392
+ it { should == 37 }
393
+ end
394
+ end
378
395
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rfd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Matsuda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-11 00:00:00.000000000 Z
11
+ date: 2013-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi-ncurses