pipetext 0.1.2 → 0.1.3

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 +7 -3
  3. data/lib/pipetext.rb +63 -8
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5883f76759f24059807937e5e3b245bb2994b69a196b1c9be7377500ec77f9b8
4
- data.tar.gz: 2af581984d9692051ad962fc3e66328e97af653eec3479b0b33c4d84119cc795
3
+ metadata.gz: 4df095ff8f81423a2a3e6f0735a581b277f9c994bb1f984607de2be6ce7611c2
4
+ data.tar.gz: a865ea8325c576699e9a3daa17cce1ffdec22648e8651eee4fc06d3caf164673
5
5
  SHA512:
6
- metadata.gz: 3b46368967758946d1b61e724dafa60e32272e04360fbe05fef35713708f6125175d45d77e3aca92bbb3cb4badc360f60614a21d4b50e1d2c9a4aefacd928bb3
7
- data.tar.gz: 85214ee6cb603c8a42b2cb32c09ccdc65b8cf0908246cc7134ac3669a1d038e9517a771b46e8feab7bfa79e55be2eedf4886461de68d31c682e50b2c57094ee1
6
+ metadata.gz: cc92d01dc1aae578c11091fbe806248f97a8b3bdd4f8d5a718206bf15503a5d68c9f765295f6b8055f395f1d594fd06c52ee3911aaee709da86fbd5ac18044ef
7
+ data.tar.gz: 81591e8ef536a0b63a0bd9f224f38f9699823f69edebd7e10bbd3ffdce61bcc4a23b8069ba6217229a417f7e7881ad4a78a58735175db3395f4d084606f70cb5
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,9 @@ 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 ||]#
29
31
 
30
32
  Emojis: https://unicode.org/emoji/charts/full-emoji-list.html
31
33
  ||[Abbreviated CLDR Short Name] |[smiling face with heart-eyes] ||[smiling face with heart-eyes] or
@@ -64,6 +66,8 @@ if(ARGV[0] == nil && STDIN.tty? == true)
64
66
  puts
65
67
  puts "pipetext '|-|50-'"
66
68
  puts
69
+ puts "pipetext '|]50Insert spaces until end (50)|;Add After'"
70
+ puts
67
71
  puts "pipetext '|10~ &r|----|O> ALL YOUR |kBASE|n |3\\~ARE|3\\~ BELONG TO US. <|----|O&n|\\n~|n'"
68
72
  puts
69
73
  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,6 +23,8 @@ 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
+ 'end_capture' => false, # Used to capture the end column number
27
+ 'end' => 0, # Number which current denotes the end of the column
26
28
  'emoji_capture' => false, # Used to capture emoji description
27
29
  'emoji' => String.new, # Used to capture emoji description
28
30
  'unicode_capture' => 0, # Used to capture Unicode using 6 character UTF-16 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)
@@ -240,8 +283,7 @@ module PipeText
240
283
  def process_repeat_pattern(character, new_text, attributes)
241
284
  if(attributes['repeat_pattern'] == true) # ~ at end of |5~Repeat 5 times~
242
285
  attributes['num'].times do
243
- new_text << pipetext(attributes['pattern'], attributes['box_mode'],
244
- attributes['ampersand_mode'])
286
+ new_text << pipetext(attributes['pattern'], attributes['box_mode'], attributes['ampersand_mode'])
245
287
  end
246
288
  attributes['num'] = 0
247
289
  attributes['pipe'] = false
@@ -558,6 +600,17 @@ module PipeText
558
600
  else # We didn't find the next character
559
601
  attributes['found'] = false
560
602
  end
603
+ when ';' # extend to end column with spaces
604
+ if(new_text =~ /\n?(.*)\Z/)
605
+ spaces = attributes['end'] - printable_length($1)
606
+ else
607
+ spaces = attributes['end']
608
+ end
609
+ spaces.times do
610
+ new_text << " "
611
+ end
612
+ when ']' # |]0-9 - end column number
613
+ attributes['end_capture'] = true
561
614
  when '[' # |[emoji]
562
615
  attributes['emoji_capture'] = true
563
616
  when '\\' # |\ - Escape mode
@@ -588,16 +641,18 @@ module PipeText
588
641
  attributes['num'].times do
589
642
  new_text << process_box_one_replace(character)
590
643
  end
644
+ attributes['num'] = 0
591
645
  elsif(attributes['box'] == 2)
592
646
  attributes['num'].times do
593
647
  new_text << process_box_two_replace(character)
594
648
  end
649
+ attributes['num'] = 0
595
650
  else
596
651
  attributes['num'].times do
597
652
  new_text << character
598
653
  end
654
+ attributes['num'] = 0
599
655
  end
600
- attributes['num'] = 0
601
656
  end
602
657
  attributes['pipe'] = false
603
658
  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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minaswan Nakamoto