piotrmurach / tty-prompt

A beautiful and powerful interactive command line prompt
https://ttytoolkit.org
MIT License
1.47k stars 136 forks source link

Multiple issues on Windows #31

Closed cwenner closed 7 years ago

cwenner commented 7 years ago

Hi,

not sure if I am missing something obvious here but I get multiple issues when trying TTY::Prompt on Windows 7.

Issues

Specifically, when running the first four examples from the readme - prompt name, like ruby?, secret, destiny - the following happens:

Code tested

require 'rubygems' #not needed but included for completeness
#require 'tty' #later test
require 'tty-prompt'

prompt = TTY::Prompt.new
# Following lines reordered and disabled depending on test.
prompt.ask('What is your name?', default: ENV['USER'])
prompt.yes?('Do you like Ruby?')
prompt.mask("What is your secret?")
prompt.select("Choose your destiny?", %w(Scorpion Kano Jax))

Screenshots

Before entering name (the first line is a standard Windows warning and translates to "Cannot find path"/"The system cannot find the path specified."?):

image

After entering name and pressing enter once (note how second prompt is printed but not queried): image

Environment

Additional info

tty-prompt seems like a great tool for making terminal applications otherwise and not sure if others experience this issue. It might just be Windows 7 or the company environment.

Thanks and merry xmas, Cenny

piotrmurach commented 7 years ago

Hi Cenny,

Thank you for this detailed report, it is really useful!

Firstly, I would recommend for you to read similar issue posted recently for deeper understanding of where I am with Windows support.

When I developed this tool I haven't had Windows in mind at all and never tested it on this system. I currently don't have access to Windows but I will try to download ISO for Windows 10 to play with. I'm happy to merge any patches that actually fix the issues mentioned above and make this tool available for Windows users but this is not my priority.

The plan for the next v0.9.0 release is to:

As you can see this is a bit of a task and until this is done I won't be in position to investigate Windows. Do you have time yourself to help out fixing this stuff?

piotrmurach commented 7 years ago

This library relies heavily on ANSI escape sequences for controlling input/output. I wonder if that's a missing factor in Windows 7 terminal. Could you please install ANSICON utility and see if that fixes the issue? see tutorial

kke commented 7 years ago

It runs fine when running through the windows linux subsystem, but that of course may not be a suitable choice for many cases.

piotrmurach commented 7 years ago

@kke Would you mind checking master again? I have changed how inputs are read and fixed multibyte characters support. I'm not swearing by it but it seems that this library works fine on regular Windows without linux subsystem according to these tests on Windows box

kke commented 7 years ago

Passing tests won't prove much in this case I think. The select/multi select things are still not working, no change from #25

I don't have the ansicon thing.

piotrmurach commented 7 years ago

I think the tests prove only that if you have ansi strings support on windows then this library works no problem. I really would need someone to install the ansicon or similar library in console to prove or disprove this theory. Because only then I could add a section in docs to advise people how to use this library. Would you have time to help me out?

kke commented 7 years ago

It looks a bit worse using ansicon it seems.

image

Cursor keys still do nothing, not in keypress.rb either.

Pressing enter now correctly clears the menu, without ansicon it didn't, but just threw the prompt to the middle of it:

image

kke commented 7 years ago

(it might be that i just don't know how to use ansicon. trying to reboot after ansicon -i now) (update: no effect)

piotrmurach commented 7 years ago

Since the help text and initial option are not highlighted in color, it makes me think that ANSI escape codes are still not recognised. Hence you cannot move up or down but can press enter.

Please have a look a this thread that provides possible fixes for win32 console.

piotrmurach commented 7 years ago

The weird characters in your output are unicode characters that are probably not supported, that would be an easy fix.

Last idea to try out. Could you please install the win32console gem and require it before tty-prompt. Looking at the source, the gem rewrites Ruby printing of escape codes with Windows support.

kke commented 7 years ago

Now ansicon made my dos prompt slower than a 300bps modem so I guess it's loaded and doing something, but the colors are still not there.

win32console requires some native stuff to be compiled, and I don't have any compilers.

kke commented 7 years ago

Hmm according to https://github.com/symfony/symfony/issues/17499#issuecomment-243481052 windows 10 should not need ansicon.

piotrmurach commented 7 years ago

That's true but you still need to enable flag manually to turn ANSI support on windows 10 on as I think it's off by default.

ENABLE_VIRTUAL_TERMINAL_PROCESSING to enable ANSI escape sequences

If that worked we could at least say this works in Windows 10.

kke commented 7 years ago

I think it's a ruby build issue. You would need to compile a ruby with the flag enabled. Maybe they could make it so in the official release.

piotrmurach commented 7 years ago

I think this is a OS flag and you could flip it on through your Ruby code if you directly called out a C function setConsoleMode through Ruby bindings.

cwenner commented 7 years ago

Wow, thanks you for the quick and thorough responses. Unfortunately I only have a running Windows partition at work atm and I cannot motivate spending too much time on this - I just thought the library would be perfect for a utility.

If you do not support Windows, it's entirely understandable. I did not see any information about it in the Readme so it seems I jumped the gun by assuming it was meant as a cross-platform utility.

cwenner commented 7 years ago

I tested Ansicon (1.66, precompiled x64 bin, then x86 bin for complteness). The issues above change somewhat.

These are the corresponding results of the two screenshots in the initial post:

Before entering name (same as before): image

After entering name and pressing enter once (different): image

C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/tty-prompt-0.8.0/lib/tty/prompt/mask _question.rb:44:in keypress: undefined method + for nil:NilClass (NoMethodEr ror) from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/wisper-1.6.1/lib/wisper/broadcasters/send_broadcaster.rb:5:in public_send from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/wisper-1.6.1/lib/wisper/broadcasters/send_broadcaster.rb:5:in broadcast from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/wisper-1.6.1/lib/wisper/registration/object.rb:16:in broadcast from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/wisper-1.6.1/lib/wisper/publisher.rb:65:in block in broadcast from C:/Ruby23-x64/lib/ruby/2.3.0/set.rb:306:in each_key from C:/Ruby23-x64/lib/ruby/2.3.0/set.rb:306:in each from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/wisper-1.6.1/lib/wisper/publisher.rb:64:in broadcast from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/tty-prompt-0.8.0/lib/tty/prompt/reader.rb:166:in emit_key_event from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/tty-prompt-0.8.0/lib/tty/prompt/reader.rb:79:in block (3 levels) in read_keypress from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/tty-prompt-0.8.0/lib/tty/prompt/reader/mode.rb:36:in raw from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/tty-prompt-0.8.0/lib/tty/pro mpt/reader/mode.rb:36:in raw from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/tty-prompt-0.8.0/lib/tty/pro mpt/reader.rb:77:in block (2 levels) in read_keypress from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/tty-prompt-0.8.0/lib/tty/pro mpt/reader/mode.rb:24:in echo from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/tty-prompt-0.8.0/lib/tty/pro mpt/reader.rb:76:in block in read_keypress from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/tty-prompt-0.8.0/lib/tty/pro mpt/reader.rb:60:in buffer from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/tty-prompt-0.8.0/lib/tty/pro mpt/reader.rb:75:in read_keypress from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/tty-prompt-0.8.0/lib/tty/pro mpt/list.rb:167:in render from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/tty-prompt-0.8.0/lib/tty/pro mpt/list.rb:96:in call from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/tty-prompt-0.8.0/lib/tty/pro mpt.rb:231:in invoke_select from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/tty-prompt-0.8.0/lib/tty/pro mpt.rb:167:in select from tty_test2.rb:10:in <main>

piotrmurach commented 7 years ago

@cwenner This is super helpful. The only thing I would suggest for the future is to test against the master branch as there may be some tiny improvements. I will soon release a new version as well.

Based on these discussion so far I have a few things to look at on Windows:

Any other thoughts what I can investigate that may help to provide basic Windows support?

piotrmurach commented 7 years ago

I've released v0.10.0 that fixes the 'cannot find the path' issue and enables colors on windows. I have finally managed to investigate windows in vm. What appears to be the case is that Ruby really cannot gather character input on Windows. I will need to call to native C apis to get single character input with echo/no echo behaviour. The only thing you can get successfully on Windows is enter, anything else is botched which explains why simple prompts kind of work. This won't be a quick fix but I feel that I stand a chance to make it work on windows!

piotrmurach commented 7 years ago

@cwenner @kke @danielpclark I could do with some help checking Windows. Pretty much all prompts should work as expected apart from mask. Things I have done:

This is all available in master branch, I haven't released a new version yet.

kke commented 7 years ago

select, multi_select, ask, yes? all seem to work fine from master in a Win10 virtual machine.

kke commented 7 years ago

I think your windows? is true for cygwin (or MinTTY which also comes with git for windows). Seems like the windows keyreader does not work under it. (the normal non-windows stuff should work fine)

piotrmurach commented 7 years ago

I use windows xp image in my vm, but I think other people having a go at testing may uncover different things. I'm happy to refine the current windows? check but I wouldn't want to make this a show stopper. It is obviously a double negative cause when people use cygwin the normal unix mode should be just fine provided this check is fixed.

I'm going to close this ticket as the said issues have been fixed and any future problems like cygwin will warrant a new ticket.