Skip to content

Commit

Permalink
Adding colorized output for file modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon COURTOIS committed Oct 23, 2009
1 parent 3755db0 commit 8175926
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/absolute_renamer/file_info.rb
Expand Up @@ -40,9 +40,15 @@ def inspect
end

# Displays the action that will be done on the file.
# some_fileinfo.display_change # => "rename a_file.txt --> A_File.TXT"
# some_fileinfo.display_change # => "rename a_file.txt --> A_File.TXT"
def display_change
puts "#{conf[:options][:mode]} #{@real_path.sub(Dir.pwd+'/', '')} --> #{new_path.sub(Dir.pwd+'/', '')}"
puts "#{color conf[:options][:mode]} #{@real_path.sub(Dir.pwd+'/', '')} #{color '-->'} #{new_path.sub(Dir.pwd+'/', '')}"
end

# Returns a text colorized in red.
# color('hello') #=> "\e[31mhello\e[0m"
def color(text)
"\e[31m#{text}\e[0m"
end

# Returns the new path of the file.
Expand Down
4 changes: 4 additions & 0 deletions test/file_info_test.rb
Expand Up @@ -33,6 +33,10 @@ class FileInfoTest < Test::Unit::TestCase
assert_equal(false, @fileinfo.dir)
end

should "be able to return a colorized string" do
assert_equal("\e[31mhello\e[0m", @fileinfo.color('hello'))
end

end

context "loaded with lib/absolute_renamer" do
Expand Down

0 comments on commit 8175926

Please sign in to comment.