pipetext 0.1.0 → 0.1.2
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 +10 -6
- data/lib/pipetext.rb +90 -4
- data/lib/substitute_emoji_names.rb +1913 -1913
- 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: 5883f76759f24059807937e5e3b245bb2994b69a196b1c9be7377500ec77f9b8
|
|
4
|
+
data.tar.gz: 2af581984d9692051ad962fc3e66328e97af653eec3479b0b33c4d84119cc795
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3b46368967758946d1b61e724dafa60e32272e04360fbe05fef35713708f6125175d45d77e3aca92bbb3cb4badc360f60614a21d4b50e1d2c9a4aefacd928bb3
|
|
7
|
+
data.tar.gz: 85214ee6cb603c8a42b2cb32c09ccdc65b8cf0908246cc7134ac3669a1d038e9517a771b46e8feab7bfa79e55be2eedf4886461de68d31c682e50b2c57094ee1
|
data/bin/pipetext
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
3
|
# Use local file
|
|
4
|
-
|
|
4
|
+
require_relative '../lib/pipetext'
|
|
5
5
|
|
|
6
6
|
# Use gem install
|
|
7
|
-
require 'pipetext'
|
|
7
|
+
#require 'pipetext'
|
|
8
8
|
|
|
9
9
|
pipe = Class.new.extend(PipeText)
|
|
10
10
|
|
|
@@ -27,9 +27,10 @@ pipetext_example = '|| pipe |||| && ampersand &&&& |&Toggle (&) backgr
|
|
|
27
27
|
|G&rbright green with red background&n |n||G&&r |xCrossed out|x ||x
|
|
28
28
|
|n&nnormal color and background ||n&&n Escape Sequence ||\\
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
||[CLDR Short Name]
|
|
32
|
-
|
|
30
|
+
Emojis: https://unicode.org/emoji/charts/full-emoji-list.html
|
|
31
|
+
||[Abbreviated CLDR Short Name] |[smiling face with heart-eyes] ||[smiling face with heart-eyes] or
|
|
32
|
+
|[gear] ||[gear] |[zzz] ||[zzz] |[man] ||[man] |[sm f w he e] ||[sm f w he e]
|
|
33
|
+
|U2714 ||U2714 |U274c ||U274c |u262E ||u262E |u1f48e ||u1f48e |u1f49c ||u1f49c
|
|
33
34
|
|
|
34
35
|
Single or double line box mode with ||- or ||=
|
|
35
36
|
|
|
@@ -52,7 +53,7 @@ Longer repetition patterns using the character ~
|
|
|
52
53
|
||3~ &&r||----||O> ALL YOUR ||kBASE||n ||3\~ARE||3\~ BELONG TO US. <||----||O&&n||\n~||n
|
|
53
54
|
|3~ &r|----|O> ALL YOUR |kBASE|n |3\~ARE|3\~ BELONG TO US. <|----|O&n|\n~|n'
|
|
54
55
|
|
|
55
|
-
if(ARGV[0] == nil)
|
|
56
|
+
if(ARGV[0] == nil && STDIN.tty? == true)
|
|
56
57
|
puts "#{File.basename(__FILE__)} <filename> | <pipetext>"
|
|
57
58
|
puts
|
|
58
59
|
puts "Example usage:"
|
|
@@ -67,6 +68,9 @@ if(ARGV[0] == nil)
|
|
|
67
68
|
puts
|
|
68
69
|
pipe.paint(pipetext_example)
|
|
69
70
|
else
|
|
71
|
+
if(STDIN.tty? == false)
|
|
72
|
+
pipe.paint(STDIN.read)
|
|
73
|
+
end
|
|
70
74
|
begin
|
|
71
75
|
f = File.open(ARGV[0].to_s)
|
|
72
76
|
rescue
|
data/lib/pipetext.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require_relative 'substitute_emoji_names.rb'
|
|
2
|
+
|
|
1
3
|
module PipeText
|
|
2
4
|
|
|
3
5
|
public
|
|
@@ -21,6 +23,8 @@ module PipeText
|
|
|
21
23
|
'box' => -1, # Default to |O (no boxes)
|
|
22
24
|
'box_mode' => box_mode,
|
|
23
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
|
|
24
28
|
'unicode_capture' => 0, # Used to capture Unicode using 6 character UTF-16 hex format
|
|
25
29
|
'unicode' => String.new,
|
|
26
30
|
'palette_capture' => 0, # Used to capture 8-bit color using 2 character hex format
|
|
@@ -33,7 +37,6 @@ module PipeText
|
|
|
33
37
|
'bg' => String.new # Needed to restore after foreground change
|
|
34
38
|
}
|
|
35
39
|
new_text = String.new
|
|
36
|
-
text = substitute_emoji_names(text)
|
|
37
40
|
text.chars.each do |character|
|
|
38
41
|
process_character(character, new_text, attributes)
|
|
39
42
|
end
|
|
@@ -44,8 +47,10 @@ module PipeText
|
|
|
44
47
|
emit_palette_color(new_text, attributes)
|
|
45
48
|
elsif(attributes['unicode_capture'] > 0)
|
|
46
49
|
emit_unicode(new_text, attributes)
|
|
50
|
+
elsif(attributes['emoji_capture'] == true)
|
|
51
|
+
new_text << "|[" + attributes['emoji']
|
|
47
52
|
end
|
|
48
|
-
|
|
53
|
+
new_text
|
|
49
54
|
end
|
|
50
55
|
|
|
51
56
|
def write(text, box_mode = true, ampersand_mode = false)
|
|
@@ -57,6 +62,46 @@ module PipeText
|
|
|
57
62
|
puts(pipetext(text, box_mode, ampersand_mode))
|
|
58
63
|
end
|
|
59
64
|
|
|
65
|
+
def ignored_character(character, ignored_characters)
|
|
66
|
+
ignored_characters.chars.each do |ignored|
|
|
67
|
+
if(character == ignored)
|
|
68
|
+
return true
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
return false
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Match abbreviated text descriptions for emojis by default ignore case and punctuation
|
|
75
|
+
# Allows for 'space anchoring' so you can use |[smi f w he e] as an abbreviation for
|
|
76
|
+
# |[smiling face with heart-eyes]
|
|
77
|
+
def abbreviated_match(input, match, case_match=false, ignored_characters=",.':-")
|
|
78
|
+
if(!input || !match)
|
|
79
|
+
return 0
|
|
80
|
+
end
|
|
81
|
+
count = 0
|
|
82
|
+
offset = 0
|
|
83
|
+
input.chars.each_with_index do |character, index|
|
|
84
|
+
while(ignored_character(match[index + offset], ignored_characters))
|
|
85
|
+
offset += 1
|
|
86
|
+
end
|
|
87
|
+
if(character == match[index + offset])
|
|
88
|
+
count += 1
|
|
89
|
+
elsif(case_match == false && character.downcase == match[index + offset].downcase)
|
|
90
|
+
count += 1
|
|
91
|
+
elsif(character == ' ' && match[index + offset..-1] =~ / /)
|
|
92
|
+
count += 1
|
|
93
|
+
while(match[index + offset] != character)
|
|
94
|
+
offset += 1
|
|
95
|
+
end
|
|
96
|
+
else
|
|
97
|
+
count = 0
|
|
98
|
+
offset = 0
|
|
99
|
+
break
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
return count + offset
|
|
103
|
+
end
|
|
104
|
+
|
|
60
105
|
private
|
|
61
106
|
|
|
62
107
|
def process_character(character, new_text, attributes)
|
|
@@ -82,6 +127,12 @@ module PipeText
|
|
|
82
127
|
capture_color(character, new_text, attributes)
|
|
83
128
|
elsif(attributes['palette_capture'] > 0 && character =~ /[0-9,A-F,a-f]/)
|
|
84
129
|
capture_palette_color(character, new_text, attributes)
|
|
130
|
+
elsif(attributes['emoji_capture'] == true)
|
|
131
|
+
if(character == ']')
|
|
132
|
+
emit_emoji(new_text, attributes)
|
|
133
|
+
else
|
|
134
|
+
attributes['emoji'] << character
|
|
135
|
+
end
|
|
85
136
|
elsif(attributes['unicode_capture'] == 1 && character == '+') # Skip
|
|
86
137
|
return
|
|
87
138
|
elsif(attributes['unicode_capture'] > 0 && character =~ /[0-9,A-F,a-f]/)
|
|
@@ -142,6 +193,41 @@ module PipeText
|
|
|
142
193
|
attributes['unicode'] = String.new
|
|
143
194
|
end
|
|
144
195
|
|
|
196
|
+
def emit_emoji(new_text, attributes)
|
|
197
|
+
emoji = String.new
|
|
198
|
+
match_length = 0
|
|
199
|
+
value_length = 0
|
|
200
|
+
$substitute_emoji_names.each do |key, value|
|
|
201
|
+
if(attributes['emoji'] == key) # Use the most precise match first
|
|
202
|
+
emoji = value
|
|
203
|
+
break
|
|
204
|
+
elsif(attributes['emoji'].length <= key.length) # Otherwise use shortest match
|
|
205
|
+
match = abbreviated_match(attributes['emoji'], key)
|
|
206
|
+
if(match == 0 && key =~ /-/)
|
|
207
|
+
match = abbreviated_match(attributes['emoji'], key.sub(/-/, ' '))
|
|
208
|
+
end
|
|
209
|
+
if(match > 0 && (match <= match_length || match_length == 0) &&
|
|
210
|
+
(value.length <= value_length || value_length == 0))
|
|
211
|
+
emoji = value
|
|
212
|
+
match_length = match
|
|
213
|
+
value_length = value.length
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
if(emoji == String.new) # No match, put copy input
|
|
218
|
+
new_text << "|[" + attributes['emoji'] + "]"
|
|
219
|
+
else
|
|
220
|
+
emoji.split(/\|U/).each do |e|
|
|
221
|
+
if(e != "")
|
|
222
|
+
attributes['unicode'] = e.sub(/^\+?/, '')
|
|
223
|
+
emit_unicode(new_text, attributes)
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
attributes['emoji'] = String.new
|
|
227
|
+
end
|
|
228
|
+
attributes['emoji_capture'] = false
|
|
229
|
+
end
|
|
230
|
+
|
|
145
231
|
def process_pipe(character, new_text, attributes)
|
|
146
232
|
if(attributes['pipe'] == true && attributes['num'] == 0) # ||
|
|
147
233
|
attributes['pipe'] = false
|
|
@@ -472,6 +558,8 @@ module PipeText
|
|
|
472
558
|
else # We didn't find the next character
|
|
473
559
|
attributes['found'] = false
|
|
474
560
|
end
|
|
561
|
+
when '[' # |[emoji]
|
|
562
|
+
attributes['emoji_capture'] = true
|
|
475
563
|
when '\\' # |\ - Escape mode
|
|
476
564
|
attributes['pattern_escape'] = true
|
|
477
565
|
else # We didn't find the next character
|
|
@@ -663,6 +751,4 @@ module PipeText
|
|
|
663
751
|
character
|
|
664
752
|
end
|
|
665
753
|
end
|
|
666
|
-
|
|
667
|
-
require_relative 'substitute_emoji_names.rb'
|
|
668
754
|
end
|