www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - readln of german Umlaute (terminal.d) / readln)

reply Andre Pany <andre s-e-a-p.de> writes:
Hi,

I want to read passwords from the console (should be work on 
windows / linux / macos).
Adam Ruppe has a quite nice library (terminal.d) which allows to 
deactivating the echo to the console, which makes sense for 
passwords.

But I do not get it working with terminal.d nor with std.stdio: 
readln if it comes to special characters like ö.

The password is saved to a file.
readln will save for "ööö": "x94x94x94\n"
terminal.d will save: CCHCCHCCH

Changing the code page (CHCP 65001) will lead to the effect that 
empty strings are saved for both (readln, terminal.d)

Does someone already solved this problem and has a solution 
working on all operation systems?

Kind regadrs
André
Oct 17 2017
next sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
On Tuesday, 17 October 2017 at 12:08:57 UTC, Andre Pany wrote:
 I want to read passwords from the console (should be work on 
 windows / linux / macos).
Do you have a little test program I can copy/paste? I suspect this is because I called ReadConsoleInputA instead of W for some weird reson..
Oct 17 2017
prev sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
Or try this newest commit 
https://github.com/adamdruppe/arsd/blob/master/terminal.d and see 
if it works better for you.
Oct 17 2017
next sibling parent notna <notna.remove.this ist-einmalig.de> writes:
On Tuesday, 17 October 2017 at 15:02:29 UTC, Adam D. Ruppe wrote:
 Or try this newest commit 
 https://github.com/adamdruppe/arsd/blob/master/terminal.d and 
 see if it works better for you.
- Here is what I use in one of my tools... and I never had problems with German password so far ;) string getPassword(char mask = '*') { import std.stdio; import libs.terminal; auto term = Terminal(ConsoleOutputType.linear); auto input = RealTimeConsoleInput(&term, ConsoleInputFlags.raw); string pass; dchar ch; ch = input.getch(); while(ch != '\r' && ch != '\n') { import std.range; if(ch == '\b' && !pass.empty) { pass = pass[0..$-1]; write('\b'); stdout.flush; } else { pass ~= ch; write(mask); stdout.flush(); } ch = input.getch(); } return pass; }
Oct 17 2017
prev sibling next sibling parent user1234 <user1234 12.nl> writes:
On Tuesday, 17 October 2017 at 15:02:29 UTC, Adam D. Ruppe wrote:
 Or try this newest commit 
 https://github.com/adamdruppe/arsd/blob/master/terminal.d and 
 see if it works better for you.
in the commit message: ~~ascii~~ ANSI.
Oct 17 2017
prev sibling parent Andre Pany <andre s-e-a-p.de> writes:
On Tuesday, 17 October 2017 at 15:02:29 UTC, Adam D. Ruppe wrote:
 Or try this newest commit 
 https://github.com/adamdruppe/arsd/blob/master/terminal.d and 
 see if it works better for you.
Thank you Adam. The ascii thing was causing the issue in the windows console. Now it is working fine. Kind regards André
Oct 17 2017