Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read 'hidden' input for CLI Dart app

What's the best way to receive 'hidden' input from a command-line Dart application? For example, in Bash, this is accomplished with:

read -s SOME_VAR
like image 419
TJ Mazeika Avatar asked Sep 06 '25 03:09

TJ Mazeika


1 Answers

Set io.stdin.echoMode to false:

import 'dart:io' as io;

void main() {
  io.stdin.echoMode = false;

  String input = io.stdin.readLineSync();

  // or 

  var input;
  while(input != 32) {
    input = io.stdin.readByteSync();
    if(input != 10)  print(input);
  }

  // restore echoMode
  io.stdin.echoMode = true;
}
like image 166
Günter Zöchbauer Avatar answered Sep 07 '25 20:09

Günter Zöchbauer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!