With further experimentation, I don’t see the advantage of changing the Canonical settings. It looks like just changing the echo setting is enough.
This code works in Mac OS 32 and 64, and Linux 32. Don’t know (or care yet) why it doesn’t work in Linux 64, but if anyone has an insight…
dim s as string
#if TargetMacOS then
const kLib = "libncurses.dylib"
#elseif TargetLinux then
const kLib = "ncurses"
#endif
const kEcho as UInteger = &h00000008
soft declare sub tcgetattr lib kLib (file as UInteger, ByRef values as Termios)
soft declare sub tcsetattr lib kLib (file as UInteger, when as UInteger, ByRef values as Termios)
dim origSettings as Termios
tcgetattr( 0, origSettings )
dim newSettings as Termios
newSettings.StringValue( true ) = origSettings.StringValue( true )
newSettings.LocalFlags = newSettings.LocalFlags and ( not kEcho )
tcsetattr( 0, 0, newSettings )
//
// Using ReadLine
//
StdOut.Write "Enter password: "
dim pw as string = StdIn.ReadLine
print EncodeHex( pw, true )
//
// In a loop
//
do
dim c as string = StdIn.ReadAll
if c = &u0A then
exit
end if
s = s + c
'StdOut.Write c // Comment to get password processing
loop
print EncodeHex( s, true )
tcsetattr( 0, 0, origSettings )
Structure Termios
InputFlags As UInteger
OutputFlags As UInteger
ControlFlags As UInteger
LocalFlags As UInteger
ControlChars(19) As Byte
InputSpeed As UInteger
OutputSpeed As UInteger
End Structure