Compute column width depending on project names.

This commit is contained in:
Glenn Y. Rolland 2015-07-14 23:05:23 +02:00
parent 798932046a
commit 06c00e545c

View file

@ -20,6 +20,9 @@ module Kook
def list_projects def list_projects
projects_exist = false projects_exist = false
# get boundary for project name + margin
column_width = @projects.map{ |name,data| name }.max
@projects.each do |project_name,project_data| @projects.each do |project_name,project_data|
projects_exist = true projects_exist = true
exist = File.exist? project_data.path exist = File.exist? project_data.path
@ -28,7 +31,7 @@ module Kook
.gsub!(/#{ENV['HOME']}/,'~') .gsub!(/#{ENV['HOME']}/,'~')
.send(exist ? :green : :red) .send(exist ? :green : :red)
) )
puts "%- 24s %s" % [project_name, display_path] puts "%- #{column_width}s %s" % [project_name, display_path]
end end
STDERR.puts "No project found." if not projects_exist STDERR.puts "No project found." if not projects_exist
end end