Skip to content

Instantly share code, notes, and snippets.

@kyrylo
Last active December 11, 2015 01:59
Show Gist options
  • Select an option

  • Save kyrylo/4527481 to your computer and use it in GitHub Desktop.

Select an option

Save kyrylo/4527481 to your computer and use it in GitHub Desktop.
Adds headings for methods in the output of `ls` command of Pry. It was rejected, because for most people it looks unpleasant.
commit e2503bc03d983f2e095bd04c7c3de7ca9b6a2e71
Author: Kyrylo Silin <kyrylosilin@gmail.com>
Date: Sun Jan 13 17:37:36 2013 +0200
Ls: slightly change the styling of heading methods
diff --git a/lib/pry/commands/ls.rb b/lib/pry/commands/ls.rb
index 5349e9e..5bf35f7 100644
--- a/lib/pry/commands/ls.rb
+++ b/lib/pry/commands/ls.rb
@@ -348,8 +348,8 @@ class Pry
end
indices
}.map { |i|
- body[i][0] = "\e[1;7m#{ body[i][0] }\e[0m"
- body[i][11..-1] = "\e[4m#{ body[i][11..-1] }\e[0m"
+ body[i][1..-1] = "\e[1m#{ body[i][1..-1] }\e[0m"
+ body[i][0] = "\e[32;1m#{ body[i][0] }\e[0m"
}
end
end
commit 1c33a7396486b1f2a76521bf5b34239d8305184e
Author: Kyrylo Silin <kyrylosilin@gmail.com>
Date: Sun Jan 13 00:02:48 2013 +0200
Add headings for methods in the output of `ls`
You will see headings when a table has more than 35 methods.
Otherwise, there is no need in them.
diff --git a/lib/pry/commands/ls.rb b/lib/pry/commands/ls.rb
index 156199b..648b387 100644
--- a/lib/pry/commands/ls.rb
+++ b/lib/pry/commands/ls.rb
@@ -296,6 +296,9 @@ class Pry
def output_section(heading, body)
return "" if body.compact.empty?
table = Pry::Helpers.tablify_to_screen_width(body)
+ if heading =~ /.+methods\z/ && body.size >= 36
+ paint_heading_methods(body)
+ end
"#{text.bold(color(:heading, heading))}: \n#{table}\n"
end
@@ -303,6 +306,22 @@ class Pry
def color(type, str)
text.send(Pry.config.ls.send(:"#{type}_color"), str)
end
+
+ # The true place for this method is {Pry::Helpers::Table}. Both JRuby and
+ # Rubinius don't like it when it's there, for some reason. *shrugs*
+ def paint_heading_methods(body)
+ cur = ''
+ body.each_with_index.inject([]) { |indices, (method, idx)|
+ if method[0] != cur && method[0] =~ /[a-z]/
+ indices << idx
+ cur = method[0]
+ end
+ indices
+ }.map { |i|
+ body[i][0] = "\e[1;7m#{ body[i][0] }\e[0m"
+ body[i][11..-1] = "\e[4m#{ body[i][11..-1] }\e[0m"
+ }
+ end
end
Pry::Commands.add_command(Pry::Command::Ls)
@kyrylo

kyrylo commented Jan 14, 2013

Copy link
Copy Markdown
Author

Screenshots: pry/pry#782 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment