mireru 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a5e44166849dd0f28a9ca3fed76087cafe5e3e9
4
- data.tar.gz: 04edc5e6fed3407dbc9ccaf755b393a5ea6c652f
3
+ metadata.gz: 30b30b55a62ebb76c00bb13f7f8fd49c80ec6ade
4
+ data.tar.gz: 62cf52fd2780daa0e6d9e62a9d666536e64afb6e
5
5
  SHA512:
6
- metadata.gz: ab3cc3ee7bdb3a33e4a179d629778366e442c2fe26e8a7798052270337a9d14b9f26cfae2998c42d2c3bc8798f7ecad5deb6ba0492b7433eaf08f6daab676ddb
7
- data.tar.gz: ca3c1b7cfc990c67b649a555667eae975fa3a77441aefdf798d3e588ef841157171de166518d6be5dfaa5f5a64d3c8f6ca089d607d8b60ecc208c4765cef4f9a
6
+ metadata.gz: ff475315e946a1aa82a60a21556899127c111f5b0a025428ded94fbb0c3a9e32dfd87a5de70c46eeff6d8fc69d536b061574e520296866e1522021077e49a509
7
+ data.tar.gz: ade0850157b14f64964c4c7d48997a7ec71c30f0bc061772a93651ca178165762559151e28017babab5601d3a0222dda82a2b4d5ea330ef86ced466d96176f5d
data/README.md CHANGED
@@ -12,10 +12,14 @@ A friend of a keyboard.
12
12
 
13
13
  ### Launch
14
14
 
15
- $ mireru [FILE...]
15
+ $ mireru [OPTION]... [FILE]...
16
16
 
17
17
  If no argument, then search current directory.
18
18
 
19
+ ### Options
20
+
21
+ -d, --deep: deep search
22
+
19
23
  ### Keybind
20
24
 
21
25
  #### Common
@@ -26,6 +30,8 @@ p: prev
26
30
 
27
31
  r: reload
28
32
 
33
+ e: expand path
34
+
29
35
  q: quit
30
36
 
31
37
  #### Scroll
@@ -6,7 +6,7 @@ require "mireru/container"
6
6
  module Mireru
7
7
  module Command
8
8
  class Mireru
9
- USAGE = "Usage: mireru [FILE...]"
9
+ USAGE = "Usage: mireru [OPTION]... [FILE]..."
10
10
 
11
11
  class << self
12
12
  def run(*arguments)
@@ -19,17 +19,14 @@ module Mireru
19
19
  end
20
20
 
21
21
  def run(arguments)
22
- if arguments.empty?
23
- files = Dir.glob("*")
24
- file_container = ::Mireru::Container.new(files)
25
- elsif /\A(-h|--help)\z/ =~ arguments[0]
22
+ if /\A(-h|--help)\z/ =~ arguments[0]
26
23
  write_help_message
27
24
  exit(true)
28
- else
29
- files = arguments
30
- file_container = ::Mireru::Container.new(files)
31
25
  end
32
26
 
27
+ files = files_from_arguments(arguments)
28
+ file_container = ::Mireru::Container.new(files)
29
+
33
30
  if file_container.empty?
34
31
  write_empty_message
35
32
  exit(false)
@@ -42,14 +39,47 @@ module Mireru
42
39
  end
43
40
 
44
41
  private
42
+ def files_from_arguments(arguments)
43
+ if arguments.empty?
44
+ files = Dir.glob("*")
45
+ elsif /\A(-d|--deep)\z/ =~ arguments[0]
46
+ arguments.shift
47
+ if arguments.empty?
48
+ files = Dir.glob("**/*")
49
+ else
50
+ files = []
51
+ arguments.each do |f|
52
+ if File.directory?(f)
53
+ files << Dir.glob("#{f}/**/*")
54
+ else
55
+ files << f
56
+ end
57
+ end
58
+ files.flatten!
59
+ end
60
+ elsif arguments.all? {|v| File.directory?(v) }
61
+ files = []
62
+ arguments.each do |f|
63
+ files << Dir.glob("#{f}/*")
64
+ end
65
+ files.flatten!
66
+ else
67
+ files = arguments
68
+ end
69
+ files
70
+ end
71
+
45
72
  def write_help_message
46
73
  message = <<-EOM
47
74
  #{USAGE}
48
75
  If no argument, then search current directory.
76
+ Options:
77
+ -d, --deep: deep search
49
78
  Keybind:
50
79
  n: next
51
80
  p: prev
52
81
  r: reload
82
+ e: expand path
53
83
  q: quit
54
84
 
55
85
  scroll:
@@ -1,3 +1,3 @@
1
1
  module Mireru
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -30,6 +30,8 @@ module Mireru
30
30
  self.add_from_file(@file)
31
31
  when Gdk::Keyval::GDK_KEY_r
32
32
  self.add_from_file(@file)
33
+ when Gdk::Keyval::GDK_KEY_e
34
+ self.title = File.expand_path(@file)
33
35
  when Gdk::Keyval::GDK_KEY_f
34
36
  if Mireru::Widget.image?(@file)
35
37
  pixbuf = Gdk::Pixbuf.new(@file, *self.size)
@@ -48,6 +50,14 @@ module Mireru
48
50
  @scroll.vadjustment.value -= 17
49
51
  when Gdk::Keyval::GDK_KEY_l
50
52
  @scroll.hadjustment.value += 17
53
+ when Gdk::Keyval::GDK_KEY_H
54
+ @scroll.hadjustment.value -= 1000000
55
+ when Gdk::Keyval::GDK_KEY_J, Gdk::Keyval::GDK_KEY_G
56
+ @scroll.vadjustment.value += 1000000
57
+ when Gdk::Keyval::GDK_KEY_K
58
+ @scroll.vadjustment.value -= 1000000
59
+ when Gdk::Keyval::GDK_KEY_L
60
+ @scroll.hadjustment.value += 1000000
51
61
  when Gdk::Keyval::GDK_KEY_q
52
62
  Gtk.main_quit
53
63
  end
@@ -1,6 +1,6 @@
1
1
  require "mireru/container"
2
2
 
3
- class TestContainer< Test::Unit::TestCase
3
+ class ContainerTest < Test::Unit::TestCase
4
4
  def setup
5
5
  @container = Mireru::Container.new
6
6
  end
@@ -1,7 +1,7 @@
1
1
  require "mireru/logger"
2
2
  require "stringio"
3
3
 
4
- class TestLogger < Test::Unit::TestCase
4
+ class LoggerTest < Test::Unit::TestCase
5
5
  def setup
6
6
  @logger = Mireru::Logger.new
7
7
  end
@@ -1,4 +1,72 @@
1
1
  require "mireru/command/mireru"
2
2
 
3
- class TestMireru < Test::Unit::TestCase
3
+ class MireruTest < Test::Unit::TestCase
4
+ def setup
5
+ @mireru = Mireru::Command::Mireru.new
6
+ end
7
+
8
+ def test_run_help_option
9
+ arguments = %w(--help)
10
+ mock(@mireru).write_help_message
11
+ assert_raise SystemExit do
12
+ @mireru.run(arguments)
13
+ end
14
+ end
15
+
16
+ def test_run_help_option_sugar
17
+ arguments = %w(-h)
18
+ mock(@mireru).write_help_message
19
+ assert_raise SystemExit do
20
+ @mireru.run(arguments)
21
+ end
22
+ end
23
+
24
+ def test_files_from_arguments_no_argument
25
+ arguments = %w()
26
+ expected = %w(dir1 file1 dir2)
27
+ mock(Dir).glob("*") { expected }
28
+ files = @mireru.__send__(:files_from_arguments, arguments)
29
+ assert_equal(files, expected)
30
+ end
31
+
32
+ def test_files_from_arguments_deep_option_only
33
+ arguments = %w(--deep)
34
+ expected = %w(dir1 file1 dir2 dir1/file1 dir1/file2 dir2/file1)
35
+ mock(Dir).glob("**/*") { expected }
36
+ files = @mireru.__send__(:files_from_arguments, arguments)
37
+ assert_equal(files, expected)
38
+ end
39
+
40
+ def test_files_from_arguments_deep_option_and_dir
41
+ arguments = %w(--deep dir1 file1 dir2)
42
+ expected_dir1 = %w(dir1/file1 dir1/file2)
43
+ expected_dir2 = %w(dir2/file1)
44
+ expected = [expected_dir1, "file1", expected_dir2].flatten
45
+ mock(File).directory?("dir1") { true }
46
+ mock(File).directory?("file1") { false }
47
+ mock(File).directory?("dir2") { true }
48
+ mock(Dir).glob("dir1/**/*") { expected_dir1 }
49
+ mock(Dir).glob("dir2/**/*") { expected_dir2 }
50
+ files = @mireru.__send__(:files_from_arguments, arguments)
51
+ assert_equal(files, expected)
52
+ end
53
+
54
+ def test_files_from_arguments_all_dir
55
+ arguments = %w(dir1 dir2)
56
+ expected_dir1 = %w(dir1/file1 dir1/file2)
57
+ expected_dir2 = %w(dir2/file1)
58
+ expected = [expected_dir1, expected_dir2].flatten
59
+ mock(File).directory?("dir1") { true }
60
+ mock(File).directory?("dir2") { true }
61
+ mock(Dir).glob("dir1/*") { expected_dir1 }
62
+ mock(Dir).glob("dir2/*") { expected_dir2 }
63
+ files = @mireru.__send__(:files_from_arguments, arguments)
64
+ assert_equal(files, expected)
65
+ end
66
+
67
+ def test_files_from_arguments_else
68
+ arguments = %w(dir1 file1 dir2)
69
+ files = @mireru.__send__(:files_from_arguments, arguments)
70
+ assert_equal(files, arguments)
71
+ end
4
72
  end
@@ -1,6 +1,6 @@
1
1
  require "mireru/widget"
2
2
 
3
- class TestWidget < Test::Unit::TestCase
3
+ class WidgetTest < Test::Unit::TestCase
4
4
  def test_image?
5
5
  assert_nil(Mireru::Widget.image?(__FILE__))
6
6
  assert_not_nil(Mireru::Widget.image?("test/fixtures/nijip.png"))
@@ -1,6 +1,6 @@
1
1
  require "mireru/window"
2
2
 
3
- class TestWindow < Test::Unit::TestCase
3
+ class WindowTest < Test::Unit::TestCase
4
4
  def setup
5
5
  @window = Mireru::Window.new
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mireru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masafumi Yokoyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-09 00:00:00.000000000 Z
11
+ date: 2013-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gtk3