The Windows "pick" command ruins the "Ruby method" gets "

Open irb and

  • type gets . It should work fine.
  • Then try system("choice /c YN") It should work as expected.
  • Now try gets again, it behaves strangely.

Can someone tell me why this is?

EDIT: for some clarification about the "odd" behavior, it allows me to type in for gets , but doesn't show me characters, and I have to press the enter key twice.

+6
source share
1 answer

Handling terminal I / O is a dark and mysterious art. Anyone who tries to draw bash colorized output to work in windows PowerShell via ssh knows about this. (And various keyboard shortcuts, such as Ctrl + Backspace, only make things worse.)

One possible cause of your problem is handling special characters. Each terminal can type characters in different modes, and it analyzes its own output in search of specific sequences of characters to switch states.

Fe here you can find ANSI escape code sequences, one of the possible supported standards for different types of terminals.

See there Esc[5;45m ? This will cause all of the following output to flash to a magenta background. And there are many more such things.

So, the answer to your question, taken literally, is that your choice command launches something with output modes using special escape sequences, and ruby ​​gets breaks in this special terminal operating mode.

But a link to the HighLine gemstone documentation will be more useful. Why is it necessary to implement platform and intrusive behavior when you can implement the same thing with about 12 LOC ? All respect for Gist goes to botimer , I just stumbled upon its code using search.

+1
source

Source: https://habr.com/ru/post/917777/


All Articles