2

Would really like to retrieve the entire line as it is typed before it is submitted so checks can be run before the user adds a line break? How would one accomplish this?

Thank you for reading.

Will Squire
  • 6,127
  • 7
  • 45
  • 57

1 Answers1

3

You can archive this by setting stdin.lineMode to false. In that case you get a stream event for every character typed instead of only one per line. If you want to handle the outputing of the entered character on your own, you can also disable stdin.echoMode. In that case you have to pring the entered characters on your own. You have to enable it again after your program exits, otherwise the terminal stays in that mode.

One problem is that you are unable to reactivate echoMode in case of a program crash as there is no global crash handler. See issue 17743 for that.

Fox32
  • 13,126
  • 9
  • 50
  • 71
  • Ah, you got me entirely! Do you know of any places I could be pointed to for handling the display of characters? (backspace also seems to be escaping now too with `lineMode = false`) Thank you. – Will Squire Nov 29 '14 at 16:11
  • You can simply echo them to [stdout.write](https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart:io.Stdout). – Fox32 Nov 29 '14 at 21:46