Permalink
Browse files

Pixel has default fg/bg colours.

  • Loading branch information...
1 parent 5237919 commit 2756dcdea31e84aa6e1a6aba04b5c090ca5d8298 @pda committed Jan 15, 2012
Showing with 8 additions and 2 deletions.
  1. +8 −2 asc.rb
View
10 asc.rb
@@ -84,9 +84,15 @@ def on_exit
end
end
-class Pixel < Struct.new(:char, :fg, :bg)
+class Pixel
+ def initialize char = " ", fg = nil, bg = nil
+ @char = char
+ @fg, @bg = fg, bg
+ end
+ def fg; @fg || 255 end
+ def bg; @bg || 0 end
def to_s
- "\033[48;5;#{bg}m\033[38;5;#{fg}m#{char}\033[0m"
+ "\033[48;5;%dm\033[38;5;%dm%s\033[0m" % [ bg, fg, @char ]
end
end

0 comments on commit 2756dcd

Please sign in to comment.