lib/everyday-cli-utils/safe/format.rb in everyday-cli-utils-1.2.0 vs lib/everyday-cli-utils/safe/format.rb in everyday-cli-utils-1.3.0

- old
+ new

@@ -117,9 +117,16 @@ bg = $5.nil? ? nil : color_map[$5] format(txt, build_string(bold, underline, fg, bg)) }.gsub(regex2) { |_| format($1, color_profile_string($2.to_sym)) } end + def self::remove_format(text) + colors = 'bk|rd|gr|yw|bl|pu|cy|wh|no' + regex = /\{(.+?)\}\((bd)?(ul)?(?:f(#{colors}))?(?:b(#{colors}))?\)/ + regex2 = /\{(.+?)\}\(:(.+?)\)/ + text.gsub(regex, '\1').gsub(regex2, '\1') {} + end + def self.mycenter(str, len, char = ' ') tlen = str.gsub(%r{\e\[.*?m}, '').length return str if tlen >= len b = ((len - tlen) / 2.0).floor a = len - tlen - b \ No newline at end of file