di 0.1.3 → 0.1.4

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.
Files changed (5) hide show
  1. data/HISTORY +4 -0
  2. data/VERSION +1 -1
  3. data/bin/di +44 -9
  4. data/di.gemspec +1 -1
  5. metadata +2 -2
data/HISTORY CHANGED
@@ -1,3 +1,7 @@
1
+ * Add --[no-]pager and turn it on by default.
2
+
3
+ * Do not choke on file names starting with a hyphen.
4
+
1
5
  == 0.1.3 2010-03-10
2
6
 
3
7
  * Fix handling of the following options and make custom format options
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
data/bin/di CHANGED
@@ -74,6 +74,7 @@ def setup
74
74
  $diff.flags = []
75
75
  $diff.format_flags = []
76
76
  $diff.custom_format_p = false
77
+ $diff.use_pager = false
77
78
  end
78
79
 
79
80
  def parse_args!(args)
@@ -92,6 +93,10 @@ usage: #{MYNAME} [flags] [files]
92
93
  hash['-'] = false
93
94
  opts.accept(miniTrueClass, hash) {|arg, val| val == nil or val}
94
95
 
96
+ opts.on('--[no-]pager',
97
+ 'Pipe output into $PAGER (or more(1) if not defined) if stdout is a terminal. [!][*]') { |val|
98
+ $diff.use_pager = val
99
+ }
95
100
  opts.on('--[no-]rsync-exclude', '--[no-]cvs-exclude',
96
101
  'Exclude some kinds of files and directories a la rsync(1). [!][*]') { |val|
97
102
  $diff.rsync_exclude = val
@@ -329,17 +334,18 @@ usage: #{MYNAME} [flags] [files]
329
334
  }
330
335
  opts.on('--help',
331
336
  'Output this help.') { |val|
332
- print opts,
333
- "\n",
334
- "Options without the [*] sign will be passed through to diff(1).\n",
335
- "Options marked as [!] sign are turned on by default. To turn them off,\n",
336
- "specify -?- for short options and --no-??? for long options, respectively.\n"
337
+ invoke_pager
338
+ print opts, <<EOS
339
+ Options without the [*] sign will be passed through to diff(1).
340
+ Options marked as [!] sign are turned on by default. To turn them off,
341
+ specify -?- for short options and --no-??? for long options, respectively.
342
+ EOS
337
343
  exit 0
338
344
  }
339
345
  }
340
346
 
341
347
  begin
342
- opts.parse('--rsync-exclude', '--fignore-exclude', '--ignore-cvs-lines',
348
+ opts.parse('--rsync-exclude', '--fignore-exclude', '--ignore-cvs-lines', '--pager',
343
349
  '-U3', '-N', '-r', '-p', '-d')
344
350
  opts.parse!(args)
345
351
 
@@ -394,6 +400,33 @@ usage: #{MYNAME} [flags] [files]
394
400
  end
395
401
  end
396
402
 
403
+ def invoke_pager
404
+ invoke_pager! if $diff.use_pager && $stdout.tty?
405
+ end
406
+
407
+ def invoke_pager!
408
+ $stdout.flush
409
+ $stderr.flush
410
+ pr, pw = IO.pipe
411
+ pid = fork {
412
+ $stdin.reopen(pr)
413
+ pr.close
414
+ pw.close
415
+ IO.select([$stdin], nil, [$stdin])
416
+ exec(ENV['PAGER'] || 'more')
417
+ }
418
+ $stdout.reopen(pw)
419
+ $stderr.reopen(pw) if $stderr.tty?
420
+ pw.close
421
+ at_exit {
422
+ $stdout.flush
423
+ $stderr.flush
424
+ $stdout.close
425
+ $stderr.close
426
+ Process.waitpid(pid)
427
+ }
428
+ end
429
+
397
430
  def set_flag(flag, val)
398
431
  case val
399
432
  when false
@@ -421,6 +454,8 @@ def set_custom_format_flag(flag, *val)
421
454
  end
422
455
 
423
456
  def diff_main
457
+ invoke_pager
458
+
424
459
  $status = 0
425
460
 
426
461
  $diff.from_files.each { |from_file|
@@ -463,13 +498,13 @@ def diff_files(file1, file2)
463
498
  file2.is_a?(Array) and raise "cannot compare two sets of multiple files"
464
499
  file1.empty? and return 0
465
500
 
466
- call_diff('--to-file', file2, file1)
501
+ call_diff('--to-file', file2, '--', file1)
467
502
  elsif file2.is_a?(Array)
468
503
  file1.empty? and return 0
469
504
 
470
- call_diff('--from-file', file1, file2)
505
+ call_diff('--from-file', file1, '--', file2)
471
506
  else
472
- call_diff(file1, file2)
507
+ call_diff('--', file1, file2)
473
508
  end
474
509
  end
475
510
 
data/di.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{di}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Akinori MUSHA"]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Akinori MUSHA