pipetext 0.2.4 → 0.2.6

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: 59d39270d503c77ab782442902e45e8a7b9390801e19aa639510c450c60eee1f
4
- data.tar.gz: af2c501cff8611be392dddce15232149a5063de5724ab0f05e36b45219490a93
3
+ metadata.gz: 1a49c4a1db0607a10805da620311a16d0686fb29b5405d1edb329ac9eb3ba05c
4
+ data.tar.gz: 761a90f52750d0c933996426770a4482d3edc8fa41890dfaa008cfcb118131cc
5
5
  SHA512:
6
- metadata.gz: eb9731040f1749bd24c3f7b2c7073700e59bff29c4cb39431c917e1ce436cebca25cf09aa2815d10fc8c6610698e33ca2571939bcdb479b45fc68fc25315641d
7
- data.tar.gz: 9bf71d085a9d59b059841d967907386ce6da673417f23a531b4adee57e2f858b1caaea914cfb0ec3f91a53a387ee62ea1c1112268dc4745b0a198e5c3788e0f0
6
+ metadata.gz: b3635c1e4e698ef6e22694b29afcd7190f1eed0372e8c6f5647b8423fdab781c8f00aa95e6485edb9d465e7ec760073ca3d3af930ab5f34dac872a45e2a7a991
7
+ data.tar.gz: 7e4f5b0b2a47d81103e605d0f9ecd3a72e1135d0901797d47db9fd272ffaa94633bd1bdb8a85ce9287768ac93dab02250663e89c47b7c40d78c8fa4b8943c47c
data/bin/pipetext CHANGED
@@ -90,7 +90,7 @@ if(ARGV[0] == nil && STDIN.tty? == true)
90
90
  puts "pipetext '|10~ &r|----|O> ALL YOUR |kBASE|n |3\\~ARE|3\\~ BELONG TO US. <|----|O&n|\\n~|n'"
91
91
  puts
92
92
  puts "Set your bash prompt:"
93
- puts "PS1=$(pipetext '|g\\u|n@|g\\h|n:|g\\w|n$ ')"
93
+ puts "PS1=$(pipetext '|$|g\\u|n@|g\\h|n:|g\\w|n$ ')"
94
94
  puts
95
95
  pipe.paint("version |c#{PipeText::VERSION}|n\n")
96
96
  else
@@ -168,21 +168,43 @@ 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)
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
+ end
182
199
  length += 1
200
+ wide = false
201
+ wide_count = 0
183
202
  end
184
203
  end
185
204
  end
205
+ if(wide == true && wide_count > 0)
206
+ length += 1
207
+ end
186
208
  return length
187
209
  end
188
210
 
@@ -4,6 +4,6 @@ module PipeText
4
4
 
5
5
  public
6
6
 
7
- VERSION = "0.2.4"
7
+ VERSION = "0.2.6"
8
8
  end
9
9
 
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.4
4
+ version: 0.2.6
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