lib/ripl/rc/anchor.rb in ripl-rc-0.1.2 vs lib/ripl/rc/anchor.rb in ripl-rc-0.1.3

- old
+ new

@@ -19,41 +19,50 @@ def prompt if Ripl::Rc.const_defined?(:Color) && kind_of?(Ripl::Rc::Color) && obj_or_binding = (config[:rc_anchor] ||= []).last - super.sub(obj_or_binding.inspect, format_result(obj_or_binding)) + super.sub(@name, format_result(obj_or_binding, @name)) else super end end # if the object is the same, then we're exiting from an anchor, # so don't print anything. def print_result result - super unless result.object_id == Ripl.config[:rc_anchor_last].object_id + super unless result != nil && + result.object_id == Ripl.config[:rc_anchor_last].object_id end module Imp + def short_inspect obj_or_binding + obj_or_binding.inspect[0..9] + end + end + + module AnchorImp def anchor obj_or_binding if Ripl.config[:rc_init].nil? Ripl::Runner.load_rc(Ripl.config[:riplrc]) Ripl.config[:rc_init] = true end (Ripl.config[:rc_anchor] ||= []) << obj_or_binding + name = Ripl::Rc::U.short_inspect(obj_or_binding) Ripl::Shell.create(Ripl.config.merge( - :name => obj_or_binding.inspect, - :prompt => obj_or_binding.inspect + - "(#{Ripl.config[:rc_anchor].size})" + + :name => name, + :prompt => "#{name}(#{Ripl.config[:rc_anchor].size})" + Ripl.config[:prompt])).loop # stores to check if we're exiting from an anchor Ripl.config[:rc_anchor_last] = Ripl.config[:rc_anchor].pop end end end -Ripl::Shell.include(Ripl::Rc::Anchor) +module Ripl::Rc::U; extend Ripl::Rc::Anchor::Imp; end -Ripl.extend(Ripl::Rc::Anchor::Imp) +Ripl::Shell.include(Ripl::Rc::Anchor) Ripl.config[:prompt] ||= Ripl::Shell::OPTIONS[:prompt] + +Ripl.extend(Ripl::Rc::Anchor::AnchorImp) # define Ripl.anchor