snibbets 2.0.32 → 2.0.33

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
  SHA256:
3
- metadata.gz: e6701119f370f7f3a6190d811e5278799c973ed65b7f69a096b2675c91a2a124
4
- data.tar.gz: 6954526979c677af6c5cf3fece76c0df0eae2f83ae2975c00e2884e99a5a2cda
3
+ metadata.gz: a04adb0bcd4439b3cd445b65bbfb4dc8494237cccca55fb6cc1a42c696e45864
4
+ data.tar.gz: 25099f85f797910222a321dbebd3e0db84098071b964f6d93e0d6ba19ef456c5
5
5
  SHA512:
6
- metadata.gz: 4e3cf0a812450aacd9dd69863bb4ba02880fb57049e396ab7d02eb31b024ed12aabe1f84dd4ace68b5ccc3d2c29e09c114776fde050b4bdc5708fcf01dfe5af9
7
- data.tar.gz: 761105292b069c127ec2e32f0d39235883c4bd75d88b395d1a20b83b7fc6819aec0e9b5df67af14c7a2990196e5611aabf212afead13587ed2d62c2356489d34
6
+ metadata.gz: 7d06a635679db42ad3a53eb21b235e21d4057f189c77760edc373306909da795e306cb7c7992e564cc517831487620904485f2007f0631a6e55ba7c434606b95
7
+ data.tar.gz: 6b0f69d918b04ead612de23ba5d7c0b0044a137da79efc24b3037caa26f0f4d63055270499a6716c3c52e3a6bebbe3b12875db4dafbb7a7de8003559d58765ec
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ### 2.0.33
2
+
3
+ 2023-04-26 10:23
4
+
5
+ #### IMPROVED
6
+
7
+ - More coloring for prompts and messages
8
+ - Colorize headers in multi-snippet output
9
+ - If skylighting highlighting is enabled and the specified
10
+ - Add some normalization for some skylighting lexers
11
+
12
+ #### FIXED
13
+
14
+ - Highlighting returns empty if language contains non-alphanumeric characters
15
+
1
16
  ### 2.0.32
2
17
 
3
18
  2023-04-25 17:14
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- snibbets (2.0.32)
4
+ snibbets (2.0.33)
5
5
  mdless (~> 1.0, >= 1.0.32)
6
6
  tty-reader (~> 0.9, >= 0.9.0)
7
7
  tty-which (~> 0.5, >= 0.5.0)
data/README.md CHANGED
@@ -159,7 +159,7 @@ Snibbet's implementation of Skylighting has limited but better-looking themes, a
159
159
  ### Usage
160
160
 
161
161
  ```
162
- Snibbets v2.0.32
162
+ Snibbets v2.0.33
163
163
 
164
164
  Usage: snibbets [options] query
165
165
  -a, --all If a file contains multiple snippets, output all of them (no menu)
data/bin/snibbets CHANGED
@@ -26,6 +26,7 @@ module Snibbets
26
26
  def run
27
27
  options = Snibbets.options
28
28
  arguments = Snibbets.arguments
29
+ Color.coloring = $stdout.isatty
29
30
 
30
31
  optparse = OptionParser.new do |opts|
31
32
  opts.banner = "Usage: #{File.basename(__FILE__)} [options] query"
@@ -94,14 +95,14 @@ module Snibbets
94
95
  end
95
96
 
96
97
  opts.on('-h', '--help', 'Display this screen') do
97
- puts "Snibbets v#{VERSION}"
98
+ puts "{by}Snibbets {w}v#{VERSION}".x
98
99
  puts
99
100
  puts optparse
100
101
  Process.exit 0
101
102
  end
102
103
 
103
104
  opts.on('-v', '--version', 'Display version information') do
104
- puts "Snibbets v#{VERSION}"
105
+ puts "{by}Snibbets {w}v#{VERSION}".x
105
106
  Process.exit 0
106
107
  end
107
108
 
@@ -116,7 +117,7 @@ module Snibbets
116
117
  if arguments[:save_config]
117
118
  config = Snibbets::Config.new
118
119
  config.write_config
119
- puts "Configuration saved to #{config.config_file}"
120
+ puts "{bg}Configuration saved to {w}#{config.config_file}".x
120
121
  end
121
122
 
122
123
  if arguments[:edit_config]
@@ -127,8 +128,8 @@ module Snibbets
127
128
  end
128
129
 
129
130
  unless File.directory?(options[:source])
130
- puts 'The Snippets folder doesn\'t exist, please configure it.'
131
- puts 'Run `snibbets --configure` to open the config file for editing.'
131
+ puts '{br}The Snippets folder doesn\'t exist, please configure it.'.x
132
+ puts '{bg}Run `{bw}snibbets --configure{bg}` to open the config file for editing.'.x
132
133
  Process.exit 1
133
134
  end
134
135
 
@@ -155,7 +156,7 @@ module Snibbets
155
156
  if arguments[:save_config]
156
157
  Process.exit 0
157
158
  else
158
- puts 'No search query'
159
+ puts '{br}No search query'.x
159
160
  puts optparse
160
161
  Process.exit 1
161
162
  end
@@ -0,0 +1,329 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Cribbed from <https://github.com/flori/term-ansicolor>
4
+ module Snibbets
5
+ class ::String
6
+ def x
7
+ Color.template(self)
8
+ end
9
+
10
+ def uncolor
11
+ Color.uncolor(self)
12
+ end
13
+ end
14
+
15
+ # Terminal output color functions.
16
+ module Color
17
+ ESCAPE_REGEX = /(?<=\[)(?:(?:(?:[349]|10)[0-9]|[0-9])?;?)+(?=m)/.freeze
18
+ # All available color names. Available as methods and string extensions.
19
+ #
20
+ # @example Use a color as a method. Color reset will be added to end of string.
21
+ # Color.yellow('This text is yellow') => "\e[33mThis text is yellow\e[0m"
22
+ #
23
+ # @example Use a color as a string extension. Color reset added automatically.
24
+ # 'This text is green'.green => "\e[1;32mThis text is green\e[0m"
25
+ #
26
+ # @example Send a text string as a color
27
+ # Color.send('red') => "\e[31m"
28
+ ATTRIBUTES = [
29
+ [:clear, 0], # String#clear is already used to empty string in Ruby 1.9
30
+ [:reset, 0], # synonym for :clear
31
+ [:bold, 1],
32
+ [:dark, 2],
33
+ [:italic, 3], # not widely implemented
34
+ [:underline, 4],
35
+ [:underscore, 4], # synonym for :underline
36
+ [:blink, 5],
37
+ [:rapid_blink, 6], # not widely implemented
38
+ [:negative, 7], # no reverse because of String#reverse
39
+ [:concealed, 8],
40
+ [:strikethrough, 9], # not widely implemented
41
+ [:strike, 9], # not widely implemented
42
+ [:black, 30],
43
+ [:red, 31],
44
+ [:green, 32],
45
+ [:yellow, 33],
46
+ [:blue, 34],
47
+ [:magenta, 35],
48
+ [:purple, 35],
49
+ [:cyan, 36],
50
+ [:white, 37],
51
+ [:bgblack, 40],
52
+ [:bgred, 41],
53
+ [:bggreen, 42],
54
+ [:bgyellow, 43],
55
+ [:bgblue, 44],
56
+ [:bgmagenta, 45],
57
+ [:bgpurple, 45],
58
+ [:bgcyan, 46],
59
+ [:bgwhite, 47],
60
+ [:boldblack, 90],
61
+ [:boldred, 91],
62
+ [:boldgreen, 92],
63
+ [:boldyellow, 93],
64
+ [:boldblue, 94],
65
+ [:boldmagenta, 95],
66
+ [:boldpurple, 95],
67
+ [:boldcyan, 96],
68
+ [:boldwhite, 97],
69
+ [:boldbgblack, 100],
70
+ [:boldbgred, 101],
71
+ [:boldbggreen, 102],
72
+ [:boldbgyellow, 103],
73
+ [:boldbgblue, 104],
74
+ [:boldbgmagenta, 105],
75
+ [:boldbgpurple, 105],
76
+ [:boldbgcyan, 106],
77
+ [:boldbgwhite, 107],
78
+ [:softpurple, '0;35;40'],
79
+ [:hotpants, '7;34;40'],
80
+ [:knightrider, '7;30;40'],
81
+ [:flamingo, '7;31;47'],
82
+ [:yeller, '1;37;43'],
83
+ [:whiteboard, '1;30;47'],
84
+ [:chalkboard, '1;37;40'],
85
+ [:led, '0;32;40'],
86
+ [:redacted, '0;30;40'],
87
+ [:alert, '1;31;43'],
88
+ [:error, '1;37;41'],
89
+ [:default, '0;39']
90
+ ].map(&:freeze).freeze
91
+
92
+ ATTRIBUTE_NAMES = ATTRIBUTES.transpose.first
93
+
94
+ # Returns true if Snibbets::Color supports the +feature+.
95
+ #
96
+ # The feature :clear, that is mixing the clear color attribute into String,
97
+ # is only supported on ruby implementations, that do *not* already
98
+ # implement the String#clear method. It's better to use the reset color
99
+ # attribute instead.
100
+ def support?(feature)
101
+ case feature
102
+ when :clear
103
+ !String.instance_methods(false).map(&:to_sym).include?(:clear)
104
+ end
105
+ end
106
+
107
+ # Template coloring
108
+ class ::String
109
+ ##
110
+ ## Extract the longest valid %color name from a string.
111
+ ##
112
+ ## Allows %colors to bleed into other text and still
113
+ ## be recognized, e.g. %greensomething still finds
114
+ ## %green.
115
+ ##
116
+ ## @return [String] a valid color name
117
+ ##
118
+ def validate_color
119
+ valid_color = nil
120
+ compiled = ''
121
+ normalize_color.split('').each do |char|
122
+ compiled += char
123
+ valid_color = compiled if Color.attributes.include?(compiled.to_sym) || compiled =~ /^([fb]g?)?#([a-f0-9]{6})$/i
124
+ end
125
+
126
+ valid_color
127
+ end
128
+
129
+ ##
130
+ ## Normalize a color name, removing underscores,
131
+ ## replacing "bright" with "bold", and converting
132
+ ## bgbold to boldbg
133
+ ##
134
+ ## @return [String] Normalized color name
135
+ ##
136
+ def normalize_color
137
+ gsub(/_/, '').sub(/bright/i, 'bold').sub(/bgbold/, 'boldbg')
138
+ end
139
+
140
+ # Get the calculated ANSI color at the end of the
141
+ # string
142
+ #
143
+ # @return ANSI escape sequence to match color
144
+ #
145
+ def last_color_code
146
+ m = scan(ESCAPE_REGEX)
147
+
148
+ em = ['0']
149
+ fg = nil
150
+ bg = nil
151
+ rgbf = nil
152
+ rgbb = nil
153
+
154
+ m.each do |c|
155
+ case c
156
+ when '0'
157
+ em = ['0']
158
+ fg, bg, rgbf, rgbb = nil
159
+ when /^[34]8/
160
+ case c
161
+ when /^3/
162
+ fg = nil
163
+ rgbf = c
164
+ when /^4/
165
+ bg = nil
166
+ rgbb = c
167
+ end
168
+ else
169
+ c.split(/;/).each do |i|
170
+ x = i.to_i
171
+ if x <= 9
172
+ em << x
173
+ elsif x >= 30 && x <= 39
174
+ rgbf = nil
175
+ fg = x
176
+ elsif x >= 40 && x <= 49
177
+ rgbb = nil
178
+ bg = x
179
+ elsif x >= 90 && x <= 97
180
+ rgbf = nil
181
+ fg = x
182
+ elsif x >= 100 && x <= 107
183
+ rgbb = nil
184
+ bg = x
185
+ end
186
+ end
187
+ end
188
+ end
189
+
190
+ escape = "\e[#{em.join(';')}m"
191
+ escape += "\e[#{rgbb}m" if rgbb
192
+ escape += "\e[#{rgbf}m" if rgbf
193
+ escape + "\e[#{[fg, bg].delete_if(&:nil?).join(';')}m"
194
+ end
195
+ end
196
+
197
+ class << self
198
+ # Returns true if the coloring function of this module
199
+ # is switched on, false otherwise.
200
+ def coloring?
201
+ @coloring
202
+ end
203
+
204
+ attr_writer :coloring
205
+
206
+ ##
207
+ ## Enables colored output
208
+ ##
209
+ ## @example Turn color on or off based on TTY
210
+ ## Snibbets::Color.coloring = STDOUT.isatty
211
+ def coloring
212
+ @coloring ||= true
213
+ end
214
+
215
+ ##
216
+ ## Convert a template string to a colored string.
217
+ ## Colors are specified with single letters inside
218
+ ## curly braces. Uppercase changes background color.
219
+ ##
220
+ ## w: white, k: black, g: green, l: blue, y: yellow, c: cyan,
221
+ ## m: magenta, r: red, b: bold, u: underline, i: italic,
222
+ ## x: reset (remove background, color, emphasis)
223
+ ##
224
+ ## @example Convert a templated string
225
+ ## Color.template('{Rwb}Warning:{x} {w}you look a little {g}ill{x}')
226
+ ##
227
+ ## @param input [String, Array] The template
228
+ ## string. If this is an array, the
229
+ ## elements will be joined with a
230
+ ## space.
231
+ ##
232
+ ## @return [String] Colorized string
233
+ ##
234
+ def template(input)
235
+ input = input.join(' ') if input.is_a? Array
236
+ fmt = input.gsub(/%/, '%%')
237
+ fmt = fmt.gsub(/(?<!\\u|\$)\{(\w+)\}/i) do
238
+ Regexp.last_match(1).split('').map { |c| "%<#{c}>s" }.join('')
239
+ end
240
+
241
+ colors = { w: white, k: black, g: green, l: blue,
242
+ y: yellow, c: cyan, m: magenta, r: red,
243
+ W: bgwhite, K: bgblack, G: bggreen, L: bgblue,
244
+ Y: bgyellow, C: bgcyan, M: bgmagenta, R: bgred,
245
+ d: dark, b: bold, u: underline, i: italic, x: reset }
246
+
247
+ fmt.empty? ? input : format(fmt, colors)
248
+ end
249
+ end
250
+
251
+ ATTRIBUTES.each do |c, v|
252
+ new_method = <<-EOSCRIPT
253
+ def #{c}(string = nil)
254
+ result = ''
255
+ result << "\e[#{v}m" if Snibbets::Color.coloring?
256
+ if block_given?
257
+ result << yield
258
+ elsif string.respond_to?(:to_str)
259
+ result << string.to_str
260
+ elsif respond_to?(:to_str)
261
+ result << to_str
262
+ else
263
+ return result #only switch on
264
+ end
265
+ result << "\e[0m" if Snibbets::Color.coloring?
266
+ result
267
+ end
268
+ EOSCRIPT
269
+
270
+ module_eval(new_method)
271
+
272
+ next unless c =~ /bold/
273
+
274
+ # Accept brightwhite in addition to boldwhite
275
+ new_method = <<-EOSCRIPT
276
+ def #{c.to_s.sub(/bold/, 'bright')}(string = nil)
277
+ result = ''
278
+ result << "\e[#{v}m" if Snibbets::Color.coloring?
279
+ if block_given?
280
+ result << yield
281
+ elsif string.respond_to?(:to_str)
282
+ result << string.to_str
283
+ elsif respond_to?(:to_str)
284
+ result << to_str
285
+ else
286
+ return result #only switch on
287
+ end
288
+ result << "\e[0m" if Snibbets::Color.coloring?
289
+ result
290
+ end
291
+ EOSCRIPT
292
+
293
+ module_eval(new_method)
294
+ end
295
+
296
+ def rgb(hex)
297
+ is_bg = hex.match(/^bg?#/) ? true : false
298
+ hex_string = hex.sub(/^([fb]g?)?#/, '')
299
+
300
+ parts = hex_string.match(/(?<r>..)(?<g>..)(?<b>..)/)
301
+ t = []
302
+ %w[r g b].each do |e|
303
+ t << parts[e].hex
304
+ end
305
+ color =
306
+ "\e[#{is_bg ? '48' : '38'};2;#{t.join(';')}m"
307
+ end
308
+
309
+ # Returns an uncolored version of the string, that is all
310
+ # ANSI-sequences are stripped from the string.
311
+ def uncolor(string = nil) # :yields:
312
+ if block_given?
313
+ yield.to_str.gsub(ESCAPE_REGEX, '')
314
+ elsif string.respond_to?(:to_str)
315
+ string.to_str.gsub(ESCAPE_REGEX, '')
316
+ elsif respond_to?(:to_str)
317
+ to_str.gsub(ESCAPE_REGEX, '')
318
+ else
319
+ ''
320
+ end
321
+ end
322
+
323
+ # Returns an array of all Snibbets::Color attributes as symbols.
324
+ def attributes
325
+ ATTRIBUTE_NAMES
326
+ end
327
+ extend self
328
+ end
329
+ end
@@ -2,6 +2,7 @@ module Snibbets
2
2
  module Highlight
3
3
  class << self
4
4
  def run_command_with_input(*cmd, input: nil, fallback: nil)
5
+
5
6
  stdout, _stderr, status = Open3.capture3(*cmd, stdin_data: input)
6
7
  if status.success?
7
8
  stdout
@@ -35,10 +36,9 @@ module Snibbets
35
36
  else
36
37
  ''
37
38
  end
38
- return code if syntax.nil? || syntax.empty?
39
+ return code if syntax.nil? || syntax.empty? || !Lexers.skylight_lexer?(syntax)
39
40
 
40
41
  run_command_with_input("#{executable} #{theme}--syntax #{syntax}", input: code)
41
- # `echo #{Shellwords.escape(code)} | #{executable} #{theme}--syntax #{syntax}`
42
42
  end
43
43
 
44
44
  def highlight_fences(code, filename, syntax)
@@ -46,7 +46,8 @@ module Snibbets
46
46
 
47
47
  content.fences.each do |f|
48
48
  rx = Regexp.new(Regexp.escape(f[:code]))
49
- highlighted = highlight(f[:code].gsub(/\\k</, '\k\<'), filename, f[:lang] || syntax).strip
49
+ syn = Lexers.normalize_lexer(f[:lang] || syntax)
50
+ highlighted = highlight(f[:code].gsub(/\\k</, '\k\<'), filename, syn).strip
50
51
  code.sub!(/#{rx}/, highlighted)
51
52
  end
52
53
 
@@ -62,6 +63,7 @@ module Snibbets
62
63
 
63
64
  theme ||= Snibbets.options[:highlight_theme] || 'monokai'
64
65
  syntax ||= Lexers.syntax_from_extension(filename)
66
+ syntax = Lexers.normalize_lexer(syntax)
65
67
 
66
68
  return code if ['text'].include?(syntax)
67
69
 
@@ -69,7 +71,11 @@ module Snibbets
69
71
  pygments = TTY::Which.which('pygmentize')
70
72
 
71
73
  if Snibbets.options[:highlighter] =~ /^s/ && !skylight.nil?
72
- return highlight_skylight(skylight, code, syntax, theme)
74
+ if !Lexers.skylight_lexer?(syntax) && !pygments.nil?
75
+ return highlight_pygments(pygments, code, syntax, 'monokai')
76
+ else
77
+ return highlight_skylight(skylight, code, syntax, theme)
78
+ end
73
79
  elsif Snibbets.options[:highlighter] =~ /^p/ && !pygments.nil?
74
80
  return highlight_pygments(pygments, code, syntax, theme)
75
81
  elsif !skylight.nil?
@@ -27,6 +27,15 @@ module Snibbets
27
27
  lex
28
28
  end
29
29
 
30
+ def skylight_lexer?(lexer)
31
+ SKYLIGHT_LEXERS_DB.split(/\n/).include?(lexer)
32
+ end
33
+
34
+ def normalize_lexer(lexer)
35
+ matches = LEXER_NORMALIZERS.select { |k, v| v.include? lexer }
36
+ matches.count.positive? ? matches.keys[0] : lexer
37
+ end
38
+
30
39
  def ext_to_lang(ext)
31
40
  return nil if ext.nil?
32
41
 
@@ -233,7 +233,7 @@ nsis, nsi, nsh [nsi, nsh]
233
233
  nusmv [smv]
234
234
  objdump [objdump]
235
235
  objective-c++, objectivec++, obj-c++, objc++ [mm, hh]
236
- objective-c, objectivec, obj-c, objc [m, h]
236
+ objectivec, objective-c, obj-c, objc [m, h]
237
237
  objective-j, objectivej, obj-j, objj [j]
238
238
  ocaml [ml, mli, mll, mly]
239
239
  odin [odin]
@@ -377,3 +377,164 @@ bro [bro]
377
377
  zephir [zep]
378
378
  zig [zig]
379
379
  EOLEXERS
380
+
381
+ SKYLIGHT_LEXERS_DB=<<EOSKYLEX
382
+ abc
383
+ asn1
384
+ asp
385
+ ats
386
+ awk
387
+ actionscript
388
+ ada
389
+ agda
390
+ alert
391
+ apache
392
+ bash
393
+ bibtex
394
+ boo
395
+ c
396
+ cs
397
+ cpp
398
+ cmake
399
+ css
400
+ changelog
401
+ clojure
402
+ coffee
403
+ coldfusion
404
+ comments
405
+ commonlisp
406
+ curry
407
+ d
408
+ dtd
409
+ default
410
+ diff
411
+ djangotemplate
412
+ dockerfile
413
+ doxygen
414
+ doxygenlua
415
+ eiffel
416
+ elixir
417
+ elm
418
+ email
419
+ erlang
420
+ fsharp
421
+ fortranfixed
422
+ fortranfree
423
+ gcc
424
+ glsl
425
+ gnuassembler
426
+ m4
427
+ go
428
+ graphql
429
+ groovy
430
+ html
431
+ hamlet
432
+ haskell
433
+ haxe
434
+ ini
435
+ isocpp
436
+ idris
437
+ fasm
438
+ nasm
439
+ j
440
+ json
441
+ jsp
442
+ java
443
+ javascript
444
+ javascriptreact
445
+ javadoc
446
+ julia
447
+ kotlin
448
+ llvm
449
+ latex
450
+ lex
451
+ lilypond
452
+ literatecurry
453
+ literatehaskell
454
+ lua
455
+ mips
456
+ makefile
457
+ markdown
458
+ mathematica
459
+ matlab
460
+ maxima
461
+ mediawiki
462
+ metafont
463
+ modelines
464
+ modula2
465
+ modula3
466
+ monobasic
467
+ mustache
468
+ nim
469
+ nix
470
+ ocaml
471
+ objectivec
472
+ objectivecpp
473
+ octave
474
+ opencl
475
+ orgmode
476
+ php
477
+ povray
478
+ pascal
479
+ perl
480
+ pike
481
+ postscript
482
+ powershell
483
+ prolog
484
+ protobuf
485
+ pure
486
+ purebasic
487
+ python
488
+ qml
489
+ r
490
+ relaxng
491
+ raku
492
+ relaxngcompact
493
+ roff
494
+ ruby
495
+ rhtml
496
+ rust
497
+ sass
498
+ scss
499
+ sgml
500
+ sml
501
+ spdxcomments
502
+ sql
503
+ sqlmysql
504
+ sqlpostgresql
505
+ scala
506
+ scheme
507
+ stan
508
+ stata
509
+ swift
510
+ systemverilog
511
+ toml
512
+ tcl
513
+ tcsh
514
+ texinfo
515
+ mandoc
516
+ typescript
517
+ vhdl
518
+ verilog
519
+ xml
520
+ xul
521
+ yaml
522
+ yacc
523
+ zsh
524
+ dot
525
+ noweb
526
+ rest
527
+ sci
528
+ sed
529
+ xorg
530
+ xslt
531
+ EOSKYLEX
532
+
533
+ LEXER_NORMALIZERS = {
534
+ 'objectivec' => %w[objective-c obj-c],
535
+ 'markdown' => %w[md mmd mkdn multimarkdown],
536
+ 'bash' => %w[csh sh shell],
537
+ 'javascript' => %w[js],
538
+ 'javascriptreact' => %w[react],
539
+ 'yaml' => %w[yml]
540
+ }.freeze
data/lib/snibbets/os.rb CHANGED
@@ -12,12 +12,12 @@ module Snibbets
12
12
  os = RbConfig::CONFIG['target_os']
13
13
  case os
14
14
  when /darwin.*/i
15
- `echo #{Shellwords.escape(text)} | pbcopy`
15
+ `echo #{Shellwords.escape(text.uncolor)} | pbcopy`
16
16
  else
17
17
  if TTY::Which.exist?('xclip')
18
- `echo #{Shellwords.escape(text)} | xclip -sel c`
18
+ `echo #{Shellwords.escape(text.uncolor)} | xclip -sel c`
19
19
  elsif TTY::Which.exist('xsel')
20
- `echo #{Shellwords.escape(text)} | xsel -ib`
20
+ `echo #{Shellwords.escape(text.uncolor)} | xsel -ib`
21
21
  else
22
22
  puts 'Copy not supported on this system, please install xclip or xsel.'
23
23
  end
@@ -84,7 +84,7 @@ module Snibbets
84
84
  # if it's a fenced code block, just discard the fence and everything
85
85
  # outside it
86
86
  if block.fenced?
87
- code_blocks = block.scan(/(`{3,})(\w+)?\s*\n(.*?)\n\1/m)
87
+ code_blocks = block.scan(/(`{3,})(\S+)?\s*\n(.*?)\n\1/m)
88
88
  code_blocks.map! { |b| b[2].strip }
89
89
  return code_blocks.join("\n\n")
90
90
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Snibbets
4
- VERSION = '2.0.32'
4
+ VERSION = '2.0.33'
5
5
  end
data/lib/snibbets.rb CHANGED
@@ -12,6 +12,7 @@ require 'tty-reader'
12
12
  require 'tty-which'
13
13
  require 'yaml'
14
14
  require_relative 'snibbets/version'
15
+ require_relative 'snibbets/colors'
15
16
  require_relative 'snibbets/config'
16
17
  require_relative 'snibbets/which'
17
18
  require_relative 'snibbets/string'
@@ -84,7 +85,7 @@ module Snibbets
84
85
  end
85
86
 
86
87
  if try == 2 && cmd.nil?
87
- puts "No search method available on this system. Please install ripgrep, silver surfer, ack, or grep."
88
+ puts "{br}No search method available on this system. Please install ripgrep, silver surfer, ack, or grep.".x
88
89
  Process.exit 1
89
90
  end
90
91
 
@@ -138,14 +139,14 @@ module Snibbets
138
139
  editor = TTY::Which.which(editor)
139
140
  system %(#{editor} "#{filepath}") if editor
140
141
  else
141
- puts "No editor configured, or editor is missing"
142
+ puts "{br}No editor configured, or editor is missing".x
142
143
  Process.exit 1
143
144
  end
144
145
  elsif TTY::Which.exist?(editor)
145
146
  editor = TTY::Which.which(editor)
146
147
  system %(#{editor} "#{filepath}") if editor
147
148
  else
148
- puts "No editor configured, or editor is missing"
149
+ puts "{br}No editor configured, or editor is missing".x
149
150
  Process.exit 1
150
151
  end
151
152
  end
@@ -163,12 +164,12 @@ module Snibbets
163
164
  reader = TTY::Reader.new
164
165
 
165
166
  # printf 'What does this snippet do? '
166
- input = reader.read_line('What does this snippet do? ').strip
167
+ input = reader.read_line('{by}What does this snippet do{bw}? '.x).strip
167
168
  # input = $stdin.gets.chomp
168
169
  title = input unless input.empty?
169
170
 
170
171
  # printf 'What language(s) does it use (separate with spaces, full names or file extensions will work)? '
171
- input = reader.read_line('What language(s) does it use (separate with spaces, full names or file extensions will work)? ').strip
172
+ input = reader.read_line('{by}What language(s) does it use ({xw}separate with spaces, full names or file extensions{by}){bw}? '.x).strip
172
173
  # input = $stdin.gets.chomp
173
174
  langs = input.split(/ +/).map(&:strip) unless input.empty?
174
175
  exts = langs.map { |lang| Lexers.lang_to_ext(lang) }.delete_if(&:nil?)
@@ -176,7 +177,7 @@ module Snibbets
176
177
 
177
178
  exts = langs if exts.empty?
178
179
 
179
- filename = "#{title}#{exts.map { |x| ".#{x}"}.join('')}.#{Snibbets.options[:extension]}"
180
+ filename = "#{title}#{exts.map { |x| ".#{x}" }.join('')}.#{Snibbets.options[:extension]}"
180
181
  filepath = File.join(File.expand_path(Snibbets.options[:source]), filename)
181
182
  File.open(filepath, 'w') do |f|
182
183
  f.puts "tags: #{tags.join(', ')}
@@ -186,7 +187,7 @@ module Snibbets
186
187
  ```"
187
188
  end
188
189
 
189
- puts "New snippet written to #{filename}."
190
+ puts "{bg}New snippet written to {bw}#{filename}.".x
190
191
 
191
192
  open_snippet_in_editor(filepath) if Snibbets.arguments[:edit_snippet]
192
193
  open_snippet_in_nvultra(filepath) if Snibbets.arguments[:nvultra]
@@ -280,8 +281,8 @@ module Snibbets
280
281
  snippets.each do |snip|
281
282
  header = File.basename(filepath, '.md')
282
283
  if $stdout.isatty
283
- puts header
284
- puts '-' * header.length
284
+ puts "{bw}#{header}{x}".x
285
+ puts "{dw}#{'-' * header.length}{x}".x
285
286
  puts ''
286
287
  end
287
288
  code = snip['code']
@@ -311,8 +312,8 @@ module Snibbets
311
312
  else
312
313
  if $stdout.isatty
313
314
  header = File.basename(filepath, '.md')
314
- warn header
315
- warn '=' * header.length
315
+ warn "{bw}#{header}{x}".x
316
+ warn "{dw}#{'=' * header.length}{x}".x
316
317
  warn ''
317
318
  end
318
319
  print_all(snippets, filepath)
@@ -321,7 +322,7 @@ module Snibbets
321
322
  print(answer.to_json, filepath)
322
323
  else
323
324
  if $stdout.isatty
324
- header = "#{File.basename(filepath, '.md')}: #{answer['title']}"
325
+ header = "{bw}#{File.basename(filepath, '.md')}: {c}#{answer['title']}{x}".x
325
326
  warn header
326
327
  warn '-' * header.length
327
328
  warn ''
@@ -340,7 +341,7 @@ module Snibbets
340
341
  snippets.each do |snippet|
341
342
  lang = snippet['language']
342
343
 
343
- puts "### #{snippet['title']} ###"
344
+ puts "{dw}### {xbw}#{snippet['title']} {xdw}### {x}".x
344
345
  puts ''
345
346
 
346
347
  print(snippet['code'], filepath, lang)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snibbets
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.32
4
+ version: 2.0.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-25 00:00:00.000000000 Z
11
+ date: 2023-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -257,6 +257,7 @@ files:
257
257
  - bin/snibbets
258
258
  - lib/snibbets.rb
259
259
  - lib/snibbets/array.rb
260
+ - lib/snibbets/colors.rb
260
261
  - lib/snibbets/config.rb
261
262
  - lib/snibbets/hash.rb
262
263
  - lib/snibbets/highlight.rb