sawaal 1.0.2 → 1.1.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: 4e155b3e80dc6a2669e19cafc05cfb7368ff5022
4
- data.tar.gz: 33caa694f2463eadc5182ea1a14760af2d5954c0
3
+ metadata.gz: f83a00ac10ede43f129020b8d41fbacd18293e36
4
+ data.tar.gz: d1fc746b0afac374c12d231e08f21fe790cd68da
5
5
  SHA512:
6
- metadata.gz: bbf490442fe0ac0963513b61b6cea744e58b60b9ea58027c7f08b855daabe4d676a39571d3f89b707e9e1ff8e790768c9bc225c29f989495884d2931ad72ebce
7
- data.tar.gz: 1d4535e9a8ee338d81e57c35bd9df9e34da0eab582b0a2eecbe9019b4f1595d398dfa2e6cd38056f0576acd457aadcb9477068aa6b8e8844501d7267ca37c519
6
+ metadata.gz: 20c2be2726ea28a67b78a3952b3173af2532a8da54c4cffdabab806deedde0e69783c7443e2c8178c7558e759e530438c959c9aa8551cc0fc4d0226275fe002b
7
+ data.tar.gz: 6d8c445b93ea703b7f20c09570d06986ad5e34a55489c0fb59a40d12d941a7b29b8d5c582f0c10cbfb6fb648a4b6691f3447b334edcb1d6764639500ed22447f
@@ -16,6 +16,17 @@ List of changes so far that have been released to ruby gems.
16
16
 
17
17
  <!-- markdown-toc end -->
18
18
 
19
+ 1.1.0 / 2015-07-29
20
+ ==================
21
+
22
+ ## Minor improvements
23
+
24
+ ### Hide help on keypress
25
+
26
+ ## Bugfixes
27
+
28
+ ### Read C-c properly
29
+
19
30
  1.0.2 / 2015-07-29
20
31
  ==================
21
32
 
@@ -3,12 +3,12 @@
3
3
  require 'io/console'
4
4
  require 'timeout'
5
5
 
6
- require 'sawaal/color'
7
- require 'sawaal/cursor'
8
- require 'sawaal/selections'
9
- require 'sawaal/selector'
10
- require 'sawaal/tty'
11
- require 'sawaal/version'
6
+ require_relative './sawaal/color'
7
+ require_relative './sawaal/cursor'
8
+ require_relative './sawaal/selections'
9
+ require_relative './sawaal/selector'
10
+ require_relative './sawaal/tty'
11
+ require_relative './sawaal/version'
12
12
 
13
13
  # Helps a command line application by allowing it to ask
14
14
  # multiple choice questions
@@ -12,6 +12,7 @@ module Sawaal
12
12
  def initialize
13
13
  @text = []
14
14
  @current_line_index = -1
15
+ @help_hidden = false
15
16
  end
16
17
 
17
18
  def save_excursion(&block)
@@ -45,6 +46,15 @@ module Sawaal
45
46
  TTY.print '(use arrow keys, press <enter> when finished)'
46
47
  end
47
48
 
49
+ def hide_help
50
+ return if @help_hidden
51
+ restore_position
52
+ clear_line
53
+ move_down
54
+ move_to_beginning
55
+ @help_hidden = true
56
+ end
57
+
48
58
  def write_item(item)
49
59
  line = "#{bold TTY::ARROW} #{item}"
50
60
  move_down
@@ -15,17 +15,15 @@ module Sawaal
15
15
  def select
16
16
  loop do
17
17
  ch = read_char
18
- case ch
19
- when TTY::RETURN
20
- break
21
- when TTY::MOVE_UP
22
- @cursor.highlight(@cursor.current_line_index - 1)
23
- when TTY::MOVE_DOWN
24
- @cursor.highlight(@cursor.current_line_index + 1)
25
- when TTY::CONTROL_C
26
- @cursor.write_selection(red('terminated'))
27
- exit 33
28
- end
18
+
19
+ # hide help after any keypress
20
+ @cursor.hide_help
21
+
22
+ # selection has been made
23
+ break if ch == TTY::RETURN
24
+
25
+ # move selection
26
+ handle_input(ch)
29
27
  end
30
28
 
31
29
  selected = @cursor.current_line_index
@@ -33,6 +31,18 @@ module Sawaal
33
31
  @keys[@cursor.current_line_index]
34
32
  end
35
33
 
34
+ def handle_input(ch)
35
+ case ch
36
+ when TTY::MOVE_UP
37
+ @cursor.highlight(@cursor.current_line_index - 1)
38
+ when TTY::MOVE_DOWN
39
+ @cursor.highlight(@cursor.current_line_index + 1)
40
+ when TTY::CONTROL_C
41
+ @cursor.write_selection(red('<terminated>'))
42
+ exit 33
43
+ end
44
+ end
45
+
36
46
  def write
37
47
  @items.each do |item|
38
48
  @cursor.write_item(item)
@@ -10,7 +10,7 @@ module Sawaal
10
10
  selections = Selections.new(cursor, options)
11
11
 
12
12
  cursor.save_excursion do
13
- cursor.write_question question
13
+ cursor.write_question(question)
14
14
  selections.write
15
15
  selections.select
16
16
  end
@@ -33,7 +33,7 @@ module Sawaal
33
33
  RESTORE_POSITION = ansii_escape('u')
34
34
 
35
35
  RETURN = "\r"
36
- CONTROL_C = '\\u0003'
36
+ CONTROL_C = "\u0003"
37
37
 
38
38
  ARROW = '‣'
39
39
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Track version of the module
4
4
  module Sawaal
5
- VERSION = '1.0.2'
5
+ VERSION = '1.1.0'
6
6
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  describe Sawaal do
4
4
  it 'has a valid version tag' do
5
- expect(Sawaal::VERSION).to(eq('1.0.2'))
5
+ expect(Sawaal::VERSION).to(eq('1.1.0'))
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sawaal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anshul Verma