Sha256: 8f0373b6489bd8fda4dae6a238a73b0ae0e20efb58226cbab979d21b20dc4a7e
Contents?: true
Size: 1.14 KB
Versions: 1
Compression:
Stored size: 1.14 KB
Contents
require 'ripl/rc/u' module Ripl::Rc::SqueezeHistory include Ripl::Rc::U # avoid some complicated conditions... def history super || (@history ||= []) end # write squeezed history def write_history return super if SqueezeHistory.disabled? File.open(history_file, 'w'){ |f| f.puts U.squeeze_history(history).join("\n") } end # squeeze history on memory too def eval_input input return super if SqueezeHistory.disabled? history.pop if input.strip == '' || (history.size > 1 && input == history.to_a[-2]) # EditLine is really broken, to_a is needed for it super end def before_loop return super if SqueezeHistory.disabled? super if history.empty? end module Imp def squeeze_history history history.to_a.inject([]){ |result, item| if result.last == item result else result << item end }.last(Ripl.config[:rc_squeeze_history_size]) end end end module Ripl::Rc::U; extend Ripl::Rc::SqueezeHistory::Imp; end Ripl::Shell.include(Ripl::Rc::SqueezeHistory) Ripl.config[:rc_squeeze_history_size] ||= 500
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ripl-rc-0.2.1 | lib/ripl/rc/squeeze_history.rb |