lib/everyday-cli-utils/safe/format.rb in everyday-cli-utils-0.4.0 vs lib/everyday-cli-utils/safe/format.rb in everyday-cli-utils-0.5.0
- old
+ new
@@ -115,7 +115,15 @@
fg = $4.nil? ? nil : color_map[$4]
bg = $5.nil? ? nil : color_map[$5]
format(txt, build_string(bold, underline, fg, bg))
}
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
+ "#{char * b}#{str}#{char * a}"
+ end
end
end
\ No newline at end of file