weixin_39746652
weixin_39746652
2021-01-06 05:44

Fiddle support?

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?

该提问来源于开源项目:oracle/truffleruby

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

8条回答

  • weixin_39869693 weixin_39869693 4月前

    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).

    点赞 评论 复制链接分享
  • weixin_39673947 weixin_39673947 4月前

    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.

    点赞 评论 复制链接分享
  • weixin_39869693 weixin_39869693 4月前

    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]
    
    点赞 评论 复制链接分享
  • weixin_39746652 weixin_39746652 4月前

    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)

    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.

    点赞 评论 复制链接分享
  • weixin_39869693 weixin_39869693 4月前

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

    点赞 评论 复制链接分享
  • weixin_39869693 weixin_39869693 4月前

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

    
    $ 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.

    点赞 评论 复制链接分享
  • weixin_39869693 weixin_39869693 4月前

    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.

    点赞 评论 复制链接分享
  • weixin_39746652 weixin_39746652 4月前

    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.

    点赞 评论 复制链接分享

相关推荐