lib/byebug/processors/command_processor.rb in byebug-3.4.2 vs lib/byebug/processors/command_processor.rb in byebug-3.5.0

- old
+ new

@@ -125,15 +125,16 @@ # Change default when in irb or code included in command line Setting[:autolist] = false if ['(irb)', '-e'].include?(file) # Bind commands to the current state. - commands = cmds.map { |cmd| cmd.new(state) } + commands = cmds.map do |cmd_class| + cmd = cmd_class.new(state) + cmd.execute if cmd.class.always_run >= run_level + cmd + end - commands.select { |cmd| cmd.class.always_run >= run_level } - .each { |cmd| cmd.execute } - [state, commands] end # # Splits a command line of the form "cmd1 ; cmd2 ; ... ; cmdN" into an @@ -156,35 +157,36 @@ # # Handle byebug commands. # def process_commands(context, file, line) - state, commands = always_run(context, file, line, 1) + state, commands = preloop(context, file, line) - if Setting[:testing] - Thread.current.thread_variable_set('state', state) - else - Thread.current.thread_variable_set('state', nil) - end + repl(state, commands, context) - preloop(commands, context) - puts(state.location) if Setting[:autolist] == 0 + postloop + end + # + # Main byebug's REPL + # + def repl(state, commands, context) until state.proceed? input = if @interface.command_queue.empty? @interface.read_command(prompt(context)) else @interface.command_queue.shift end - break unless input + return unless input if input == '' next unless @last_cmd input = @last_cmd else @last_cmd = input end + split_commands(input).each do |cmd| one_cmd(commands, context, cmd) end end end @@ -213,27 +215,48 @@ cmd.execute end # - # Tasks to do before processor loop + # Tasks to do before processor loop. # - def preloop(_commands, context) + def preloop(context, file, line) + state, commands = always_run(context, file, line, 1) + + if Setting[:testing] + Thread.current.thread_variable_set('state', state) + else + Thread.current.thread_variable_set('state', nil) + end + @context_was_dead = true if context.dead? && !@context_was_dead - return unless @context_was_dead + if @context_was_dead + puts 'The program finished.' + @context_was_dead = false + end - puts 'The program finished.' - @context_was_dead = false + puts(state.location) if Setting[:autolist] == 0 + + @interface.history.restore if Setting[:autosave] + + [state, commands] end + # + # Tasks to do after processor loop. + # + def postloop + Setting[:autosave] ? @interface.history.save : @interface.history.clear + end + class State - attr_accessor :commands, :context, :display, :file, :frame_pos - attr_accessor :interface, :line, :previous_line + attr_accessor :commands, :context, :display, :file, :frame_pos, + :interface, :line, :prev_line def initialize(commands, context, display, file, interface, line) @commands, @context, @display = commands, context, display - @file, @interface, @line = file, interface, line - @frame_pos, @previous_line, @proceed = 0, nil, false + @file, @frame_pos, @interface = file, 0, interface + @line, @prev_line, @proceed = line, nil, false end extend Forwardable def_delegators :@interface, :errmsg, :puts, :confirm