omnibar 0.0.6 → 0.0.7

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: 513b1e361992c5857eeb37e52f0a0d2c52486d99
4
- data.tar.gz: da3effe0d3c63a840d6294b97df44f1d0598835b
3
+ metadata.gz: 89901327f67e2c6978f867ae24b906fc604b56ad
4
+ data.tar.gz: 3be4ad5cdd64cf4413cb73e3e87775e2190e22bd
5
5
  SHA512:
6
- metadata.gz: 2b372c0dde29e27c51d2e566ddd7f1a86de1dfe4487e29aff65c5d532882d6f539a6157bc1f791ab3f3bdd04dd70dcd3d7f39bb1ab955465ba5c705a0e5209d7
7
- data.tar.gz: 4ed39d98bf94668617a15609daf02d1bf023f8a3f7c9759b4edbd41b685ad65adb400f02d6106793f3a7db436eb329c159b43914e1c892dc86d5a6abfbd5f28d
6
+ metadata.gz: e8193d63a0129aaf5fc30d5d3444958c07862e9201adfce4d34c929d29edf50938a0033a55a79468b77396be994c6dfe8dd064045e86c49f8c1d6eb05af9fcb0
7
+ data.tar.gz: 52be6f30e7e997e787741ff42209aaaa5ae160ee85c385957177b2d982338cd0759ee31add06e13934777e47414df5784def08fedd44e4045585208d96a0b053
data/.gitignore CHANGED
@@ -6,4 +6,5 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
- *.gem
9
+ *.gem
10
+ /log/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- omnibar (0.0.5)
4
+ omnibar (0.0.7)
5
5
  amatch (~> 0.4.0)
6
6
  dry-configurable (~> 0.7.0)
7
7
  ffi-aspell (~> 1.1, >= 1.1.0)
@@ -28,7 +28,7 @@ GEM
28
28
  ruby_parser (3.10.1)
29
29
  sexp_processor (~> 4.9)
30
30
  sexp_processor (4.10.0)
31
- tins (1.15.0)
31
+ tins (1.16.3)
32
32
 
33
33
  PLATFORMS
34
34
  ruby
data/Rakefile CHANGED
@@ -1,2 +1 @@
1
- require "bundler/gem_tasks"
2
- task :default => :spec
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,258 @@
1
+ {
2
+ "Black": 0,
3
+ "Maroon": 1,
4
+ "Green": 2,
5
+ "Olive": 3,
6
+ "Navy": 4,
7
+ "Purple": 5,
8
+ "Teal": 6,
9
+ "Silver": 7,
10
+ "Grey": 8,
11
+ "Red": 9,
12
+ "Lime": 10,
13
+ "Yellow": 11,
14
+ "Blue": 12,
15
+ "Fuchsia": 13,
16
+ "Aqua": 14,
17
+ "White": 15,
18
+ "Grey0": 16,
19
+ "NavyBlue": 17,
20
+ "DarkBlue": 18,
21
+ "Blue2": 19,
22
+ "Blue3": 20,
23
+ "Blue1": 21,
24
+ "DarkGreen": 22,
25
+ "DeepSkyBlue4": 23,
26
+ "DeepSkyBlue4": 24,
27
+ "DeepSkyBlue4": 25,
28
+ "DodgerBlue3": 26,
29
+ "DodgerBlue2": 27,
30
+ "Green4": 28,
31
+ "SpringGreen4": 29,
32
+ "Turquoise4": 30,
33
+ "DeepSkyBlue3": 31,
34
+ "DeepSkyBlue3": 32,
35
+ "DodgerBlue1": 33,
36
+ "Green3": 34,
37
+ "SpringGreen3": 35,
38
+ "DarkCyan": 36,
39
+ "LightSeaGreen": 37,
40
+ "DeepSkyBlue2": 38,
41
+ "DeepSkyBlue1": 39,
42
+ "Green3": 40,
43
+ "SpringGreen3": 41,
44
+ "SpringGreen2": 42,
45
+ "Cyan3": 43,
46
+ "DarkTurquoise": 44,
47
+ "Turquoise2": 45,
48
+ "Green1": 46,
49
+ "SpringGreen2": 47,
50
+ "SpringGreen1": 48,
51
+ "MediumSpringGreen": 49,
52
+ "Cyan2": 50,
53
+ "Cyan1": 51,
54
+ "DarkRed": 52,
55
+ "DeepPink4": 53,
56
+ "Purple2": 54,
57
+ "Purple4": 55,
58
+ "Purple3": 56,
59
+ "BlueViolet": 57,
60
+ "Orange4": 58,
61
+ "Grey37": 59,
62
+ "MediumPurple4": 60,
63
+ "SlateBlue3": 61,
64
+ "SlateBlue3": 62,
65
+ "RoyalBlue1": 63,
66
+ "Chartreuse4": 64,
67
+ "DarkSeaGreen4": 65,
68
+ "PaleTurquoise4": 66,
69
+ "SteelBlue": 67,
70
+ "SteelBlue3": 68,
71
+ "CornflowerBlue": 69,
72
+ "Chartreuse3": 70,
73
+ "DarkSeaGreen4": 71,
74
+ "CadetBlue": 72,
75
+ "CadetBlue": 73,
76
+ "SkyBlue3": 74,
77
+ "SteelBlue1": 75,
78
+ "Chartreuse3": 76,
79
+ "PaleGreen3": 77,
80
+ "SeaGreen3": 78,
81
+ "Aquamarine3": 79,
82
+ "MediumTurquoise": 80,
83
+ "SteelBlue1": 81,
84
+ "Chartreuse2": 82,
85
+ "SeaGreen2": 83,
86
+ "SeaGreen1": 84,
87
+ "SeaGreen1": 85,
88
+ "Aquamarine1": 86,
89
+ "DarkSlateGray2": 87,
90
+ "DarkRed": 88,
91
+ "DeepPink4": 89,
92
+ "DarkMagenta": 90,
93
+ "DarkMagenta": 91,
94
+ "DarkViolet": 92,
95
+ "Purple5": 93,
96
+ "Orange4": 94,
97
+ "LightPink4": 95,
98
+ "Plum4": 96,
99
+ "MediumPurple3": 97,
100
+ "MediumPurple3": 98,
101
+ "SlateBlue1": 99,
102
+ "Yellow4": 100,
103
+ "Wheat4": 101,
104
+ "Grey53": 102,
105
+ "LightSlateGrey": 103,
106
+ "MediumPurple": 104,
107
+ "LightSlateBlue": 105,
108
+ "Yellow4": 106,
109
+ "DarkOliveGreen3": 107,
110
+ "DarkSeaGreen": 108,
111
+ "LightSkyBlue3": 109,
112
+ "LightSkyBlue3": 110,
113
+ "SkyBlue2": 111,
114
+ "Chartreuse2": 112,
115
+ "DarkOliveGreen3": 113,
116
+ "PaleGreen3": 114,
117
+ "DarkSeaGreen3": 115,
118
+ "DarkSlateGray3": 116,
119
+ "SkyBlue1": 117,
120
+ "Chartreuse1": 118,
121
+ "LightGreen": 119,
122
+ "LightGreen": 120,
123
+ "PaleGreen1": 121,
124
+ "Aquamarine1": 122,
125
+ "DarkSlateGray1": 123,
126
+ "Red3": 124,
127
+ "DeepPink4": 125,
128
+ "MediumVioletRed": 126,
129
+ "Magenta3": 127,
130
+ "DarkViolet": 128,
131
+ "Purple6": 129,
132
+ "DarkOrange3": 130,
133
+ "IndianRed": 131,
134
+ "HotPink3": 132,
135
+ "MediumOrchid3": 133,
136
+ "MediumOrchid": 134,
137
+ "MediumPurple2": 135,
138
+ "DarkGoldenrod": 136,
139
+ "LightSalmon3": 137,
140
+ "RosyBrown": 138,
141
+ "Grey63": 139,
142
+ "MediumPurple2": 140,
143
+ "MediumPurple1": 141,
144
+ "Gold3": 142,
145
+ "DarkKhaki": 143,
146
+ "NavajoWhite3": 144,
147
+ "Grey69": 145,
148
+ "LightSteelBlue3": 146,
149
+ "LightSteelBlue": 147,
150
+ "Yellow3": 148,
151
+ "DarkOliveGreen3": 149,
152
+ "DarkSeaGreen3": 150,
153
+ "DarkSeaGreen2": 151,
154
+ "LightCyan3": 152,
155
+ "LightSkyBlue1": 153,
156
+ "GreenYellow": 154,
157
+ "DarkOliveGreen2": 155,
158
+ "PaleGreen1": 156,
159
+ "DarkSeaGreen2": 157,
160
+ "DarkSeaGreen1": 158,
161
+ "PaleTurquoise1": 159,
162
+ "Red3": 160,
163
+ "DeepPink3": 161,
164
+ "DeepPink3": 162,
165
+ "Magenta3": 163,
166
+ "Magenta3": 164,
167
+ "Magenta2": 165,
168
+ "DarkOrange3": 166,
169
+ "IndianRed": 167,
170
+ "HotPink3": 168,
171
+ "HotPink2": 169,
172
+ "Orchid": 170,
173
+ "MediumOrchid1": 171,
174
+ "Orange3": 172,
175
+ "LightSalmon3": 173,
176
+ "LightPink3": 174,
177
+ "Pink3": 175,
178
+ "Plum3": 176,
179
+ "Violet": 177,
180
+ "Gold3": 178,
181
+ "LightGoldenrod3": 179,
182
+ "Tan": 180,
183
+ "MistyRose3": 181,
184
+ "Thistle3": 182,
185
+ "Plum2": 183,
186
+ "Yellow3": 184,
187
+ "Khaki3": 185,
188
+ "LightGoldenrod2": 186,
189
+ "LightYellow3": 187,
190
+ "Grey84": 188,
191
+ "LightSteelBlue1": 189,
192
+ "Yellow2": 190,
193
+ "DarkOliveGreen1": 191,
194
+ "DarkOliveGreen1": 192,
195
+ "DarkSeaGreen1": 193,
196
+ "Honeydew2": 194,
197
+ "LightCyan1": 195,
198
+ "Red1": 196,
199
+ "DeepPink2": 197,
200
+ "DeepPink1": 198,
201
+ "DeepPink1": 199,
202
+ "Magenta2": 200,
203
+ "Magenta1": 201,
204
+ "OrangeRed1": 202,
205
+ "IndianRed1": 203,
206
+ "IndianRed1": 204,
207
+ "HotPink": 205,
208
+ "HotPink": 206,
209
+ "MediumOrchid1": 207,
210
+ "DarkOrange": 208,
211
+ "Salmon1": 209,
212
+ "LightCoral": 210,
213
+ "PaleVioletRed1": 211,
214
+ "Orchid2": 212,
215
+ "Orchid1": 213,
216
+ "Orange1": 214,
217
+ "SandyBrown": 215,
218
+ "LightSalmon1": 216,
219
+ "LightPink1": 217,
220
+ "Pink1": 218,
221
+ "Plum1": 219,
222
+ "Gold1": 220,
223
+ "LightGoldenrod2": 221,
224
+ "LightGoldenrod2": 222,
225
+ "NavajoWhite1": 223,
226
+ "MistyRose1": 224,
227
+ "Thistle1": 225,
228
+ "Yellow1": 226,
229
+ "LightGoldenrod1": 227,
230
+ "Khaki1": 228,
231
+ "Wheat1": 229,
232
+ "Cornsilk1": 230,
233
+ "Grey100": 231,
234
+ "Grey3": 232,
235
+ "Grey7": 233,
236
+ "Grey11": 234,
237
+ "Grey15": 235,
238
+ "Grey19": 236,
239
+ "Grey23": 237,
240
+ "Grey27": 238,
241
+ "Grey30": 239,
242
+ "Grey35": 240,
243
+ "Grey39": 241,
244
+ "Grey42": 242,
245
+ "Grey46": 243,
246
+ "Grey50": 244,
247
+ "Grey54": 245,
248
+ "Grey58": 246,
249
+ "Grey62": 247,
250
+ "Grey66": 248,
251
+ "Grey70": 249,
252
+ "Grey74": 250,
253
+ "Grey78": 251,
254
+ "Grey82": 252,
255
+ "Grey85": 253,
256
+ "Grey89": 254,
257
+ "Grey93": 255
258
+ }
@@ -1,15 +1,25 @@
1
+ require 'json'
2
+
1
3
  # This module contains helpers for various ansi-code operations
2
4
  module ANSI
3
5
  # ANSI color escape codes set the foreground and background colors.
4
6
  # Forground color is a number between 30 and 37.
5
7
  # Background color is a number between 40 and 47.
6
8
  # The ones place represents the same color for both.
7
- COLORS = [:black, :red, :green, :yellow, :blue, :magenta, :cyan, 'white', nil, :white].freeze
9
+ COLORS = JSON.parse(File.read(File.expand_path('../db/ansi.json', File.dirname(__FILE__)))).freeze
8
10
 
9
11
  def self.clear_screen
10
12
  $stdout.write "\e[2J"
11
13
  end
12
14
 
15
+ def self.save_screen
16
+ $stdout.write `tput smcup`
17
+ end
18
+
19
+ def self.restore_screen
20
+ $stdout.write `tput rmcup`
21
+ end
22
+
13
23
  def self.move_cursor(row, col)
14
24
  $stdout.write "\e[#{row + 1};#{col + 1}H"
15
25
  end
@@ -21,17 +31,22 @@ module ANSI
21
31
  move_cursor(row, col)
22
32
  end
23
33
 
24
- def self.color(text, fg: :white, bg: :black)
25
- fg = COLORS.index(fg) + 30
26
- bg = COLORS.index(bg) + 40
27
- code = "\e[#{[fg, bg].compact.join(';')}m"
28
- "#{code}#{text}\e[0m"
34
+ def self.color(text, fg: nil, bg: nil, res: true)
35
+ fg = COLORS[@private.snake_to_camel(fg)] if fg
36
+ bg = COLORS[@private.snake_to_camel(bg)] if bg
37
+ fg = "\e[38;5;#{fg}m" if fg
38
+ bg = "\e[48;5;#{bg}m" if bg
39
+ "#{fg}#{bg}#{text}#{reset if res}"
29
40
  end
30
41
 
31
42
  def self.reset
32
43
  "\e[0m"
33
44
  end
34
45
 
46
+ def self.strip(text)
47
+ text.gsub(/\e\[[0-9,;]+\w/, '')
48
+ end
49
+
35
50
  def self.position
36
51
  res = ''
37
52
  $stdin.raw do |stdin|
@@ -55,4 +70,28 @@ module ANSI
55
70
  width: win[1]
56
71
  }
57
72
  end
73
+
74
+ def self.print_colors
75
+ colors = COLORS.keys.count
76
+ groups = COLORS.to_a.sort_by { |p| p[1] }.each_slice(colors / 3).to_a.map(&:to_h)
77
+
78
+ groups.first.keys.length.times.each do |i|
79
+ 3.times do |j|
80
+ name = groups[j].keys[i]
81
+ code = groups[j][name]
82
+
83
+ pad = ' ' * (40 - (name.length * 2))
84
+ lpad = ' ' * (3 - code.digits.count)
85
+ print "#{lpad}#{code} \e[38;5;#{code}m#{name}\e[0m \e[48;5;#{code}m#{name}\e[0m #{pad}"
86
+ end
87
+ print "\n"
88
+ end
89
+ true
90
+ end
91
+
92
+ @private = Module.new do
93
+ def self.snake_to_camel(string)
94
+ string.to_s.split('_').map(&:capitalize).join
95
+ end
96
+ end
58
97
  end
@@ -2,6 +2,7 @@
2
2
  require 'dry-configurable'
3
3
  require 'fuzzy_match'
4
4
  require 'amatch'
5
+ require 'logger'
5
6
 
6
7
  require_relative 'ansi'
7
8
 
@@ -15,6 +16,8 @@ require_relative 'omnibar/view'
15
16
  module Omnibar
16
17
  extend Dry::Configurable
17
18
 
19
+ setting :log, Logger.new('log/omnibar.log'), reader: true rescue nil
20
+
18
21
  setting :queries, []
19
22
 
20
23
  setting :github do
@@ -31,13 +34,14 @@ module Omnibar
31
34
  setting :prompt, ->(width) { (' ' * width) << ANSI.color('★', fg: :magenta) }
32
35
 
33
36
  setting :highlight do
34
- setting :fg, :black
35
- setting :bg, :yellow
37
+ setting :fg, :white
38
+ setting :bg, :grey15
36
39
  end
37
40
  end
38
41
 
39
42
  setting :events do
40
43
  setting :after_start, ->(app) {}
44
+ setting :keypress, ->(state) {}
41
45
  setting :after_perform, -> {}
42
46
  end
43
47
 
@@ -52,7 +56,3 @@ FuzzyMatch.engine = :amatch
52
56
  # Require all the queries
53
57
  dir = File.join(File.dirname(File.expand_path(__FILE__)), 'omnibar/queries')
54
58
  Dir["#{dir}/*.rb"].each { |file| require file }
55
-
56
- # Move fallback queries to the end
57
- Omnibar.config.queries << Omnibar.config.queries.delete(Omnibar::DuckDuckGo)
58
- Omnibar.config.queries << Omnibar.config.queries.delete(Omnibar::Google)
@@ -12,7 +12,7 @@ module Omnibar
12
12
 
13
13
  def run
14
14
  IO.console.raw do
15
- ANSI.clear_screen
15
+ ANSI.save_screen
16
16
  ANSI.move_cursor(0, 0)
17
17
  loop do
18
18
  render
@@ -36,9 +36,9 @@ module Omnibar
36
36
  @state.backspace
37
37
  when "\e", "\e["
38
38
  handle_input(char)
39
- when "\e[A" # Up Arrow
39
+ when "\e[A", "\v" # Up Arrow, ctrl-k
40
40
  @state.select_up
41
- when "\e[B" # Down Arrow
41
+ when "\e[B", "\n" # Down Arrow, ctrl-j
42
42
  @state.select_down
43
43
  when "\e[C"
44
44
  @state.move_cursor_left
@@ -50,8 +50,11 @@ module Omnibar
50
50
  perform_action!
51
51
  reset_state!
52
52
  else
53
+ puts char.inspect
53
54
  @state.add_to_input(char)
54
55
  end
56
+
57
+ Omnibar.config.events.keypress.call(@state)
55
58
  end
56
59
 
57
60
  def reset_state!
@@ -64,7 +67,7 @@ module Omnibar
64
67
  end
65
68
 
66
69
  def quit
67
- ANSI.clear_screen
70
+ ANSI.restore_screen
68
71
  exit 0
69
72
  end
70
73
  end