[Mono-dev] Unix console implementation

Greg Najda gregnajda at gmail.com
Wed Jul 31 03:05:04 UTC 2013


I'm attempting to fix https://bugzilla.xamarin.com/show_bug.cgi?id=12552and
https://bugzilla.xamarin.com/show_bug.cgi?id=12551. Console, ConsoleDriver,
and the IConsoleDriver implementations make the flawed assumption that "is
console" is a simple boolean value when standard input or standard output
can be redirected to a file or a pipeline independently of each other.

I got rid of NullConsoleDriver and made WindowsConsoleDriver do the right
thing depending on whether or not standard input or standard output is a
console. This was straightforward; For example,
WindowsConsoleDriver.KeyAvailable does the usual if standard input is a
console, if not it returns false (which should throw an exception instead
as per
http://msdn.microsoft.com/en-us/library/system.console.keyavailable.aspxbut
that's for another commit...).

I am running into some trouble doing the same with TermInfoDriver. It looks
like mono disables the normal echoing of console input characters to the
console and handles that logic itself, echoing input characters to standard
output, instead letting the terminal take care of it. This is quite
problematic if standard output is redirected but standard input is not.

Why does this matter? Here's one use case. A program wants to read in a
password from the user. If standard input is a console, the program uses
ReadKey(true) to read the password without displaying it on the screen.
Consider what happens if the user wants to run output through tee. What
should happen is that everything is the same except that any output the
program itself outputted should go to the file specified to tee. For
example:

greg at Kubuntu:~$ echo "abc" > test.txt
greg at Kubuntu:~$ sudo cat test.txt | tee sudo_output.txt
[sudo] password for greg:
abc

As another example

greg at Kubuntu:~$ cat - > test_cat_output.txt

Even though standard output is redirected to a file, standard input is
still echoed to the console.

Taking over the job of echoing input characters instead of letting the
terminal handle it strikes me as an odd design. What's the reason for this
approach? Is there a solution to the problem of allowing one of
input/output to be redirected and letting the one using the console to
still function correctly that does not involve rewriting large parts of
TermInfoDriver and associated internal calls?

- Greg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20130730/3e6a5166/attachment.html>


More information about the Mono-devel-list mailing list