File: util.rb

package info (click to toggle)
ruby-paint 2.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 232 kB
  • sloc: ruby: 688; makefile: 4
file content (16 lines) | stat: -rw-r--r-- 405 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# frozen_string_literal: true

module Paint
  # Standalone helpers which add functionality you sometimes need when working with terminal colors
  class << self
    # Removes any color and effect strings
    def unpaint(string)
      string.gsub(/\e\[(?:[0-9];?)+m/, '')
    end

    # Creates a random ANSI color
    def random(background = false)
      (background ? 40 : 30) + rand(8)
    end
  end
end