[LrdeTools] 234: Add color to the status.

https://svn.lrde.epita.fr/svn/lrdetools/trunk Index: ChangeLog from Nicolas Pouillard <ertai@lrde.epita.fr> Add color to the status. * vcs/lib/vcs/app.rb: Honor the configuration file. * vcs/lib/vcs/status.rb: Add `color_status'. The `status' command call `color_status' depending of Vcs.color and/or tty?. * vcs/lib/vcs/vcs.rb: . * vcs/NEWS: Add an entry for color. NEWS | 5 +++++ lib/vcs/app.rb | 1 + lib/vcs/status.rb | 28 ++++++++++++++++++++++++++++ lib/vcs/vcs.rb | 6 ++++++ 4 files changed, 40 insertions(+) Index: vcs/lib/vcs/app.rb --- vcs/lib/vcs/app.rb (revision 233) +++ vcs/lib/vcs/app.rb (working copy) @@ -91,6 +91,7 @@ vcs_user_conf = home/'.vcsrc' if vcs_user_conf.exist? Vcs.user_conf = OpenStruct.new(YAML.load(vcs_user_conf.read)) + Vcs.color = Vcs.user_conf.color.to_sym unless Vcs.user_conf.color.nil? end end Index: vcs/NEWS --- vcs/NEWS (revision 233) +++ vcs/NEWS (working copy) @@ -25,6 +25,11 @@ - Files which match global_unmask are prepend by 'U' - Files which begins by `,' (vcs internal use) are prepend by ',' + * Color: + - Status: the status output is now colored depending of the meaning of + the status. The color activation can be choose in your configuration + file (auto, never, always). + New in 0.3 2005-09-16: * The help command now show all commands including vcs ones. Index: vcs/lib/vcs/vcs.rb --- vcs/lib/vcs/vcs.rb (revision 233) +++ vcs/lib/vcs/vcs.rb (working copy) @@ -30,9 +30,11 @@ @@version ||= '0.3.0' @@user_conf ||= OpenStruct.new + @@color ||= :auto cattr_accessor :version cattr_accessor :default cattr_accessor :user_conf + cattr_accessor :color class Failure < Exception end @@ -162,6 +164,10 @@ @cmd_data.puts(*a, &b) end + def output + @cmd_data.out_io + end + def run ( *args ) sub_vcs.run!(*args) end Index: vcs/lib/vcs/status.rb --- vcs/lib/vcs/status.rb (revision 233) +++ vcs/lib/vcs/status.rb (working copy) @@ -27,10 +27,38 @@ end protected :from_status + def color_status! ( *args ) + from_status(*args) do |line, file_st, prop_st, cpy, file| + line[0] = @h.color(file_st, *@@style[file_st[0]]) + puts line + end + end + def status! ( *args ) + case Vcs.color + when :never + when :auto then return color_status!(*args) if output.tty? + when :always then return color_status!(*args) + else raise ArgumentError, "Bad value for Vcs.color: #{Vcs.color}" + end from_status(*args) do |line, file_st, prop_st, cpy, file| puts line end end + @@style ||= + { + ?A => [:GREEN], + ?M => [:GREEN], + ?\\ => [:YELLOW], + ?, => [:YELLOW], + ?G => [:BLUE], + ?D => [:MAGENTA], + ?R => [:MAGENTA], + ?~ => [:RED], + ?! => [:RED], + ?? => [:BLINK, :RED], + ?C => [:BLINK, :RED], + } + end # class Svn
participants (1)
-
Nicolas Pouillard