0x2c7/ruby_jard

undefined method `clear_screen' for #<IO:<STDOUT>>

ruprict opened this issue · 7 comments

Hey, just trying to kick the tires on jard and I got the error mentioned above. Using Ruby 2.6.3 and RVM. Here's the script:

#!/usr/bin/env ruby
require 'ruby_jard'


def sieve(n)

  primes = (0..n).to_a
  limit =  Math.sqrt(n)
  jard
  (2..limit).each do |i|
    (( i + i )..n).step(i) do |x|
      primes[x] = nil
    end
  end

  primes.compact
end

puts sieve(100).inspect

and the traceback:

Internal error from Jard. I'm sorry to mess up your debugging experience.
It would be great if you can submit an issue in https://github.com/nguyenquangminh0711/ruby_jard/issues

undefined method `clear_screen' for #<IO:<STDOUT>>
/Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/console.rb:44:in `clear_screen'
/Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/screen_manager.rb:199:in `clear_screen'
/Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/screen_manager.rb:113:in `rescue in update'
/Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/screen_manager.rb:112:in `update'
/Users/ggoodrich/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/forwardable.rb:230:in `update'
/Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/repl_processor.rb:45:in `process_commands'
/Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/repl_processor.rb:37:in `block (2 levels) in process_commands_with_lock'
/Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/session.rb:56:in `block in lock'
/Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/session.rb:55:in `synchronize'
/Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/session.rb:55:in `lock'
/Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/repl_processor.rb:36:in `block in process_commands_with_lock'
/Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/byebug-11.1.3/lib/byebug/helpers/eval.rb:94:in `allowing_other_threads'
/Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/repl_processor.rb:35:in `process_commands_with_lock'
/Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/repl_processor.rb:21:in `at_line'
/Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/byebug-11.1.3/lib/byebug/context.rb:98:in `at_line'
primes.rb:10:in `sieve'
primes.rb:19:in `<main>'
-------------

Traceback (most recent call last):
	15: from primes.rb:19:in `<main>'
	14: from primes.rb:10:in `sieve'
	13: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/byebug-11.1.3/lib/byebug/context.rb:98:in `at_line'
	12: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/repl_processor.rb:21:in `at_line'
	11: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/repl_processor.rb:35:in `process_commands_with_lock'
	10: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/byebug-11.1.3/lib/byebug/helpers/eval.rb:94:in `allowing_other_threads'
	 9: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/repl_processor.rb:36:in `block in process_commands_with_lock'
	 8: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/session.rb:55:in `lock'
	 7: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/session.rb:55:in `synchronize'
	 6: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/session.rb:56:in `block in lock'
	 5: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/repl_processor.rb:37:in `block (2 levels) in process_commands_with_lock'
	 4: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/repl_processor.rb:45:in `process_commands'
	 3: from /Users/ggoodrich/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/forwardable.rb:230:in `update'
	 2: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/screen_manager.rb:106:in `update'
	 1: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/screen_manager.rb:199:in `clear_screen'
/Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/console.rb:44:in `clear_screen': undefined method `clear_screen' for #<IO:<STDOUT>> (NoMethodError)
	16: from primes.rb:19:in `<main>'
	15: from primes.rb:10:in `sieve'
	14: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/byebug-11.1.3/lib/byebug/context.rb:98:in `at_line'
	13: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/repl_processor.rb:21:in `at_line'
	12: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/repl_processor.rb:35:in `process_commands_with_lock'
	11: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/byebug-11.1.3/lib/byebug/helpers/eval.rb:94:in `allowing_other_threads'
	10: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/repl_processor.rb:36:in `block in process_commands_with_lock'
	 9: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/session.rb:55:in `lock'
	 8: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/session.rb:55:in `synchronize'
	 7: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/session.rb:56:in `block in lock'
	 6: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/repl_processor.rb:37:in `block (2 levels) in process_commands_with_lock'
	 5: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/repl_processor.rb:45:in `process_commands'
	 4: from /Users/ggoodrich/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/forwardable.rb:230:in `update'
	 3: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/screen_manager.rb:112:in `update'
	 2: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/screen_manager.rb:113:in `rescue in update'
	 1: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/screen_manager.rb:199:in `clear_screen'
/Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/ruby_jard-0.2.0/lib/ruby_jard/console.rb:44:in `clear_screen': undefined method `clear_screen' for #<IO:<STDOUT>> (NoMethodError)

Thanks.

0x2c7 commented

Hi @ruprict, thank you for your bug report. I already pushed a patch as an attempt to fix your error. Could you try again with the source code on master branch, by putting this in your gem file, and run bundle update ruby_jard?

gem 'ruby_jard', git: 'https://github.com/nguyenquangminh0711/ruby_jard'

I tested the patch with Ruby 2.6.3 installed by RVM in my local machine, and it works quite well.
Screenshot from 2020-07-27 22-02-25

The root cause of the bug is still unknown. Internally, Ruby Jard uses Ruby's IO Console (https://ruby-doc.org/stdlib-2.6.3/libdoc/io/console/rdoc/IO.html) to achieve cursor movement, screen cleaning, etc. It is a C extension belong to Ruby's stdlib. So, maybe, your ruby installation in your machine skips this extension. I removed the dependency, and use ANSI escape sequence instead.

I'm not sure whether the patch could fix your issue or not, so I will publish a release after the fix is confirmed. If it doesn't work or gets weird behaviors again, please let me know some more information, including: your operating system, your terminal emulator, the output if you run tput colors?

K...new traceback:

Traceback (most recent call last):
	14: from primes.rb:21:in `<main>'
	13: from primes.rb:12:in `sieve'
	12: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/byebug-11.1.3/lib/byebug/context.rb:98:in `at_line'
	11: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/bundler/gems/ruby_jard-5f138fdd5f37/lib/ruby_jard/repl_processor.rb:21:in `at_line'
	10: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/bundler/gems/ruby_jard-5f138fdd5f37/lib/ruby_jard/repl_processor.rb:35:in `process_commands_with_lock'
	 9: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/gems/byebug-11.1.3/lib/byebug/helpers/eval.rb:94:in `allowing_other_threads'
	 8: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/bundler/gems/ruby_jard-5f138fdd5f37/lib/ruby_jard/repl_processor.rb:36:in `block in process_commands_with_lock'
	 7: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/bundler/gems/ruby_jard-5f138fdd5f37/lib/ruby_jard/session.rb:71:in `lock'
	 6: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/bundler/gems/ruby_jard-5f138fdd5f37/lib/ruby_jard/session.rb:71:in `synchronize'
	 5: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/bundler/gems/ruby_jard-5f138fdd5f37/lib/ruby_jard/session.rb:72:in `block in lock'
	 4: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/bundler/gems/ruby_jard-5f138fdd5f37/lib/ruby_jard/repl_processor.rb:37:in `block (2 levels) in process_commands_with_lock'
	 3: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/bundler/gems/ruby_jard-5f138fdd5f37/lib/ruby_jard/repl_processor.rb:45:in `process_commands'
	 2: from /Users/ggoodrich/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/forwardable.rb:230:in `update'
	 1: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/bundler/gems/ruby_jard-5f138fdd5f37/lib/ruby_jard/screen_manager.rb:130:in `update'
/Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/bundler/gems/ruby_jard-5f138fdd5f37/lib/ruby_jard/console.rb:76:in `cooked!': undefined method `cooked!' for #<IO:<STDOUT>> (NoMethodError)
	2: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/bundler/gems/ruby_jard-5f138fdd5f37/lib/ruby_jard/screen_manager.rb:79:in `block in start'
	1: from /Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/bundler/gems/ruby_jard-5f138fdd5f37/lib/ruby_jard/screen_manager.rb:97:in `stop'
/Users/ggoodrich/.rvm/gems/ruby-2.6.3@jard/bundler/gems/ruby_jard-5f138fdd5f37/lib/ruby_jard/console.rb:76:in `cooked!': undefined method `cooked!' for #<IO:<STDOUT>> (NoMethodError)
0x2c7 commented

It is so weird. Could you provide some more information about your environment, like your operating system, or your terminal emulator? And if it is possile, could you provide the output from tput colors?

Mac OS Catalina (10.15.4)

I do use tmux, but I am not using it for this.

[I] ➜ tput colors

256
0x2c7 commented

Hi @ruprict, I pushed another patch into master of the Gem. Could you try again? In this patch, I added multiple fallback mechanism to serve the case that io/console is not available, or even tput is not available. I tested the patch with a custom Ruby build without io/console, and borrow a Mac OS catalina machine to test, and it works now. Sorry for wasting for time on this back, and forth debugging.

That did it! And this is not wasting time, this is open source. Glad to help.

0x2c7 commented

I published a new release (0.2.1) to address this bug at https://github.com/nguyenquangminh0711/ruby_jard/releases/tag/v0.2.1. So I think this issue is resolved. Please let me know if you have futher questions. Regards.