Is there something comparable to getpasswd functionality in Go?
I tried using syscall.Read, but it echoes what is typed.
-Ostsol
> I used a similar technique (calling stty) for reading a single
> uncooked character.
> However, as was pointed out to me calling stty is rather unportable.
> I think that Go needs to support more file control attributes.
Everything in the area of terminal control is unportable. I took a
quick look at Tcl, which tries pretty hard to be portable across
operating systems, but it doesn't appear to handle this either.
The POSIX termios interface is pretty widely available on Unix systems
these days, thank goodness. However, it is a poor match for Windows.
Termios is used to control the command line, pseudo-terminals, and
serial ports, which are all different things on Windows. For echo the
relevant case here is what Windows call the console, but there is no
exact mapping between termios options and console options (e.g.,
termios separates raw-mode from echo-mode, but Windows does not).
Perhaps the Unix syscall interface should add Termios, Tcsetattr, and
friends, and the Windows syscall interface should add SetConsoleMode.
Then somebody can think about a higher level package which provides
simple functions like turning off echo, and has different
implementations on Unix and Windows.
Ian
On Jan 26, 9:26 am, Ian Lance Taylor <i...@google.com> wrote:
If I'm doing a perl script utility and feel compelled to have a UI, I
slap on a TK/Perl form, which is windowing GUI-based.
Most of us tend to do something like a daemon service and hang a web
UI on to it for any admin, etc. So cgi support in Apache, or the
various Go web frameworks would seem to fill the bill.
Or we do command line tools that take all their UI needs on the
invocation command line. The one exception being a way to convey a
password without exposing it to the passerby.
Hmm, would seem like Getpasswd() may be a sufficient effort for
special console UI needs that meets what folks actually write code to
do.
About three weeks ago I solved this same get-password-with-no-echo
problem for a Perl script on Windows - used the Windows Console APIs,
which are exposed in an ActiveState Perl package.
So looks like a Go portable solution for Getpasswd() would be stty on
*nix platforms and Console APIs on Windows. Thereafter Go would sport
a portable means to solve this specific need.
Abstracting full blown terminal UI across platforms sounds like a lot
of work for perhaps too small an audience.