This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'epitools' | |
class State | |
attr_accessor :fore, :back, :attrs | |
COLORS = [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white] | |
ATTRS = { | |
0 => :reset, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# The original idea was to use set operations to help dealing with a method's "options" hash. | |
# | |
# However, since I can't override || and &&, I wasn't able to figure out reasonable semantics. | |
# | |
# Therefore, I implemented `with_defaults`, which is what you want most of the time, and then | |
# wrote some thoughts about how set operations might work. | |
# | |
class Hash |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pry.plugin("something") do | |
command "amazing" do | |
... | |
end.help do | |
short "blah" | |
long "A long description." | |
end | |
command /more-amazing!*/ do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# An Array-like class that's used for a very specific purpose: the `out[]` array | |
# in Pry. MRU stands for most-recently-used.) | |
# | |
# It acts like an array with a maximum size -- if you try to add more elements than | |
# the maximum, the elements at the beginning of the array are discarded. | |
# | |
# Also, it keeps track of which entries are most recently accessed, and throws | |
# out only the oldest entries. | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'curses' | |
def init_screen | |
Curses.noecho # do not show typed keys | |
Curses.init_screen | |
Curses.start_color | |
Curses.stdscr.keypad(true) # enable arrow keys | |
Curses.curs_set(0) | |
Curses.ESCDELAY = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def req(mod) | |
puts " |_ #{mod}" | |
require mod | |
yield if block_given? | |
rescue Exception => e | |
p e | |
end | |
## Fancy Require w/ Modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Creates a new CommandSet and automatically mixes it into Pry::Commands. | |
# | |
Pry.plugin :test do | |
settings do | |
bool :make_awesome, :default => true | |
enum :goat_type, :default => "plain", :options => %w[ plain mountain billy ] | |
string :favorite_goat, :default => "Super Dave the Goat", :validate => proc { goat[/super/i] } | |
int :expire_goats, :default => 5.minutes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# The result is an anonymous module (named "name") that can be mixed into the | |
# Commands class. | |
# | |
Pry.plugin "name" do | |
## Settings | |
settings do | |
bool :make_awesome, :default => true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
command "gems", "List/search installed gems. (Optional parameter: a regexp to limit the search)" do |arg| | |
gems = Gem.source_index.gems.values.group_by(&:name) | |
if arg | |
query = Regexp.new(arg, Regexp::IGNORECASE) | |
gems = gems.select { |gemname, specs| gemname =~ query } | |
end | |
gems.each do |gemname, specs| | |
versions = specs.map(&:version).sort.reverse.map(&:to_s) | |
versions = [bright_green(versions.first)] + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
command "require", "Require gem(s)" do |*gems| | |
gems = gems.join(' ').gsub(',', '').split(/\s+/) | |
gems.each do |gem| | |
begin | |
if require gem | |
output.puts "#{gem.yellow} loaded" | |
else | |
output.puts "#{gem.white} already loaded" | |
end | |
rescue LoadError => e |