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

Error when no TTY (Errno::ENOTTY: Inappropriate ioctl for device) #49

Closed
MMartyn opened this issue Mar 10, 2017 · 9 comments
Closed

Error when no TTY (Errno::ENOTTY: Inappropriate ioctl for device) #49

MMartyn opened this issue Mar 10, 2017 · 9 comments

Comments

@MMartyn
Copy link

MMartyn commented Mar 10, 2017

I am hitting an error in my specs as there is no TTY on the build server. I have come up with two ways to address it and would like your input on which you think is best (if either).

Option 1: Update console.rb

def get_char(options)
  return input.getc unless input.tty?
  mode.raw(options[:raw]) do
    mode.echo(options[:echo]) { input.getc }
  end
end

Option 2: Override read_keypress in TestPrompt

def read_keypress(options = {})
  super(options.merge({ echo: true, raw: false }))
end

I am leaning towards Option 1. Let me know and I can submit a PR.

Thanks.

@piotrmurach
Copy link
Owner

Hi Matt, thanks for using the library.

Option 1 - I see the intention behind it, it will work when reading from file or other IO object and also allow piping stuff to command etc.... Though I'm not sure about the implementation itself. Option 2 feels rather 'dirty' to me and not very maintainable. Currently I have changes in master which will in effect make majority of prompts work in raw mode. This is to do with providing line editing functionality for prompts such as #ask or #multiline. I more inclined to go with Option 1 but would probably put the checks for presence of console down to mode level. However, the tty? check is pretty unreliable on windows console emulators, for example in cygwin it returns false. Do you have any experience in Windows domain to tackle this problem? Anyways, if you fancy submitting PR I will review.

@MMartyn
Copy link
Author

MMartyn commented Mar 11, 2017

It's a pretty great library, so thanks for sharing it.

No, I don't have experience working with ruby on a Windows machine, just Linux and Mac. So are you thinking of maybe checking if the input responds to raw/noecho in the mode and if not fall back to yield?

Also, I was curious about this in console.rb

def initialize(input)
  @input = input
  @mode  = Mode.new
  @keys  = Codes.keys
  @escape_codes = [[ESC.ord], CSI.bytes.to_a]
end

Should the @mode = Mode.new be @mode = Mode.new(input)?

@piotrmurach
Copy link
Owner

This is really good catch. This makes things ever more interesting as at this point input.tty? would return nil in test environment when stringio is used. This in turn wouldn't be great as many tests depend on the mode being raw. Not sure how to solve this conundrum.

@piotrmurach
Copy link
Owner

Thanks a lot for pointing out all of these problems, they are fixed in master. Would you mind taking tty-prompt for a spin?

@MMartyn
Copy link
Author

MMartyn commented Mar 13, 2017

Thanks for the update. I am going to give master a spin this morning. I'll let you know how it goes.

@MMartyn
Copy link
Author

MMartyn commented Mar 13, 2017

Master works. My specs are now green. Want me to close this issue? Also, do you know if/when you might be cutting the next release. Thanks again.

@piotrmurach
Copy link
Owner

Great. Naaa let's keep this issue open for now until I release new version - this will act as a reminder. I don't want to subscribe to a strict deadline - it is open source after all and I want to get this right 😄 However, I'm planning to release shortly after I've implemented #40 and possibly #50 as I'm really close getting it done. All the ground work has been done but I need to implement few bits and ensure all works fine on Windows as well. Can you wait? In the meantime if possible you could point your Gemfile at master sha?

@MMartyn
Copy link
Author

MMartyn commented Mar 14, 2017

Yep, totally understand. I can point to the master sha for now while I am developing. Was only curious as I don't believe it is possible to point to a github repo in a gemspec.

@piotrmurach
Copy link
Owner

I've just released v0.12.0 with the fix and many changes. Enjoy!

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

2 participants