pipetext 0.1.6 → 0.2.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
  SHA256:
3
- metadata.gz: 8ca1788110ca471e3592a78b3f91285af91338551836a6b39addf9f6a4b4049c
4
- data.tar.gz: db0162ba573ac6498c0356d0f91264998f460aa1b903a79a1d9edccdfd1ce923
3
+ metadata.gz: b0ae63046e780049e0d20b63aab5604e11dcb8c0a3906e12c4db118bd317e5fd
4
+ data.tar.gz: 39edba4cb4b0b899c5692f57ee71e371254f3f2b199ee5a1207872cb89eb7ef3
5
5
  SHA512:
6
- metadata.gz: b197769b04cb90d36106524f18d7e8459ad0dd96358a6a7bbc350c3c4572fcd204ff25834f67c730b0676a4e4f3b55462a120367a9e23d5e93e93fd3a8754aba
7
- data.tar.gz: 27a1232cfb0ad1be0d5d6b641ee633e44846200a1ba69c42f28f997c5cf6b0769923171aee4bb764f9aab6f0a58be973fcb8b3a6d403e06431d053fbcc8eef05
6
+ metadata.gz: 84eae6ce6e8581f67281d46e34da26c427ebae034b6bfd3bfcc56f059569ad3366fdc74dd05db1cacd0ee9345fd4e28394d4be8923e3629421c2d8c2937eb507
7
+ data.tar.gz: cd59a5cca225c9819947601ad39449c7fc4d70576027f09721287ad215798a965a09847f329eda0f246fd89ce5fed8bacbfccc908bb96ce5812b33cb14097ed2
data/bin/pipetext CHANGED
@@ -40,7 +40,7 @@ Move cursor up 1 line ||^ Hide cursor ||h
40
40
  Move cursor down 1 line ||v Unhide cursor ||H
41
41
  Move cursor forward 1 character ||> Sleep timer in seconds ||[#s]
42
42
  Move cursor back 1 character ||< Sleep timer in milliseconds ||[#ms]
43
-
43
+ Capture variable ||(variable name=data) Display variable ||(variable name)
44
44
 
45
45
  Emojis: https://unicode.org/emoji/charts/full-emoji-list.html
46
46
  ||[Abbreviated CLDR Short Name] |[smiling face with heart-eyes] ||[smiling face with heart-eyes] or
@@ -69,22 +69,21 @@ Longer repetition patterns using the character ~
69
69
  |3~ &r|----|O> ALL YOUR |kBASE|n |3\~ARE|3\~ BELONG TO US. <|----|O&n|\n~|n'
70
70
 
71
71
  if(ARGV[0] == nil && STDIN.tty? == true)
72
- puts "#{File.basename(__FILE__)} <filename> | <pipetext>"
72
+ puts "PipeText capabilities:"
73
73
  puts
74
- puts "Example usage:"
74
+ pipe.paint(pipetext_example)
75
+ puts "Command Syntax: #{File.basename(__FILE__)} <filename> | <pipetext>"
76
+ puts "Example usages:"
75
77
  puts
76
78
  puts "pipetext '|RBright red|n, |cCyan|n, |g&rGreen and Red|n,&n Normal |R|u1f49c |g|U2714|n'"
77
- puts
78
79
  puts "pipetext '|50-'"
79
- puts
80
80
  puts "pipetext '|-|50-'"
81
- puts
82
81
  puts "pipetext '|]50Insert spaces until end (50)|W|{centered}|n|;Add After'"
83
- puts
82
+ puts "pipetext 'Capture a variable named gear line|(gear line=|r|[gear]|n|-|60-|O|r|[gear]|n)|\\n" +
83
+ "|(gear line)|\\n|(gear line)|\\n|(gear line)|\\n||(gear line) = |(gear line)'"
84
84
  puts "pipetext '|10~ &r|----|O> ALL YOUR |kBASE|n |3\\~ARE|3\\~ BELONG TO US. <|----|O&n|\\n~|n'"
85
85
  puts
86
- pipe.paint(pipetext_example)
87
- pipe.paint("PipeText Version |c#{PipeText::VERSION}|n")
86
+ pipe.paint("version |c#{PipeText::VERSION}|n")
88
87
  else
89
88
  if(STDIN.tty? == false)
90
89
  pipe.paint(STDIN.read)
@@ -6,40 +6,43 @@ module PipeText
6
6
 
7
7
  def pipetext_init(box_mode=true, ampersand_mode=false)
8
8
  attributes = {
9
- 'pipe' => false, # Pipe already been found?
10
- 'repeat_pattern' => false, # Used by |<#>~repeat pattern~
11
- 'pattern' => String.new, # Used by |<#>~repeat pattern~ to capture
12
- 'pattern_escape' => false, # Has an escape \ already been found in front of this character?
13
- 'ampersand' => false, # Has an ampersand already been found in front of this character?
14
- 'ampersand_mode' => ampersand_mode, # Do we even process ampersands for background colors?
15
- 'blink' => false, # Is blink turned on?
16
- 'bold' => false,
17
- 'crossed_out' => false,
18
- 'faint' => false,
19
- 'found' => false, # At the end -- did we find a match?
20
- 'italic' => false,
21
- 'inverse' => false,
22
- 'underline' => false,
23
- 'box' => -1, # Default to |O (no boxes)
24
- 'box_mode' => box_mode,
25
- 'num' => 0, # Number of times to repeat pattern
26
- 'end_capture' => false, # Used to capture the end column number
27
- 'end' => 0, # Number which current denotes the end of the column
28
- 'position' => 0, # Number which current position in the column
29
- 'center_capture' => false, # Used to capture text for centering
30
- 'center' => String.new, # Text to be centered
31
- 'emoji_capture' => false, # Used to capture emoji description or bell/move to position
32
- 'emoji' => String.new, # Used to capture emoji description or bell/move to position
33
- 'unicode_capture' => 0, # Used to capture Unicode using 6 character UTF-16 hex format
34
- 'unicode' => String.new,
35
- 'palette_capture' => 0, # Used to capture 8-bit color using 2 character hex format
36
- 'p' => String.new, # |p00 to |pFF
37
- 'color_capture' => 0, # Used to capture RGB color using #RRGGBB format
38
- 'r' => String.new,
39
- 'g' => String.new,
40
- 'b' => String.new,
41
- 'fg' => String.new, # Needed to restore after background change
42
- 'bg' => String.new # Needed to restore after foreground change
9
+ 'pipe' => false, # Pipe already been found?
10
+ 'repeat_pattern' => false, # Used by |<#>~repeat pattern~
11
+ 'pattern' => String.new, # Used by |<#>~repeat pattern~ to capture
12
+ 'escape' => false, # Has an escape \ already been found in front of this character?
13
+ 'ampersand' => false, # Has an ampersand already been found in front of this character?
14
+ 'ampersand_mode' => ampersand_mode, # Do we even process ampersands for background colors?
15
+ 'blink' => false, # Is blink turned on?
16
+ 'bold' => false,
17
+ 'crossed_out' => false,
18
+ 'faint' => false,
19
+ 'found' => false, # At the end -- did we find a match?
20
+ 'italic' => false,
21
+ 'inverse' => false,
22
+ 'underline' => false,
23
+ 'box' => -1, # Default to |O (no boxes)
24
+ 'box_mode' => box_mode,
25
+ 'num' => 0, # Number of times to repeat pattern
26
+ 'end_capture' => false, # Used to capture the end column number
27
+ 'end' => 0, # Number which current denotes the end of the column
28
+ 'position' => 0, # Number which current position in the column
29
+ 'center_capture' => false, # Used to capture text for centering
30
+ 'center' => String.new, # Text to be centered
31
+ 'variable_capture' => false, # Used to capture a variable for update or to display
32
+ 'variable' => String.new, # Variable captured
33
+ 'variables' => Hash.new, # Stores all captured variables
34
+ 'emoji_capture' => false, # Used to capture emoji description or bell/move to position
35
+ 'emoji' => String.new, # Used to capture emoji description or bell/move to position
36
+ 'unicode_capture' => 0, # Used to capture Unicode using 6 character UTF-16 hex format
37
+ 'unicode' => String.new,
38
+ 'palette_capture' => 0, # Used to capture 8-bit color using 2 character hex format
39
+ 'p' => String.new, # |p00 to |pFF
40
+ 'color_capture' => 0, # Used to capture RGB color using #RRGGBB format
41
+ 'r' => String.new,
42
+ 'g' => String.new,
43
+ 'b' => String.new,
44
+ 'fg' => String.new, # Needed to restore after background change
45
+ 'bg' => String.new # Needed to restore after foreground change
43
46
  }
44
47
  end
45
48
 
@@ -64,6 +67,8 @@ module PipeText
64
67
  new_text << "|[" + attributes['emoji']
65
68
  elsif(attributes['center_capture'] == true)
66
69
  new_text << "|{" + attributes['center']
70
+ elsif(attributes['variable_capture'] == true)
71
+ new_text << "|(" + attributes['variable']
67
72
  end
68
73
  return new_text
69
74
  end
@@ -98,6 +103,8 @@ module PipeText
98
103
  new_text << "|[" + attributes['emoji']
99
104
  elsif(attributes['center_capture'] == true)
100
105
  new_text << "|{" + attributes['center']
106
+ elsif(attributes['variable_capture'] == true)
107
+ new_text << "|(" + attributes['variable']
101
108
  end
102
109
  print(new_text)
103
110
  end
@@ -205,22 +212,35 @@ module PipeText
205
212
  end
206
213
  attributes['num'] += character.to_i
207
214
  end
208
- elsif(character == '|' && attributes['repeat_pattern'] == false)
209
- process_pipe(character, new_text, attributes)
210
- elsif(character == '~' && attributes['pipe'] == true &&
211
- attributes['num'] > 0 && attributes['pattern_escape'] == false)
212
- process_repeat_pattern(character, new_text, attributes)
213
- elsif(attributes['repeat_pattern'] == true)
214
- capture_character_pattern(character, attributes)
215
- elsif(attributes['color_capture'] > 0 && character =~ /[0-9,A-F,a-f]/)
216
- capture_color(character, new_text, attributes)
217
- elsif(attributes['palette_capture'] > 0 && character =~ /[0-9,A-F,a-f]/)
218
- capture_palette_color(character, new_text, attributes)
215
+ elsif(character == ')' && attributes['variable_capture'] == true && attributes['escape'] == false)
216
+ if(attributes['variable'] =~ /=/) # Update
217
+ update_variable(attributes)
218
+ else # Display
219
+ emit_variable(new_text, attributes)
220
+ end
221
+ elsif(attributes['variable_capture'] == true)
222
+ if(character == '\\')
223
+ attributes['escape'] = true
224
+ else
225
+ if(attributes['escape'] == true)
226
+ attributes['variable'] << "\\#{character}"
227
+ attributes['escape'] = false
228
+ else
229
+ attributes['variable'] << character
230
+ end
231
+ end
219
232
  elsif(attributes['center_capture'] == true)
220
- if(character == '}')
221
- emit_center(new_text, attributes)
233
+ if(character == '\\')
234
+ attributes['escape'] = true
222
235
  else
223
- attributes['center'] << character
236
+ if(attributes['escape'] == true)
237
+ attributes['center'] << "\\#{character}"
238
+ attributes['escape'] = false
239
+ elsif(character == '}')
240
+ emit_center(new_text, attributes)
241
+ else
242
+ attributes['center'] << character
243
+ end
224
244
  end
225
245
  elsif(attributes['emoji_capture'] == true)
226
246
  if(character == ']')
@@ -246,13 +266,24 @@ module PipeText
246
266
  else
247
267
  attributes['emoji'] << character
248
268
  end
269
+ elsif(character == '|' && attributes['repeat_pattern'] == false)
270
+ process_pipe(character, new_text, attributes)
271
+ elsif(character == '~' && attributes['pipe'] == true &&
272
+ attributes['num'] > 0 && attributes['escape'] == false)
273
+ process_repeat_pattern(character, new_text, attributes)
274
+ elsif(attributes['repeat_pattern'] == true)
275
+ capture_character_pattern(character, attributes)
276
+ elsif(attributes['color_capture'] > 0 && character =~ /[0-9,A-F,a-f]/)
277
+ capture_color(character, new_text, attributes)
278
+ elsif(attributes['palette_capture'] > 0 && character =~ /[0-9,A-F,a-f]/)
279
+ capture_palette_color(character, new_text, attributes)
249
280
  elsif(attributes['unicode_capture'] == 1 && character == '+') # Skip
250
281
  return
251
282
  elsif(attributes['unicode_capture'] > 0 && character =~ /[0-9,A-F,a-f]/)
252
283
  capture_unicode(character, new_text, attributes)
253
284
  elsif(attributes['pipe'] == true &&
254
285
  attributes['repeat_pattern'] == false &&
255
- attributes['pattern_escape'] == true)
286
+ attributes['escape'] == true)
256
287
  process_escaped_character(character, new_text, attributes)
257
288
  elsif(character == '&' && attributes['ampersand_mode'] == true &&
258
289
  attributes['pipe'] == false)
@@ -306,8 +337,30 @@ module PipeText
306
337
  attributes['unicode'] = String.new
307
338
  end
308
339
 
340
+ def update_variable(attributes)
341
+ if(attributes['variable'] =~ /(.*)=(.*)/)
342
+ attributes['variables'][$1] = $2
343
+ end
344
+ attributes['variable_capture'] = false
345
+ attributes['variable'] = String.new
346
+ end
347
+
348
+ def emit_variable(new_text, attributes)
349
+ if(attributes['variables'][attributes['variable']])
350
+ new_text << pipetext(escape_fix(attributes['variables'][attributes['variable']]),
351
+ attributes['box_mode'], attributes['ampersand_mode'])
352
+ else
353
+ new_text << "|(" + attributes['variable'] + ")"
354
+ end
355
+ attributes['variable_capture'] = false
356
+ attributes['variable'] = String.new
357
+ end
358
+
309
359
  def emit_center(new_text, attributes)
310
360
  spaces = attributes['end'] - attributes['position'] - printable_length(attributes['center'])
361
+ if(printable_length(attributes['center']) % 2)
362
+ spaces += 1
363
+ end
311
364
  if(spaces > 0)
312
365
  spaces /= 2
313
366
  spaces.times do
@@ -370,7 +423,7 @@ module PipeText
370
423
  end
371
424
  attributes['num'] = 0
372
425
  attributes['pipe'] = false
373
- attributes['pattern_escape'] = false
426
+ attributes['escape'] = false
374
427
  attributes['repeat_pattern'] = false
375
428
  attributes['pattern'] = String.new
376
429
  else # ~ after number in |5~Repeat 5 times~
@@ -380,7 +433,8 @@ module PipeText
380
433
 
381
434
  def escape_fix(text) # Done this way for old Ruby versions
382
435
  text = text.gsub(/\\a/, "\a").gsub(/\\b/, "\b").gsub(/\\e/, "\e").gsub(/\\f/, "\f")
383
- text.gsub(/\\n/, "\n").gsub(/\\r/, "\r").gsub(/\\t/, "\t").gsub(/\\v/, "\v").gsub(/\\~/, '~')
436
+ text = text.gsub(/\\n/, "\n").gsub(/\\r/, "\r").gsub(/\\t/, "\t").gsub(/\\v/, "\v")
437
+ text = text.gsub(/\\~/, '~').gsub(/\\\(/, '(').gsub(/\\\)/, ')')
384
438
  end
385
439
 
386
440
  def process_escaped_character(character, new_text, attributes)
@@ -393,7 +447,7 @@ module PipeText
393
447
  end
394
448
  attributes['num'] = 0
395
449
  attributes['pipe'] = false
396
- attributes['pattern_escape'] = false
450
+ attributes['escape'] = false
397
451
  attributes['pattern'] = String.new
398
452
  attributes['repeat_pattern'] = false
399
453
  end
@@ -417,11 +471,11 @@ module PipeText
417
471
 
418
472
  def capture_character_pattern(character, attributes)
419
473
  if(character == '\\')
420
- attributes['pattern_escape'] = true
474
+ attributes['escape'] = true
421
475
  else
422
- if(attributes['pattern_escape'] == true)
476
+ if(attributes['escape'] == true)
423
477
  attributes['pattern'] << "\\#{character}"
424
- attributes['pattern_escape'] = false
478
+ attributes['escape'] = false
425
479
  else
426
480
  attributes['pattern'] << character
427
481
  end
@@ -701,17 +755,19 @@ module PipeText
701
755
  spaces.times do
702
756
  new_text << " "
703
757
  end
704
- when ']' # |]0-9 - end column number
758
+ when ']' # |]0-9* - end column number
705
759
  attributes['end_capture'] = true
706
760
  when '[' # |[emoji]
707
761
  attributes['emoji_capture'] = true
762
+ when '(' # |(variable) or |(variable=Some value)
763
+ attributes['variable_capture'] = true
708
764
  when '\\' # |\ - Escape mode
709
- attributes['pattern_escape'] = true
765
+ attributes['escape'] = true
710
766
  else # We didn't find the next character
711
767
  attributes['found'] = false
712
768
  end
713
769
  elsif(character == '\\')
714
- attributes['pattern_escape'] = true
770
+ attributes['escape'] = true
715
771
  else # We didn't find the next character
716
772
  attributes['found'] = false
717
773
  end
@@ -748,7 +804,7 @@ module PipeText
748
804
  end
749
805
  attributes['pipe'] = false
750
806
  end
751
- elsif(attributes['pattern_escape'] == false)
807
+ elsif(attributes['escape'] == false)
752
808
  attributes['pipe'] = false
753
809
  end
754
810
  end
@@ -4,6 +4,6 @@ module PipeText
4
4
 
5
5
  public
6
6
 
7
- VERSION = "0.1.5"
7
+ VERSION = "0.2.0"
8
8
  end
9
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pipetext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minaswan Nakamoto
@@ -37,7 +37,8 @@ description: "== Easily add colors, boxes, repetitions and emojis to your termin
37
37
  bell |[bell]\n Move cursor up 1 line |^ Hide cursor |h\n
38
38
  \ Move cursor down 1 line |v Unhide cursor |H\n Move cursor
39
39
  forward 1 character |> Sleep timer in seconds |[#s]\n Move cursor back
40
- 1 character |< Sleep timer in milliseconds |[#ms]\n---\n Emojis:
40
+ 1 character |< Sleep timer in milliseconds |[#ms]\n Capture variable
41
+ \ |(variable name=data) Display variable |(variable name)\n\n---\n Emojis:
41
42
  \ https://unicode.org/emoji/charts/full-emoji-list.html\n |[Abbreviated
42
43
  CLDR Short Name] \U0001F60D |[smiling face with heart-eyes] or\n ⚙ |[gear]
43
44
  \ \U0001F4A4 |[zzz] \U0001F468 |[man] \U0001F60D |[sm f w he e]\n ✔ |U2714