pipetext 0.1.5 → 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: 8913bda36e869217758103b0ceb485ec76b5ebac30ae1b126bcad79ed7f4c4cc
4
- data.tar.gz: 5b1dcc7770082b825b962fa3a7b2ab46dec40105eb61604ff3a27b0987190ee9
3
+ metadata.gz: b0ae63046e780049e0d20b63aab5604e11dcb8c0a3906e12c4db118bd317e5fd
4
+ data.tar.gz: 39edba4cb4b0b899c5692f57ee71e371254f3f2b199ee5a1207872cb89eb7ef3
5
5
  SHA512:
6
- metadata.gz: 0eff6ce751e2fc0a8043db2ce0e31071a17e6b3ccefeaca9e72decad10cada1dcd778f94c1d28d84351ee4870ada2ac46d6dbd0dd0b067b8bd967aaed8b8ff02
7
- data.tar.gz: d6f716f80d88ed75811ac841398dcb5bbfad125a61aebd13c8a07edf8c8665523157270cae8411163cdb9d91a87b3ab81d144a61bf33fbdde72258e24e04e6f7
6
+ metadata.gz: 84eae6ce6e8581f67281d46e34da26c427ebae034b6bfd3bfcc56f059569ad3366fdc74dd05db1cacd0ee9345fd4e28394d4be8923e3629421c2d8c2937eb507
7
+ data.tar.gz: cd59a5cca225c9819947601ad39449c7fc4d70576027f09721287ad215798a965a09847f329eda0f246fd89ce5fed8bacbfccc908bb96ce5812b33cb14097ed2
data/bin/pipetext CHANGED
@@ -33,13 +33,14 @@ pipetext_example = '|| pipe |||| && ampersand &&&& Toggle (&) backgrou
33
33
  |G&rbright green with red background&n |n||G&&r |xCrossed out|x ||x
34
34
  |n&nnormal color and background ||n&&n Escape sequence ||\\
35
35
 
36
+ Center text using current position and line end number ||{text to center}
36
37
  Add spaces to line end ||; Set line end ||]#
37
38
  Set current x,y cursor position ||[x,y] Terminal bell ||[bell]
38
39
  Move cursor up 1 line ||^ Hide cursor ||h
39
40
  Move cursor down 1 line ||v Unhide cursor ||H
40
41
  Move cursor forward 1 character ||> Sleep timer in seconds ||[#s]
41
42
  Move cursor back 1 character ||< Sleep timer in milliseconds ||[#ms]
42
-
43
+ Capture variable ||(variable name=data) Display variable ||(variable name)
43
44
 
44
45
  Emojis: https://unicode.org/emoji/charts/full-emoji-list.html
45
46
  ||[Abbreviated CLDR Short Name] |[smiling face with heart-eyes] ||[smiling face with heart-eyes] or
@@ -68,22 +69,21 @@ Longer repetition patterns using the character ~
68
69
  |3~ &r|----|O> ALL YOUR |kBASE|n |3\~ARE|3\~ BELONG TO US. <|----|O&n|\n~|n'
69
70
 
70
71
  if(ARGV[0] == nil && STDIN.tty? == true)
71
- puts "#{File.basename(__FILE__)} <filename> | <pipetext>"
72
+ puts "PipeText capabilities:"
72
73
  puts
73
- puts "Example usage:"
74
+ pipe.paint(pipetext_example)
75
+ puts "Command Syntax: #{File.basename(__FILE__)} <filename> | <pipetext>"
76
+ puts "Example usages:"
74
77
  puts
75
78
  puts "pipetext '|RBright red|n, |cCyan|n, |g&rGreen and Red|n,&n Normal |R|u1f49c |g|U2714|n'"
76
- puts
77
79
  puts "pipetext '|50-'"
78
- puts
79
80
  puts "pipetext '|-|50-'"
80
- puts
81
- puts "pipetext '|]50Insert spaces until end (50)|;Add After'"
82
- puts
81
+ puts "pipetext '|]50Insert spaces until end (50)|W|{centered}|n|;Add After'"
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)'"
83
84
  puts "pipetext '|10~ &r|----|O> ALL YOUR |kBASE|n |3\\~ARE|3\\~ BELONG TO US. <|----|O&n|\\n~|n'"
84
85
  puts
85
- pipe.paint(pipetext_example)
86
- pipe.paint("PipeText Version |c#{PipeText::VERSION}|n")
86
+ pipe.paint("version |c#{PipeText::VERSION}|n")
87
87
  else
88
88
  if(STDIN.tty? == false)
89
89
  pipe.paint(STDIN.read)
@@ -6,37 +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
- 'emoji_capture' => false, # Used to capture emoji description or bell/move to position
29
- 'emoji' => String.new, # Used to capture emoji description or bell/move to position
30
- 'unicode_capture' => 0, # Used to capture Unicode using 6 character UTF-16 hex format
31
- 'unicode' => String.new,
32
- 'palette_capture' => 0, # Used to capture 8-bit color using 2 character hex format
33
- 'p' => String.new, # |p00 to |pFF
34
- 'color_capture' => 0, # Used to capture RGB color using #RRGGBB format
35
- 'r' => String.new,
36
- 'g' => String.new,
37
- 'b' => String.new,
38
- 'fg' => String.new, # Needed to restore after background change
39
- '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
40
46
  }
41
47
  end
42
48
 
@@ -44,6 +50,11 @@ module PipeText
44
50
  new_text = String.new
45
51
  text.chars.each do |character|
46
52
  process_character(character, new_text, attributes)
53
+ if(new_text =~ /\n(.*)$/)
54
+ attributes['position'] = printable_length($1)
55
+ else
56
+ attributes['position'] += printable_length(new_text)
57
+ end
47
58
  end
48
59
  # Clean up in case we've captured something we didn't process yet
49
60
  if(attributes['color_capture'] > 0)
@@ -54,6 +65,10 @@ module PipeText
54
65
  emit_unicode(new_text, attributes)
55
66
  elsif(attributes['emoji_capture'] == true)
56
67
  new_text << "|[" + attributes['emoji']
68
+ elsif(attributes['center_capture'] == true)
69
+ new_text << "|{" + attributes['center']
70
+ elsif(attributes['variable_capture'] == true)
71
+ new_text << "|(" + attributes['variable']
57
72
  end
58
73
  return new_text
59
74
  end
@@ -62,13 +77,51 @@ module PipeText
62
77
  pipe(text, pipetext_init(box_mode, ampersand_mode))
63
78
  end
64
79
 
80
+ # Immediate output to screen, no string buffer
81
+ def fastpipe(text, attributes)
82
+ new_text = String.new
83
+ text.chars.each do |character|
84
+ process_character(character, new_text, attributes)
85
+ if(new_text != "")
86
+ print(new_text)
87
+ if(new_text =~ /\n(.*)$/)
88
+ attributes['position'] = printable_length($1)
89
+ else
90
+ attributes['position'] += printable_length(new_text)
91
+ end
92
+ new_text = String.new
93
+ end
94
+ end
95
+ # Clean up in case we've captured something we didn't process yet
96
+ if(attributes['color_capture'] > 0)
97
+ emit_color(new_text, attributes)
98
+ elsif(attributes['palette_capture'] > 0)
99
+ emit_palette_color(new_text, attributes)
100
+ elsif(attributes['unicode_capture'] > 0)
101
+ emit_unicode(new_text, attributes)
102
+ elsif(attributes['emoji_capture'] == true)
103
+ new_text << "|[" + attributes['emoji']
104
+ elsif(attributes['center_capture'] == true)
105
+ new_text << "|{" + attributes['center']
106
+ elsif(attributes['variable_capture'] == true)
107
+ new_text << "|(" + attributes['variable']
108
+ end
109
+ print(new_text)
110
+ end
111
+
112
+ def fastpipetext(text, box_mode=true, ampersand_mode=false)
113
+ fastpipe(text, pipetext_init(box_mode, ampersand_mode))
114
+ end
115
+
65
116
  def write(text, box_mode=true, ampersand_mode=false)
66
- puts(pipetext(text, box_mode, ampersand_mode))
117
+ fastpipetext(text, box_mode, ampersand_mode)
118
+ puts
67
119
  end
68
120
 
69
121
  # Defaults to using & for background colors
70
122
  def paint(text, box_mode=true, ampersand_mode=true)
71
- puts(pipetext(text, box_mode, ampersand_mode))
123
+ fastpipetext(text, box_mode, ampersand_mode)
124
+ puts
72
125
  end
73
126
 
74
127
  def ignored_character(character, ignored_characters)
@@ -159,17 +212,36 @@ module PipeText
159
212
  end
160
213
  attributes['num'] += character.to_i
161
214
  end
162
- elsif(character == '|' && attributes['repeat_pattern'] == false)
163
- process_pipe(character, new_text, attributes)
164
- elsif(character == '~' && attributes['pipe'] == true &&
165
- attributes['num'] > 0 && attributes['pattern_escape'] == false)
166
- process_repeat_pattern(character, new_text, attributes)
167
- elsif(attributes['repeat_pattern'] == true)
168
- capture_character_pattern(character, attributes)
169
- elsif(attributes['color_capture'] > 0 && character =~ /[0-9,A-F,a-f]/)
170
- capture_color(character, new_text, attributes)
171
- elsif(attributes['palette_capture'] > 0 && character =~ /[0-9,A-F,a-f]/)
172
- 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
232
+ elsif(attributes['center_capture'] == true)
233
+ if(character == '\\')
234
+ attributes['escape'] = true
235
+ else
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
244
+ end
173
245
  elsif(attributes['emoji_capture'] == true)
174
246
  if(character == ']')
175
247
  if(attributes['emoji'] =~ /bell/)
@@ -194,13 +266,24 @@ module PipeText
194
266
  else
195
267
  attributes['emoji'] << character
196
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)
197
280
  elsif(attributes['unicode_capture'] == 1 && character == '+') # Skip
198
281
  return
199
282
  elsif(attributes['unicode_capture'] > 0 && character =~ /[0-9,A-F,a-f]/)
200
283
  capture_unicode(character, new_text, attributes)
201
284
  elsif(attributes['pipe'] == true &&
202
285
  attributes['repeat_pattern'] == false &&
203
- attributes['pattern_escape'] == true)
286
+ attributes['escape'] == true)
204
287
  process_escaped_character(character, new_text, attributes)
205
288
  elsif(character == '&' && attributes['ampersand_mode'] == true &&
206
289
  attributes['pipe'] == false)
@@ -254,6 +337,41 @@ module PipeText
254
337
  attributes['unicode'] = String.new
255
338
  end
256
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
+
359
+ def emit_center(new_text, attributes)
360
+ spaces = attributes['end'] - attributes['position'] - printable_length(attributes['center'])
361
+ if(printable_length(attributes['center']) % 2)
362
+ spaces += 1
363
+ end
364
+ if(spaces > 0)
365
+ spaces /= 2
366
+ spaces.times do
367
+ new_text << " "
368
+ end
369
+ end
370
+ new_text << attributes['center']
371
+ attributes['center_capture'] = false
372
+ attributes['center'] = String.new
373
+ end
374
+
257
375
  def emit_emoji(new_text, attributes)
258
376
  emoji = String.new
259
377
  match_length = 0
@@ -305,7 +423,7 @@ module PipeText
305
423
  end
306
424
  attributes['num'] = 0
307
425
  attributes['pipe'] = false
308
- attributes['pattern_escape'] = false
426
+ attributes['escape'] = false
309
427
  attributes['repeat_pattern'] = false
310
428
  attributes['pattern'] = String.new
311
429
  else # ~ after number in |5~Repeat 5 times~
@@ -315,7 +433,8 @@ module PipeText
315
433
 
316
434
  def escape_fix(text) # Done this way for old Ruby versions
317
435
  text = text.gsub(/\\a/, "\a").gsub(/\\b/, "\b").gsub(/\\e/, "\e").gsub(/\\f/, "\f")
318
- 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(/\\\)/, ')')
319
438
  end
320
439
 
321
440
  def process_escaped_character(character, new_text, attributes)
@@ -328,7 +447,7 @@ module PipeText
328
447
  end
329
448
  attributes['num'] = 0
330
449
  attributes['pipe'] = false
331
- attributes['pattern_escape'] = false
450
+ attributes['escape'] = false
332
451
  attributes['pattern'] = String.new
333
452
  attributes['repeat_pattern'] = false
334
453
  end
@@ -352,11 +471,11 @@ module PipeText
352
471
 
353
472
  def capture_character_pattern(character, attributes)
354
473
  if(character == '\\')
355
- attributes['pattern_escape'] = true
474
+ attributes['escape'] = true
356
475
  else
357
- if(attributes['pattern_escape'] == true)
476
+ if(attributes['escape'] == true)
358
477
  attributes['pattern'] << "\\#{character}"
359
- attributes['pattern_escape'] = false
478
+ attributes['escape'] = false
360
479
  else
361
480
  attributes['pattern'] << character
362
481
  end
@@ -629,26 +748,26 @@ module PipeText
629
748
  else # We didn't find the next character
630
749
  attributes['found'] = false
631
750
  end
751
+ when '{' # center
752
+ attributes['center_capture'] = true
632
753
  when ';' # extend to end column with spaces
633
- if(new_text =~ /\n?(.*)\Z/)
634
- spaces = attributes['end'] - printable_length($1)
635
- else
636
- spaces = attributes['end']
637
- end
754
+ spaces = attributes['end'] - attributes['position']
638
755
  spaces.times do
639
756
  new_text << " "
640
757
  end
641
- when ']' # |]0-9 - end column number
758
+ when ']' # |]0-9* - end column number
642
759
  attributes['end_capture'] = true
643
760
  when '[' # |[emoji]
644
761
  attributes['emoji_capture'] = true
762
+ when '(' # |(variable) or |(variable=Some value)
763
+ attributes['variable_capture'] = true
645
764
  when '\\' # |\ - Escape mode
646
- attributes['pattern_escape'] = true
765
+ attributes['escape'] = true
647
766
  else # We didn't find the next character
648
767
  attributes['found'] = false
649
768
  end
650
769
  elsif(character == '\\')
651
- attributes['pattern_escape'] = true
770
+ attributes['escape'] = true
652
771
  else # We didn't find the next character
653
772
  attributes['found'] = false
654
773
  end
@@ -685,7 +804,7 @@ module PipeText
685
804
  end
686
805
  attributes['pipe'] = false
687
806
  end
688
- elsif(attributes['pattern_escape'] == false)
807
+ elsif(attributes['escape'] == false)
689
808
  attributes['pipe'] = false
690
809
  end
691
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.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minaswan Nakamoto
@@ -31,12 +31,14 @@ description: "== Easily add colors, boxes, repetitions and emojis to your termin
31
31
  \ Italics |~\n bright red with blue background |R&b Bold |+\n
32
32
  \ green with yellow background |g&y Faint |.\n bright green
33
33
  with red background |G&r Crossed out |x\n normal color and background
34
- \ |n&n Escape Sequence |\\\n\n Add spaces to line end |;
34
+ \ |n&n Escape Sequence |\\\n\n Center text using current position and
35
+ line end number |{text to center}\n Add spaces to line end |;
35
36
  \ Set line end |]#\n Set current x,y cursor position |[x,y] Terminal
36
37
  bell |[bell]\n Move cursor up 1 line |^ Hide cursor |h\n
37
38
  \ Move cursor down 1 line |v Unhide cursor |H\n Move cursor
38
39
  forward 1 character |> Sleep timer in seconds |[#s]\n Move cursor back
39
- 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:
40
42
  \ https://unicode.org/emoji/charts/full-emoji-list.html\n |[Abbreviated
41
43
  CLDR Short Name] \U0001F60D |[smiling face with heart-eyes] or\n ⚙ |[gear]
42
44
  \ \U0001F4A4 |[zzz] \U0001F468 |[man] \U0001F60D |[sm f w he e]\n ✔ |U2714