Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fiddle support? #1572

Closed
piotrmurach opened this issue Feb 6, 2019 · 8 comments
Closed

Fiddle support? #1572

piotrmurach opened this issue Feb 6, 2019 · 8 comments
Assignees
Milestone

Comments

@piotrmurach
Copy link

I've added TruffleRuby to tty-prompt gem travis configuration to see if it works with a more interesting project of mine. I hope to help you make the 1.0.0 relaese with this issue report. The tty-prompt ci fails due to lack of Fiddle::DLError which will probably be masking a real cause of the issue.

Does TruffleRuby provide support for fiddle anyway? Or does it handle native C calls differently?

@eregon
Copy link
Member

eregon commented Feb 6, 2019

Hello and thank you for the report!

We intend to support Fiddle, although currently our support is very minimal.
I'll try to take a look at what's needed to run tty-prompt.

What I see is that Fiddle is used for size_from_win_api in https://github.com/piotrmurach/tty-screen/blob/282ae528974059c16090212dbcfb4a3d5aa3bbeb/lib/tty/screen.rb#L80-L81
So probably just raising Fiddle::DLError when there is missing library is enough to go through that method (we don't support Windows currently).

@eregon eregon self-assigned this Feb 6, 2019
@chrisseaton
Copy link
Collaborator

We worked a bit on Fiddle support in the past but paused when we realised we didn't really have any use-cases at the time. It's good to have a motivating user.

@eregon
Copy link
Member

eregon commented Feb 6, 2019

I have a fix for the usage of Fiddle in tty-screen going through CI.
It now works with both IO#ioctl, and also through io/console:

$ jt ruby -rtty-screen -e 'p TTY::Screen.size'
[72, 140]

@piotrmurach
Copy link
Author

@eregon Ohh forgotten that tty-screen uses Fiddle as well. The actual dependency in tty-prompt is tty-reader that uses Fiddle to support Windows keyboard input on older systems(please see https://github.com/piotrmurach/tty-reader/blob/master/lib/tty/reader/win_api.rb)

@chrisseaton I thought this may be an interesting gem to try on travis due to Win API integration. I need to support this due to many Windows servers only supporting basic console.

dougxc pushed a commit that referenced this issue Feb 7, 2019
@eregon eregon added this to the 1.0.0-rc13 milestone Feb 7, 2019
@eregon
Copy link
Member

eregon commented Feb 7, 2019

@piotrmurach My fix for tty-screen got merged (e4211f0) and will be in the next release.
I'll try to run tty-prompt tests locally to see if there are other issues.

@eregon
Copy link
Member

eregon commented Feb 7, 2019

I ran the tty-prompt specs locally, and they all passed 😃

$ bundle exec rake ci
/home/eregon/code/truffleruby-ws/truffleruby/bin/truffleruby -I/home/eregon/code/truffleruby-ws/truffleruby/lib/ruby/gems/2.4.0/gems/rspec-core-3.8.0/lib:/home/eregon/code/truffleruby-ws/truffleruby/lib/ruby/gems/2.4.0/gems/rspec-support-3.8.0/lib /home/eregon/code/truffleruby-ws/truffleruby/lib/ruby/gems/2.4.0/gems/rspec-core-3.8.0/exe/rspec --pattern spec/\{unit,integration\}\{,/\*/\*\*\}/\*_spec.rb

Randomized with seed 28403
.................................................................................................................................................................................................................................................................................................................

Top 2 slowest examples (0.536 seconds, 14.0% of total time):
  TTY::Prompt::Question#keypress receives line feed with echo on
    0.38 seconds ./spec/unit/keypress_spec.rb:4
  TTY::Prompt::Question#keypress timeouts when no key provided
    0.156 seconds ./spec/unit/keypress_spec.rb:59

Top 2 slowest example groups:
  TTY::Prompt::Question#keypress
    0.1126 seconds average (0.563 seconds / 5 examples) ./spec/unit/keypress_spec.rb:3
  TTY::Prompt#collect
    0.0608 seconds average (0.304 seconds / 5 examples) ./spec/unit/collect_spec.rb:3

Finished in 3.82 seconds (files took 1.25 seconds to load)
305 examples, 0 failures

So I'll close this issue, and notify you when the next release is out.
Thank you again for the report.

@eregon eregon closed this as completed Feb 7, 2019
@eregon
Copy link
Member

eregon commented Feb 7, 2019

BTW, I noticed tty-prompt depends on timers 4.1.2, which depends on hitimes.
hitimes works fine on Linux with TruffleRuby, but not yet on macOS (#1436).
More recent timers releases solve this problem by dropping the hitimes dependency and use Process.clock_gettime, but that also means Ruby >= 2.1 is required.

@piotrmurach
Copy link
Author

@eregon Nice one! Thanks for the heads up. I use timers only for one of the prompts, I may consider dropping it altogether and roll my own solution for scheduling calling proc in equal intervals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants