pipetext 0.1.6 → 0.2.1

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: 0f7f0d849921eef214577fe5b3418bcda0815b9158de41079c5ded31beb06e39
4
+ data.tar.gz: 31623762e3303061e8753b07a4a44b5efbd1eda8748fb411871ca643b54dbe6f
5
5
  SHA512:
6
- metadata.gz: b197769b04cb90d36106524f18d7e8459ad0dd96358a6a7bbc350c3c4572fcd204ff25834f67c730b0676a4e4f3b55462a120367a9e23d5e93e93fd3a8754aba
7
- data.tar.gz: 27a1232cfb0ad1be0d5d6b641ee633e44846200a1ba69c42f28f997c5cf6b0769923171aee4bb764f9aab6f0a58be973fcb8b3a6d403e06431d053fbcc8eef05
6
+ metadata.gz: 500918c7d15469238f5c1f3424570a759cabd9a80dbbd8c2faec1b781ce44cbabcb1ea0c4cfdf19a6914b2f80d3d5e88136f7f0f68ec1fe1ab26eee1adb1afc0
7
+ data.tar.gz: 41a068587aed07e5c3fc360497c8296640509951e12d6d513e3cf8c89a88c43c9ea5f1517a3a373ec12eb0a470de32901b2b79575aa46c30ad0802e73807af7f
data/bin/pipetext CHANGED
@@ -38,9 +38,12 @@ Add spaces to line end ||; Set line end ||]#
38
38
  Set current x,y cursor position ||[x,y] Terminal bell ||[bell]
39
39
  Move cursor up 1 line ||^ Hide cursor ||h
40
40
  Move cursor down 1 line ||v Unhide cursor ||H
41
- Move cursor forward 1 character ||> Sleep timer in seconds ||[#s]
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
+ Add to variable ||(variable name+=data) Subtract from variable ||(variable name-=data)
45
+ Multiple variable ||(variable name*=data) Divide variable ||(variable name/=data)
46
+ Copy variable to current number ||(#variable name)
44
47
 
45
48
  Emojis: https://unicode.org/emoji/charts/full-emoji-list.html
46
49
  ||[Abbreviated CLDR Short Name] |[smiling face with heart-eyes] ||[smiling face with heart-eyes] or
@@ -69,22 +72,22 @@ Longer repetition patterns using the character ~
69
72
  |3~ &r|----|O> ALL YOUR |kBASE|n |3\~ARE|3\~ BELONG TO US. <|----|O&n|\n~|n'
70
73
 
71
74
  if(ARGV[0] == nil && STDIN.tty? == true)
72
- puts "#{File.basename(__FILE__)} <filename> | <pipetext>"
75
+ puts "PipeText capabilities:"
73
76
  puts
74
- puts "Example usage:"
77
+ pipe.paint(pipetext_example)
78
+ puts "Command Syntax: #{File.basename(__FILE__)} <filename> | <pipetext>"
79
+ puts "Example usages:"
75
80
  puts
76
81
  puts "pipetext '|RBright red|n, |cCyan|n, |g&rGreen and Red|n,&n Normal |R|u1f49c |g|U2714|n'"
77
- puts
78
82
  puts "pipetext '|50-'"
79
- puts
80
83
  puts "pipetext '|-|50-'"
81
- puts
82
84
  puts "pipetext '|]50Insert spaces until end (50)|W|{centered}|n|;Add After'"
83
- puts
85
+ puts "pipetext 'Capture a variable named gear line|(gear line=|r|[gear]|n|-|60-|O|r|[gear]|n)|\\n" +
86
+ "|(gear line)|\\n|(gear line)|\\n|(gear line)|\\n||(gear line) = |(gear line)'"
87
+ puts "pipetext '|(test=15)Print 10 stars: |(#test-=5)* and 20 hashes: |(#test+=5)#'"
84
88
  puts "pipetext '|10~ &r|----|O> ALL YOUR |kBASE|n |3\\~ARE|3\\~ BELONG TO US. <|----|O&n|\\n~|n'"
85
89
  puts
86
- pipe.paint(pipetext_example)
87
- pipe.paint("PipeText Version |c#{PipeText::VERSION}|n")
90
+ pipe.paint("version |c#{PipeText::VERSION}|n")
88
91
  else
89
92
  if(STDIN.tty? == false)
90
93
  pipe.paint(STDIN.read)
@@ -6,41 +6,47 @@ 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
  }
47
+ attributes['variables']['height'] = `tput lines`.chomp
48
+ attributes['variables']['width'] = `tput cols`.chomp
49
+ return attributes
44
50
  end
45
51
 
46
52
  def pipe(text, attributes)
@@ -64,6 +70,8 @@ module PipeText
64
70
  new_text << "|[" + attributes['emoji']
65
71
  elsif(attributes['center_capture'] == true)
66
72
  new_text << "|{" + attributes['center']
73
+ elsif(attributes['variable_capture'] == true)
74
+ new_text << "|(" + attributes['variable']
67
75
  end
68
76
  return new_text
69
77
  end
@@ -98,6 +106,8 @@ module PipeText
98
106
  new_text << "|[" + attributes['emoji']
99
107
  elsif(attributes['center_capture'] == true)
100
108
  new_text << "|{" + attributes['center']
109
+ elsif(attributes['variable_capture'] == true)
110
+ new_text << "|(" + attributes['variable']
101
111
  end
102
112
  print(new_text)
103
113
  end
@@ -195,32 +205,45 @@ module PipeText
195
205
  attributes['end_capture'] = false
196
206
  end
197
207
  if(attributes['end_capture'] == true && character =~ /[0-9]/)
198
- if(character == '0') # |10+
208
+ if(character == '0') # |10+
199
209
  if(attributes['num'] > 0)
200
210
  attributes['num'] *= 10
201
211
  end
202
- elsif(character >= '1' && character <= '9') # |1+ through |9+
212
+ elsif(character >= '1' && character <= '9') # |1+ through |9+
203
213
  if(attributes['num'] > 0)
204
214
  attributes['num'] *= 10
205
215
  end
206
216
  attributes['num'] += character.to_i
207
217
  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)
218
+ elsif(character == ')' && attributes['variable_capture'] == true && attributes['escape'] == false)
219
+ if(attributes['variable'] =~ /=/ && attributes['variable'][0] != '#') # Update
220
+ update_variable(attributes)
221
+ else # Display
222
+ emit_variable(new_text, attributes)
223
+ end
224
+ elsif(attributes['variable_capture'] == true)
225
+ if(character == '\\')
226
+ attributes['escape'] = true
227
+ else
228
+ if(attributes['escape'] == true)
229
+ attributes['variable'] << "\\#{character}"
230
+ attributes['escape'] = false
231
+ else
232
+ attributes['variable'] << character
233
+ end
234
+ end
219
235
  elsif(attributes['center_capture'] == true)
220
- if(character == '}')
221
- emit_center(new_text, attributes)
236
+ if(character == '\\')
237
+ attributes['escape'] = true
222
238
  else
223
- attributes['center'] << character
239
+ if(attributes['escape'] == true)
240
+ attributes['center'] << "\\#{character}"
241
+ attributes['escape'] = false
242
+ elsif(character == '}')
243
+ emit_center(new_text, attributes)
244
+ else
245
+ attributes['center'] << character
246
+ end
224
247
  end
225
248
  elsif(attributes['emoji_capture'] == true)
226
249
  if(character == ']')
@@ -246,13 +269,24 @@ module PipeText
246
269
  else
247
270
  attributes['emoji'] << character
248
271
  end
272
+ elsif(character == '|' && attributes['repeat_pattern'] == false)
273
+ process_pipe(character, new_text, attributes)
274
+ elsif(character == '~' && attributes['pipe'] == true &&
275
+ attributes['num'] > 0 && attributes['escape'] == false)
276
+ process_repeat_pattern(character, new_text, attributes)
277
+ elsif(attributes['repeat_pattern'] == true)
278
+ capture_character_pattern(character, attributes)
279
+ elsif(attributes['color_capture'] > 0 && character =~ /[0-9,A-F,a-f]/)
280
+ capture_color(character, new_text, attributes)
281
+ elsif(attributes['palette_capture'] > 0 && character =~ /[0-9,A-F,a-f]/)
282
+ capture_palette_color(character, new_text, attributes)
249
283
  elsif(attributes['unicode_capture'] == 1 && character == '+') # Skip
250
284
  return
251
285
  elsif(attributes['unicode_capture'] > 0 && character =~ /[0-9,A-F,a-f]/)
252
286
  capture_unicode(character, new_text, attributes)
253
287
  elsif(attributes['pipe'] == true &&
254
288
  attributes['repeat_pattern'] == false &&
255
- attributes['pattern_escape'] == true)
289
+ attributes['escape'] == true)
256
290
  process_escaped_character(character, new_text, attributes)
257
291
  elsif(character == '&' && attributes['ampersand_mode'] == true &&
258
292
  attributes['pipe'] == false)
@@ -306,8 +340,82 @@ module PipeText
306
340
  attributes['unicode'] = String.new
307
341
  end
308
342
 
343
+ def number?(text)
344
+ text.chars.each do |character|
345
+ if(character !~ /[0-9 ]/)
346
+ return false
347
+ end
348
+ end
349
+ return true
350
+ end
351
+
352
+ def update_variable(attributes)
353
+ if(attributes['variable'] =~ /(.*)\-=(.*)/)
354
+ if(!number?($2) || !number?(attributes['variables'][$1]))
355
+ attributes['variables'][$1].slice!($2)
356
+ elsif(attributes['variable'] =~ /(.*) \-= ?(.*)/ || attributes['variable'] =~ /(.*)\-= ?(.*)/)
357
+ value = attributes['variables'][$1].to_i - $2.to_i
358
+ attributes['variables'][$1] = value.to_s
359
+ end
360
+ elsif(attributes['variable'] =~ /(.*)\+=(.*)/)
361
+ if(!number?($2) || !number?(attributes['variables'][$1]))
362
+ attributes['variables'][$1] += $2
363
+ elsif(attributes['variable'] =~ /(.*) \+= ?(.*)/ || attributes['variable'] =~ /(.*)\+= ?(.*)/)
364
+ value = attributes['variables'][$1].to_i + $2.to_i
365
+ attributes['variables'][$1] = value.to_s
366
+ end
367
+ elsif(attributes['variable'] =~ /(.*) \*= ?(.*)/ || attributes['variable'] =~ /(.*)\*= ?(.*)/)
368
+ value = attributes['variables'][$1].to_i * $2.to_i
369
+ attributes['variables'][$1] = value.to_s
370
+ elsif(attributes['variable'] =~ /(.*) \/= ?(.*)/ || attributes['variable'] =~ /(.*)\/= ?(.*)/)
371
+ value = attributes['variables'][$1].to_i / $2.to_i
372
+ attributes['variables'][$1] = value.to_s
373
+ elsif(attributes['variable'] =~ /(.*) = ?(.*)/ || attributes['variable'] =~ /(.*)= ?(.*)/)
374
+ attributes['variables'][$1] = $2
375
+ end
376
+ attributes['variable_capture'] = false
377
+ attributes['variable'] = String.new
378
+ end
379
+
380
+ def emit_variable(new_text, attributes)
381
+ if(attributes['variable'][0] == '#') # We are manipulating attributes['num']
382
+ if(attributes['variable'][1..-1] =~ /(.*) \-= ?(.*)/ ||
383
+ attributes['variable'][1..-1] =~ /(.*)\-= ?(.*)/)
384
+ attributes['num'] = pipetext(escape_fix(attributes['variables'][$1]), attributes['box_mode'],
385
+ attributes['ampersand_mode']).to_i - $2.to_i
386
+ elsif(attributes['variable'][1..-1] =~ /(.*) \+= ?(.*)/ ||
387
+ attributes['variable'][1..-1] =~ /(.*)\+= ?(.*)/)
388
+ attributes['num'] = pipetext(escape_fix(attributes['variables'][$1]), attributes['box_mode'],
389
+ attributes['ampersand_mode']).to_i + $2.to_i
390
+ elsif(attributes['variable'][1..-1] =~ /(.*) \*= ?(.*)/ ||
391
+ attributes['variable'][1..-1] =~ /(.*)\*= ?(.*)/)
392
+ attributes['num'] = pipetext(escape_fix(attributes['variables'][$1]), attributes['box_mode'],
393
+ attributes['ampersand_mode']).to_i * $2.to_i
394
+ elsif(attributes['variable'][1..-1] =~ /(.*) \/= ?(.*)/ ||
395
+ attributes['variable'][1..-1] =~ /(.*)\/= ?(.*)/)
396
+ attributes['num'] = pipetext(escape_fix(attributes['variables'][$1]), attributes['box_mode'],
397
+ attributes['ampersand_mode']).to_i / $2.to_i
398
+ else
399
+ attributes['num'] = pipetext(escape_fix(attributes['variables'][attributes['variable'][1..-1]]),
400
+ attributes['box_mode'], attributes['ampersand_mode']).to_i
401
+ end
402
+ attributes['pipe'] = true
403
+ attributes['found'] = false
404
+ elsif(attributes['variables'][attributes['variable']])
405
+ new_text << pipetext(escape_fix(attributes['variables'][attributes['variable']]),
406
+ attributes['box_mode'], attributes['ampersand_mode'])
407
+ else
408
+ new_text << "|(" + attributes['variable'] + ")"
409
+ end
410
+ attributes['variable_capture'] = false
411
+ attributes['variable'] = String.new
412
+ end
413
+
309
414
  def emit_center(new_text, attributes)
310
415
  spaces = attributes['end'] - attributes['position'] - printable_length(attributes['center'])
416
+ if(printable_length(attributes['center']) % 2)
417
+ spaces += 1
418
+ end
311
419
  if(spaces > 0)
312
420
  spaces /= 2
313
421
  spaces.times do
@@ -370,7 +478,7 @@ module PipeText
370
478
  end
371
479
  attributes['num'] = 0
372
480
  attributes['pipe'] = false
373
- attributes['pattern_escape'] = false
481
+ attributes['escape'] = false
374
482
  attributes['repeat_pattern'] = false
375
483
  attributes['pattern'] = String.new
376
484
  else # ~ after number in |5~Repeat 5 times~
@@ -380,7 +488,8 @@ module PipeText
380
488
 
381
489
  def escape_fix(text) # Done this way for old Ruby versions
382
490
  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(/\\~/, '~')
491
+ text = text.gsub(/\\n/, "\n").gsub(/\\r/, "\r").gsub(/\\t/, "\t").gsub(/\\v/, "\v")
492
+ text = text.gsub(/\\~/, '~').gsub(/\\\(/, '(').gsub(/\\\)/, ')')
384
493
  end
385
494
 
386
495
  def process_escaped_character(character, new_text, attributes)
@@ -393,7 +502,7 @@ module PipeText
393
502
  end
394
503
  attributes['num'] = 0
395
504
  attributes['pipe'] = false
396
- attributes['pattern_escape'] = false
505
+ attributes['escape'] = false
397
506
  attributes['pattern'] = String.new
398
507
  attributes['repeat_pattern'] = false
399
508
  end
@@ -417,11 +526,11 @@ module PipeText
417
526
 
418
527
  def capture_character_pattern(character, attributes)
419
528
  if(character == '\\')
420
- attributes['pattern_escape'] = true
529
+ attributes['escape'] = true
421
530
  else
422
- if(attributes['pattern_escape'] == true)
531
+ if(attributes['escape'] == true)
423
532
  attributes['pattern'] << "\\#{character}"
424
- attributes['pattern_escape'] = false
533
+ attributes['escape'] = false
425
534
  else
426
535
  attributes['pattern'] << character
427
536
  end
@@ -701,17 +810,19 @@ module PipeText
701
810
  spaces.times do
702
811
  new_text << " "
703
812
  end
704
- when ']' # |]0-9 - end column number
813
+ when ']' # |]0-9* - end column number
705
814
  attributes['end_capture'] = true
706
815
  when '[' # |[emoji]
707
816
  attributes['emoji_capture'] = true
817
+ when '(' # |(variable) or |(variable=Some value)
818
+ attributes['variable_capture'] = true
708
819
  when '\\' # |\ - Escape mode
709
- attributes['pattern_escape'] = true
820
+ attributes['escape'] = true
710
821
  else # We didn't find the next character
711
822
  attributes['found'] = false
712
823
  end
713
824
  elsif(character == '\\')
714
- attributes['pattern_escape'] = true
825
+ attributes['escape'] = true
715
826
  else # We didn't find the next character
716
827
  attributes['found'] = false
717
828
  end
@@ -748,7 +859,7 @@ module PipeText
748
859
  end
749
860
  attributes['pipe'] = false
750
861
  end
751
- elsif(attributes['pattern_escape'] == false)
862
+ elsif(attributes['escape'] == false)
752
863
  attributes['pipe'] = false
753
864
  end
754
865
  end
@@ -4,6 +4,6 @@ module PipeText
4
4
 
5
5
  public
6
6
 
7
- VERSION = "0.1.5"
7
+ VERSION = "0.2.1"
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minaswan Nakamoto
@@ -36,8 +36,12 @@ description: "== Easily add colors, boxes, repetitions and emojis to your termin
36
36
  \ Set line end |]#\n Set current x,y cursor position |[x,y] Terminal
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
- forward 1 character |> Sleep timer in seconds |[#s]\n Move cursor back
40
- 1 character |< Sleep timer in milliseconds |[#ms]\n---\n Emojis:
39
+ forward 1 character |> Sleep timer in seconds |[#s]\n Move cursor
40
+ back 1 character |< Sleep timer in milliseconds |[#ms]\n Capture
41
+ variable |(variable name=data) Display variable |(variable name)\n
42
+ \ Add to variable |(variable name+=data) Subtract from variable |(variable
43
+ name-=data)\n Multiple variable |(variable name*=data) Divide variable |(variable
44
+ name/=data)\n Copy variable to current number |(#variable name)\n\n---\n Emojis:
41
45
  \ https://unicode.org/emoji/charts/full-emoji-list.html\n |[Abbreviated
42
46
  CLDR Short Name] \U0001F60D |[smiling face with heart-eyes] or\n ⚙ |[gear]
43
47
  \ \U0001F4A4 |[zzz] \U0001F468 |[man] \U0001F60D |[sm f w he e]\n ✔ |U2714