dart - readByteSync - is this behavior correct? -
stdin.readbytesync has been added dart.
using stdin.readbytesync data entry, attempting allow default value , if entry made operator, clear default value. if no entry made , enter pressed, default used.
what appears happening no terminal output sent terminal until newline character entered. therefore when print() or stdout.write(), delayed until newline entered.
therefore, when operator enters first character override default, default not cleared. ie. default "abc", data entered "xx", "xxc" showing on screen after entry of "xx". "problem" appears no "writes" terminal sent until newline entered.
while can find alternative way of doing this, know if way readbytesync should or must work. if so, i’ll find alternative way of doing want.
// example program //
import 'dart:io'; void main () { int iinput; list<int> lcharcodes = []; print(""); print(""); string sdefault = "abc"; stdout.write ("enter data : $sdefault\b\b\b"); while (iinput != 10) { // wait newline iinput = stdin.readbytesync(); if (iinput == 8 && lcharcodes.length > 0) { // bs lcharcodes.removelast(); } else if (iinput > 31) { // ascii printable char lcharcodes.add(iinput); if (lcharcodes.length == 1) stdout.write (" \b\b\b\b chars cleared"); // clear line print ("\nlcharcodes length = ${lcharcodes.length}"); } } print ("\ndata entered = ${new string.fromcharcodes(lcharcodes).trim()}"); }
results on command screen :
c:\users\brian\dart-dev1\test\bin>dart testsync001.dart enter data : xxc chars cleared lcharcodes length = 1 lcharcodes length = 2 data entered = xx c:\users\brian\dart-dev1\test\bin>
i added stdin.readbytesync , readlinesync, easier create small scrips reading stdin. however, 2 things still missing, feature-complete.
1) line mode vs raw mode. asking for, way char it's printed.
2) echo on/off. mode useful e.g. typing in passwords, can disable default echo of characters.
i hope able implement , land these features rather soon.
you can star this bug track development of it!
Comments
Post a Comment