lib/eye/cli/render.rb in reel-eye-0.5 vs lib/eye/cli/render.rb in reel-eye-0.5.1

- old
+ new

@@ -1,9 +1,7 @@ module Eye::Cli::Render private - DF = '%d %b %H:%M' - def render_info(data) error!("unexpected server answer #{data.inspect}") unless data.is_a?(Hash) make_str data end @@ -24,19 +22,19 @@ short_state = (data[:type] == :application && data[:states]) is_text = data[:state] || data[:states] name = (data[:type] == :application && !is_text) ? "\033[1m#{data[:name]}\033[0m" : data[:name].to_s - off_len = short_state ? 20 : 35 + off_len = 35 str = off_str + (name + ' ').ljust(off_len - off, is_text ? '.' : ' ') if short_state str += ' ' + data[:states].map { |k, v| "#{k}:#{v}" }.join(', ') elsif data[:state] str += ' ' + data[:state].to_s str += ' (' + resources_str(data[:resources]) + ')' if data[:resources] && data[:state].to_sym == :up - str += " (#{data[:state_reason]} at #{data[:state_changed_at].strftime(DF)})" if data[:state_reason] && data[:state] == 'unmonitored' + str += " (#{data[:state_reason]} at #{Eye::Utils.human_time2(data[:state_changed_at])})" if data[:state_reason] && data[:state] == 'unmonitored' elsif data[:current_command] chain_progress = if data[:chain_progress] " #{data[:chain_progress][0]} of #{data[:chain_progress][1]}" rescue '' end str += " \e[1;33m[#{data[:current_command]}#{chain_progress}]\033[0m" @@ -58,44 +56,38 @@ def resources_str(r) return '' if !r || r.empty? memory, cpu, start_time, pid = r[:memory], r[:cpu], r[:start_time], r[:pid] return '' unless memory && cpu && start_time - res = "#{Eye::Utils.human_time(start_time)}, #{cpu.to_i}%" - res += ", #{memory / 1024 / 1024}Mb" - res += ", <#{pid}>" - - res + "#{Eye::Utils.human_time(start_time)}, #{cpu.to_i}%, #{memory / 1024 / 1024}Mb, <#{pid}>" end def render_debug_info(data) error!("unexpected server answer #{data.inspect}") unless data.is_a?(Hash) s = "" - config_yaml = data.delete(:config_yaml) + if config_yaml = data.delete(:config_yaml) + s << config_yaml - data.each do |k, v| - s << "#{"#{k}:".ljust(10)} " + else + data.each do |k, v| + s << "#{"#{k}:".ljust(10)} " - case k - when :resources - s << resources_str(v) - else - s << "#{v}" + case k + when :resources + s << resources_str(v) + else + s << "#{v}" + end + + s << "\n" end s << "\n" end - s << "\n" - - if config_yaml - s << "Current config:\n" - s << config_yaml - end - s end def render_history(data) error!("unexpected server answer #{data.inspect}") unless data.is_a?(Hash) @@ -115,11 +107,11 @@ history = history.reverse history.chunk{|h| [h[:state], h[:reason].to_s] }.each do |_, hist| if hist.size >= 3 res << detail_process_info_string(hist[0]) - res << detail_process_info_string(:state => "... #{hist.size - 2} times", :reason => '...', :at => hist[-1][:at]) + res << detail_process_info_string(:state => "... #{hist.size - 2} times", :reason => '...') res << detail_process_info_string(hist[-1]) else hist.each do |h| res << detail_process_info_string(h) end @@ -129,9 +121,10 @@ res end def detail_process_info_string(h) state = h[:state].to_s.ljust(14) - "#{Time.at(h[:at]).strftime(DF)} - #{state} (#{h[:reason]})\n" + at = h[:at] ? Eye::Utils.human_time2(h[:at]) : '.' * 12 + "#{at} - #{state} (#{h[:reason]})\n" end end