Skip to content

Commit

Permalink
adding dependency to the arsd.terminal AND replacing "readPassword"
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonOks committed Mar 5, 2017
1 parent 654139b commit e007a41
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 34 deletions.
5 changes: 4 additions & 1 deletion dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"description": "Because colors are awesome.",
"authors": ["robik", "quickfur", "Adam D. Ruppe", "Ianis G. Vasilev"],
"targetType": "library",
"license": "Boost License"
"license": "Boost License",
"dependencies": {
"arsd-official:terminal":"~master"
}
}
62 changes: 29 additions & 33 deletions source/consoled.d
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/**
* Provides simple API for coloring and formatting text in terminal.
* Using arsd.terminal.d is recommended as it is more mature and stable.
*
* Provides simple API for coloring and formatting text in arsd.terminal.
* On Windows OS it uses WinAPI functions, on POSIX systems it uses mainly ANSI codes.
*
* Using terminal.d is recommended as it is more mature and stable.
*
* $(B Important notes):
* $(UL
Expand All @@ -18,7 +19,6 @@
module consoled;

import std.typecons, std.algorithm;
import std.array : replicate;


/// Console output stream
Expand Down Expand Up @@ -567,7 +567,7 @@ version(Windows)
////////////////////////////////////////////////////////////////////////
else version(Posix)
{
static import terminal;
static import arsd.terminal;
import std.stdio,
std.conv,
std.string,
Expand Down Expand Up @@ -1082,35 +1082,31 @@ else version(Posix)
*/
string readPassword(char mask = '*')
{
string pass;
int c;

version(Windows)
{
int backspace = 8;
int enter = 13;
}
version(Posix)
{
int backspace = 127;
int enter = 10;
}

while((c = getch()) != enter)
{
if(c == backspace) {
if(pass.length > 0) {
pass = pass[0..$-1];
write("\b \b");
stdout.flush();
}
} else {
pass ~= cast(char)c;
write(mask);
}
}

return pass;
// import terminal;
static import arsd.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;
}


Expand Down

0 comments on commit e007a41

Please sign in to comment.