pipetext 0.1.2 → 0.1.4

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/pipetext +12 -3
  3. data/lib/pipetext.rb +92 -11
  4. metadata +8 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5883f76759f24059807937e5e3b245bb2994b69a196b1c9be7377500ec77f9b8
4
- data.tar.gz: 2af581984d9692051ad962fc3e66328e97af653eec3479b0b33c4d84119cc795
3
+ metadata.gz: 6fc9491b4fce47f35c9169cada5aa9f17c64c230f1e8d82946ac1fa7f8f448a7
4
+ data.tar.gz: b064d18f993760700a51d4dfb1edc47439ceec32506c4dca9207ab5f23e714d4
5
5
  SHA512:
6
- metadata.gz: 3b46368967758946d1b61e724dafa60e32272e04360fbe05fef35713708f6125175d45d77e3aca92bbb3cb4badc360f60614a21d4b50e1d2c9a4aefacd928bb3
7
- data.tar.gz: 85214ee6cb603c8a42b2cb32c09ccdc65b8cf0908246cc7134ac3669a1d038e9517a771b46e8feab7bfa79e55be2eedf4886461de68d31c682e50b2c57094ee1
6
+ metadata.gz: d4e9bbb7c99ad5a004a75e5c5f256ccbdd3d15ab2b7679b7760fcc2ffa4800fa569d7c2ca08d4ab06645225254c5313e711cee9cfd8f4c6a2a4e9732d325d834
7
+ data.tar.gz: 2fa9b749fa9cefb19979d88b86d2c1372bb5671d81fbbda5a26d3ee2d864153c6410ae1e49bf836c493d0ca87f8ed6cf2b068c61ea516fe65e5c4028dbfe462b
data/bin/pipetext CHANGED
@@ -8,7 +8,7 @@ require_relative '../lib/pipetext'
8
8
 
9
9
  pipe = Class.new.extend(PipeText)
10
10
 
11
- pipetext_example = '|| pipe |||| && ampersand &&&& |&Toggle (&) background color mode ||&|&
11
+ pipetext_example = '|| pipe |||| && ampersand &&&& Toggle (&) background color mode ||&
12
12
  |ssmoke |n||s |wwhite |n||W |k&wblack text on white background&n|n ||k&&w
13
13
  |rred |n||r |Rbright red |n||R &rred background&n &&r
14
14
  |ggreen |n||g |Gbright green |n||G &ggreen background&n &&g
@@ -17,7 +17,7 @@ pipetext_example = '|| pipe |||| && ampersand &&&& |&Toggle (&) backgr
17
17
  |yyellow |n||y |Ybright yellow |n||Y &yyellow background&n &&y
18
18
  |mmagenta |n||m |Mbright magenta |n||M &mmagenta background&n &&m
19
19
  |#FFFFFF&#555555Hex RGB color codes:|n&n Foreground ||#RRGGBB Background &&#RRGGBB
20
- |p33&pF8Palette colors (256) using Hex:|n&n ||p33&&pF8 Clear Screen ||!
20
+ |p33&pF8Palette colors (256) using Hex:|n&n ||p33&&pF8 Clear screen ||!
21
21
  |K&wblack with white background&n |n||K&&w |@Blink|@ing ||@
22
22
  |w&mwhite with magenta background&n |n||w&&m |w&mi|invert&n|i ||i
23
23
  |s&gsmoke with green background&n |n||s&&g |_Underline|_d ||_
@@ -25,7 +25,14 @@ pipetext_example = '|| pipe |||| && ampersand &&&& |&Toggle (&) backgr
25
25
  |R&bbright red with blue background&n |n||R&&b |+Bold|+ ||+
26
26
  |g&ygreen with yellow background&n |n||g&&y |.Faint|. ||.
27
27
  |G&rbright green with red background&n |n||G&&r |xCrossed out|x ||x
28
- |n&nnormal color and background ||n&&n Escape Sequence ||\\
28
+ |n&nnormal color and background ||n&&n Escape sequence ||\\
29
+
30
+ Add spaces to line end ||; Set line end ||]#
31
+ Set current x,y cursor position ||[x,y] Terminal bell ||[bell]
32
+ Move cursor up 1 line ||^ Hide cursor ||h
33
+ Move cursor down 1 line ||v Unhide cursor ||H
34
+ Move cursor forward 1 character ||>
35
+ Move cursor back 1 character ||< Sleep timer in float seconds ||[#.#z]
29
36
 
30
37
  Emojis: https://unicode.org/emoji/charts/full-emoji-list.html
31
38
  ||[Abbreviated CLDR Short Name] |[smiling face with heart-eyes] ||[smiling face with heart-eyes] or
@@ -64,6 +71,8 @@ if(ARGV[0] == nil && STDIN.tty? == true)
64
71
  puts
65
72
  puts "pipetext '|-|50-'"
66
73
  puts
74
+ puts "pipetext '|]50Insert spaces until end (50)|;Add After'"
75
+ puts
67
76
  puts "pipetext '|10~ &r|----|O> ALL YOUR |kBASE|n |3\\~ARE|3\\~ BELONG TO US. <|----|O&n|\\n~|n'"
68
77
  puts
69
78
  pipe.paint(pipetext_example)
data/lib/pipetext.rb CHANGED
@@ -4,7 +4,7 @@ module PipeText
4
4
 
5
5
  public
6
6
 
7
- def pipetext(text, box_mode = true, ampersand_mode = false)
7
+ def pipetext_init(box_mode=true, ampersand_mode=false)
8
8
  attributes = {
9
9
  'pipe' => false, # Pipe already been found?
10
10
  'repeat_pattern' => false, # Used by |<#>~repeat pattern~
@@ -23,8 +23,10 @@ module PipeText
23
23
  'box' => -1, # Default to |O (no boxes)
24
24
  'box_mode' => box_mode,
25
25
  'num' => 0, # Number of times to repeat pattern
26
- 'emoji_capture' => false, # Used to capture emoji description
27
- 'emoji' => String.new, # Used to capture emoji description
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
28
30
  'unicode_capture' => 0, # Used to capture Unicode using 6 character UTF-16 hex format
29
31
  'unicode' => String.new,
30
32
  'palette_capture' => 0, # Used to capture 8-bit color using 2 character hex format
@@ -36,6 +38,9 @@ module PipeText
36
38
  'fg' => String.new, # Needed to restore after background change
37
39
  'bg' => String.new # Needed to restore after foreground change
38
40
  }
41
+ end
42
+
43
+ def pipe(text, attributes)
39
44
  new_text = String.new
40
45
  text.chars.each do |character|
41
46
  process_character(character, new_text, attributes)
@@ -50,15 +55,19 @@ module PipeText
50
55
  elsif(attributes['emoji_capture'] == true)
51
56
  new_text << "|[" + attributes['emoji']
52
57
  end
53
- new_text
58
+ return new_text
59
+ end
60
+
61
+ def pipetext(text, box_mode=true, ampersand_mode=false)
62
+ pipe(text, pipetext_init(box_mode, ampersand_mode))
54
63
  end
55
64
 
56
- def write(text, box_mode = true, ampersand_mode = false)
65
+ def write(text, box_mode=true, ampersand_mode=false)
57
66
  puts(pipetext(text, box_mode, ampersand_mode))
58
67
  end
59
68
 
60
69
  # Defaults to using & for background colors
61
- def paint(text, box_mode = true, ampersand_mode = true)
70
+ def paint(text, box_mode=true, ampersand_mode=true)
62
71
  puts(pipetext(text, box_mode, ampersand_mode))
63
72
  end
64
73
 
@@ -102,6 +111,24 @@ module PipeText
102
111
  return count + offset
103
112
  end
104
113
 
114
+ # This is not entirely accurate because of emojis
115
+ def printable_length(string)
116
+ length = 0
117
+ escape = false
118
+ string.chars.each do |character|
119
+ if(character.ord == 27)
120
+ escape = true
121
+ elsif(character.ord >= 32)
122
+ if(escape == true && character.ord == 109)
123
+ escape = false
124
+ elsif(escape == false)
125
+ length += 1
126
+ end
127
+ end
128
+ end
129
+ return length
130
+ end
131
+
105
132
  private
106
133
 
107
134
  def process_character(character, new_text, attributes)
@@ -116,7 +143,23 @@ module PipeText
116
143
  emit_unicode(new_text, attributes)
117
144
  end
118
145
  end
119
- if(character == '|' && attributes['repeat_pattern'] == false)
146
+ if(attributes['end_capture'] == true && character !~ /[0-9]/)
147
+ attributes['end'] = attributes['num']
148
+ attributes['num'] = 0
149
+ attributes['end_capture'] = false
150
+ end
151
+ if(attributes['end_capture'] == true && character =~ /[0-9]/)
152
+ if(character == '0') # |10+
153
+ if(attributes['num'] > 0)
154
+ attributes['num'] *= 10
155
+ end
156
+ elsif(character >= '1' && character <= '9') # |1+ through |9+
157
+ if(attributes['num'] > 0)
158
+ attributes['num'] *= 10
159
+ end
160
+ attributes['num'] += character.to_i
161
+ end
162
+ elsif(character == '|' && attributes['repeat_pattern'] == false)
120
163
  process_pipe(character, new_text, attributes)
121
164
  elsif(character == '~' && attributes['pipe'] == true &&
122
165
  attributes['num'] > 0 && attributes['pattern_escape'] == false)
@@ -129,7 +172,21 @@ module PipeText
129
172
  capture_palette_color(character, new_text, attributes)
130
173
  elsif(attributes['emoji_capture'] == true)
131
174
  if(character == ']')
132
- emit_emoji(new_text, attributes)
175
+ if(attributes['emoji'] =~ /bell/)
176
+ new_text << "\a"
177
+ attributes['emoji'] = String.new
178
+ attributes['emoji_capture'] = false
179
+ elsif(attributes['emoji'] =~ /^([0-9]*)[,;]([0-9]*)$/)
180
+ new_text << "\e[#{$1};#{$2}H"
181
+ attributes['emoji'] = String.new
182
+ attributes['emoji_capture'] = false
183
+ elsif(attributes['emoji'] =~ /^([\.0-9]*)[zZ]$/)
184
+ attributes['emoji'] = String.new
185
+ attributes['emoji_capture'] = false
186
+ sleep($1.to_f)
187
+ else
188
+ emit_emoji(new_text, attributes)
189
+ end
133
190
  else
134
191
  attributes['emoji'] << character
135
192
  end
@@ -240,8 +297,7 @@ module PipeText
240
297
  def process_repeat_pattern(character, new_text, attributes)
241
298
  if(attributes['repeat_pattern'] == true) # ~ at end of |5~Repeat 5 times~
242
299
  attributes['num'].times do
243
- new_text << pipetext(attributes['pattern'], attributes['box_mode'],
244
- attributes['ampersand_mode'])
300
+ new_text << pipetext(attributes['pattern'], attributes['box_mode'], attributes['ampersand_mode'])
245
301
  end
246
302
  attributes['num'] = 0
247
303
  attributes['pipe'] = false
@@ -416,6 +472,18 @@ module PipeText
416
472
  new_text << "\e[25m"
417
473
  attributes['blink'] = false
418
474
  end
475
+ when '^' # |^ - Move up 1 line
476
+ new_text << "\e[A"
477
+ when 'v', 'V' # |v - Move down 1 line
478
+ new_text << "\e[B"
479
+ when '>' # |> - Move forward 1 character
480
+ new_text << "\e[C"
481
+ when '<' # |< - Move back 1 character
482
+ new_text << "\e[D"
483
+ when 'h' # |h - Hide cursor
484
+ new_text << "\e[?25l"
485
+ when 'H' # |H - Unhide cursor
486
+ new_text << "\e[?25h"
419
487
  when 'i', 'I' # |i - Inverse
420
488
  if(attributes['inverse'] == false)
421
489
  new_text << "\e[7m"
@@ -558,6 +626,17 @@ module PipeText
558
626
  else # We didn't find the next character
559
627
  attributes['found'] = false
560
628
  end
629
+ when ';' # extend to end column with spaces
630
+ if(new_text =~ /\n?(.*)\Z/)
631
+ spaces = attributes['end'] - printable_length($1)
632
+ else
633
+ spaces = attributes['end']
634
+ end
635
+ spaces.times do
636
+ new_text << " "
637
+ end
638
+ when ']' # |]0-9 - end column number
639
+ attributes['end_capture'] = true
561
640
  when '[' # |[emoji]
562
641
  attributes['emoji_capture'] = true
563
642
  when '\\' # |\ - Escape mode
@@ -588,16 +667,18 @@ module PipeText
588
667
  attributes['num'].times do
589
668
  new_text << process_box_one_replace(character)
590
669
  end
670
+ attributes['num'] = 0
591
671
  elsif(attributes['box'] == 2)
592
672
  attributes['num'].times do
593
673
  new_text << process_box_two_replace(character)
594
674
  end
675
+ attributes['num'] = 0
595
676
  else
596
677
  attributes['num'].times do
597
678
  new_text << character
598
679
  end
680
+ attributes['num'] = 0
599
681
  end
600
- attributes['num'] = 0
601
682
  end
602
683
  attributes['pipe'] = false
603
684
  end
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.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minaswan Nakamoto
@@ -31,11 +31,16 @@ 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 Emojis: https://unicode.org/emoji/charts/full-emoji-list.html\n
34
+ \ |n&n Escape Sequence |\\\n\n Add spaces to line end |;
35
+ \ Set line end |]#\n Set current x,y cursor position |[x,y] Terminal
36
+ bell |[bell]\n Move cursor up 1 line |^ Hide cursor |h\n
37
+ \ Move cursor down 1 line |v Unhide cursor |H\n Move cursor
38
+ forward 1 character |>\n Move cursor back 1 character |< Sleep
39
+ timer in float seconds |[#.#z]\n---\n Emojis: https://unicode.org/emoji/charts/full-emoji-list.html\n
35
40
  \ |[Abbreviated CLDR Short Name] \U0001F60D |[smiling face with heart-eyes]
36
41
  or\n ⚙ |[gear] \U0001F4A4 |[zzz] \U0001F468 |[man] \U0001F60D |[sm
37
42
  f w he e]\n ✔ |U2714 ❌ |U274c ☮ |u262E \U0001F48E |u1f48e \U0001F49C
38
- |u1f49c\n---\n Single or double line box mode with |- or |=\n \n ┌──┬──┐
43
+ |u1f49c\n---\n\n Single or double line box mode with |- or |=\n \n ┌──┬──┐
39
44
  ╔══╦══╗ +--+--+ <-- Draw this with this: |15 |-[--v--] |=[--v--] |o[--v--]\n │
40
45
  \ │ │ ║ ║ ║ | | | |15 |-! ! ! |=! ! ! |o! !
41
46
  \ !\n 123456789012345├──┴──┤ ╠══╩══╣ +--+--+ |y1234567890|g12345|n|->--^--<