pipetext 0.2.5 → 0.2.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 685bbe79ca57a8040a92176e5b746d293331435a27b62cbf62b98d0be128b232
4
- data.tar.gz: de13755f037a063cd397f2070c4d065a9c473cae149e9dafad6db52bc7fc221c
3
+ metadata.gz: aa217b6ffbf3d726efa7e28c5f8e190d05f8f09da02995a4a2d575c372674bf4
4
+ data.tar.gz: a272e83e9336d39b158e0cc00467afb5f89d061cba70ce2ee6616ec2bafcd38d
5
5
  SHA512:
6
- metadata.gz: c3e2e2937254a31aaf4a976ecd7812b910f4fa3ce5cb95bb9c6357664e0fecd7cde693056e841b970336cbd954021c31dcde13bfb893377f300cd19fa5de74a7
7
- data.tar.gz: 32ce0d5766f3b40219e5c5941618a4336aa2911b0157ae02aae68297b151252d2fecc8c997e27fb53ad65ac6da3b66d3ccd955e600ef3b9f838c138855e9f9e2
6
+ metadata.gz: ef2b34b99b343908b04aedadcbb7c2c7c943c6430b414097c0f9cbdecffb483b1168f73b375c961f166660626db2dc838aa9fec94b69c5378cb08cd7ac224d67
7
+ data.tar.gz: 9e2dc194f697ba535339ed951534ce7c07eb426ef2ecf42597eefee63f0ee9a8cff3378af057742ab171a1af237a0b4379da07831abf6c4adc222681a9d35dbb
data/bin/pipetext CHANGED
@@ -77,6 +77,7 @@ if(ARGV[0] == nil && STDIN.tty? == true)
77
77
  puts "PipeText capabilities:"
78
78
  puts
79
79
  pipe.paint(pipetext_example)
80
+ puts
80
81
  puts "Command Syntax: #{File.basename(__FILE__)} <filename> | <pipetext>"
81
82
  puts "Example usages:"
82
83
  puts
@@ -168,21 +168,44 @@ module PipeText
168
168
 
169
169
  # This is not entirely accurate because of emojis, which we assume are 2 characters
170
170
  def printable_length(string)
171
+ if(string == "")
172
+ return 0
173
+ end
171
174
  length = 0
172
175
  escape = false
176
+ wide = false
177
+ wide_count = 0
173
178
  string.chars.each do |character|
174
- if(character.ord == 27)
179
+ if(character[0].ord == 27)
175
180
  escape = true
176
- elsif(character.ord >= 32)
177
- if(escape == true && character.ord == 109)
181
+ elsif(character[0].ord == 226 && wide == false)
182
+ wide = true
183
+ elsif(character[0].ord == 240 && wide == false)
184
+ wide = true
185
+ elsif(character[0].ord >= 32)
186
+ if(escape == true && character[0].ord == 109)
178
187
  escape = false
179
- elsif(character.ord > 9600) # ~ Emoji / Unicode - double wide characters start
188
+ elsif(character[0].ord > 9600) # ~ Emoji / Unicode - double wide characters start
180
189
  length += 2
181
- elsif(escape == false)
190
+ elsif(escape == false && wide == false)
182
191
  length += 1
192
+ elsif(wide == true)
193
+ wide_count += 1
194
+ end
195
+ if(wide == true && wide_count >= 2)
196
+ if(character[0].ord == 147)
197
+ length += 1
198
+ else
199
+ length += 1
200
+ wide = false
201
+ wide_count = 0
202
+ end
183
203
  end
184
204
  end
185
205
  end
206
+ if(wide == true && wide_count > 0)
207
+ length += 1
208
+ end
186
209
  return length
187
210
  end
188
211
 
@@ -206,20 +229,20 @@ module PipeText
206
229
  attributes['end_capture'] = false
207
230
  end
208
231
  if(attributes['end_capture'] == true && character =~ /[0-9]/)
209
- if(character == '0') # |10+
232
+ if(character == '0') # |10+
210
233
  if(attributes['num'] > 0)
211
234
  attributes['num'] *= 10
212
235
  end
213
- elsif(character >= '1' && character <= '9') # |1+ through |9+
236
+ elsif(character >= '1' && character <= '9') # |1+ through |9+
214
237
  if(attributes['num'] > 0)
215
238
  attributes['num'] *= 10
216
239
  end
217
240
  attributes['num'] += character.to_i
218
241
  end
219
242
  elsif(character == ')' && attributes['variable_capture'] == true && attributes['escape'] == false)
220
- if(attributes['variable'] =~ /=/ && attributes['variable'][0] != '#') # Update
243
+ if(attributes['variable'] =~ /=/ && attributes['variable'][0] != '#') # Update
221
244
  update_variable(attributes)
222
- else # Display
245
+ else # Display
223
246
  emit_variable(new_text, attributes)
224
247
  end
225
248
  elsif(attributes['variable_capture'] == true)
@@ -399,7 +422,7 @@ module PipeText
399
422
  end
400
423
 
401
424
  def emit_variable(new_text, attributes)
402
- if(attributes['variable'][0] == '#') # We are manipulating attributes['num']
425
+ if(attributes['variable'][0] == '#') # We are manipulating attributes['num']
403
426
  if(attributes['variable'][1..-1] =~ /(.*) \-= ?(.*)/ ||
404
427
  attributes['variable'][1..-1] =~ /(.*)\-= ?(.*)/)
405
428
  attributes['num'] = pipetext(escape_fix(attributes['variables'][$1]), attributes['box_mode'],
@@ -453,10 +476,10 @@ module PipeText
453
476
  match_length = 0
454
477
  value_length = 0
455
478
  $substitute_emoji_names.each do |key, value|
456
- if(attributes['emoji'] == key) # Use the most precise match first
479
+ if(attributes['emoji'] == key) # Use the most precise match first
457
480
  emoji = value
458
481
  break
459
- elsif(attributes['emoji'].length <= key.length) # Otherwise use shortest match
482
+ elsif(attributes['emoji'].length <= key.length) # Otherwise use shortest match
460
483
  match = abbreviated_match(attributes['emoji'], key)
461
484
  if(match == 0 && key =~ /-/)
462
485
  match = abbreviated_match(attributes['emoji'], key.sub(/-/, ' '))
@@ -469,7 +492,7 @@ module PipeText
469
492
  end
470
493
  end
471
494
  end
472
- if(emoji == String.new) # No match, put copy input
495
+ if(emoji == String.new) # No match, put copy input
473
496
  new_text << "|[" + attributes['emoji'] + "]"
474
497
  else
475
498
  emoji.split(/\|U/).each do |e|
File without changes
@@ -4,6 +4,5 @@ module PipeText
4
4
 
5
5
  public
6
6
 
7
- VERSION = "0.2.5"
7
+ VERSION = "0.2.7"
8
8
  end
9
-
data/lib/pipetext.rb CHANGED
File without changes
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.2.5
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minaswan Nakamoto
@@ -16,7 +16,7 @@ description: "== Easily add colors, boxes, repetitions and emojis to your termin
16
16
  print(string)\n write('|Y' + string + '|n')\n end\n end\n \n printer
17
17
  = YellowPrinter.new\n printer.print('This is yellow')\n \n The gem includes a
18
18
  command line interface too:\n \n > pipetext\n\n > pipetext '|Ccyan|n'\n\n Easily
19
- set your bash prompt colors using pipetext:\n\n > PS1=$(pipetext '|g\\u|n@|g\\h|n:|g\\w|n$
19
+ set your bash prompt colors using pipetext:\n\n > PS1=$(pipetext '|$|g\\u|n@|g\\h|n:|g\\w|n$
20
20
  ')\n\n Works with files:\n\n > pipetext <filename>\n\n Works with pipes too:\n\n
21
21
  \ > echo '|RRed test |u1f49c|n' | pipetext\n\n---\n | pipe || & ampersand &&
22
22
  \ Toggle (&) background color mode |&\n smoke |s white |W black text