pipetext 0.0.1
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 +7 -0
- data/bin/pipetext +72 -0
- data/lib/pipetext.rb +665 -0
- metadata +43 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 189175f70306e70147da5d70a1fa0c541d73f60e9174f95965f44a35199625ab
|
|
4
|
+
data.tar.gz: a43d6f3095053170b85f7838ec63999c9fff7b1a63fcd7a63b99f142d89f2699
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 75a4bbe23ee4417cd000d9c5019d5ae65f4f026f625d25d145a14417fbacddbe14d2cfb52266afb76848d86b47680fede6f6f59ea91a9adcf8efb55657945f7c
|
|
7
|
+
data.tar.gz: be8bb30d38ee21fa304b2e68e0834df9a93bbf30a0f1f70139e8f2fc652f616d1a47a9b0f17ba96e9cefb8dcaad106de98ec1b42b1021908c4c6bdda3517fbee
|
data/bin/pipetext
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'pipetext'
|
|
4
|
+
|
|
5
|
+
pipe = Class.new.extend(PipeText)
|
|
6
|
+
|
|
7
|
+
pipetext_example = '|| pipe |||| && ampersand &&&& |&Toggle (&) background color mode ||&|&
|
|
8
|
+
|ssmoke |n||s |wwhite |n||W |k&wblack text on white background&n|n ||k&&w
|
|
9
|
+
|rred |n||r |Rbright red |n||R &rred background&n &&r
|
|
10
|
+
|ggreen |n||g |Gbright green |n||G &ggreen background&n &&g
|
|
11
|
+
|bblue |n||b |Bbright blue |n||B &bblue background&n &&b
|
|
12
|
+
|ccyan |n||c |Cbright cyan |n||C &ccyan background&n &&c
|
|
13
|
+
|yyellow |n||y |Ybright yellow |n||Y &yyellow background&n &&y
|
|
14
|
+
|mmagenta |n||m |Mbright magenta |n||M &mmagenta background&n &&m
|
|
15
|
+
|#FFFFFF򇨣Hex RGB color codes:|n&n Foreground ||#RRGGBB Background &&#RRGGBB
|
|
16
|
+
|p33&pF8Palette colors (256) using Hex:|n&n ||p33&&pF8 Clear Screen ||!
|
|
17
|
+
|K&wblack with white background&n |n||K&&w |@Blink|@ing ||@
|
|
18
|
+
|w&mwhite with magenta background&n |n||w&&m |w&mi|invert&n|i ||i
|
|
19
|
+
|s&gsmoke with green background&n |n||s&&g |_Underline|_d ||_
|
|
20
|
+
|r&cred with cyan background&n |n||r&&c |~Italic|~s ||~
|
|
21
|
+
|R&bbright red with blue background&n |n||R&&b |+Bold|+ ||+
|
|
22
|
+
|g&ygreen with yellow background&n |n||g&&y |.Faint|. ||.
|
|
23
|
+
|G&rbright green with red background&n |n||G&&r |xCrossed out|x ||x
|
|
24
|
+
|n&nnormal color and background ||n&&n Escape Sequence ||\\
|
|
25
|
+
Example unicode sequences: |U2714 ||U2714 |U274c ||U274c |u262E ||u262E |u1f48e ||u1f48e |u1f49c ||u1f49c
|
|
26
|
+
|
|
27
|
+
Single or double line box mode with ||- or ||=
|
|
28
|
+
|
|
29
|
+
|15 |-[--v--] |=[--v--] |o[--v--]|O <-- Draw this with this: ||15 ||-[--v--] ||=[--v--] ||o[--v--]
|
|
30
|
+
|15 |-! ! ! |=! ! ! |o! ! !|O ||15 ||-! ! ! ||=! ! ! ||o! ! !
|
|
31
|
+
|y1234567890|g12345|n|->--^--< |=>--^--< |o>--^--<|O ||y1234567890||g12345||n||->--^--< ||=>--^--< ||o>--^--<
|
|
32
|
+
|c15|n Spaces|6 |-! ! |=! ! |o! !|O ||c15||n Spaces||6 ||-! ! ||=! ! ||o! !
|
|
33
|
+
(||15 )|9 |-{-----} |={-----} |o{-----}|O (||||15 )||9 ||-{-----} ||={-----} ||o{-----}
|
|
34
|
+
|
|
35
|
+
|-[|18-]|4 |g&m|=[|20-]|n&n|O ||-[||18-]||4 ||g&&m||=[||20-]||n&&n||O
|
|
36
|
+
|-!|18 !|4 |g&m|=!|20 !|n&n|O ||-!||18 !||4 ||g&&m||=!||20 !||n&&n||O
|
|
37
|
+
|->|18-<|4 &m|g|=>|20-<|n&n|O ||->||18-<||4 &&m||g||=>||20-<||n&&n||O
|
|
38
|
+
|-!|18 !|4 |g&m|=!|20 !|n&n|O ||-!||18 !||4 ||g&&m||=!||20 !||n&&n||O
|
|
39
|
+
|-{|18-}|4 |g&m|={|20-}|n&n|O ||-{||18-}||4 ||g&&m||={||20-}||n&&n||O
|
|
40
|
+
|
|
41
|
+
Repetition using || followed by the number of characters to repeat and then the character to repeat.
|
|
42
|
+
||15* does the * character 15 times like this: |15*
|
|
43
|
+
|
|
44
|
+
Longer repetition patterns using the character ~
|
|
45
|
+
||3~ &&r||----||O> ALL YOUR ||kBASE||n ||3\~ARE||3\~ BELONG TO US. <||----||O&&n||\n~||n
|
|
46
|
+
|3~ &r|----|O> ALL YOUR |kBASE|n |3\~ARE|3\~ BELONG TO US. <|----|O&n|\n~|n'
|
|
47
|
+
|
|
48
|
+
if(ARGV[0] == nil)
|
|
49
|
+
puts "#{File.basename(__FILE__)} <filename> | <pipetext>"
|
|
50
|
+
puts
|
|
51
|
+
puts "Example usage:"
|
|
52
|
+
puts
|
|
53
|
+
puts "pipetext '|RBright red|n, |cCyan|n, |g&rGreen and Red|n,&n Normal |R|u1f49c |g|U2714|n'"
|
|
54
|
+
puts
|
|
55
|
+
puts "pipetext '|50-'"
|
|
56
|
+
puts
|
|
57
|
+
puts "pipetext '|-|50-'"
|
|
58
|
+
puts
|
|
59
|
+
puts "pipetext '|10~ &r|----|O> ALL YOUR |kBASE|n |3\\~ARE|3\\~ BELONG TO US. <|----|O&n|\\n~|n'"
|
|
60
|
+
puts
|
|
61
|
+
pipe.paint(pipetext_example)
|
|
62
|
+
else
|
|
63
|
+
begin
|
|
64
|
+
f = File.open(ARGV[0].to_s)
|
|
65
|
+
rescue
|
|
66
|
+
end
|
|
67
|
+
if(f != nil)
|
|
68
|
+
pipe.paint(f.read)
|
|
69
|
+
else
|
|
70
|
+
pipe.paint(ARGV[0].to_s)
|
|
71
|
+
end
|
|
72
|
+
end
|
data/lib/pipetext.rb
ADDED
|
@@ -0,0 +1,665 @@
|
|
|
1
|
+
module PipeText
|
|
2
|
+
|
|
3
|
+
public
|
|
4
|
+
|
|
5
|
+
def pipetext(text, box_mode = true, ampersand_mode = false)
|
|
6
|
+
attributes = {
|
|
7
|
+
'pipe' => false, # Pipe already been found?
|
|
8
|
+
'repeat_pattern' => false, # Used by |<#>~repeat pattern~
|
|
9
|
+
'pattern' => String.new, # Used by |<#>~repeat pattern~ to capture
|
|
10
|
+
'pattern_escape' => false, # Has an escape \ already been found in front of this character?
|
|
11
|
+
'ampersand' => false, # Has an ampersand already been found in front of this character?
|
|
12
|
+
'ampersand_mode' => ampersand_mode, # Do we even process ampersands for background colors?
|
|
13
|
+
'blink' => false, # Is blink turned on?
|
|
14
|
+
'bold' => false,
|
|
15
|
+
'crossed_out' => false,
|
|
16
|
+
'faint' => false,
|
|
17
|
+
'found' => false, # At the end -- did we find a match?
|
|
18
|
+
'italic' => false,
|
|
19
|
+
'inverse' => false,
|
|
20
|
+
'underline' => false,
|
|
21
|
+
'box' => -1, # Default to |O (no boxes)
|
|
22
|
+
'box_mode' => box_mode,
|
|
23
|
+
'num' => 0, # Number of times to repeat pattern
|
|
24
|
+
'unicode_capture' => 0, # Used to capture Unicode using 6 character UTF-16 hex format
|
|
25
|
+
'unicode' => String.new,
|
|
26
|
+
'palette_capture' => 0, # Used to capture 8-bit color using 2 character hex format
|
|
27
|
+
'p' => String.new, # |p00 to |pFF
|
|
28
|
+
'color_capture' => 0, # Used to capture RGB color using #RRGGBB format
|
|
29
|
+
'r' => String.new,
|
|
30
|
+
'g' => String.new,
|
|
31
|
+
'b' => String.new,
|
|
32
|
+
'fg' => String.new, # Needed to restore after background change
|
|
33
|
+
'bg' => String.new # Needed to restore after foreground change
|
|
34
|
+
}
|
|
35
|
+
new_text = String.new
|
|
36
|
+
text.chars.each do |character|
|
|
37
|
+
process_character(character, new_text, attributes)
|
|
38
|
+
end
|
|
39
|
+
# Clean up in case we've captured something we didn't process yet
|
|
40
|
+
if(attributes['color_capture'] > 0)
|
|
41
|
+
emit_color(new_text, attributes)
|
|
42
|
+
elsif(attributes['palette_capture'] > 0)
|
|
43
|
+
emit_palette_color(new_text, attributes)
|
|
44
|
+
elsif(attributes['unicode_capture'] > 0)
|
|
45
|
+
emit_unicode(new_text, attributes)
|
|
46
|
+
end
|
|
47
|
+
return new_text
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def write(text, box_mode = true, ampersand_mode = false)
|
|
51
|
+
puts(pipetext(text, box_mode, ampersand_mode))
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Defaults to using & for background colors
|
|
55
|
+
def paint(text, box_mode = true, ampersand_mode = true)
|
|
56
|
+
puts(pipetext(text, box_mode, ampersand_mode))
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
def process_character(character, new_text, attributes)
|
|
62
|
+
if(attributes['repeat_pattern'] == false)
|
|
63
|
+
# Will still need to process character, first process incorrect formats
|
|
64
|
+
if(attributes['color_capture'] > 0 && character !~ /[0-9,A-F,a-f]/)
|
|
65
|
+
emit_color(new_text, attributes)
|
|
66
|
+
elsif(attributes['palette_capture'] > 0 && character !~ /[0-9,A-F,a-f]/)
|
|
67
|
+
emit_palette_color(new_text, attributes)
|
|
68
|
+
elsif(attributes['unicode_capture'] > 0 && character !~ /[0-9,A-F,a-f,+]/ ||
|
|
69
|
+
(attributes['unicode_capture'] != 1 && character == '+'))
|
|
70
|
+
emit_unicode(new_text, attributes)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
if(character == '|' && attributes['repeat_pattern'] == false)
|
|
74
|
+
process_pipe(character, new_text, attributes)
|
|
75
|
+
elsif(character == '~' && attributes['pipe'] == true &&
|
|
76
|
+
attributes['num'] > 0 && attributes['pattern_escape'] == false)
|
|
77
|
+
process_repeat_pattern(character, new_text, attributes)
|
|
78
|
+
elsif(attributes['repeat_pattern'] == true)
|
|
79
|
+
capture_character_pattern(character, attributes)
|
|
80
|
+
elsif(attributes['color_capture'] > 0 && character =~ /[0-9,A-F,a-f]/)
|
|
81
|
+
capture_color(character, new_text, attributes)
|
|
82
|
+
elsif(attributes['palette_capture'] > 0 && character =~ /[0-9,A-F,a-f]/)
|
|
83
|
+
capture_palette_color(character, new_text, attributes)
|
|
84
|
+
elsif(attributes['unicode_capture'] == 1 && character == '+') # Skip
|
|
85
|
+
return
|
|
86
|
+
elsif(attributes['unicode_capture'] > 0 && character =~ /[0-9,A-F,a-f]/)
|
|
87
|
+
capture_unicode(character, new_text, attributes)
|
|
88
|
+
elsif(attributes['pipe'] == true &&
|
|
89
|
+
attributes['repeat_pattern'] == false &&
|
|
90
|
+
attributes['pattern_escape'] == true)
|
|
91
|
+
process_escaped_character(character, new_text, attributes)
|
|
92
|
+
elsif(character == '&' && attributes['ampersand_mode'] == true &&
|
|
93
|
+
attributes['pipe'] == false)
|
|
94
|
+
process_ampersand(character, new_text, attributes)
|
|
95
|
+
elsif(attributes['pipe'] == true)
|
|
96
|
+
process_piped_character(character, new_text, attributes)
|
|
97
|
+
elsif(attributes['ampersand'] == true)
|
|
98
|
+
process_ampersanded_character(character, new_text, attributes)
|
|
99
|
+
elsif(attributes['box'] == 0)
|
|
100
|
+
new_text << process_box_zero_replace(character)
|
|
101
|
+
elsif(attributes['box'] == 1)
|
|
102
|
+
new_text << process_box_one_replace(character)
|
|
103
|
+
elsif(attributes['box'] == 2)
|
|
104
|
+
new_text << process_box_two_replace(character)
|
|
105
|
+
else
|
|
106
|
+
new_text << character
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def emit_color(new_text, attributes)
|
|
111
|
+
r = attributes['r'].to_i(16).to_s
|
|
112
|
+
g = attributes['g'].to_i(16).to_s
|
|
113
|
+
b = attributes['b'].to_i(16).to_s
|
|
114
|
+
if(attributes['ampersand'] == true) # Background Color
|
|
115
|
+
new_text << "\e[48;2;#{r};#{g};#{b}m"
|
|
116
|
+
attributes['ampersand'] = false
|
|
117
|
+
else # Foreground Color
|
|
118
|
+
new_text << "\e[38;2;#{r};#{g};#{b}m"
|
|
119
|
+
end
|
|
120
|
+
attributes['color_capture'] = 0
|
|
121
|
+
attributes['r'] = String.new
|
|
122
|
+
attributes['g'] = String.new
|
|
123
|
+
attributes['b'] = String.new
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def emit_palette_color(new_text, attributes)
|
|
127
|
+
p = attributes['p'].to_i(16).to_s
|
|
128
|
+
if(attributes['ampersand'] == true) # Background Color
|
|
129
|
+
new_text << "\e[48;5;#{p}m"
|
|
130
|
+
attributes['ampersand'] = false
|
|
131
|
+
else # Foreground Color
|
|
132
|
+
new_text << "\e[38;5;#{p}m"
|
|
133
|
+
end
|
|
134
|
+
attributes['palette_capture'] = 0
|
|
135
|
+
attributes['p'] = String.new
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def emit_unicode(new_text, attributes)
|
|
139
|
+
new_text << [attributes['unicode'].to_i(16)].pack('U*')
|
|
140
|
+
attributes['unicode_capture'] = 0
|
|
141
|
+
attributes['unicode'] = String.new
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def process_pipe(character, new_text, attributes)
|
|
145
|
+
if(attributes['pipe'] == true && attributes['num'] == 0) # ||
|
|
146
|
+
attributes['pipe'] = false
|
|
147
|
+
new_text << character
|
|
148
|
+
else
|
|
149
|
+
attributes['pipe'] = true
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def process_repeat_pattern(character, new_text, attributes)
|
|
154
|
+
if(attributes['repeat_pattern'] == true) # ~ at end of |5~Repeat 5 times~
|
|
155
|
+
attributes['num'].times do
|
|
156
|
+
new_text << pipetext(attributes['pattern'], attributes['box_mode'],
|
|
157
|
+
attributes['ampersand_mode'])
|
|
158
|
+
end
|
|
159
|
+
attributes['num'] = 0
|
|
160
|
+
attributes['pipe'] = false
|
|
161
|
+
attributes['pattern_escape'] = false
|
|
162
|
+
attributes['repeat_pattern'] = false
|
|
163
|
+
attributes['pattern'] = String.new
|
|
164
|
+
else # ~ after number in |5~Repeat 5 times~
|
|
165
|
+
attributes['repeat_pattern'] = true
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def escape_fix(text)
|
|
170
|
+
text.gsub(/\\a/, "\a").gsub(/\\b/, "\b").gsub(/\\e/, "\e")
|
|
171
|
+
.gsub(/\\f/, "\f").gsub(/\\n/, "\n").gsub(/\\r/, "\r")
|
|
172
|
+
.gsub(/\\t/, "\t").gsub(/\\v/, "\v").gsub(/\\~/, '~')
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def process_escaped_character(character, new_text, attributes)
|
|
176
|
+
if(attributes['num'] > 0)
|
|
177
|
+
attributes['num'].times do
|
|
178
|
+
new_text << escape_fix("\\#{character}")
|
|
179
|
+
end
|
|
180
|
+
else
|
|
181
|
+
new_text << escape_fix("\\#{character}")
|
|
182
|
+
end
|
|
183
|
+
attributes['num'] = 0
|
|
184
|
+
attributes['pipe'] = false
|
|
185
|
+
attributes['pattern_escape'] = false
|
|
186
|
+
attributes['pattern'] = String.new
|
|
187
|
+
attributes['repeat_pattern'] = false
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def capture_color(character, new_text, attributes)
|
|
191
|
+
if(character =~ /[0-9,A-F,a-f]/)
|
|
192
|
+
if(attributes['color_capture'] <= 2)
|
|
193
|
+
attributes['r'] << character
|
|
194
|
+
elsif(attributes['color_capture'] <= 4)
|
|
195
|
+
attributes['g'] << character
|
|
196
|
+
elsif(attributes['color_capture'] <= 6)
|
|
197
|
+
attributes['b'] << character
|
|
198
|
+
end
|
|
199
|
+
if(attributes['color_capture'] == 6)
|
|
200
|
+
emit_color(new_text, attributes)
|
|
201
|
+
else
|
|
202
|
+
attributes['color_capture'] += 1
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def capture_character_pattern(character, attributes)
|
|
208
|
+
if(character == '\\')
|
|
209
|
+
attributes['pattern_escape'] = true
|
|
210
|
+
else
|
|
211
|
+
if(attributes['pattern_escape'] == true)
|
|
212
|
+
attributes['pattern'] << "\\#{character}"
|
|
213
|
+
attributes['pattern_escape'] = false
|
|
214
|
+
else
|
|
215
|
+
attributes['pattern'] << character
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def capture_palette_color(character, new_text, attributes)
|
|
221
|
+
if(character =~ /[0-9,A-F,a-f]/)
|
|
222
|
+
if(attributes['palette_capture'] <= 2)
|
|
223
|
+
attributes['p'] << character
|
|
224
|
+
end
|
|
225
|
+
if(attributes['palette_capture'] == 2)
|
|
226
|
+
emit_palette_color(new_text, attributes)
|
|
227
|
+
else
|
|
228
|
+
attributes['palette_capture'] += 1
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def capture_unicode(character, new_text, attributes)
|
|
234
|
+
if(character =~ /[0-9,A-F,a-f]/)
|
|
235
|
+
if(attributes['unicode_capture'] <= 6)
|
|
236
|
+
attributes['unicode'] << character
|
|
237
|
+
end
|
|
238
|
+
if(attributes['unicode_capture'] == 6)
|
|
239
|
+
emit_unicode(new_text, attributes)
|
|
240
|
+
else
|
|
241
|
+
attributes['unicode_capture'] += 1
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
def process_ampersand(character, new_text, attributes)
|
|
247
|
+
if(attributes['ampersand'] == true) # &&
|
|
248
|
+
attributes['ampersand'] = false
|
|
249
|
+
new_text << character
|
|
250
|
+
else
|
|
251
|
+
attributes['ampersand'] = true
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
def update_attributes(new_text, attributes)
|
|
256
|
+
if(attributes['bold'] == true)
|
|
257
|
+
new_text << "\e[1m"
|
|
258
|
+
end
|
|
259
|
+
if(attributes['faint'] == true)
|
|
260
|
+
new_text << "\e[2m"
|
|
261
|
+
end
|
|
262
|
+
if(attributes['italic'] == true)
|
|
263
|
+
new_text << "\e[3m"
|
|
264
|
+
end
|
|
265
|
+
if(attributes['underline'] == true)
|
|
266
|
+
new_text << "\e[4m"
|
|
267
|
+
end
|
|
268
|
+
if(attributes['blink'] == true)
|
|
269
|
+
new_text << "\e[5m"
|
|
270
|
+
end
|
|
271
|
+
if(attributes['inverse'] == true)
|
|
272
|
+
new_text << "\e[7m"
|
|
273
|
+
end
|
|
274
|
+
if(attributes['crossed_out'] == true)
|
|
275
|
+
new_text << "\e[9m"
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
def process_piped_character(character, new_text, attributes)
|
|
280
|
+
attributes['found'] = true # Assume we will find the next character
|
|
281
|
+
if(attributes['num'] == 0) # We are not in repeat character mode
|
|
282
|
+
case character
|
|
283
|
+
when '&' # |& - Toggle & on/off for Background Colors
|
|
284
|
+
if(attributes['ampersand_mode'] == true)
|
|
285
|
+
attributes['ampersand_mode'] = false
|
|
286
|
+
else
|
|
287
|
+
attributes['ampersand_mode'] = true
|
|
288
|
+
end
|
|
289
|
+
attributes['pipe'] = false
|
|
290
|
+
when '!' # |! - Clear screen
|
|
291
|
+
new_text << "\e[H\e[J"
|
|
292
|
+
when '+' # |+ - Bold
|
|
293
|
+
if(attributes['bold'] == false)
|
|
294
|
+
new_text << "\e[1m"
|
|
295
|
+
attributes['bold'] = true
|
|
296
|
+
else
|
|
297
|
+
new_text << "\e[22m"
|
|
298
|
+
attributes['bold'] = false
|
|
299
|
+
end
|
|
300
|
+
when '.' # |. - Faint / Dim
|
|
301
|
+
if(attributes['faint'] == false)
|
|
302
|
+
new_text << "\e[2m"
|
|
303
|
+
attributes['faint'] = true
|
|
304
|
+
else
|
|
305
|
+
new_text << "\e[22m"
|
|
306
|
+
attributes['faint'] = false
|
|
307
|
+
end
|
|
308
|
+
when '~' # |~ - Italic
|
|
309
|
+
if(attributes['italic'] == false)
|
|
310
|
+
new_text << "\e[3m"
|
|
311
|
+
attributes['italic'] = true
|
|
312
|
+
else
|
|
313
|
+
new_text << "\e[23m"
|
|
314
|
+
attributes['italic'] = false
|
|
315
|
+
end
|
|
316
|
+
when '_' # |_ - Underline
|
|
317
|
+
if(attributes['underline'] == false)
|
|
318
|
+
new_text << "\e[4m"
|
|
319
|
+
attributes['underline'] = true
|
|
320
|
+
else
|
|
321
|
+
new_text << "\e[24m"
|
|
322
|
+
attributes['underline'] = false
|
|
323
|
+
end
|
|
324
|
+
when '@' # |@ - Blink
|
|
325
|
+
if(attributes['blink'] == false)
|
|
326
|
+
new_text << "\e[5m"
|
|
327
|
+
attributes['blink'] = true
|
|
328
|
+
else
|
|
329
|
+
new_text << "\e[25m"
|
|
330
|
+
attributes['blink'] = false
|
|
331
|
+
end
|
|
332
|
+
when 'i', 'I' # |i - Inverse
|
|
333
|
+
if(attributes['inverse'] == false)
|
|
334
|
+
new_text << "\e[7m"
|
|
335
|
+
attributes['inverse'] = true
|
|
336
|
+
else
|
|
337
|
+
new_text << "\e[27m"
|
|
338
|
+
attributes['inverse'] = false
|
|
339
|
+
end
|
|
340
|
+
when 'x', 'X' # |x - Crossed Out
|
|
341
|
+
if(attributes['crossed_out'] == false)
|
|
342
|
+
new_text << "\e[9m"
|
|
343
|
+
attributes['crossed_out'] = true
|
|
344
|
+
else
|
|
345
|
+
new_text << "\e[29m"
|
|
346
|
+
attributes['crossed_out'] = false
|
|
347
|
+
end
|
|
348
|
+
when '#' # |#RRGGBB
|
|
349
|
+
attributes['color_capture'] = 1
|
|
350
|
+
when 'P', 'p' # |P or |p - 2 character hex format color (256 colors)
|
|
351
|
+
attributes['palette_capture'] = 1
|
|
352
|
+
when 'U', 'u' # |U or |u - Unicode 6 character hex format
|
|
353
|
+
attributes['unicode_capture'] = 1
|
|
354
|
+
when 'K', 'k' # |K or |k - Foreground text black
|
|
355
|
+
attributes['fg'] = "\e[30m"
|
|
356
|
+
new_text << "\e[0;30m"
|
|
357
|
+
attributes['bold'] = false
|
|
358
|
+
update_attributes(new_text, attributes)
|
|
359
|
+
new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
|
|
360
|
+
when 'S', 's' # |S or |s - Foreground text smoke
|
|
361
|
+
attributes['fg'] = "\e[1;30m"
|
|
362
|
+
new_text << "\e[1;30m"
|
|
363
|
+
attributes['bold'] = false
|
|
364
|
+
update_attributes(new_text, attributes)
|
|
365
|
+
attributes['bold'] = true
|
|
366
|
+
new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
|
|
367
|
+
when 'r' # |r - Foreground text red
|
|
368
|
+
attributes['fg'] = "\e[31m"
|
|
369
|
+
new_text << "\e[0;31m"
|
|
370
|
+
attributes['bold'] = false
|
|
371
|
+
update_attributes(new_text, attributes)
|
|
372
|
+
new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
|
|
373
|
+
when 'R' # |R - Foreground text bright red
|
|
374
|
+
attributes['fg'] = "\e[1;31m"
|
|
375
|
+
new_text << "\e[1;31m"
|
|
376
|
+
attributes['bold'] = false
|
|
377
|
+
update_attributes(new_text, attributes)
|
|
378
|
+
attributes['bold'] = true
|
|
379
|
+
new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
|
|
380
|
+
when 'g' # |g - Foreground text green
|
|
381
|
+
attributes['fg'] = "\e[32m"
|
|
382
|
+
new_text << "\e[0;32m"
|
|
383
|
+
attributes['bold'] = false
|
|
384
|
+
update_attributes(new_text, attributes)
|
|
385
|
+
new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
|
|
386
|
+
when 'G' # |G - Foreground text bright green
|
|
387
|
+
attributes['fg'] = "\e[1;32m"
|
|
388
|
+
new_text << "\e[1;32m"
|
|
389
|
+
attributes['bold'] = false
|
|
390
|
+
update_attributes(new_text, attributes)
|
|
391
|
+
attributes['bold'] = true
|
|
392
|
+
new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
|
|
393
|
+
when 'y' # |y - Foreground text yellow (brown)
|
|
394
|
+
attributes['fg'] = "\e[33m"
|
|
395
|
+
new_text << "\e[0;33m"
|
|
396
|
+
attributes['bold'] = false
|
|
397
|
+
update_attributes(new_text, attributes)
|
|
398
|
+
new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
|
|
399
|
+
when 'Y' # |Y - Foreground text bright yellow
|
|
400
|
+
attributes['fg'] = "\e[1;33m"
|
|
401
|
+
new_text << "\e[1;33m"
|
|
402
|
+
attributes['bold'] = false
|
|
403
|
+
update_attributes(new_text, attributes)
|
|
404
|
+
attributes['bold'] = true
|
|
405
|
+
new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
|
|
406
|
+
when 'b' # |b - Foreground text blue
|
|
407
|
+
attributes['fg'] = "\e[34m"
|
|
408
|
+
new_text << "\e[0;34m"
|
|
409
|
+
attributes['bold'] = false
|
|
410
|
+
update_attributes(new_text, attributes)
|
|
411
|
+
new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
|
|
412
|
+
when 'B' # |B - Foreground text bright blue
|
|
413
|
+
attributes['fg'] = "\e[1;34m"
|
|
414
|
+
new_text << "\e[1;34m"
|
|
415
|
+
attributes['bold'] = false
|
|
416
|
+
update_attributes(new_text, attributes)
|
|
417
|
+
attributes['bold'] = true
|
|
418
|
+
new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
|
|
419
|
+
when 'm' # |m - Foreground text magenta
|
|
420
|
+
attributes['fg'] = "\e[35m"
|
|
421
|
+
new_text << "\e[0;35m"
|
|
422
|
+
attributes['bold'] = false
|
|
423
|
+
update_attributes(new_text, attributes)
|
|
424
|
+
new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
|
|
425
|
+
when 'M' # |M - Foreground text bright magenta
|
|
426
|
+
attributes['fg'] = "\e[1;35m"
|
|
427
|
+
new_text << "\e[1;35m"
|
|
428
|
+
attributes['bold'] = false
|
|
429
|
+
update_attributes(new_text, attributes)
|
|
430
|
+
attributes['bold'] = true
|
|
431
|
+
new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
|
|
432
|
+
when 'c' # |c - Foreground text cyan
|
|
433
|
+
attributes['fg'] = "\e[36m"
|
|
434
|
+
new_text << "\e[0;36m"
|
|
435
|
+
attributes['bold'] = false
|
|
436
|
+
update_attributes(new_text, attributes)
|
|
437
|
+
new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
|
|
438
|
+
when 'C' # |C - Foreground text bright cyan
|
|
439
|
+
attributes['fg'] = "\e[1;36m"
|
|
440
|
+
new_text << "\e[1;36m"
|
|
441
|
+
attributes['bold'] = false
|
|
442
|
+
update_attributes(new_text, attributes)
|
|
443
|
+
attributes['bold'] = true
|
|
444
|
+
new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
|
|
445
|
+
when 'W', 'w' # |W or |w - Foreground text white
|
|
446
|
+
attributes['fg'] = "\e[1;37m"
|
|
447
|
+
new_text << "\e[1;37m"
|
|
448
|
+
attributes['bold'] = false
|
|
449
|
+
update_attributes(new_text, attributes)
|
|
450
|
+
attributes['bold'] = true
|
|
451
|
+
new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
|
|
452
|
+
when 'N', 'n' # |N or |n - Foreground text normal
|
|
453
|
+
attributes['fg'] = ""
|
|
454
|
+
new_text << "\e[0;37m"
|
|
455
|
+
attributes['bold'] = false
|
|
456
|
+
update_attributes(new_text, attributes)
|
|
457
|
+
new_text << attributes['bg'] == "\e[0m" ? "" : attributes['bg']
|
|
458
|
+
when 'O' # |O - Box mode off
|
|
459
|
+
attributes['box'] = -1
|
|
460
|
+
when 'o' # |o - Box mode 0
|
|
461
|
+
attributes['box'] = 0
|
|
462
|
+
when '-' # |- - Box mode 1
|
|
463
|
+
if(attributes['box_mode'] == true)
|
|
464
|
+
attributes['box'] = 1
|
|
465
|
+
else # We didn't find the next character
|
|
466
|
+
attributes['found'] = false
|
|
467
|
+
end
|
|
468
|
+
when '=' # |= - Box mode 2
|
|
469
|
+
if(attributes['box_mode'] == true)
|
|
470
|
+
attributes['box'] = 2
|
|
471
|
+
else # We didn't find the next character
|
|
472
|
+
attributes['found'] = false
|
|
473
|
+
end
|
|
474
|
+
when '\\' # |\ - Escape mode
|
|
475
|
+
attributes['pattern_escape'] = true
|
|
476
|
+
else # We didn't find the next character
|
|
477
|
+
attributes['found'] = false
|
|
478
|
+
end
|
|
479
|
+
elsif(character == '\\')
|
|
480
|
+
attributes['pattern_escape'] = true
|
|
481
|
+
else # We didn't find the next character
|
|
482
|
+
attributes['found'] = false
|
|
483
|
+
end
|
|
484
|
+
if(attributes['found'] == false)
|
|
485
|
+
if(character == '0') # |10+
|
|
486
|
+
if(attributes['num'] > 0)
|
|
487
|
+
attributes['num'] *= 10
|
|
488
|
+
end
|
|
489
|
+
elsif(character >= '1' && character <= '9') # |1+ through |9+
|
|
490
|
+
if(attributes['num'] > 0)
|
|
491
|
+
attributes['num'] *= 10
|
|
492
|
+
end
|
|
493
|
+
attributes['num'] += character.to_i
|
|
494
|
+
else
|
|
495
|
+
if(attributes['num'] <= 0) # No replacement found
|
|
496
|
+
new_text << '|' + character
|
|
497
|
+
else # Repeat number replacement found
|
|
498
|
+
if(attributes['box'] == 1)
|
|
499
|
+
attributes['num'].times do
|
|
500
|
+
new_text << process_box_one_replace(character)
|
|
501
|
+
end
|
|
502
|
+
elsif(attributes['box'] == 2)
|
|
503
|
+
attributes['num'].times do
|
|
504
|
+
new_text << process_box_two_replace(character)
|
|
505
|
+
end
|
|
506
|
+
else
|
|
507
|
+
attributes['num'].times do
|
|
508
|
+
new_text << character
|
|
509
|
+
end
|
|
510
|
+
end
|
|
511
|
+
attributes['num'] = 0
|
|
512
|
+
end
|
|
513
|
+
attributes['pipe'] = false
|
|
514
|
+
end
|
|
515
|
+
elsif(attributes['pattern_escape'] == false)
|
|
516
|
+
attributes['pipe'] = false
|
|
517
|
+
end
|
|
518
|
+
end
|
|
519
|
+
|
|
520
|
+
def process_ampersanded_character(character, new_text, attributes)
|
|
521
|
+
case character
|
|
522
|
+
when '#' # &#RRGGBB
|
|
523
|
+
attributes['color_capture'] = 1
|
|
524
|
+
return
|
|
525
|
+
when 'P', 'p' # |P or |p - 2 character hex format color (256 colors)
|
|
526
|
+
attributes['palette_capture'] = 1
|
|
527
|
+
return
|
|
528
|
+
when 'W', 'w' # &W or &w - Background white
|
|
529
|
+
new_text << "\e[0;47m"
|
|
530
|
+
attributes['bg'] = "\e[47m"
|
|
531
|
+
update_attributes(new_text, attributes)
|
|
532
|
+
new_text << attributes['fg'] == "\e[0m" ? "" : attributes['fg']
|
|
533
|
+
when 'C', 'c' # &C or &c - Background cyan
|
|
534
|
+
new_text << "\e[0;46m"
|
|
535
|
+
attributes['bg'] = "\e[46m"
|
|
536
|
+
update_attributes(new_text, attributes)
|
|
537
|
+
new_text << attributes['fg'] == "\e[0m" ? "" : attributes['fg']
|
|
538
|
+
when 'M', 'm' # &M or &m - Background magenta
|
|
539
|
+
new_text << "\e[0;45m"
|
|
540
|
+
attributes['bg'] = "\e[45m"
|
|
541
|
+
update_attributes(new_text, attributes)
|
|
542
|
+
new_text << attributes['fg'] == "\e[0m" ? "" : attributes['fg']
|
|
543
|
+
when 'B', 'b' # &B or &b - Background blue
|
|
544
|
+
new_text << "\e[0;44m"
|
|
545
|
+
attributes['bg'] = "\e[44m"
|
|
546
|
+
update_attributes(new_text, attributes)
|
|
547
|
+
new_text << attributes['fg'] == "\e[0m" ? "" : attributes['fg']
|
|
548
|
+
when 'Y', 'y' # &Y or &y - Background yellow (brown)
|
|
549
|
+
new_text << "\e[0;43m"
|
|
550
|
+
attributes['bg'] = "\e[43m"
|
|
551
|
+
update_attributes(new_text, attributes)
|
|
552
|
+
new_text << attributes['fg'] == "\e[0m" ? "" : attributes['fg']
|
|
553
|
+
when 'G', 'g' # &G or &g - Background green
|
|
554
|
+
new_text << "\e[0;42m"
|
|
555
|
+
attributes['bg'] = "\e[42m"
|
|
556
|
+
update_attributes(new_text, attributes)
|
|
557
|
+
new_text << attributes['fg'] == "\e[0m" ? "" : attributes['fg']
|
|
558
|
+
when 'R', 'r' # &R or &r - Background red
|
|
559
|
+
new_text << "\e[0;41m"
|
|
560
|
+
attributes['bg'] ="\e[41m"
|
|
561
|
+
update_attributes(new_text, attributes)
|
|
562
|
+
new_text << attributes['fg'] == "\e[0m" ? "" : attributes['fg']
|
|
563
|
+
when 'S', 's', 'K', 'k' # &S, &s, &K, &k - Background black/smoke
|
|
564
|
+
new_text << "\e[0;40m"
|
|
565
|
+
attributes['bg'] = "\e[40m"
|
|
566
|
+
update_attributes(new_text, attributes)
|
|
567
|
+
new_text << attributes['fg'] == "\e[0m" ? "" : attributes['fg']
|
|
568
|
+
when 'N', 'n' # &N or &n - Background normal
|
|
569
|
+
new_text << "\e[0m"
|
|
570
|
+
attributes['bg'] = ""
|
|
571
|
+
update_attributes(new_text, attributes)
|
|
572
|
+
new_text << attributes['fg'] == "\e[0m" ? "" : attributes['fg']
|
|
573
|
+
else
|
|
574
|
+
new_text << '&' + character
|
|
575
|
+
end
|
|
576
|
+
attributes['ampersand'] = false
|
|
577
|
+
end
|
|
578
|
+
|
|
579
|
+
def process_box_zero_replace(character)
|
|
580
|
+
case character
|
|
581
|
+
when '['
|
|
582
|
+
'+'
|
|
583
|
+
when ']'
|
|
584
|
+
'+'
|
|
585
|
+
when '-'
|
|
586
|
+
'-'
|
|
587
|
+
when '!'
|
|
588
|
+
'|'
|
|
589
|
+
when '>'
|
|
590
|
+
'+'
|
|
591
|
+
when '<'
|
|
592
|
+
'+'
|
|
593
|
+
when '+'
|
|
594
|
+
'+'
|
|
595
|
+
when '{'
|
|
596
|
+
'+'
|
|
597
|
+
when '}'
|
|
598
|
+
'+'
|
|
599
|
+
when 'v'
|
|
600
|
+
'+'
|
|
601
|
+
when '^'
|
|
602
|
+
'+'
|
|
603
|
+
else
|
|
604
|
+
character
|
|
605
|
+
end
|
|
606
|
+
end
|
|
607
|
+
|
|
608
|
+
def process_box_one_replace(character)
|
|
609
|
+
case character
|
|
610
|
+
when '['
|
|
611
|
+
'┌'
|
|
612
|
+
when ']'
|
|
613
|
+
'┐'
|
|
614
|
+
when '-'
|
|
615
|
+
'─'
|
|
616
|
+
when '!'
|
|
617
|
+
'│'
|
|
618
|
+
when '>'
|
|
619
|
+
'├'
|
|
620
|
+
when '<'
|
|
621
|
+
'┤'
|
|
622
|
+
when '+'
|
|
623
|
+
'┼'
|
|
624
|
+
when '{'
|
|
625
|
+
'└'
|
|
626
|
+
when '}'
|
|
627
|
+
'┘'
|
|
628
|
+
when 'v'
|
|
629
|
+
'┬'
|
|
630
|
+
when '^'
|
|
631
|
+
'┴'
|
|
632
|
+
else
|
|
633
|
+
character
|
|
634
|
+
end
|
|
635
|
+
end
|
|
636
|
+
|
|
637
|
+
def process_box_two_replace(character)
|
|
638
|
+
case character
|
|
639
|
+
when '['
|
|
640
|
+
'╔'
|
|
641
|
+
when ']'
|
|
642
|
+
'╗'
|
|
643
|
+
when '-'
|
|
644
|
+
'═'
|
|
645
|
+
when '!'
|
|
646
|
+
'║'
|
|
647
|
+
when '>'
|
|
648
|
+
'╠'
|
|
649
|
+
when '<'
|
|
650
|
+
'╣'
|
|
651
|
+
when '+'
|
|
652
|
+
'╬'
|
|
653
|
+
when '{'
|
|
654
|
+
'╚'
|
|
655
|
+
when '}'
|
|
656
|
+
'╝'
|
|
657
|
+
when 'v'
|
|
658
|
+
'╦'
|
|
659
|
+
when '^'
|
|
660
|
+
'╩'
|
|
661
|
+
else
|
|
662
|
+
character
|
|
663
|
+
end
|
|
664
|
+
end
|
|
665
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: pipetext
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Minaswan Nakamoto
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: Easily add colors, boxes, repetitions and emojis to your terminal output
|
|
13
|
+
using pipes(|).
|
|
14
|
+
email: minaswan.nakamoto@onionmail.org
|
|
15
|
+
executables:
|
|
16
|
+
- pipetext
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- bin/pipetext
|
|
21
|
+
- lib/pipetext.rb
|
|
22
|
+
homepage: https://github.com/MinaswanNakamoto/pipetext
|
|
23
|
+
licenses:
|
|
24
|
+
- MIT
|
|
25
|
+
metadata: {}
|
|
26
|
+
rdoc_options: []
|
|
27
|
+
require_paths:
|
|
28
|
+
- lib
|
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
requirements: []
|
|
40
|
+
rubygems_version: 3.6.9
|
|
41
|
+
specification_version: 4
|
|
42
|
+
summary: Use pipe (|) characters to easily add colors, boxes and emojis in the terminal.
|
|
43
|
+
test_files: []
|