interact 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -273,8 +273,6 @@ module Interactive
273
273
  end
274
274
 
275
275
  def handler(which, state)
276
- echo = state.options[:echo]
277
-
278
276
  ans = state.answer
279
277
  pos = state.position
280
278
 
@@ -286,15 +284,16 @@ module Interactive
286
284
  # nothing
287
285
 
288
286
  when :tab
289
- if choices = state.options[:choices]
290
- matches = choices.select { |c| c.start_with? ans }
291
-
292
- if matches.size == 1
293
- ans = state.answer = matches[0]
294
- state.display(ans[pos .. -1])
287
+ matches =
288
+ if choices = state.options[:choices]
289
+ choices.select { |c| c.start_with? ans }
295
290
  else
296
- print("\a") # bell
291
+ matching_paths(ans)
297
292
  end
293
+
294
+ if matches.size == 1
295
+ ans = state.answer = matches[0].dup
296
+ state.display(ans[pos .. -1])
298
297
  else
299
298
  print("\a") # bell
300
299
  end
@@ -386,6 +385,14 @@ module Interactive
386
385
  true
387
386
  end
388
387
 
388
+ def matching_paths(input)
389
+ home = Dir.home
390
+
391
+ Dir.glob(input.sub("~", home) + "*").collect do |p|
392
+ p.sub(home, "~")
393
+ end
394
+ end
395
+
389
396
  def prompt(question, options = {})
390
397
  print question
391
398
 
@@ -480,22 +487,45 @@ module Interactive
480
487
  chr(input.getc)
481
488
  end
482
489
  rescue LoadError
483
- def set_input_state(input)
484
- return nil unless input.tty?
490
+ begin
491
+ require "ffi-ncurses"
485
492
 
486
- before = `stty -g`
493
+ def set_input_state(input)
494
+ return nil unless input.tty?
487
495
 
488
- system("stty -echo -icanon isig")
496
+ FFI::NCurses.initscr
497
+ FFI::NCurses.cbreak
489
498
 
490
- before
491
- end
499
+ true
500
+ end
492
501
 
493
- def restore_input_state(input, before)
494
- system("stty #{before}") if before
495
- end
502
+ def restore_input_state(input, before)
503
+ if before
504
+ FFI::NCurses.endwin
505
+ end
506
+ end
496
507
 
497
- def get_character(input)
498
- chr(input.getc)
508
+ def get_character(input)
509
+ chr(input.getc)
510
+ end
511
+ rescue LoadError
512
+ def set_input_state(input)
513
+ return nil unless input.tty?
514
+
515
+ before = `stty -g`
516
+
517
+ system("stty -echo -icanon isig")
518
+
519
+ before
520
+ end
521
+
522
+ def restore_input_state(input, before)
523
+ system("stty #{before}") if before
524
+ end
525
+
526
+ def get_character(input)
527
+ chr(input.getc)
528
+ end
499
529
  end
500
530
  end
501
531
  end
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2011 Alex Suraci
2
2
 
3
3
  module Interact
4
- VERSION = "0.4.1"
4
+ VERSION = "0.4.2"
5
5
  end
metadata CHANGED
@@ -1,62 +1,48 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: interact
3
- version: !ruby/object:Gem::Version
4
- hash: 13
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.2
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- - 1
10
- version: 0.4.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Alex Suraci
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-03-07 00:00:00 -08:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-04-03 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rake
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70353524549480 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :development
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: rspec
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70353524549480
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70353524548860 !ruby/object:Gem::Requirement
39
28
  none: false
40
- requirements:
29
+ requirements:
41
30
  - - ~>
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 2
46
- - 0
47
- version: "2.0"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
48
33
  type: :development
49
- version_requirements: *id002
50
- description: A simple API for command-line interaction. Provides a novel 'rewinding' feature, allowing users to go back in time and re-enter a botched answer. Supports multiple-choice, password prompting, overriding input events, defaults, etc.
34
+ prerelease: false
35
+ version_requirements: *70353524548860
36
+ description: A simple API for command-line interaction. Provides a novel 'rewinding'
37
+ feature, allowing users to go back in time and re-enter a botched answer. Supports
38
+ multiple-choice, password prompting, overriding input events, defaults, etc.
51
39
  email: i.am@toogeneric.com
52
40
  executables: []
53
-
54
41
  extensions: []
55
-
56
- extra_rdoc_files:
42
+ extra_rdoc_files:
57
43
  - README.md
58
44
  - LICENSE
59
- files:
45
+ files:
60
46
  - LICENSE
61
47
  - README.md
62
48
  - Rakefile
@@ -64,39 +50,28 @@ files:
64
50
  - lib/interact/rewindable.rb
65
51
  - lib/interact/version.rb
66
52
  - lib/interact.rb
67
- has_rdoc: true
68
53
  homepage: http://github.com/vito/interact
69
54
  licenses: []
70
-
71
55
  post_install_message:
72
56
  rdoc_options: []
73
-
74
- require_paths:
57
+ require_paths:
75
58
  - lib
76
- required_ruby_version: !ruby/object:Gem::Requirement
59
+ required_ruby_version: !ruby/object:Gem::Requirement
77
60
  none: false
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- hash: 3
82
- segments:
83
- - 0
84
- version: "0"
85
- required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
66
  none: false
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- hash: 3
91
- segments:
92
- - 0
93
- version: "0"
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
94
71
  requirements: []
95
-
96
72
  rubyforge_project:
97
- rubygems_version: 1.6.2
73
+ rubygems_version: 1.8.10
98
74
  signing_key:
99
75
  specification_version: 3
100
76
  summary: A simple API for command-line interaction.
101
77
  test_files: []
102
-