diff options
| author | Casey Dahlin <cdahlin@redhat.com> | 2008-10-08 14:59:25 -0400 |
|---|---|---|
| committer | Casey Dahlin <cdahlin@redhat.com> | 2008-10-08 14:59:25 -0400 |
| commit | 9870591732ebb419e1130fb1a9cca6bce8e908c1 (patch) | |
| tree | cd47a34d14b4c645dcf71dfc2c7e95321794f170 | |
| parent | a0f92d4563b8af41e5f6ff7c38f04586dbb9e500 (diff) | |
| download | upstate-9870591732ebb419e1130fb1a9cca6bce8e908c1.tar.gz upstate-9870591732ebb419e1130fb1a9cca6bce8e908c1.tar.xz upstate-9870591732ebb419e1130fb1a9cca6bce8e908c1.zip | |
Change State#to_s and add State#to_s_color
The State#to_s method has been modified to only display the direct class name
and not the full module name, and to display parameters. Also, to_s_color has
been added which uses tty color escapes to color its output according to the
state's status.
| -rw-r--r-- | state.rb | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -90,7 +90,24 @@ class State # Puts the class name and parameters def to_s - "#{self.class.name}#{params.inspect} (#{@status.to_s})" + "#{name} (#{@status.to_s})" + end + + # The name of this state + def name + "#{self.class.name.split("::").last}#{params.inspect}" + end + + # Prints a string that uses TTY color escapes + def to_s_color + colors = { + :up => "1;32", + :down => "1;31", + :rising => "0;32", + :dropping => "0;31", + } + + "\e[%sm%s\e[0;49m" % [colors[status], name] end # Hold this state. Holding a state informs the system that you would like it |
