1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Intermediate merge step

This commit is contained in:
☈king 2013-01-08 13:07:45 -06:00 committed by rking@sharpsaw.org
parent 4a059fd3a6
commit 4e89649ac7
2 changed files with 66 additions and 12 deletions

View file

@ -1,8 +1,30 @@
class Pry
class Command::Ls < Pry::ClassCommand
module Helpers
module Formatting
def self.tablify(things, screen_width)
maximum_width = things.map{|t| Pry::Helpers::Text.strip_color(t).length}.max + Pry.config.ls.separator.length
maximum_width = screen_width if maximum_width > screen_width
columns = screen_width / maximum_width
things.each_slice(columns).map do |slice|
slice.map do |s|
padding_width = maximum_width - Pry::Helpers::Text.strip_color(s).length
padding = Pry.config.ls.separator.ljust(padding_width, Pry.config.ls.separator)
s + padding
end.join("")
end.join("\n")
end
end
end
class Command::Ls < Pry::ClassCommand
match 'ls'
group 'Context'
description 'Show the list of vars and methods in the current scope.'
Pry::Commands.create_command "ls" do
group "Context"
description "Show the list of vars and methods in the current scope."
command_options :shellwords => false, :interpolate => false
def options(opt)
@ -303,17 +325,7 @@ class Pry
end
screen_width = (TerminalInfo.screen_size || [25, 80])[1]
maximum_width = things.map{|t| Pry::Helpers::Text.strip_color(t).length}.max + Pry.config.ls.separator.length
maximum_width = screen_width if maximum_width > screen_width
columns = screen_width / maximum_width
things.each_slice(columns).map do |slice|
slice.map do |s|
padding_width = maximum_width - Pry::Helpers::Text.strip_color(s).length
padding = Pry.config.ls.separator.ljust(padding_width, Pry.config.ls.separator)
s + padding
end.join("")
end.join("\n")
Pry::Helpers::Formatting.tablify(things, screen_width)
end
# Color output based on config.ls.*_color

View file

@ -28,6 +28,48 @@ describe "ls" do
end
end
describe 'formatting - should order downward and wrap to columns' do
FAKE_COLUMNS = 62
def try_round_trip(text)
text.strip!
things = text.split(/\s+/)
actual = Pry::Helpers::Formatting.tablify(things, FAKE_COLUMNS)
if actual != text
actual.strip.should == text
puts text, 'vs.', actual
end
end
it 'should handle the basic case' do
try_round_trip(<<-EOT)
aadd ddasffssdad sdsaadaasd ssfasaafssd
adassdfffaasds f sdsfasddasfds ssssdaa
assfsafsfsds fsasa ssdsssafsdasdf
EOT
end
it 'should handle... another basic case' do
try_round_trip(<<-EOT)
aaad dasaasffaasf fdasfdfss safdfdddsasd
aaadfasassdfff ddadadassasdf fddsasadfssdss sasf
aaddaafaf dddasaaaaaa fdsasad sddsa
aas dfsddffdddsdfd ff sddsfsaa
adasadfaaffds dsfafdsfdfssda ffadsfafsaafa ss
asddaadaaadfdd dssdss ffssfsfafaadss ssas
asdsdaa faadf fsddfff ssdfssff
asfadsssaaad fasfaafdssd s
EOT
end
it 'should handle empty input' do
try_round_trip('')
end
it 'should handle one-token input' do
try_round_trip('asdf')
end
end
describe "help" do
it 'should show help with -h' do
pry_eval("ls -h").should =~ /Usage: ls/