pipetext 0.1.1 → 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.
- checksums.yaml +4 -4
- data/bin/pipetext +15 -7
- data/lib/pipetext.rb +150 -16
- data/lib/substitute_emoji_names.rb +426 -434
- metadata +36 -35
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4df095ff8f81423a2a3e6f0735a581b277f9c994bb1f984607de2be6ce7611c2
|
|
4
|
+
data.tar.gz: a865ea8325c576699e9a3daa17cce1ffdec22648e8651eee4fc06d3caf164673
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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 &&&&
|
|
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򇨣Hex RGB color codes:|n&n Foreground ||#RRGGBB Background &&#RRGGBB
|
|
20
|
-
|p33&pF8Palette colors (256) using Hex:|n&n ||p33&&pF8 Clear
|
|
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,11 +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
|
|
28
|
+
|n&nnormal color and background ||n&&n Escape sequence ||\\
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
Add spaces to line end ||; Set line end ||]#
|
|
31
|
+
|
|
32
|
+
Emojis: https://unicode.org/emoji/charts/full-emoji-list.html
|
|
33
|
+
||[Abbreviated CLDR Short Name] |[smiling face with heart-eyes] ||[smiling face with heart-eyes] or
|
|
34
|
+
|[gear] ||[gear] |[zzz] ||[zzz] |[man] ||[man] |[sm f w he e] ||[sm f w he e]
|
|
35
|
+
|U2714 ||U2714 |U274c ||U274c |u262E ||u262E |u1f48e ||u1f48e |u1f49c ||u1f49c
|
|
33
36
|
|
|
34
37
|
Single or double line box mode with ||- or ||=
|
|
35
38
|
|
|
@@ -52,7 +55,7 @@ Longer repetition patterns using the character ~
|
|
|
52
55
|
||3~ &&r||----||O> ALL YOUR ||kBASE||n ||3\~ARE||3\~ BELONG TO US. <||----||O&&n||\n~||n
|
|
53
56
|
|3~ &r|----|O> ALL YOUR |kBASE|n |3\~ARE|3\~ BELONG TO US. <|----|O&n|\n~|n'
|
|
54
57
|
|
|
55
|
-
if(ARGV[0] == nil)
|
|
58
|
+
if(ARGV[0] == nil && STDIN.tty? == true)
|
|
56
59
|
puts "#{File.basename(__FILE__)} <filename> | <pipetext>"
|
|
57
60
|
puts
|
|
58
61
|
puts "Example usage:"
|
|
@@ -63,10 +66,15 @@ if(ARGV[0] == nil)
|
|
|
63
66
|
puts
|
|
64
67
|
puts "pipetext '|-|50-'"
|
|
65
68
|
puts
|
|
69
|
+
puts "pipetext '|]50Insert spaces until end (50)|;Add After'"
|
|
70
|
+
puts
|
|
66
71
|
puts "pipetext '|10~ &r|----|O> ALL YOUR |kBASE|n |3\\~ARE|3\\~ BELONG TO US. <|----|O&n|\\n~|n'"
|
|
67
72
|
puts
|
|
68
73
|
pipe.paint(pipetext_example)
|
|
69
74
|
else
|
|
75
|
+
if(STDIN.tty? == false)
|
|
76
|
+
pipe.paint(STDIN.read)
|
|
77
|
+
end
|
|
70
78
|
begin
|
|
71
79
|
f = File.open(ARGV[0].to_s)
|
|
72
80
|
rescue
|
data/lib/pipetext.rb
CHANGED
|
@@ -4,7 +4,7 @@ module PipeText
|
|
|
4
4
|
|
|
5
5
|
public
|
|
6
6
|
|
|
7
|
-
def
|
|
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,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
|
+
'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
|
|
29
|
+
'emoji' => String.new, # Used to capture emoji description
|
|
26
30
|
'unicode_capture' => 0, # Used to capture Unicode using 6 character UTF-16 hex format
|
|
27
31
|
'unicode' => String.new,
|
|
28
32
|
'palette_capture' => 0, # Used to capture 8-bit color using 2 character hex format
|
|
@@ -34,8 +38,10 @@ module PipeText
|
|
|
34
38
|
'fg' => String.new, # Needed to restore after background change
|
|
35
39
|
'bg' => String.new # Needed to restore after foreground change
|
|
36
40
|
}
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def pipe(text, attributes)
|
|
37
44
|
new_text = String.new
|
|
38
|
-
text = substitute_emojis(text)
|
|
39
45
|
text.chars.each do |character|
|
|
40
46
|
process_character(character, new_text, attributes)
|
|
41
47
|
end
|
|
@@ -46,19 +52,83 @@ module PipeText
|
|
|
46
52
|
emit_palette_color(new_text, attributes)
|
|
47
53
|
elsif(attributes['unicode_capture'] > 0)
|
|
48
54
|
emit_unicode(new_text, attributes)
|
|
55
|
+
elsif(attributes['emoji_capture'] == true)
|
|
56
|
+
new_text << "|[" + attributes['emoji']
|
|
49
57
|
end
|
|
50
|
-
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))
|
|
51
63
|
end
|
|
52
64
|
|
|
53
|
-
def write(text, box_mode
|
|
65
|
+
def write(text, box_mode=true, ampersand_mode=false)
|
|
54
66
|
puts(pipetext(text, box_mode, ampersand_mode))
|
|
55
67
|
end
|
|
56
68
|
|
|
57
69
|
# Defaults to using & for background colors
|
|
58
|
-
def paint(text, box_mode
|
|
70
|
+
def paint(text, box_mode=true, ampersand_mode=true)
|
|
59
71
|
puts(pipetext(text, box_mode, ampersand_mode))
|
|
60
72
|
end
|
|
61
73
|
|
|
74
|
+
def ignored_character(character, ignored_characters)
|
|
75
|
+
ignored_characters.chars.each do |ignored|
|
|
76
|
+
if(character == ignored)
|
|
77
|
+
return true
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
return false
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Match abbreviated text descriptions for emojis by default ignore case and punctuation
|
|
84
|
+
# Allows for 'space anchoring' so you can use |[smi f w he e] as an abbreviation for
|
|
85
|
+
# |[smiling face with heart-eyes]
|
|
86
|
+
def abbreviated_match(input, match, case_match=false, ignored_characters=",.':-")
|
|
87
|
+
if(!input || !match)
|
|
88
|
+
return 0
|
|
89
|
+
end
|
|
90
|
+
count = 0
|
|
91
|
+
offset = 0
|
|
92
|
+
input.chars.each_with_index do |character, index|
|
|
93
|
+
while(ignored_character(match[index + offset], ignored_characters))
|
|
94
|
+
offset += 1
|
|
95
|
+
end
|
|
96
|
+
if(character == match[index + offset])
|
|
97
|
+
count += 1
|
|
98
|
+
elsif(case_match == false && character.downcase == match[index + offset].downcase)
|
|
99
|
+
count += 1
|
|
100
|
+
elsif(character == ' ' && match[index + offset..-1] =~ / /)
|
|
101
|
+
count += 1
|
|
102
|
+
while(match[index + offset] != character)
|
|
103
|
+
offset += 1
|
|
104
|
+
end
|
|
105
|
+
else
|
|
106
|
+
count = 0
|
|
107
|
+
offset = 0
|
|
108
|
+
break
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
return count + offset
|
|
112
|
+
end
|
|
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
|
+
|
|
62
132
|
private
|
|
63
133
|
|
|
64
134
|
def process_character(character, new_text, attributes)
|
|
@@ -73,7 +143,23 @@ module PipeText
|
|
|
73
143
|
emit_unicode(new_text, attributes)
|
|
74
144
|
end
|
|
75
145
|
end
|
|
76
|
-
if(
|
|
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)
|
|
77
163
|
process_pipe(character, new_text, attributes)
|
|
78
164
|
elsif(character == '~' && attributes['pipe'] == true &&
|
|
79
165
|
attributes['num'] > 0 && attributes['pattern_escape'] == false)
|
|
@@ -84,6 +170,12 @@ module PipeText
|
|
|
84
170
|
capture_color(character, new_text, attributes)
|
|
85
171
|
elsif(attributes['palette_capture'] > 0 && character =~ /[0-9,A-F,a-f]/)
|
|
86
172
|
capture_palette_color(character, new_text, attributes)
|
|
173
|
+
elsif(attributes['emoji_capture'] == true)
|
|
174
|
+
if(character == ']')
|
|
175
|
+
emit_emoji(new_text, attributes)
|
|
176
|
+
else
|
|
177
|
+
attributes['emoji'] << character
|
|
178
|
+
end
|
|
87
179
|
elsif(attributes['unicode_capture'] == 1 && character == '+') # Skip
|
|
88
180
|
return
|
|
89
181
|
elsif(attributes['unicode_capture'] > 0 && character =~ /[0-9,A-F,a-f]/)
|
|
@@ -144,6 +236,41 @@ module PipeText
|
|
|
144
236
|
attributes['unicode'] = String.new
|
|
145
237
|
end
|
|
146
238
|
|
|
239
|
+
def emit_emoji(new_text, attributes)
|
|
240
|
+
emoji = String.new
|
|
241
|
+
match_length = 0
|
|
242
|
+
value_length = 0
|
|
243
|
+
$substitute_emoji_names.each do |key, value|
|
|
244
|
+
if(attributes['emoji'] == key) # Use the most precise match first
|
|
245
|
+
emoji = value
|
|
246
|
+
break
|
|
247
|
+
elsif(attributes['emoji'].length <= key.length) # Otherwise use shortest match
|
|
248
|
+
match = abbreviated_match(attributes['emoji'], key)
|
|
249
|
+
if(match == 0 && key =~ /-/)
|
|
250
|
+
match = abbreviated_match(attributes['emoji'], key.sub(/-/, ' '))
|
|
251
|
+
end
|
|
252
|
+
if(match > 0 && (match <= match_length || match_length == 0) &&
|
|
253
|
+
(value.length <= value_length || value_length == 0))
|
|
254
|
+
emoji = value
|
|
255
|
+
match_length = match
|
|
256
|
+
value_length = value.length
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
if(emoji == String.new) # No match, put copy input
|
|
261
|
+
new_text << "|[" + attributes['emoji'] + "]"
|
|
262
|
+
else
|
|
263
|
+
emoji.split(/\|U/).each do |e|
|
|
264
|
+
if(e != "")
|
|
265
|
+
attributes['unicode'] = e.sub(/^\+?/, '')
|
|
266
|
+
emit_unicode(new_text, attributes)
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
attributes['emoji'] = String.new
|
|
270
|
+
end
|
|
271
|
+
attributes['emoji_capture'] = false
|
|
272
|
+
end
|
|
273
|
+
|
|
147
274
|
def process_pipe(character, new_text, attributes)
|
|
148
275
|
if(attributes['pipe'] == true && attributes['num'] == 0) # ||
|
|
149
276
|
attributes['pipe'] = false
|
|
@@ -156,8 +283,7 @@ module PipeText
|
|
|
156
283
|
def process_repeat_pattern(character, new_text, attributes)
|
|
157
284
|
if(attributes['repeat_pattern'] == true) # ~ at end of |5~Repeat 5 times~
|
|
158
285
|
attributes['num'].times do
|
|
159
|
-
new_text << pipetext(attributes['pattern'], attributes['box_mode'],
|
|
160
|
-
attributes['ampersand_mode'])
|
|
286
|
+
new_text << pipetext(attributes['pattern'], attributes['box_mode'], attributes['ampersand_mode'])
|
|
161
287
|
end
|
|
162
288
|
attributes['num'] = 0
|
|
163
289
|
attributes['pipe'] = false
|
|
@@ -474,6 +600,19 @@ module PipeText
|
|
|
474
600
|
else # We didn't find the next character
|
|
475
601
|
attributes['found'] = false
|
|
476
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
|
|
614
|
+
when '[' # |[emoji]
|
|
615
|
+
attributes['emoji_capture'] = true
|
|
477
616
|
when '\\' # |\ - Escape mode
|
|
478
617
|
attributes['pattern_escape'] = true
|
|
479
618
|
else # We didn't find the next character
|
|
@@ -502,16 +641,18 @@ module PipeText
|
|
|
502
641
|
attributes['num'].times do
|
|
503
642
|
new_text << process_box_one_replace(character)
|
|
504
643
|
end
|
|
644
|
+
attributes['num'] = 0
|
|
505
645
|
elsif(attributes['box'] == 2)
|
|
506
646
|
attributes['num'].times do
|
|
507
647
|
new_text << process_box_two_replace(character)
|
|
508
648
|
end
|
|
649
|
+
attributes['num'] = 0
|
|
509
650
|
else
|
|
510
651
|
attributes['num'].times do
|
|
511
652
|
new_text << character
|
|
512
653
|
end
|
|
654
|
+
attributes['num'] = 0
|
|
513
655
|
end
|
|
514
|
-
attributes['num'] = 0
|
|
515
656
|
end
|
|
516
657
|
attributes['pipe'] = false
|
|
517
658
|
end
|
|
@@ -665,11 +806,4 @@ module PipeText
|
|
|
665
806
|
character
|
|
666
807
|
end
|
|
667
808
|
end
|
|
668
|
-
|
|
669
|
-
def substitute_emojis(text)
|
|
670
|
-
$substitute_emoji_names.each do |key, value|
|
|
671
|
-
text = text.gsub(/\|\[#{key}\]/i, value)
|
|
672
|
-
end
|
|
673
|
-
text
|
|
674
|
-
end
|
|
675
809
|
end
|