utils 0.18.1 → 0.19.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
  SHA256:
3
- metadata.gz: 7bee4cb885dc46160028f6011fdf435fffd82234d901fa0b7bf1db3db409245b
4
- data.tar.gz: 29b8c82dc580506bc25b3097cfdc3a08b585383b3d09f6d41df59b3c0b27498d
3
+ metadata.gz: 4d96c7cf970c92753376fda93b80ddaacaddc369e6b76016b32f1ba4dca4e481
4
+ data.tar.gz: 734f6d3bb32ca8c8afaef530d6634be5672cd30569c728a62bf9dd3282e9b143
5
5
  SHA512:
6
- metadata.gz: 63478f0d27f7cedcc8e1d5bf784f88840067647d0f69494d0213800ce62b9d5e61ceeef501a88905dc2edd705ec25c584da0946b31504610682e07301b46d6a4
7
- data.tar.gz: 6b3f95eccd99acd8054f06fd045c1b0a939e3569ca0dfb62b4be47c15164187b824ad5d3a651be04bdd57da078b7b41840fb68e7a7b6de9f92df6a9cd9142460
6
+ metadata.gz: f40d11fbdb46906ca04c51dea3c326ea74a4fdd2fcc1f7900d57c3cafb6c98565e444c5ba2e1aeca35f02c882d3ffe67f0827b671eadaddecbe8926394f90c95
7
+ data.tar.gz: a734f2ac070ad39bffa1428855ec64cc09e76e6149c710b9e7876a180a72a1df274d5fb51994087ec8388ff803900be6f5ea3fd240dba9443621f0721a420a72
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.18.1
1
+ 0.19.0
@@ -84,13 +84,13 @@ when args[?s]
84
84
  args[?n] = Term::ANSIColor.terminal_lines - 1
85
85
  path = nil
86
86
  found = Utils::SearchUI.new(
87
- query: -> answer {
87
+ query: -> answer, selector {
88
88
  pattern.replace answer
89
89
  f = finder.()
90
- f.search.output.join(?\n)
90
+ f.search.output.each_with_index.map { |l, i| (i == selector ? '> ' : ' ') + l }.join(?\n)
91
91
  },
92
- found: -> answer {
93
- f and path = f.paths.first
92
+ found: -> answer, selector {
93
+ f and path = f.paths[selector]
94
94
  },
95
95
  output: STDERR
96
96
  ).start
@@ -4,6 +4,7 @@ class Utils::SearchUI
4
4
  include Term::ANSIColor
5
5
 
6
6
  def initialize(query:, found:, output: STDOUT, prompt: 'Search? %s')
7
+ @selector = 0
7
8
  @query = query
8
9
  @found = found
9
10
  @output = output
@@ -18,7 +19,7 @@ class Utils::SearchUI
18
19
  case getc
19
20
  when true
20
21
  @output.print clear_screen, move_home, reset
21
- if result = @found.(@answer)
22
+ if result = @found.(@answer, @selector)
22
23
  return result
23
24
  else
24
25
  return nil
@@ -26,7 +27,7 @@ class Utils::SearchUI
26
27
  when false
27
28
  return nil
28
29
  end
29
- result = @query.(@answer)
30
+ result = @query.(@answer, @selector)
30
31
  @output.print clear_screen
31
32
  unless @answer.empty?
32
33
  @output.print move_home { ?\n + result }
@@ -41,19 +42,32 @@ class Utils::SearchUI
41
42
  c = STDIN.getc
42
43
  system 'stty cooked echo'
43
44
  case c
44
- when "\x03", "\e"
45
+ when "\x03"
45
46
  false
47
+ when "\e"
48
+ STDIN.getc == ?[ or return nil
49
+ STDIN.getc =~ /\A([AB])\z/ or return nil
50
+ if $1 == ?A
51
+ @selector -= 1
52
+ else
53
+ @selector += 1
54
+ end
55
+ @selector = [ @selector, 0 ].max
56
+ nil
46
57
  when ?\r
47
58
  true
48
59
  when "\x7f"
60
+ @selector = 0
49
61
  @answer.chop!
50
62
  nil
51
63
  when "\v"
64
+ @selector = 0
52
65
  @answer.clear
53
66
  nil
54
67
  when /\A[\x00-\x1f]\z/
55
68
  nil
56
69
  else
70
+ @selector = 0
57
71
  @answer << c
58
72
  nil
59
73
  end
@@ -1,6 +1,6 @@
1
1
  module Utils
2
2
  # Utils version
3
- VERSION = '0.18.1'
3
+ VERSION = '0.19.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: utils 0.18.1 ruby lib
2
+ # stub: utils 0.19.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "utils".freeze
6
- s.version = "0.18.1"
6
+ s.version = "0.19.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.1
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank