Skip to content
This repository was archived by the owner on Mar 12, 2023. It is now read-only.

Fix Jard is bypassed when writting something to stdout while debugging #5

Merged
merged 2 commits into from
Jul 29, 2020

Conversation

0x2c7
Copy link
Owner

@0x2c7 0x2c7 commented Jul 29, 2020

Scenario

    a = "Hello" * 20

    jard
    puts "Hello"
    puts "WTF is going on?"

    b = 1..20

Explanation

Internally, Ruby Jard overrides STDOUT#write method to append all the output to a buffer, and print it out after the program exits.

      def $stdout.write(string)
        # NOTE: `RubyJard::ScreenManager.instance` is a must. Jard doesn't work well with delegator
        if !RubyJard::ScreenManager.instance.updating? && RubyJard::ScreenManager.instance.started?
          RubyJard::ScreenManager.instance.output_storage.write(string)
        end
        super
      end

In the source code:

    class << self
      extend Forwardable

      def_delegators :instance, :update, :draw_error, :started?, :updating?

      def instance
        @instance ||= new
      end
    end

It turns out Byebug doesn't work well with delegators. Fixing the root cause is not easy. I'll work with byebug later.

@0x2c7 0x2c7 merged commit 8fc0aca into master Jul 29, 2020
@0x2c7 0x2c7 deleted the bug/fix-skipped-next branch July 29, 2020 14:37
@0x2c7 0x2c7 changed the title Fix skipped next Fix Jard is bypassed when writting something to stdout while debugging Jul 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant