equal
deleted
inserted
replaced
1 #include <console.h> |
1 #include <console.h> |
2 #include <cstdio> |
2 #include <cstdio> |
3 |
3 |
4 #ifdef WIN32 |
4 #ifdef WIN32 |
|
5 #include <windows.h> |
5 #include <conio.h> |
6 #include <conio.h> |
|
7 |
6 int Console::getch () |
8 int Console::getch () |
7 { |
9 { |
8 return::getch (); |
10 int pressed = 0; |
|
11 int ch = -1; |
|
12 |
|
13 while (!pressed) { |
|
14 if (kbhit ()) { |
|
15 ch =::getch (); |
|
16 pressed = 1; |
|
17 } |
|
18 Sleep (10); |
|
19 } |
|
20 return ch; |
9 } |
21 } |
10 #else |
22 #else |
11 #include <termios.h> |
23 #include <termios.h> |
|
24 |
12 int Console::getch () |
25 int Console::getch () |
13 { |
26 { |
14 static int ch = -1, fd = 0; |
27 int ch = -1, fd = 0; |
15 struct termios neu, alt; |
28 struct termios neu, alt; |
16 |
29 |
17 fd = fileno (stdin); |
30 fd = fileno (stdin); |
18 tcgetattr (fd, &alt); |
31 tcgetattr (fd, &alt); |
19 neu = alt; |
32 neu = alt; |
29 { |
42 { |
30 int i = 0; |
43 int i = 0; |
31 int c; |
44 int c; |
32 char buffer[17]; |
45 char buffer[17]; |
33 |
46 |
34 while ((c = Console::getch ()) != '\n' && i < 17) { |
47 while (((c = Console::getch ()) != '\n') && i < 17) { |
35 buffer[i++] = c; |
48 if (c != BS) { |
36 std::cout << "\b*"; |
49 buffer[i++] = c; |
|
50 std::cout << "*"; |
|
51 } else if (i > 0) { |
|
52 i--; |
|
53 std::cout << "\b \b"; |
|
54 } |
37 } |
55 } |
38 buffer[i] = 0; |
56 buffer[i] = 0; |
|
57 std::cout << std::endl; |
39 |
58 |
40 password = std::string (buffer); |
59 password = std::string (buffer); |
41 std::cout << std::endl; |
|
42 } |
60 } |