Skip to content

Instantly share code, notes, and snippets.

/Color.rb Secret

Created February 11, 2015 09:39
Show Gist options
  • Save anonymous/0ea039f7ff22d0239117 to your computer and use it in GitHub Desktop.
Save anonymous/0ea039f7ff22d0239117 to your computer and use it in GitHub Desktop.
module Color
def colorize(color, options = {})
background = options[:background] || options[:bg] || false
style = options[:style]
offsets = ["gray","red", "green", "yellow", "blue", "magenta", "cyan","white"]
styles = ["normal","bold","dark","italic","underline","xx","xx","underline","xx","strikethrough"]
start = background ? 40 : 30
color_code = start + (offsets.index(color) || 8)
style_code = styles.index(style) || 0
"\e[#{style_code};#{color_code}m#{self}\e[0m"
end
end
FileDirectory.rb:24:in `block in listFile': undefined method `colorize'
require 'fileutils'
require_relative 'color'
module FileAttr
def pathFile
@@done = "/mnt/donner/"
end
def listFile
FileUtils.cd(pathFile)
dirValue = Dir.glob("#{@@done}/*")
puts "Files in #{@@done} \n"
dirValue.each do |f|
name = File.basename(f)
puts name.colorize("blue", :style => "italic")
end
end
class String
include Color
end
end
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment