gum 0.2.1 → 0.3.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.
Files changed (65) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE.txt +1 -1
  3. data/README.md +435 -16
  4. data/exe/gum +11 -0
  5. data/gum.gemspec +28 -32
  6. data/lib/gum/command.rb +159 -0
  7. data/lib/gum/commands/choose.rb +95 -0
  8. data/lib/gum/commands/confirm.rb +57 -0
  9. data/lib/gum/commands/file.rb +84 -0
  10. data/lib/gum/commands/filter.rb +119 -0
  11. data/lib/gum/commands/format.rb +74 -0
  12. data/lib/gum/commands/input.rb +68 -0
  13. data/lib/gum/commands/join.rb +41 -0
  14. data/lib/gum/commands/log.rb +98 -0
  15. data/lib/gum/commands/pager.rb +55 -0
  16. data/lib/gum/commands/spin.rb +167 -0
  17. data/lib/gum/commands/style.rb +93 -0
  18. data/lib/gum/commands/table.rb +93 -0
  19. data/lib/gum/commands/write.rb +84 -0
  20. data/lib/gum/upstream.rb +17 -0
  21. data/lib/gum/version.rb +5 -1
  22. data/lib/gum.rb +170 -10
  23. data/sig/gum/command.rbs +23 -0
  24. data/sig/gum/commands/choose.rbs +42 -0
  25. data/sig/gum/commands/confirm.rbs +30 -0
  26. data/sig/gum/commands/file.rbs +38 -0
  27. data/sig/gum/commands/filter.rbs +48 -0
  28. data/sig/gum/commands/format.rbs +47 -0
  29. data/sig/gum/commands/input.rbs +32 -0
  30. data/sig/gum/commands/join.rbs +24 -0
  31. data/sig/gum/commands/log.rbs +56 -0
  32. data/sig/gum/commands/pager.rbs +28 -0
  33. data/sig/gum/commands/spin.rbs +55 -0
  34. data/sig/gum/commands/style.rbs +44 -0
  35. data/sig/gum/commands/table.rbs +35 -0
  36. data/sig/gum/commands/write.rbs +35 -0
  37. data/sig/gum/upstream.rbs +9 -0
  38. data/sig/gum/version.rbs +5 -0
  39. data/sig/gum.rbs +79 -0
  40. metadata +49 -145
  41. data/.gitignore +0 -9
  42. data/.rspec +0 -2
  43. data/.travis.yml +0 -5
  44. data/Gemfile +0 -4
  45. data/Rakefile +0 -6
  46. data/bin/console +0 -14
  47. data/bin/setup +0 -8
  48. data/gum-0.2.0.gem +0 -0
  49. data/lib/gum/factory.rb +0 -33
  50. data/lib/gum/filter.rb +0 -28
  51. data/lib/gum/filters/exists.rb +0 -25
  52. data/lib/gum/filters/fuzzy.rb +0 -11
  53. data/lib/gum/filters/geo/bbox.rb +0 -70
  54. data/lib/gum/filters/geo/distance.rb +0 -26
  55. data/lib/gum/filters/geo/range.rb +0 -33
  56. data/lib/gum/filters/geo.rb +0 -10
  57. data/lib/gum/filters/prefix.rb +0 -15
  58. data/lib/gum/filters/range.rb +0 -22
  59. data/lib/gum/filters/regexp.rb +0 -11
  60. data/lib/gum/filters/term.rb +0 -15
  61. data/lib/gum/filters/terms.rb +0 -11
  62. data/lib/gum/filters/wildcard.rb +0 -15
  63. data/lib/gum/filters.rb +0 -35
  64. data/lib/gum/order.rb +0 -18
  65. data/lib/gum/search.rb +0 -83
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a02c8427e4f3b3cecd799d40eafa9c0e7255fb89
4
- data.tar.gz: 4d77a6c86e9e28e1d0fb8e7256482215c70eb73a
2
+ SHA256:
3
+ metadata.gz: 88374c0fc709544b235e42532afa044db6c1942c94038e2cf7812d61993b179f
4
+ data.tar.gz: 3a5899c9aa058bd33ac932cb746ada5abfbb2d7db12b7d442964d52a1d10e8a0
5
5
  SHA512:
6
- metadata.gz: 18154411713179aece9cc1d5174ef2a5973e66b586bcef7b3557f785ece3e32ab4ee0f58e93b21cc1f2e79375c29b727355f4c4074db7f7f5ab129dc572abeb9
7
- data.tar.gz: 676e2721de554a6bdc9b5b71511e3a33f2973e941d535e7755f71798cc131e617dedf0a3c44aac480efbe6312f4192173f058c855e8d5d306ba759bfe067a9b7
6
+ metadata.gz: 0e83f09326ff0f52a4333c5da044bb36f698af6b7714bfbd9ccbb500bc66de3b087e80e5ec07eab6598d321417fbe8ebeac541345592ba8cbb66028fd8255388
7
+ data.tar.gz: dfa419bb6acf8cab4ba247485dbd0d67db96f709566917d8a577f01a462b0613090c0b0e900d3dd270169ec3f753ee794b99b5e30215c3b0da82f7f39975e02d
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 Anton Sozontov
3
+ Copyright (c) 2025 Marco Roth
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,41 +1,460 @@
1
- # Gum
1
+ # Gum for Ruby
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gum`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ <p>
4
+ <a href="https://github.com/marcoroth/gum-ruby" target="_blank"><img src="assets/logo.png" alt="Gum Image" width="450" /></a>
5
+ </p>
4
6
 
5
- TODO: Delete this and the text above, and describe your gem
7
+ Ruby wrapper for [Charm's Gum](https://github.com/charmbracelet/gum). A tool for glamorous scripts.
8
+
9
+ This gem bundles the `gum` binary and provides an idiomatic Ruby API for all gum commands.
6
10
 
7
11
  ## Installation
8
12
 
9
- Add this line to your application's Gemfile:
13
+ **Add to your Gemfile:**
14
+
15
+ ```bash
16
+ bundle add gum
17
+ ```
18
+
19
+ **Or install directly:**
20
+
21
+ ```bash
22
+ gem install gum
23
+ ```
24
+
25
+ ## Usage
10
26
 
11
27
  ```ruby
12
- gem 'gum'
28
+ require "gum"
13
29
  ```
14
30
 
15
- And then execute:
31
+ ### Input
16
32
 
17
- $ bundle
33
+ **Prompt for single-line input:**
18
34
 
19
- Or install it yourself as:
35
+ ```ruby
36
+ name = Gum.input(placeholder: "Enter your name")
37
+ ```
20
38
 
21
- $ gem install gum
39
+ **Password input (masked):**
22
40
 
23
- ## Usage
41
+ ```ruby
42
+ password = Gum.input(password: true)
43
+ ```
44
+
45
+ **With default value and custom prompt:**
46
+
47
+ ```ruby
48
+ email = Gum.input(value: "user@", prompt: "> ", placeholder: "email")
49
+ ```
50
+
51
+ **With character limit:**
52
+
53
+ ```ruby
54
+ code = Gum.input(placeholder: "Enter code", char_limit: 6)
55
+ ```
56
+
57
+ ### Write
58
+
59
+ **Prompt for multi-line text input (Ctrl+D to submit):**
60
+
61
+ ```ruby
62
+ description = Gum.write(placeholder: "Enter description...")
63
+ ```
64
+
65
+ **With dimensions:**
66
+
67
+ ```ruby
68
+ notes = Gum.write(width: 80, height: 10, header: "Notes")
69
+ ```
70
+
71
+ **With line numbers:**
72
+
73
+ ```ruby
74
+ content = Gum.write(show_line_numbers: true)
75
+ ```
76
+
77
+ ### Choose
78
+
79
+ **Single selection (array):**
80
+
81
+ ```ruby
82
+ color = Gum.choose(["red", "green", "blue"])
83
+ ```
84
+
85
+ **Single selection (splat):**
86
+
87
+ ```ruby
88
+ color = Gum.choose("red", "green", "blue")
89
+ ```
90
+
91
+ **Multiple selection with limit:**
92
+
93
+ ```ruby
94
+ colors = Gum.choose(["red", "green", "blue"], limit: 2)
95
+ ```
96
+
97
+ **Unlimited selection:**
98
+
99
+ ```ruby
100
+ colors = Gum.choose(["red", "green", "blue"], no_limit: true)
101
+ ```
102
+
103
+ **With header and custom height:**
104
+
105
+ ```ruby
106
+ choice = Gum.choose(options, header: "Pick one:", height: 10)
107
+ ```
108
+
109
+ **Pre-selected items:**
110
+
111
+ ```ruby
112
+ choice = Gum.choose(["a", "b", "c"], selected: ["b"])
113
+ ```
114
+
115
+ ### Filter
116
+
117
+ **Single selection (array):**
118
+
119
+ ```ruby
120
+ file = Gum.filter(Dir.glob("**/*.rb"))
121
+ ```
122
+
123
+ **Single selection (splat):**
124
+
125
+ ```ruby
126
+ file = Gum.filter("file1.rb", "file2.rb", "file3.rb")
127
+ ```
128
+
129
+ **Multiple selection:**
130
+
131
+ ```ruby
132
+ files = Gum.filter(Dir.glob("*"), limit: 5)
133
+ ```
134
+
135
+ **Unlimited selection:**
136
+
137
+ ```ruby
138
+ files = Gum.filter(items, no_limit: true)
139
+ ```
140
+
141
+ **With placeholder and height:**
142
+
143
+ ```ruby
144
+ selection = Gum.filter(items, placeholder: "Search...", height: 20)
145
+ ```
146
+
147
+ **Disable fuzzy matching for exact search:**
148
+
149
+ ```ruby
150
+ result = Gum.filter(items, fuzzy: false)
151
+ ```
152
+
153
+ ### Confirm
154
+
155
+ **Ask for yes/no confirmation:**
156
+
157
+ ```ruby
158
+ if Gum.confirm("Delete file?")
159
+ File.delete(path)
160
+ end
161
+ ```
162
+
163
+ **With default value:**
164
+
165
+ ```ruby
166
+ proceed = Gum.confirm("Continue?", default: true)
167
+ ```
24
168
 
25
- TODO: Write usage instructions here
169
+ **Custom button labels:**
170
+
171
+ ```ruby
172
+ Gum.confirm("Save changes?", affirmative: "Save", negative: "Discard")
173
+ ```
174
+
175
+ ### File
176
+
177
+ **Start from current directory:**
178
+
179
+ ```ruby
180
+ path = Gum.file
181
+ ```
182
+
183
+ **Start from specific directory:**
184
+
185
+ ```ruby
186
+ path = Gum.file("~/Documents")
187
+ ```
188
+
189
+ **Show hidden files:**
190
+
191
+ ```ruby
192
+ path = Gum.file(all: true)
193
+ ```
194
+
195
+ **Only show directories:**
196
+
197
+ ```ruby
198
+ dir = Gum.file(directory_only: true)
199
+ ```
200
+
201
+ ### Pager
202
+
203
+ **Scroll through content:**
204
+
205
+ ```ruby
206
+ Gum.pager(File.read("README.md"))
207
+ ```
208
+
209
+ **With line numbers:**
210
+
211
+ ```ruby
212
+ Gum.pager(content, show_line_numbers: true)
213
+ ```
214
+
215
+ **Soft wrap long lines:**
216
+
217
+ ```ruby
218
+ Gum.pager(content, soft_wrap: true)
219
+ ```
220
+
221
+ ### Spin
222
+
223
+ **With shell command:**
224
+
225
+ ```ruby
226
+ Gum.spin("Installing...", command: "npm install")
227
+ ```
228
+
229
+ **With Ruby block:**
230
+
231
+ ```ruby
232
+ result = Gum.spin("Processing...") do
233
+ expensive_computation
234
+ end
235
+ ```
236
+
237
+ **Custom spinner type:**
238
+
239
+ ```ruby
240
+ Gum.spin("Loading...", spinner: :dot, command: "sleep 5")
241
+ ```
242
+
243
+ Available spinner types: `:line`, `:dot`, `:minidot`, `:jump`, `:pulse`, `:points`, `:globe`, `:moon`, `:monkey`, `:meter`, `:hamburger`
244
+
245
+ ### Style
246
+
247
+ **Basic styling:**
248
+
249
+ ```ruby
250
+ styled = Gum.style("Hello", foreground: "212", bold: true)
251
+ ```
252
+
253
+ **With border:**
254
+
255
+ ```ruby
256
+ box = Gum.style("Content", border: :double, padding: "1 2")
257
+ ```
258
+
259
+ **Multiple lines with alignment:**
260
+
261
+ ```ruby
262
+ styled = Gum.style("Line 1", "Line 2", align: :center, width: 50)
263
+ ```
264
+
265
+ **Full styling example:**
266
+
267
+ ```ruby
268
+ styled = Gum.style(
269
+ "Bubble Gum",
270
+ foreground: "212",
271
+ border: :double,
272
+ border_foreground: "212",
273
+ align: :center,
274
+ width: 50,
275
+ margin: "1 2",
276
+ padding: "2 4"
277
+ )
278
+ ```
279
+
280
+ Available border types: `:none`, `:hidden`, `:rounded`, `:double`, `:thick`, `:normal`
281
+
282
+ ### Join
283
+
284
+ Join text blocks horizontally or vertically:
285
+
286
+ ```ruby
287
+ box1 = Gum.style("A", border: :rounded, padding: "1 3")
288
+ box2 = Gum.style("B", border: :rounded, padding: "1 3")
289
+ ```
290
+
291
+ **Horizontal join (default):**
292
+
293
+ ```ruby
294
+ combined = Gum.join(box1, box2)
295
+ ```
296
+
297
+ **Vertical join:**
298
+
299
+ ```ruby
300
+ stacked = Gum.join(box1, box2, vertical: true)
301
+ ```
302
+
303
+ **With alignment:**
304
+
305
+ ```ruby
306
+ aligned = Gum.join(box1, box2, vertical: true, align: :center)
307
+ ```
308
+
309
+ ### Format
310
+
311
+ **Markdown:**
312
+
313
+ ```ruby
314
+ Gum.format("# Hello\n- Item 1\n- Item 2", type: :markdown)
315
+ ```
316
+
317
+ **Template (see Termenv docs for helpers):**
318
+
319
+ ```ruby
320
+ Gum.format('{{ Bold "Hello" }} {{ Color "99" "0" " World " }}', type: :template)
321
+ ```
322
+
323
+ **Emoji:**
324
+
325
+ ```ruby
326
+ Gum.format("I :heart: Ruby :gem:", type: :emoji)
327
+ # => "I ❤️ Ruby 💎"
328
+ ```
329
+
330
+ **Shorthand methods:**
331
+
332
+ ```ruby
333
+ Gum::Format.markdown("# Hello")
334
+ Gum::Format.emoji("I :heart: Ruby")
335
+ ```
336
+
337
+ ### Table
338
+
339
+ **From array of arrays:**
340
+
341
+ ```ruby
342
+ data = [["Alice", "30"], ["Bob", "25"]]
343
+ selection = Gum.table(data, columns: %w[Name Age])
344
+ ```
345
+
346
+ **Just print (no selection):**
347
+
348
+ ```ruby
349
+ Gum.table(data, columns: %w[Name Age], print: true)
350
+ ```
351
+
352
+ **From CSV string:**
353
+
354
+ ```ruby
355
+ Gum.table(File.read("data.csv"))
356
+ ```
357
+
358
+ **With custom border:**
359
+
360
+ ```ruby
361
+ Gum.table(data, columns: %w[Name Age], border: :rounded)
362
+ ```
363
+
364
+ ### Log
365
+
366
+ **Basic logging:**
367
+
368
+ ```ruby
369
+ Gum.log("Application started", level: :info)
370
+ ```
371
+
372
+ **Structured logging with key-value pairs:**
373
+
374
+ ```ruby
375
+ Gum.log("User created", level: :info, user_id: 123, email: "user@example.com")
376
+ ```
377
+
378
+ **With timestamp:**
379
+
380
+ ```ruby
381
+ Gum.log("Error occurred", level: :error, time: :rfc822)
382
+ ```
383
+
384
+ **Shorthand methods:**
385
+
386
+ ```ruby
387
+ Gum::Log.debug("Debug message")
388
+ Gum::Log.info("Info message")
389
+ Gum::Log.warn("Warning message")
390
+ Gum::Log.error("Error message", code: 500)
391
+ ```
392
+
393
+ Available log levels: `:debug`, `:info`, `:warn`, `:error`, `:fatal`
394
+
395
+ ## Styling Options
396
+
397
+ Most commands support styling options as hashes. Common style properties include:
398
+
399
+ ```ruby
400
+ {
401
+ foreground: "212", # ANSI color code, hex (#ff0000), or name
402
+ background: "0",
403
+ bold: true,
404
+ italic: true,
405
+ underline: true,
406
+ strikethrough: true,
407
+ faint: true,
408
+ }
409
+ ```
410
+
411
+ **Example with input styling:**
412
+
413
+ ```ruby
414
+ Gum.input(
415
+ placeholder: "Enter name",
416
+ cursor: { foreground: "#FF0" },
417
+ prompt_style: { foreground: "#0FF" }
418
+ )
419
+ ```
420
+
421
+ ## Environment Variables
422
+
423
+ - `GUM_INSTALL_DIR` - Override the path to the gum binary
424
+
425
+ ## Raw Command Execution
426
+
427
+ For commands not covered by the Ruby API, you can execute gum directly:
428
+
429
+ ```ruby
430
+ Gum.execute("choose", "a", "b", "c", "--limit", "2")
431
+ ```
26
432
 
27
433
  ## Development
28
434
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
435
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
436
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
437
+ ### Building Platform Gems
32
438
 
33
- ## Contributing
439
+ ```bash
440
+ rake gem:ruby # Build pure Ruby gem (no binary)
441
+ rake gem:arm64-darwin # Build macOS ARM64 gem
442
+ rake gem:x86_64-darwin # Build macOS Intel gem
443
+ rake gem:arm64-linux # Build Linux ARM64 gem
444
+ rake gem:x86_64-linux # Build Linux x86_64 gem
445
+ rake package # Build all platform gems
446
+ rake download # Download all binaries
447
+ ```
34
448
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gum.
449
+ ## Contributing
36
450
 
451
+ Bug reports and pull requests are welcome on GitHub at https://github.com/marcoroth/gum-ruby.
37
452
 
38
453
  ## License
39
454
 
40
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
455
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
456
+
457
+ ## Acknowledgements
41
458
 
459
+ - [Charm](https://charm.sh/) for creating the amazing [gum](https://github.com/charmbracelet/gum) tool
460
+ - Inspired by [`litestream-ruby`](https://github.com/fractaledmind/litestream-ruby) for the native binary packaging approach
data/exe/gum ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Because rubygems shims assume a gem's executables are Ruby scripts,
5
+ # we need this wrapper to find and exec the native gum binary.
6
+
7
+ $LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
8
+
9
+ require "gum"
10
+
11
+ exec(Gum.executable, *ARGV)
data/gum.gemspec CHANGED
@@ -1,39 +1,35 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'gum/version'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/gum/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = 'gum'
8
- spec.version = Gum::VERSION
9
- spec.authors = ['Anton Sozontov']
10
- spec.email = ['a.sozontov@gmail.com']
6
+ spec.name = "gum"
7
+ spec.version = Gum::VERSION
8
+ spec.authors = ["Marco Roth"]
9
+ spec.email = ["marco.roth@intergga.ch"]
11
10
 
12
- spec.summary = 'Search DSL on top of chewy gem'
13
- spec.description = %q{Gum provides simple DSL for searching in your Elasticsearch}
14
- spec.homepage = 'https://github.com/qwiqer/gum'
15
- spec.license = 'MIT'
11
+ spec.summary = "Ruby wrapper for Charm's gum CLI tool."
12
+ spec.description = "Integrate Charm's gum with the RubyGems infrastructure."
13
+ spec.homepage = "https://github.com/marcoroth/gum-ruby"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 3.2.0"
16
16
 
17
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
- # to allow pushing to a single host or delete this section to allow pushing to any host.
19
- if spec.respond_to?(:metadata)
20
- spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
- else
22
- raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
- end
17
+ spec.metadata = {
18
+ "homepage_uri" => spec.homepage,
19
+ "source_code_uri" => "https://github.com/marcoroth/gum-ruby",
20
+ "changelog_uri" => "https://github.com/marcoroth/gum-ruby/releases",
21
+ "rubygems_mfa_required" => "true",
22
+ }
24
23
 
25
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
- f.match(%r{^(test|spec|features)/})
27
- end
28
- spec.bindir = 'exe'
29
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
- spec.require_paths = ['lib']
24
+ spec.files = Dir[
25
+ "gum.gemspec",
26
+ "lib/**/*",
27
+ "sig/**/*",
28
+ "LICENSE.txt",
29
+ "README.md"
30
+ ]
31
31
 
32
- spec.add_development_dependency 'bundler', '~> 1.13'
33
- spec.add_development_dependency 'rake', '~> 10.0'
34
- spec.add_development_dependency 'rspec', '~> 3.0'
35
- spec.add_development_dependency 'pry-byebug', '~> 3.4'
36
- spec.add_development_dependency 'simplecov', '~> 0'
37
- spec.add_dependency 'activesupport', '>=3.2', '<5.1'
38
- spec.add_dependency 'chewy', '~> 0.8.4'
32
+ spec.bindir = "exe"
33
+ spec.executables = ["gum"]
34
+ spec.require_paths = ["lib"]
39
35
  end