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 +4 -4
- data/bin/pipetext +8 -9
- data/lib/pipetext/pipetext.rb +115 -59
- data/lib/pipetext/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b0ae63046e780049e0d20b63aab5604e11dcb8c0a3906e12c4db118bd317e5fd
|
|
4
|
+
data.tar.gz: 39edba4cb4b0b899c5692f57ee71e371254f3f2b199ee5a1207872cb89eb7ef3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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 "
|
|
72
|
+
puts "PipeText capabilities:"
|
|
73
73
|
puts
|
|
74
|
-
|
|
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(
|
|
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)
|
data/lib/pipetext/pipetext.rb
CHANGED
|
@@ -6,40 +6,43 @@ module PipeText
|
|
|
6
6
|
|
|
7
7
|
def pipetext_init(box_mode=true, ampersand_mode=false)
|
|
8
8
|
attributes = {
|
|
9
|
-
'pipe'
|
|
10
|
-
'repeat_pattern'
|
|
11
|
-
'pattern'
|
|
12
|
-
'
|
|
13
|
-
'ampersand'
|
|
14
|
-
'ampersand_mode'
|
|
15
|
-
'blink'
|
|
16
|
-
'bold'
|
|
17
|
-
'crossed_out'
|
|
18
|
-
'faint'
|
|
19
|
-
'found'
|
|
20
|
-
'italic'
|
|
21
|
-
'inverse'
|
|
22
|
-
'underline'
|
|
23
|
-
'box'
|
|
24
|
-
'box_mode'
|
|
25
|
-
'num'
|
|
26
|
-
'end_capture'
|
|
27
|
-
'end'
|
|
28
|
-
'position'
|
|
29
|
-
'center_capture'
|
|
30
|
-
'center'
|
|
31
|
-
'
|
|
32
|
-
'
|
|
33
|
-
'
|
|
34
|
-
'
|
|
35
|
-
'
|
|
36
|
-
'
|
|
37
|
-
'
|
|
38
|
-
'
|
|
39
|
-
'
|
|
40
|
-
'
|
|
41
|
-
'
|
|
42
|
-
'
|
|
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 == '
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
-
|
|
233
|
+
if(character == '\\')
|
|
234
|
+
attributes['escape'] = true
|
|
222
235
|
else
|
|
223
|
-
attributes['
|
|
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['
|
|
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['
|
|
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")
|
|
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['
|
|
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['
|
|
474
|
+
attributes['escape'] = true
|
|
421
475
|
else
|
|
422
|
-
if(attributes['
|
|
476
|
+
if(attributes['escape'] == true)
|
|
423
477
|
attributes['pattern'] << "\\#{character}"
|
|
424
|
-
attributes['
|
|
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['
|
|
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['
|
|
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['
|
|
807
|
+
elsif(attributes['escape'] == false)
|
|
752
808
|
attributes['pipe'] = false
|
|
753
809
|
end
|
|
754
810
|
end
|
data/lib/pipetext/version.rb
CHANGED
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.
|
|
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
|
|
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
|