Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TNhBC-0000Rq-DX for pgsql-bugs@postgresql.org; Mon, 15 Oct 2012 09:41:46 +0000 Received: from mail-qa0-f53.google.com ([209.85.216.53]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TNhB7-0007Rz-K3 for pgsql-bugs@postgresql.org; Mon, 15 Oct 2012 09:41:46 +0000 Received: by mail-qa0-f53.google.com with SMTP id s11so1084076qaa.19 for ; Mon, 15 Oct 2012 02:41:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent :x-gm-message-state; bh=Px9WOiJEClepuOnjpIYna0eAunBtnYy2cTAd8uxMdJ4=; b=grORiF5bQRMceO13lPI0aSlpFIK9uODTFLy9/l3q+6lELR54D5jEKDJVrlMtKLDuue elo+PzFzOfyNqoqPbBUPspG0nTn8k8EeIiF210zgd/tEIArcLLkvAbfeQsod2gsT1+cj 4Bz6NUdF4aVCxTfKeIL06I0NzRq/u7kSYxQ9/owlZbEGKV5AFHV7umB6GK4QPMXRb+SB zQ62h9ETG6ho/LKKZ42LevRVRSh1bNeUD6J5lH/1dLbBo6rHe7MNmAJI1AIGxivuVKVX rZuATohe4aBR6ZWdiu1v4Z0kgdVJorqexALE2SZZGWbztxUfSO13wNo2K7TpJ+tghn/v GqPw== Received: by 10.49.87.36 with SMTP id u4mr25849277qez.57.1350294100082; Mon, 15 Oct 2012 02:41:40 -0700 (PDT) Received: from tornado.leadboat.com (ip68-105-236-221.hr.hr.cox.net. [68.105.236.221]) by mx.google.com with ESMTPS id j9sm2632814qac.15.2012.10.15.02.41.37 (version=SSLv3 cipher=OTHER); Mon, 15 Oct 2012 02:41:39 -0700 (PDT) Date: Mon, 15 Oct 2012 05:41:36 -0400 From: Noah Misch To: Alexander Law Cc: Alvaro Herrera , Pg Bugs Subject: Re: BUG #6510: A simple prompt is displayed using wrong charset Message-ID: <20121015094136.GA4627@tornado.leadboat.com> References: <1331925178-sup-9261@alvh.no-ip.org> <4F65A533.7090208@gmail.com> <1332187409-sup-4631@alvh.no-ip.org> <4F68DF76.1030609@gmail.com> <20121010110555.GA21405@tornado.leadboat.com> <507A5D18.3080107@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <507A5D18.3080107@gmail.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-Gm-Message-State: ALoCoQk91hzCJFlWkPPv/evq5SQpqAxSCPGJREE5pTrudG0yk4uHn0MhVxwgeMqle+gfYiWbHWT8 X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201210/133 X-Sequence-Number: 34433 On Sun, Oct 14, 2012 at 10:35:04AM +0400, Alexander Law wrote: > I agree with you, CONOUT$ way is much simpler. Please look at the patch. See comments below. > Regarding msys - yes, that check was not correct. > In fact you can use "con" with msys, if you run sh.exe, not a graphical > terminal. > So the issue with con not related to msys, but to some terminal > implementations. > Namely, I see that con is not supported by rxvt, mintty and xterm (from > x.cygwin project). > (rxvt was default terminal for msys 1.0.10, so I think such behavior was > considered as msys feature because of this) > Your solution to use IsWindowVisible(GetConsoleWindow()) works for these > terminals (I've made simple test and it returns false for all of them), > but this check will not work for telnet (console app running through > telnet can use con/conout). Thanks for testing those environments. I can reproduce the distinctive behavior when a Windows telnet client connects to a Windows telnet server. When I connect to a Windows telnet server from a GNU/Linux system, I get the normal invisible-console behavior. I also get the invisible-console behavior in PowerShell ISE. > Maybe this should be considered as a distinct bug with another patch > required? (I see no ideal solution for it yet. Probably it's possible to > detect not "ostype", but these terminals, though it would not be generic > too.) Using stdin/stderr when we could have used the console is a mild loss; use cases involving redirected output will need to account for the abnormality. Interacting with a user-invisible console is a large loss; prompts will hang indefinitely. Therefore, the test should err on the side of stdin/stderr. Since any change here seems to have its own trade-offs, yes, let's leave it for a separate patch. > And there is another issue with a console charset. When writing string > to a console CRT converts it to console encoding, but when reading input > back it doesn't. So it seems, there should be conversion from > ConsoleCP() to ACP() and then probably to UTF-8 to make postgres > utilities support national chars in passwords or usernames (with > createuser --interactive). Yes, that also deserves attention. I do not know whether converting to UTF-8 is correct. Given a username containing non-ASCII characters, you should be able to input the same way for both "psql -U " and the createuser prompt. We should also be thoughtful about backward compatibility. > I think it can be fixed as another bug too. Agreed. > --- a/src/port/sprompt.c > +++ b/src/port/sprompt.c > @@ -60,8 +60,13 @@ simple_prompt(const char *prompt, int maxlen, bool echo) > * Do not try to collapse these into one "w+" mode file. Doesn't work on > * some platforms (eg, HPUX 10.20). > */ > +#ifdef WIN32 > + termin = fopen("CONIN$", "r"); > + termout = fopen("CONOUT$", "w+"); This definitely needs a block comment explaining the behaviors that led us to select this particular implementation. > +#else > termin = fopen(DEVTTY, "r"); > termout = fopen(DEVTTY, "w"); This thread has illustrated that the DEVTTY abstraction does not suffice. I think we should remove it entirely. Remove it from port.h; use literal "/dev/tty" here; re-add it as a local #define near the one remaining use, with an XXX comment indicating that the usage is broken. If it would help, I can prepare a version with the comment changes and refactoring I have in mind. > +#endif > if (!termin || !termout > #ifdef WIN32 > /* See DEVTTY comment for msys */ Thanks, nm